Skip to content

Commit ebb7baf

Browse files
ramsay-jonesgitster
authored andcommitted
Makefile: add a hdr-check target
Commit ef3ca95 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d3b1c5 commit ebb7baf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ ifndef V
17931793
QUIET_MSGFMT = @echo ' ' MSGFMT $@;
17941794
QUIET_GCOV = @echo ' ' GCOV $@;
17951795
QUIET_SP = @echo ' ' SP $<;
1796+
QUIET_HDR = @echo ' ' HDR $<;
17961797
QUIET_RC = @echo ' ' RC $@;
17971798
QUIET_SUBDIR0 = +@subdir=
17981799
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
@@ -2675,6 +2676,17 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
26752676
.PHONY: sparse $(SP_OBJ)
26762677
sparse: $(SP_OBJ)
26772678

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+
26782690
.PHONY: style
26792691
style:
26802692
git clang-format --style file --diff --extensions c,h

0 commit comments

Comments
 (0)