{"thread":{"id":"23101","subject":"[PATCH] Makefile: Fix occasional GIT-CFLAGS breakage","startedAt":"2010-03-20T03:20:12Z","lastAt":"2010-03-20T03:20:12Z","messageCount":1,"participants":["Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"137300","messageId":"20100320031937.GA18894@progeny.tock","threadId":"23101","inReplyTo":null,"subject":"[PATCH] Makefile: Fix occasional GIT-CFLAGS breakage","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-03-20T03:20:12Z","receivedAt":"2010-03-20T03:20:12Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"GNU make’s target-specific variables facility has one weird facet: any\nvariables set for a given target apply to all of its dependencies,\ntoo.  For example, when running “make exec_cmd.o”, since exec_cmd.o\ndepends on GIT-CFLAGS, the variable assignment in\n\n\texec_cmd.s exec_cmd.o: ALL_CFLAGS += \\\n\t\t'-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n\t\t'-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n\t\t'-DPREFIX=\"$(prefix_SQ)\"'\n\napplies when refreshing GIT-CFLAGS, and the extra options get included\nin the tracked compiler flags.  If an object file like this is the\nfirst target built, GIT-CFLAGS will appear to be out of date,\nresulting in useless rebuilds and the dreaded “new build flags or\nprefix” message.\n\nThis does not happen with every build because GIT-CFLAGS is only\nrefreshed once in a given “make” run, and usually the first target\ndoes not set any variables.  When this problem does rear its head, it\nis very annoying.\n\nSo put target-specific flags in a separate EXTRA_CPPFLAGS variable\nthat is not included in $(TRACK_CFLAGS).\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nRan into this today.  Reproducible by running \"make tag.o\" and then\n\"make exec_cmd.o\".  Presumably caused by my commit 373a5ed (Makefile:\nuse target-specific variable to pass flags to cc, 2010-01-06); sorry.\n\n Makefile |   21 +++++++++++----------\n 1 files changed, 11 insertions(+), 10 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 7c616f8..fc03436 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -316,6 +316,7 @@ BUILTIN_OBJS =\n BUILT_INS =\n COMPAT_CFLAGS =\n COMPAT_OBJS =\n+EXTRA_CPPFLAGS =\n LIB_H =\n LIB_OBJS =\n PROGRAM_OBJS =\n@@ -1480,7 +1481,7 @@ strip: $(PROGRAMS) git$X\n \t$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X\n \n git.o: common-cmds.h\n-git.s git.o: ALL_CFLAGS += -DGIT_VERSION='\"$(GIT_VERSION)\"' \\\n+git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='\"$(GIT_VERSION)\"' \\\n \t'-DGIT_HTML_PATH=\"$(htmldir_SQ)\"'\n \n git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)\n@@ -1488,7 +1489,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)\n \t\t$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)\n \n builtin/help.o: common-cmds.h\n-builtin/help.s builtin/help.o: ALL_CFLAGS += \\\n+builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \\\n \t'-DGIT_HTML_PATH=\"$(htmldir_SQ)\"' \\\n \t'-DGIT_MAN_PATH=\"$(mandir_SQ)\"' \\\n \t'-DGIT_INFO_PATH=\"$(infodir_SQ)\"'\n@@ -1714,13 +1715,13 @@ endif\n \n ifndef CHECK_HEADER_DEPENDENCIES\n $(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs)\n-\t$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n $(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs)\n-\t$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n endif\n \n %.s: %.c GIT-CFLAGS FORCE\n-\t$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<\n+\t$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n \n ifdef USE_COMPUTED_HEADER_DEPENDENCIES\n # Take advantage of gcc's on-the-fly dependency generation\n@@ -1760,20 +1761,20 @@ xdiff-interface.o $(XDIFF_OBJS): \\\n \txdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h\n endif\n \n-exec_cmd.s exec_cmd.o: ALL_CFLAGS += \\\n+exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n \t'-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n \t'-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n \t'-DPREFIX=\"$(prefix_SQ)\"'\n \n-builtin/init-db.s builtin/init-db.o: ALL_CFLAGS += \\\n+builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \\\n \t-DDEFAULT_GIT_TEMPLATE_DIR='\"$(template_dir_SQ)\"'\n \n-config.s config.o: ALL_CFLAGS += -DETC_GITCONFIG='\"$(ETC_GITCONFIG_SQ)\"'\n+config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='\"$(ETC_GITCONFIG_SQ)\"'\n \n-http.s http.o: ALL_CFLAGS += -DGIT_USER_AGENT='\"git/$(GIT_VERSION)\"'\n+http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='\"git/$(GIT_VERSION)\"'\n \n ifdef NO_EXPAT\n-http-walker.s http-walker.o: ALL_CFLAGS += -DNO_EXPAT\n+http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT\n endif\n \n git-%$X: %.o $(GITLIBS)\n-- \n1.7.0\n"}]}