Makefile: Track changes to LDFLAGS and relink when necessary

Some profiling tools (e.g., google-perftools and mutrace) work by linking in a new library into the executables. When using these tools it is convenient to only relink instead of doing a full make clean; make cycle. This change complements the auto-detection of changes to CFLAGS that we already have. Tracking of more variables that affect the build can be added when the need arise. Signed-off-by: Fredrik Kuivinen <frekui@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Fredrik Kuivinen committed Jun 22, 2011 at 12:50 UTC d9a25fca5fc01ab4e2e114795c442906bc67de26
2 files changed +18 -8
.gitignore
+1
@@ -1,5 +1,6 @@
1 /GIT-BUILD-OPTIONS
2 /GIT-CFLAGS
3 +/GIT-LDFLAGS
4 /GIT-GUI-VARS
5 /GIT-VERSION-FILE
6 /bin-wrappers/
Makefile
+17 -8
@@ -1706,7 +1706,7 @@ git.sp git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='"$(GIT_VERSION)"' \
1706 '-DGIT_MAN_PATH="$(mandir_SQ)"' \
1707 '-DGIT_INFO_PATH="$(infodir_SQ)"'
1708
1709 -git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
1709 +git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
1710 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
1711 $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
1712
@@ -2004,17 +2004,17 @@ compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
2004 -DNDEBUG -DOVERRIDE_STRDUP -DREPLACE_SYSTEM_ALLOCATOR
2005 endif
2006
2007 -git-%$X: %.o $(GITLIBS)
2007 +git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
2008 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
2009
2010 -git-imap-send$X: imap-send.o $(GITLIBS)
2010 +git-imap-send$X: imap-send.o GIT-LDFLAGS $(GITLIBS)
2011 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2012 $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
2013
2014 -git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS)
2014 +git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2015 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2016 $(LIBS) $(CURL_LIBCURL)
2017 -git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
2017 +git-http-push$X: revision.o http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2018 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2019 $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
2020
@@ -2024,7 +2024,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
2024 ln -s $< $@ 2>/dev/null || \
2025 cp $< $@
2026
2027 -$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(GITLIBS)
2027 +$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2028 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2029 $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
2030
@@ -2094,6 +2094,15 @@ GIT-CFLAGS: FORCE
2094 echo "$$FLAGS" >GIT-CFLAGS; \
2095 fi
2096
2097 +TRACK_LDFLAGS = $(subst ','\'',$(ALL_LDFLAGS))
2098 +
2099 +GIT-LDFLAGS: FORCE
2100 + @FLAGS='$(TRACK_LDFLAGS)'; \
2101 + if test x"$$FLAGS" != x"`cat GIT-LDFLAGS 2>/dev/null`" ; then \
2102 + echo 1>&2 " * new link flags"; \
2103 + echo "$$FLAGS" >GIT-LDFLAGS; \
2104 + fi
2105 +
2106 # We need to apply sq twice, once to protect from the shell
2107 # that runs GIT-BUILD-OPTIONS, and then again to protect it
2108 # and the first level quoting from the shell that runs "echo".
@@ -2165,7 +2174,7 @@ test-svn-fe$X: vcs-svn/lib.a
2174
2175 .PRECIOUS: $(TEST_OBJS)
2176
2168 -test-%$X: test-%.o $(GITLIBS)
2177 +test-%$X: test-%.o GIT-LDFLAGS $(GITLIBS)
2178 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
2179
2180 check-sha1:: test-sha1$X
@@ -2375,7 +2384,7 @@ ifndef NO_TCLTK
2384 $(MAKE) -C gitk-git clean
2385 $(MAKE) -C git-gui clean
2386 endif
2378 - $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
2387 + $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
2388
2389 .PHONY: all install clean strip
2390 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell