From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Roskin Subject: [PATCH] Using CFLAGS on the make command line Date: Sun, 03 Jul 2005 22:06:24 -0400 Message-ID: <1120442784.1265.20.camel@dv> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-From: git-owner@vger.kernel.org Mon Jul 04 04:07:00 2005 Return-path: Received: from vger.kernel.org ([12.107.209.244]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DpGMA-0005hQ-JK for gcvg-git@gmane.org; Mon, 04 Jul 2005 04:06:46 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261205AbVGDCGg (ORCPT ); Sun, 3 Jul 2005 22:06:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261240AbVGDCGg (ORCPT ); Sun, 3 Jul 2005 22:06:36 -0400 Received: from h-64-105-159-118.phlapafg.covad.net ([64.105.159.118]:1762 "HELO roinet.com") by vger.kernel.org with SMTP id S261205AbVGDCGZ (ORCPT ); Sun, 3 Jul 2005 22:06:25 -0400 Received: (qmail 4350 invoked from network); 4 Jul 2005 02:06:25 -0000 Received: from mtproxy.roinet.com (HELO dv) (192.168.1.1) by roinet.com with SMTP; 4 Jul 2005 02:06:25 -0000 To: git X-Mailer: Evolution 2.2.3 (2.2.3-8) Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org 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 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