Makefile: use target-specific variable to pass flags to cc
This allows reusing the standard %.o: %.c pattern rule even for targets that require special flags to be set. Thus after this change, any changes in the command for compilation only have to be performed in one place. Target-specific variables have been supported in GNU make since version 3.77, which has been available since 1998. Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Jan 6, 2010 at 02:05 UTC
373a5ede53863132dbd3eeab262a8e29e763ddab
1 file changed
+18
-23
Makefile
+18
-23
@@ -1467,20 +1467,19 @@ shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
1467
strip: $(PROGRAMS) git$X
1468
$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
1469
1470
-git.o: git.c common-cmds.h GIT-CFLAGS
1471
- $(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
1472
- '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
1473
- $(ALL_CFLAGS) -o $@ -c $(filter %.c,$^)
1470
+git.o: common-cmds.h
1471
+git.o: ALL_CFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' \
1472
+ '-DGIT_HTML_PATH="$(htmldir_SQ)"'
1473
1474
git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
1475
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
1476
$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
1477
1479
-builtin-help.o: builtin-help.c common-cmds.h GIT-CFLAGS
1480
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
1481
- '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
1482
- '-DGIT_MAN_PATH="$(mandir_SQ)"' \
1483
- '-DGIT_INFO_PATH="$(infodir_SQ)"' $<
1478
+builtin-help.o: common-cmds.h
1479
+builtin-help.o: ALL_CFLAGS += \
1480
+ '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
1481
+ '-DGIT_MAN_PATH="$(mandir_SQ)"' \
1482
+ '-DGIT_INFO_PATH="$(infodir_SQ)"'
1483
1484
$(BUILT_INS): git$X
1485
$(QUIET_BUILT_IN)$(RM) $@ && \
@@ -1638,25 +1637,21 @@ git.o git.spec \
1637
%.o: %.S GIT-CFLAGS
1638
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
1639
1641
-exec_cmd.o: exec_cmd.c GIT-CFLAGS
1642
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
1643
- '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
1644
- '-DBINDIR="$(bindir_relative_SQ)"' \
1645
- '-DPREFIX="$(prefix_SQ)"' \
1646
- $<
1640
+exec_cmd.o: ALL_CFLAGS += \
1641
+ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
1642
+ '-DBINDIR="$(bindir_relative_SQ)"' \
1643
+ '-DPREFIX="$(prefix_SQ)"'
1644
1648
-builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
1649
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
1645
+builtin-init-db.o: ALL_CFLAGS += \
1646
+ -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
1647
1651
-config.o: config.c GIT-CFLAGS
1652
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $<
1648
+config.o: ALL_CFLAGS += -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
1649
1654
-http.o: http.c GIT-CFLAGS
1655
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
1650
+http.o: ALL_CFLAGS += -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
1651
1652
ifdef NO_EXPAT
1658
-http-walker.o: http-walker.c http.h GIT-CFLAGS
1659
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $<
1653
+http-walker.o: http.h
1654
+http-walker.o: ALL_CFLAGS += -DNO_EXPAT
1655
endif
1656
1657
git-%$X: %.o $(GITLIBS)