Makefile: add a hdr-check target

Commit ef3ca95475 ("Add missing includes and forward declarations", 2018-08-15) resulted from the author employing a manual method to create a C file consisting of a pair of pre-processor #include lines (for 'git-compat-util.h' and a given toplevel header), and fixing any resulting compiler errors or warnings. Add a Makefile target to automate this process. This implementation relies on the '-include' and '-xc' arguments to the 'gcc' and 'clang' compilers, which allows us to effectively create the required C compilation unit on-the-fly. This limits the portability of this solution to those systems which have such a compiler. The new 'hdr-check' target can be used to check most header files in the project (for various reasons, the 'compat' and 'xdiff' directories are not included). Also, note that individual header files can be checked directly using the '.hco' extension (read: Hdr-Check Object) like so: $ make config.hco HDR config.h $ Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed Sep 19, 2018 at 01:07 UTC ebb7baf02f69f2164b1f89148945d18c376fc6a8
1 file changed +12
Makefile
+12
@@ -1793,6 +1793,7 @@ ifndef V
1793 QUIET_MSGFMT = @echo ' ' MSGFMT $@;
1794 QUIET_GCOV = @echo ' ' GCOV $@;
1795 QUIET_SP = @echo ' ' SP $<;
1796 + QUIET_HDR = @echo ' ' HDR $<;
1797 QUIET_RC = @echo ' ' RC $@;
1798 QUIET_SUBDIR0 = +@subdir=
1799 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
@@ -2675,6 +2676,17 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
2676 .PHONY: sparse $(SP_OBJ)
2677 sparse: $(SP_OBJ)
2678
2679 +GEN_HDRS := command-list.h unicode-width.h
2680 +EXCEPT_HDRS := $(GEN_HDRS) compat% xdiff%
2681 +CHK_HDRS = $(filter-out $(EXCEPT_HDRS),$(patsubst ./%,%,$(LIB_H)))
2682 +HCO = $(patsubst %.h,%.hco,$(CHK_HDRS))
2683 +
2684 +$(HCO): %.hco: %.h FORCE
2685 + $(QUIET_HDR)$(CC) -include git-compat-util.h -I. -o /dev/null -c -xc $<
2686 +
2687 +.PHONY: hdr-check $(HCO)
2688 +hdr-check: $(HCO)
2689 +
2690 .PHONY: style
2691 style:
2692 git clang-format --style file --diff --extensions c,h