]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Makefile: emulate compile in $(HCO) target better
authorDenton Liu <liu.denton@gmail.com>
Wed, 25 Sep 2019 08:21:01 +0000 (01:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 28 Sep 2019 05:04:22 +0000 (14:04 +0900)
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 <peff@peff.net>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
.gitignore
Makefile

index 521d8f4fb421c25e5f733242796fddfa47f39f93..34efe125cbd756000a9206a6f4d307303c446736 100644 (file)
 /tags
 /TAGS
 /cscope*
+*.hcc
 *.obj
 *.lib
 *.res
index f879697ea3b23f6ad6308afb33ae0f08ec262591..581cc617e37e2441e10e33afb88c96c75693cf72 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1872,7 +1872,7 @@ ifndef V
        QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
        QUIET_GCOV     = @echo '   ' GCOV $@;
        QUIET_SP       = @echo '   ' SP $<;
-       QUIET_HDR      = @echo '   ' HDR $<;
+       QUIET_HDR      = @echo '   ' HDR $(<:hcc=h);
        QUIET_RC       = @echo '   ' RC $@;
        QUIET_SUBDIR0  = +@subdir=
        QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
@@ -2771,9 +2771,14 @@ ifndef GCRYPT_SHA256
 endif
 CHK_HDRS = $(filter-out $(EXCEPT_HDRS),$(patsubst ./%,%,$(LIB_H)))
 HCO = $(patsubst %.h,%.hco,$(CHK_HDRS))
+HCC = $(HCO:hco=hcc)
 
-$(HCO): %.hco: %.h FORCE
-       $(QUIET_HDR)$(CC) -include git-compat-util.h -I. -o /dev/null -c -xc $<
+%.hcc: %.h
+       @echo '#include "git-compat-util.h"' >$@
+       @echo '#include "$<"' >>$@
+
+$(HCO): %.hco: %.hcc FORCE
+       $(QUIET_HDR)$(CC) $(ALL_CFLAGS) -o /dev/null -c -xc $<
 
 .PHONY: hdr-check $(HCO)
 hdr-check: $(HCO)
@@ -3082,6 +3087,7 @@ clean: profile-clean coverage-clean cocciclean
        $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
        $(RM) $(TEST_PROGRAMS)
        $(RM) $(FUZZ_PROGRAMS)
+       $(RM) $(HCC)
        $(RM) -r bin-wrappers $(dep_dirs)
        $(RM) -r po/build/
        $(RM) *.pyc *.pyo */*.pyc */*.pyo command-list.h $(ETAGS_TARGET) tags cscope*