git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/5] Makefile: use target-specific variable to pass flags to cc

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 7, 2010, 07:42 UTC
Message-ID
<20100107074253.GA13125@progeny.tock>
In-Reply-To
<20100106080504.GC7298@progeny.tock>
Jonathan Nieder wrote:
Show 16 quoted lines
> diff --git a/Makefile b/Makefile
> index ba4d071..81190a6 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1467,20 +1467,19 @@ shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
>  strip: $(PROGRAMS) git$X
>  	$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
>  
> -git.o: git.c common-cmds.h GIT-CFLAGS
> -	$(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
> -		'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
> -		$(ALL_CFLAGS) -o $@ -c $(filter %.c,$^)
> +git.o: common-cmds.h
> +git.o: ALL_CFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' \
> +	'-DGIT_HTML_PATH="$(htmldir_SQ)"'
>  
[...]

One annoying feature I wasn't thinking of: the values of target-specific variables propagate to the dependencies of a target (why? I can't imagine), and GIT-CFLAGS keeps on changing because of this.

Maybe a new CMD_CFLAGS variable is needed for this, i.e. something like the following squashed in.

diff --git a/Makefile b/Makefile
index 2580e23..d20e456 100644
--- a/Makefile
+++ b/Makefile
@@ -1468,7 +1468,7 @@ strip: $(PROGRAMS) git$X
 	$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
 
 git.o: common-cmds.h
-git.o: ALL_CFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' \
+git.o: CMD_CFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' \
 	'-DGIT_HTML_PATH="$(htmldir_SQ)"'
 
 git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
@@ -1476,7 +1476,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
 		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 
 builtin-help.o: common-cmds.h
-builtin-help.o: ALL_CFLAGS += \
+builtin-help.o: CMD_CFLAGS += \
 	'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
 	'-DGIT_MAN_PATH="$(mandir_SQ)"' \
 	'-DGIT_INFO_PATH="$(infodir_SQ)"'
@@ -1630,28 +1630,31 @@ git.o git.spec \
 	$(patsubst %.perl,%,$(SCRIPT_PERL)) \
 	: GIT-VERSION-FILE
 
+# This can vary by target
+CMD_CFLAGS = $(ALL_CFLAGS)
+
 %.o: %.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+	$(QUIET_CC)$(CC) -o $*.o -c $(CMD_CFLAGS) $<
 %.s: %.c GIT-CFLAGS .FORCE-LISTING
-	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
+	$(QUIET_CC)$(CC) -S $(CMD_CFLAGS) $<
 %.o: %.S GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+	$(QUIET_CC)$(CC) -o $*.o -c $(CMD_CFLAGS) $<
 
-exec_cmd.o: ALL_CFLAGS += \
+exec_cmd.o: CMD_CFLAGS += \
 	'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
 	'-DBINDIR="$(bindir_relative_SQ)"' \
 	'-DPREFIX="$(prefix_SQ)"'
 
-builtin-init-db.o: ALL_CFLAGS += \
+builtin-init-db.o: CMD_CFLAGS += \
 	-DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
 
-config.o: ALL_CFLAGS += -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
+config.o: CMD_CFLAGS += -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
 
-http.o: ALL_CFLAGS += -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
+http.o: CMD_CFLAGS += -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
 
 ifdef NO_EXPAT
 http-walker.o: http.h
-http-walker.o: ALL_CFLAGS += -DNO_EXPAT
+http-walker.o: CMD_CFLAGS += -DNO_EXPAT
 endif
 
 git-%$X: %.o $(GITLIBS)
Previous: Jonathan NiederNext: Jonathan Nieder
Message 11 of 20 in “Makefile fixes”
  1. 0/4 Makefile fixesJonathan Nieder, Nov 28, 2009
  2. 1/4 Makefile: fix http-push.o dependenciesJonathan Nieder, Nov 28, 2009
  3. Junio C HamanoNov 28, 2009
  4. 2/4 Makefile: make ppc/sha1ppc.o depend on GIT-CFLAGSJonathan Nieder, Nov 28, 2009
  5. Makefile: make ppc/sha1ppc.o depend on GIT-CFLAGSJonathan Nieder, Jan 6, 2010
  6. Nicolas PitreJan 6, 2010
  7. 3/4 Makefile: fix .s pattern rule dependenciesJonathan Nieder, Nov 28, 2009
  8. 0/5 Makefile: fix generation of assembler listingsJonathan Nieder, Jan 6, 2010
  9. 1/5 Makefile: regenerate assembler listings when askedJonathan Nieder, Jan 6, 2010
  10. 2/5 Makefile: use target-specific variable to pass flags to ccJonathan Nieder, Jan 6, 2010
  11. Jonathan NiederJan 7, 2010
  12. 3/5 Makefile: learn to generate listings for targets requiring special flagsJonathan Nieder, Jan 6, 2010
  13. 4/5 Makefile: consolidate .FORCE-* targetsJonathan Nieder, Jan 6, 2010
  14. 5/5 git-gui/Makefile: consolidate .FORCE-* targetsJonathan Nieder, Jan 6, 2010
  15. Shawn O. PearceJan 7, 2010
  16. Linus TorvaldsJan 6, 2010
  17. 4/4 Makefile: do not clean arm directoryJonathan Nieder, Nov 28, 2009
  18. Nanako ShiraishiJan 1, 2010
  19. Junio C HamanoJan 6, 2010
  20. Jonathan NiederJan 6, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.