summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-20 13:56:08 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-20 13:56:08 -0600
commit318162fdf1ff86297afcce334f61d2d6ff5e3345 (patch)
treee2b805c86ab7616c57f7ba3b0ed5181aa51103b7 /Makefile
parent5b54ce0a9e7708e373ecb28669f3ef1e2332e783 (diff)
Makefile: Use editorconfig for lint/format
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile91
1 files changed, 66 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index a89ec25..d0c5c78 100644
--- a/Makefile
+++ b/Makefile
@@ -50,30 +50,71 @@ generate-clean:
rm -f -- $(generate/files)
.PHONY: generate-clean
-sources_sh = 3rd-party/linux-errno.txt.gen
-sources_sh += libusb/include/libusb/tusb_helpers.h.gen
-sources_py = lib9p/idl.gen
-sources_py += lib9p/include/lib9p/linux-errno.h.gen
+################################################################################
+
+.PHONY: FORCE
+
+# List of sources, by type.
+.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
+-include .sources.mk
+sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v))
+
+# lint #############
lint:
- shellcheck $(sources_sh)
- mypy --strict --scripts-are-modules $(sources_py)
- black --check $(sources_py)
- isort --check $(sources_py)
- r=0; find $$(git ls-files -- $(foreach f,$(generate/files),:!$f) :!cmd/*/static/*) -maxdepth 0 -type f | while read -r filename; do \
- grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename || \
- { echo "$$filename is missing a copyright statement"; r=1; continue; }; \
- dscname=$$(sed -n '1,3{ /^#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*# ]*,,; s/ - .*//;p; q; }' $$filename); \
- filename_alt1=$$(echo "$$filename" | sed \
- -e 's,^cmd/,,' \
- -e 's,.*/include/,,' \
- -e 's,^lib9p/idl/,,' \
- -e 's/\.wip$$//'); \
- filename_alt2=$$(echo "$$filename_alt1" | sed \
- -e 's,^sbc_harness/hw/,hw/,'); \
- [ "$$dscname" == "$$filename" ] || [ "$$dscname" == "$$filename_alt1" ] || [ "$$dscname" == "$$filename_alt2" ] || \
- { echo "$$filename self-identifies as $$dscname"; r=1; continue; }; \
- done; exit $$r
+ $(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/%:
+ @: TODO
+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; continue; \
+ fi; \
+ dscname=$$(sed -n '1,3{ /^#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*# ]*,,; s/ - .*//;p; q; }' $$filename); \
+ filename_alt1=$$(echo "$$filename" | sed \
+ -e 's,^cmd/,,' \
+ -e 's,.*/include/,,' \
+ -e 's,^lib9p/idl/,,' \
+ -e 's/\.wip$$//'); \
+ filename_alt2=$$(echo "$$filename_alt1" | sed \
+ -e 's,^sbc_harness/hw/,hw/,'); \
+ if ! { [ "$$dscname" == "$$filename" ] || [ "$$dscname" == "$$filename_alt1" ] || [ "$$dscname" == "$$filename_alt2" ]; }; then \
+ echo "$$filename self-identifies as $$dscname"; r=1; continue; \
+ fi; \
+ done; exit $$r; }
+.PHONY: lint lint/%
+
+# format ###########
format:
- black $(sources_py)
- isort $(sources_py)
-.PHONY: lint 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/%