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

[PATCH 3/5] Makefile: add OBJECTS variable listing object files

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 7, 2010, 07:19 UTC
Message-ID
<20100107071943.GD11777@progeny.tock>
In-Reply-To
<20100107071305.GA11777@progeny.tock>

To find the generated dependencies to include, we will need a comprehensive list of all object file targets. To make sure it is truly comprehensive, restrict the scope of the %.o pattern rule to only generate objects in that list.

Attempts to build other object files will fail loudly:
	$ touch foo.c
	$ make foo.o
	make: *** No rule to make target `foo.o'.  Stop.
providing a reminder to add the new object to the OBJECTS list.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Makefile |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
index 9a5d897..87de3c3 100644
--- a/Makefile
+++ b/Makefile
@@ -388,6 +388,18 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
 # Empty...
 EXTRA_PROGRAMS =
 
+TEST_PROGRAMS += test-chmtime$X
+TEST_PROGRAMS += test-ctype$X
+TEST_PROGRAMS += test-date$X
+TEST_PROGRAMS += test-delta$X
+TEST_PROGRAMS += test-dump-cache-tree$X
+TEST_PROGRAMS += test-genrandom$X
+TEST_PROGRAMS += test-match-trees$X
+TEST_PROGRAMS += test-parse-options$X
+TEST_PROGRAMS += test-path-utils$X
+TEST_PROGRAMS += test-sha1$X
+TEST_PROGRAMS += test-sigchain$X
+
 # ... and all the rest that could be moved out of bindir to gitexecdir
 PROGRAMS += $(EXTRA_PROGRAMS)
 PROGRAMS += git-fast-import$X
@@ -1634,14 +1646,20 @@ GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) git.o http.o http-walker.o \
 	$(patsubst git-%$X,%.o,$(PROGRAMS))
 XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
 	xdiff/xmerge.o xdiff/xpatience.o
+TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
+OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(TEST_OBJS)
+
+ASM_SRC := $(wildcard $(OBJECTS:o=S))
+ASM_OBJ := $(ASM_SRC:S=o)
+C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS))
 
 .SUFFIXES:
 
-%.o: %.c GIT-CFLAGS
+$(C_OBJ): %.o: %.c GIT-CFLAGS
 	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 %.s: %.c GIT-CFLAGS FORCE
 	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
-%.o: %.S GIT-CFLAGS
+$(ASM_OBJ): %.o: %.S GIT-CFLAGS
 	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 
 $(GIT_OBJS): $(LIB_H)
@@ -1757,18 +1775,6 @@ endif
 
 ### Testing rules
 
-TEST_PROGRAMS += test-chmtime$X
-TEST_PROGRAMS += test-ctype$X
-TEST_PROGRAMS += test-date$X
-TEST_PROGRAMS += test-delta$X
-TEST_PROGRAMS += test-dump-cache-tree$X
-TEST_PROGRAMS += test-genrandom$X
-TEST_PROGRAMS += test-match-trees$X
-TEST_PROGRAMS += test-parse-options$X
-TEST_PROGRAMS += test-path-utils$X
-TEST_PROGRAMS += test-sha1$X
-TEST_PROGRAMS += test-sigchain$X
-
 all:: $(TEST_PROGRAMS)
 
 # GNU make supports exporting all variables by "export" without parameters.
-- 
1.6.6.rc2
Previous: Jonathan NiederNext: Jonathan Nieder
Message 24 of 28 in “Makefile: determine the list of header files using a glob”
  1. Makefile: determine the list of header files using a globJohannes Sixt, Nov 27, 2009
  2. Mike HommeyNov 27, 2009
  3. Johannes SixtNov 27, 2009
  4. Mike HommeyNov 27, 2009
  5. Junio C HamanoNov 27, 2009
  6. Mike HommeyDec 30, 2009
  7. Junio C HamanoDec 30, 2009
  8. Johannes SchindelinNov 27, 2009
  9. 0/2 Lazily generate header dependenciesJonathan Nieder, Nov 27, 2009
  10. 1/2 Makefile: use target-specific variable to pass flags to ccJonathan Nieder, Nov 27, 2009
  11. 2/2 Makefile: automatically compute header dependenciesJonathan Nieder, Nov 27, 2009
  12. Sverre RabbelierNov 27, 2009
  13. Jonathan NiederNov 28, 2009
  14. 2/2 Makefile: lazily compute header dependenciesJonathan Nieder, Nov 28, 2009
  15. Andreas SchwabNov 28, 2009
  16. Jonathan NiederNov 28, 2009
  17. Nanako ShiraishiJan 1, 2010
  18. Junio C HamanoJan 6, 2010
  19. Johannes SchindelinJan 6, 2010
  20. Jonathan NiederJan 6, 2010
  21. 0/5 Lazily generate header dependenciesJonathan Nieder, Jan 7, 2010
  22. 1/5 Makefile: rearrange dependency rulesJonathan Nieder, Jan 7, 2010
  23. 2/5 Makefile: clear list of default rulesJonathan Nieder, Jan 7, 2010
  24. 3/5 Makefile: add OBJECTS variable listing object filesJonathan Nieder, Jan 7, 2010
  25. 4/5 Makefile: lazily compute header dependenciesJonathan Nieder, Jan 7, 2010
  26. 5/5 Teach Makefile to check header dependenciesJonathan Nieder, Jan 7, 2010
  27. Erik Faye-LundJan 7, 2010
  28. Junio C HamanoNov 27, 2009

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.