diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-27 23:07:51 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-27 23:07:51 -0700 |
commit | 1e2b67047da4ad0f567ef5956f813b2d33b3cfa6 (patch) | |
tree | 5f186c02fd3649894f2a5c28c2db6efa3abf9df6 /GNUmakefile | |
parent | f7b7c04e2ebb24ccae89b77ce76f0b405eb213d1 (diff) | |
parent | 3199e6a45fd5e8bd9ec44616d5dcfb856ba6a888 (diff) |
Merge branch 'lukeshu/lint'
Diffstat (limited to 'GNUmakefile')
-rw-r--r-- | GNUmakefile | 59 |
1 files changed, 14 insertions, 45 deletions
diff --git a/GNUmakefile b/GNUmakefile index ab28ede..db7f7fd 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -42,6 +42,7 @@ libusb/include/libusb/tusb_helpers.h 3rd-party/MS-LCID.pdf 3rd-party/MS-LCID.txt $^ generate/files += build-aux/sources.mk +ifeq ($(INNER),) build-aux/sources.mk: $(if $(wildcard .git),FORCE) git ls-files | grep -vFx $(foreach f,$(generate/files),-e $f) \ | sed 's,^,$(CURDIR)/,' | xargs editorconfig \ @@ -50,6 +51,8 @@ build-aux/sources.mk: $(if $(wildcard .git),FORCE) | sort \ >$@.tmp if ! cmp -s $@.tmp $@; then mv $@.tmp $@; fi + @echo '################################################################################' +endif generate: $(generate/files) .PHONY: generate @@ -70,15 +73,15 @@ $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/Makefile)): buil mkdir -p $(@D) && cd $(@D) && cmake -DPICO_PLATFORM=$(firstword $(subst -, ,$*)) -DCMAKE_BUILD_TYPE=$(lastword $(subst -, ,$*)) ../.. $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/build)): build/%/build: build/%/Makefile generate - $(MAKE) -C $(<D) + $(MAKE) -C $(<D) INNER=t .PHONY: $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/build)) check: build - $(MAKE) -j1 -k $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/check)) + $(MAKE) -j1 -k INNER=t $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/check)) .PHONY: check $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/check)): build/%/check: build/%/Makefile - CTEST_OUTPUT_ON_FAILURE=1 $(MAKE) -C $(<D) test + CTEST_OUTPUT_ON_FAILURE=1 $(MAKE) -C $(<D) INNER=t test .PHONY: $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/check)) # `lint` and `format` ########################################################## @@ -86,8 +89,6 @@ $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/check)): build/% -include build-aux/sources.mk sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v)) -get_dscname = sed -n '1,3{ /^\#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*\# ]*,,; s/ - .*//;p; q; }' - build-aux/venv: build-aux/requirements.txt python3 -m venv $@ $@/bin/pip install -r $< @@ -95,58 +96,26 @@ build-aux/venv: build-aux/requirements.txt # `lint` ########### lint: - $(MAKE) -k $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES))) + $(MAKE) -k INNER=t $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES))) lint/sh lint/bash: lint/%: shellcheck $(sources_$*) lint/python3: lint/%: build-aux/venv ./build-aux/venv/bin/mypy --strict --scripts-are-modules $(sources_$*) ./build-aux/venv/bin/black --check $(sources_$*) ./build-aux/venv/bin/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; exit $$r +lint/c: lint/%: build-aux/lint-h build-aux/get-dscname + ./build-aux/lint-h $(filter %.h,$(sources_$*)) 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 '^lib9p/tests/[^/]+/static/') \ - -maxdepth 0 -type f | \ - { r=0; while read -r filename; do \ - if ! grep -E -q 'Copyright \(C\) 202[4-9]((-|, )202[5-9])* 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,.*/config\.h$$,config.h,' \ - -e 's,.*include/,,' \ - -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; } +lint/unknown: lint/%: build-aux/lint-unknown + ./build-aux/lint-unknown $(sources_$*) +lint/all: lint/%: build-aux/lint-generic build-aux/get-dscname + ./build-aux/lint-generic $$(printf '%s\n' $(sources_$*) | grep -vE '^lib9p/tests/[^/]+/static/') .PHONY: lint lint/% # `format` ######### format: - $(MAKE) -k $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES)))) + $(MAKE) -k INNER=t $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES)))) format/python3: format/%: ./build-aux/venv ./build-aux/venv/bin/black $(sources_$*) ./build-aux/venv/bin/isort $(sources_$*) |