@matheusbsbs / matheus-bagliano / commits / a673cfede6
Fork 0

Makefile: Fix occasional GIT-CFLAGS breakage

GNU make’s target-specific variables facility has one weird facet: any variables set for a given target apply to all of its dependencies, too. For example, when running “make exec_cmd.o”, since exec_cmd.o depends on GIT-CFLAGS, the variable assignment in exec_cmd.s exec_cmd.o: ALL_CFLAGS += \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' applies when refreshing GIT-CFLAGS, and the extra options get included in the tracked compiler flags. If an object file like this is the first target built, GIT-CFLAGS will appear to be out of date, resulting in useless rebuilds and the dreaded “new build flags or prefix” message. This does not happen with every build because GIT-CFLAGS is only refreshed once in a given “make” run, and usually the first target does not set any variables. When this problem does rear its head, it is very annoying. So put target-specific flags in a separate EXTRA_CPPFLAGS variable that is not included in $(TRACK_CFLAGS). Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Mar 19, 2010 at 22:20 UTC a673cfede6987ee815de9189eab054fc462e5c9f
1 file changed +11 -10
Makefile
+11 -10
@@ -316,6 +316,7 @@ BUILTIN_OBJS =
316 BUILT_INS =
317 COMPAT_CFLAGS =
318 COMPAT_OBJS =
319 +EXTRA_CPPFLAGS =
320 LIB_H =
321 LIB_OBJS =
322 PROGRAM_OBJS =
@@ -1480,7 +1481,7 @@ strip: $(PROGRAMS) git$X
1481 $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
1482
1483 git.o: common-cmds.h
1483 -git.s git.o: ALL_CFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' \
1484 +git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='"$(GIT_VERSION)"' \
1485 '-DGIT_HTML_PATH="$(htmldir_SQ)"'
1486
1487 git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
@@ -1488,7 +1489,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
1489 $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
1490
1491 builtin/help.o: common-cmds.h
1491 -builtin/help.s builtin/help.o: ALL_CFLAGS += \
1492 +builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
1493 '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
1494 '-DGIT_MAN_PATH="$(mandir_SQ)"' \
1495 '-DGIT_INFO_PATH="$(infodir_SQ)"'
@@ -1714,13 +1715,13 @@ endif
1715
1716 ifndef CHECK_HEADER_DEPENDENCIES
1717 $(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs)
1717 - $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<
1718 + $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
1719 $(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs)
1719 - $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<
1720 + $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
1721 endif
1722
1723 %.s: %.c GIT-CFLAGS FORCE
1723 - $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
1724 + $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
1725
1726 ifdef USE_COMPUTED_HEADER_DEPENDENCIES
1727 # Take advantage of gcc's on-the-fly dependency generation
@@ -1760,20 +1761,20 @@ xdiff-interface.o $(XDIFF_OBJS): \
1761 xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
1762 endif
1763
1763 -exec_cmd.s exec_cmd.o: ALL_CFLAGS += \
1764 +exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
1765 '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
1766 '-DBINDIR="$(bindir_relative_SQ)"' \
1767 '-DPREFIX="$(prefix_SQ)"'
1768
1768 -builtin/init-db.s builtin/init-db.o: ALL_CFLAGS += \
1769 +builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
1770 -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
1771
1771 -config.s config.o: ALL_CFLAGS += -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
1772 +config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
1773
1773 -http.s http.o: ALL_CFLAGS += -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
1774 +http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
1775
1776 ifdef NO_EXPAT
1776 -http-walker.s http-walker.o: ALL_CFLAGS += -DNO_EXPAT
1777 +http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
1778 endif
1779
1780 git-%$X: %.o $(GITLIBS)