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

[PATCH] Using CFLAGS on the make command line

From
PRPavel Roskin <proski@gnu.org>
Date
Jul 4, 2005, 02:06 UTC
Message-ID
<1120442784.1265.20.camel@dv>
Hello!

This patch changes the top-level Makefile to be more compatible with expectations of users accustomed to automake-generated makefiles.

I'm used to specifying CFLAGS after make, i.e. as an argument rather than as an environment variable. It doesn't work with git because CFLAGS is modified in Makefile.

Automake and Autoconf allow CFLAGS to be fully user-serviceable. It defaults to something reasonable (usually "-O2 -g") that can be replaced without breaking compilation. Other variables such as CPPFLAGS are recognized, but they are rarely used.

COPTS is not recognized, and I don't think it's needed in git once CFLAGS works in the expected way. Besides, why is -O2 in COPTS whereas -Wall is not?

Automake-generated makefiles use the COMPILE variable to hold all compile flags. COMPILE is not user-serviceable.

Also, projects generated by Automake can be compiled with "make -r", i.e. without implicit rules. It's useful to have all rules we need (there are just 2 of them) written explicitly so that users can understand and modify them. It's also needed to use COMPILE instead of the implicit CFLAGS in the .o.c rule.

Signed-off-by: Pavel Roskin <proski@gnu.org>
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -9,8 +9,8 @@
 # BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely randomly
 # break unless your underlying filesystem supports those sub-second times
 # (my ext3 doesn't).
-COPTS=-O2
-CFLAGS=-g $(COPTS) -Wall
+CFLAGS=-g -O2 -Wall
+COMPILE=$(CFLAGS)
 
 prefix=$(HOME)
 bin=$(prefix)/bin
@@ -82,22 +82,28 @@ else
 endif
 endif
 
-CFLAGS += '-DSHA1_HEADER=$(SHA1_HEADER)'
+COMPILE += '-DSHA1_HEADER=$(SHA1_HEADER)'
 
 $(LIB_FILE): $(LIB_OBJS)
 	$(AR) rcs $@ $(LIB_OBJS)
 
 check:
-	for i in *.c; do sparse $(CFLAGS) $(SPARSE_FLAGS) $$i; done
+	for i in *.c; do sparse $(COMPILE) $(SPARSE_FLAGS) $$i; done
 
 test-date: test-date.c date.o
-	$(CC) $(CFLAGS) -o $@ test-date.c date.o
+	$(CC) $(COMPILE) -o $@ test-date.c date.o
 
 test-delta: test-delta.c diff-delta.o patch-delta.o
-	$(CC) $(CFLAGS) -o $@ $^
+	$(CC) $(COMPILE) -o $@ $^
 
 git-%: %.c $(LIB_FILE)
-	$(CC) $(CFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
+	$(CC) $(COMPILE) -o $@ $(filter %.c,$^) $(LIBS)
+
+.c.o:
+	$(CC) -c $(COMPILE) $<
+
+.S.o:
+	$(CC) -c $(ASFLAGS) $<
 
 git-update-cache: update-cache.c
 git-diff-files: diff-files.c
@@ -172,3 +178,5 @@ clean:
 
 backup: clean
 	cd .. ; tar czvf dircache.tar.gz dir-cache
+
+.SUFFIXES: .c .o .S
-- 
Regards,
Pavel Roskin
Message 1 of 1 in “Using CFLAGS on the make command line”
  1. Using CFLAGS on the make command linePavel Roskin, Jul 4, 2005

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.