threads / patch / 1098

patchUsing CFLAGS on the make command line

Subject: [PATCH] Using CFLAGS on the make command line

## tl;dr

One message between Jul 4, 2005 and Jul 4, 2005. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Pavel Roskin· Jul 4, 2005, 02:06 UTC · lore
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>
Show changes to Makefile +15 −7
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

← back to recent threads