diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-31 15:39:37 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-31 16:00:34 -0600 |
commit | 3c81186daf97cf7011fd2806dfd0bc3b875e92f3 (patch) | |
tree | 30a6a4b50ab2eb15e7c6dcf934dc6052bbea0224 /GNUmakefile | |
parent | f2d53195fd86023d2ff9fcce68d2e150bfd97059 (diff) |
Clean up the build system
Diffstat (limited to 'GNUmakefile')
-rw-r--r-- | GNUmakefile | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..28f287a --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,146 @@ +# GNUmakefile - Main build script for sbc-harness project +# +# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Project configuration ######################################################## + +linux.git = $(HOME)/src/github.com/torvalds/linux + +all: build +.PHONY: all + +# Configure GNU Make itself #################################################### + +ifeq ($(filter notintermediate,$(.FEATURES)),) +$(error This $(firstword $(MAKEFILE_LIST)) requies GNU Make 4.4 or later for .NOTINTERMEDIATE) +endif + +.NOTINTERMEDIATE: +.DELETE_ON_ERROR: + +.PHONY: FORCE + +# `generate` ################################################################### + +generate/files = + +generate/files += 3rd-party/linux-errno.txt +3rd-party/linux-errno.txt: build-aux/linux-errno.txt.gen + $< $(linux.git) $@ + +generate/files += lib9p/include/lib9p/linux-errno.h +lib9p/include/lib9p/linux-errno.h: %: %.gen 3rd-party/linux-errno.txt + $^ >$@ + +generate/files += lib9p/9p.generated.c lib9p/include/lib9p/9p.generated.h +lib9p/9p.generated.c lib9p/include/lib9p/9p.generated.h &: lib9p/idl.gen lib9p/idl/*.9p + $^ + +generate/files += libusb/include/libusb/tusb_helpers.h 3rd-party/MS-LCID.pdf 3rd-party/MS-LCID.txt +libusb/include/libusb/tusb_helpers.h 3rd-party/MS-LCID.pdf 3rd-party/MS-LCID.txt &: libusb/include/libusb/tusb_helpers.h.gen + $^ + +generate/files += build-aux/sources.mk +build-aux/sources.mk: $(if $(wildcard .git),FORCE) + git ls-files | grep -vFx $(foreach f,$(generate/files),-e $f) \ + | sed 's,^,$(CURDIR)/,' | xargs editorconfig \ + | sed -nE -e 's,\[$(CURDIR)/(.*)\],\1,p' -e 's/^_mode=//p' \ + | sed -E '{N;s/(.*)\n(.*)/sources_\2 += \1/;}' \ + | sort \ + >$@.tmp + if ! cmp -s $@.tmp $@; then mv $@.tmp $@; fi + +generate: $(generate/files) +.PHONY: generate + +generate-clean: + rm -f -- $(generate/files) +.PHONY: generate-clean + +# `build` ###################################################################### + +platforms := $(shell sed -nE 's/if *\(PICO_PLATFORM STREQUAL "(.*)"\)/\1/p' cmd/*/CMakeLists.txt) + +build: $(foreach p,$(platforms),build/$p/build) +.PHONY: build + +$(foreach p,$(platforms),build/$p/Makefile): build/%/Makefile: + mkdir -p $(@D) && cd $(@D) && cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_PLATFORM=$* ../.. + +$(foreach p,$(platforms),build/$p/build): build/%/build: build/%/Makefile generate + $(MAKE) -C $(<D) +.PHONY: $(foreach p,$(platforms),build/$p/build) + +# `lint` and `format` ########################################################## + +-include build-aux/sources.mk + +get_dscname = sed -n '1,3{ /^\#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*\# ]*,,; s/ - .*//;p; q; }' + +# `lint` ########### +lint: + $(MAKE) -k $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES))) +lint/sh lint/bash: lint/%: + shellcheck $(sources_$*) +lint/python3: lint/%: + mypy --strict --scripts-are-modules $(sources_$*) + black --check $(sources_$*) + isort --check $(sources_$*) +lint/c: lint/%: + @for filename in $(filter %.h,$(sources_$*)); do \ + dscname=$$($(get_dscname) $$filename); \ + guard=$${dscname//'/'/'_'}; \ + guard=$${guard//'.'/'_'}; \ + guard="_$${guard^^}_"; \ + if ! { grep -Fxq "#ifndef $${guard}" "$$filename" && \ + grep -Fxq "#define $${guard}" "$$filename" && \ + grep -Fxq "#endif /* $${guard} */" "$$filename"; }; then \ + echo "$$filename does not have $${guard} guard"; r=1; \ + fi; \ + done +lint/make lint/cmake lint/gitignore lint/ini lint/9p lint/markdown: lint/%: + @: +lint/unknown: lint/%: + @printf "%s: cannot lint unknown file type\n" $(sources_$*) >&2 +lint/all: lint/%: + $(eval export sources_$*) + @find $$(printf '%s\n' $${sources_$*} | grep -vE '^cmd/[^/]+/static/') \ + -maxdepth 0 -type f | \ + { r=0; while read -r filename; do \ + if ! grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename; then \ + echo "$$filename is missing a copyright statement"; r=1; \ + fi; \ + if ! grep -q ' SPDX-License-Identifier[:] ' $$filename; then \ + echo "$$filename is missing an SPDX-License-Identifier"; r=1; \ + fi; \ + dscname_act=$$($(get_dscname) $$filename); \ + dscname_exp=$$(echo "$$filename" | sed \ + -e 's,.*/config/,,' \ + -e 's,.*include/,,' \ + -e 's,^lib9p/idl/,,' \ + -e 's/\.wip$$//'); \ + if [ "$$dscname_act" != "$$dscname_exp" ] && [ "cmd/$$dscname_act" != "$$dscname_exp" ]; then \ + echo "$$filename self-identifies as $$dscname_act (expected $$dscname_exp)"; r=1; \ + fi; \ + if grep -n --color=auto "$$(printf '\\S\t')" $$filename; then \ + echo "$$filename uses tabs for alignment"; r=1; \ + fi; \ + done; exit $$r; } +.PHONY: lint lint/% + +# `format` ######### +format: + $(MAKE) -k $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES)))) +format/python3: format/%: + black $(sources_$*) + isort $(sources_$*) +format/sh format/bash: format/% + @: +format/c: format/%: + @: TODO +format/make format/cmake format/gitignore format/ini format/9p format/markdown: format/%: + @: +format/unknown: format/%: + @: +.PHONY: format format/% |