summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-27 23:16:58 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-27 23:21:44 -0600
commit89761191a98f7dce4d1049b9a84c3d645378222a (patch)
tree4a60eab88b515af663171aa9bee343f46ca98115 /Makefile
parent7f3507b606b0f5c0c44cc59eb27e87575cf87701 (diff)
Lint that include-guards match the filename
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile18
1 files changed, 16 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 0b22e66..bd4f9cc 100644
--- a/Makefile
+++ b/Makefile
@@ -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$$//'); \