diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-27 23:16:58 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-27 23:21:44 -0600 |
commit | 89761191a98f7dce4d1049b9a84c3d645378222a (patch) | |
tree | 4a60eab88b515af663171aa9bee343f46ca98115 /Makefile | |
parent | 7f3507b606b0f5c0c44cc59eb27e87575cf87701 (diff) |
Lint that include-guards match the filename
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -69,6 +69,9 @@ generate-clean: sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v)) # lint ############# + +get_dscname = sed -n '1,3{ /^\#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*\# ]*,,; s/ - .*//;p; q; }' + lint: $(MAKE) -k $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES))) lint/sh lint/bash: lint/%: @@ -78,7 +81,17 @@ lint/python3: lint/%: black --check $(sources_$*) isort --check $(sources_$*) lint/c: lint/%: - @: TODO + @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/%: @@ -91,9 +104,10 @@ lint/all: lint/%: if ! grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename; then \ echo "$$filename is missing a copyright statement"; r=1; \ fi; \ - dscname=$$(sed -n '1,3{ /^#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*# ]*,,; s/ - .*//;p; q; }' $$filename); \ + dscname=$$($(get_dscname) $$filename); \ filename_alt1=$$(echo "$$filename" | sed \ -e 's,^cmd/,,' \ + -e 's,.*/config/,,' \ -e 's,.*/include/,,' \ -e 's,^lib9p/idl/,,' \ -e 's/\.wip$$//'); \ |