Skip to content

Commit b503a2d

Browse files
Denton-Lgitster
authored andcommitted
Makefile: emulate compile in $(HCO) target better
Currently, when testing headers using `make hdr-check`, headers are directly compiled. Although this seems to test the headers, this is too strict since we treat the headers as C sources. As a result, this will cause warnings to appear that would otherwise not, such as a static variable definition intended for later use throwing a unused variable warning. In addition, on platforms that can run `make hdr-check` but require custom flags, this target was failing because none of them were being passed to the compiler. For example, on MacOS, the NO_OPENSSL flag was being set but it was not being passed into compiler so the check was failing. Fix these problems by emulating the compile process better, including test compiling dummy *.hcc C sources generated from the *.h files and passing $(ALL_CFLAGS) into the compiler for the $(HCO) target so that these custom flags can be used. Helped-by: Jeff King <[email protected]> Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af26e2a commit b503a2d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
/tags
217217
/TAGS
218218
/cscope*
219+
*.hcc
219220
*.obj
220221
*.lib
221222
*.res

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ ifndef V
18721872
QUIET_MSGFMT = @echo ' ' MSGFMT $@;
18731873
QUIET_GCOV = @echo ' ' GCOV $@;
18741874
QUIET_SP = @echo ' ' SP $<;
1875-
QUIET_HDR = @echo ' ' HDR $<;
1875+
QUIET_HDR = @echo ' ' HDR $(<:hcc=h);
18761876
QUIET_RC = @echo ' ' RC $@;
18771877
QUIET_SUBDIR0 = +@subdir=
18781878
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
@@ -2771,9 +2771,14 @@ ifndef GCRYPT_SHA256
27712771
endif
27722772
CHK_HDRS = $(filter-out $(EXCEPT_HDRS),$(patsubst ./%,%,$(LIB_H)))
27732773
HCO = $(patsubst %.h,%.hco,$(CHK_HDRS))
2774+
HCC = $(HCO:hco=hcc)
27742775

2775-
$(HCO): %.hco: %.h FORCE
2776-
$(QUIET_HDR)$(CC) -include git-compat-util.h -I. -o /dev/null -c -xc $<
2776+
%.hcc: %.h
2777+
@echo '#include "git-compat-util.h"' >$@
2778+
@echo '#include "$<"' >>$@
2779+
2780+
$(HCO): %.hco: %.hcc FORCE
2781+
$(QUIET_HDR)$(CC) $(ALL_CFLAGS) -o /dev/null -c -xc $<
27772782

27782783
.PHONY: hdr-check $(HCO)
27792784
hdr-check: $(HCO)
@@ -3082,6 +3087,7 @@ clean: profile-clean coverage-clean cocciclean
30823087
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
30833088
$(RM) $(TEST_PROGRAMS)
30843089
$(RM) $(FUZZ_PROGRAMS)
3090+
$(RM) $(HCC)
30853091
$(RM) -r bin-wrappers $(dep_dirs)
30863092
$(RM) -r po/build/
30873093
$(RM) *.pyc *.pyo */*.pyc */*.pyo command-list.h $(ETAGS_TARGET) tags cscope*

0 commit comments

Comments
 (0)