threads / patch / 8581

patchTeach Makefile to respect external variables: CFLAGS and others.

Subject: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

## tl;dr

7 messages between Jun 13, 2007 and Jun 13, 2007. Diffs are folded; open one to read it.

replies: 6people: 4as markdown or json

Eygene Ryabinkin· Jun 13, 2007, 05:42 UTC · lore

If one is not using the configure script, then there is no way to redefine variables CFLAGS, LFLAGS, CC, AR, TAR, INSTALL, RPMBUILD, TCL_PATCH and TCLTK_PATH. This shouldn't be so, since these variables can be manually set by user and we should respect them.

The patch originates from the FreeBSD port and was originally made by Ed Schouten, ed at fxq dot nl.

Signed-off-by: Eygene Ryabinkin <rea-git@codelabs.ru>
---
 Makefile |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
Show changes to Makefile +9 −9
diff --git a/Makefile b/Makefile
index 30a4052..6cd9ea2 100644
--- a/Makefile
+++ b/Makefile
@@ -135,8 +135,8 @@ uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
 
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
-CFLAGS = -g -O2 -Wall
-LDFLAGS =
+CFLAGS ?= -g -O2 -Wall
+LDFLAGS ?=
 ALL_CFLAGS = $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
@@ -172,13 +172,13 @@ GITWEB_SITE_FOOTER =
 
 export prefix bindir gitexecdir sharedir template_dir sysconfdir
 
-CC = gcc
-AR = ar
-TAR = tar
-INSTALL = install
-RPMBUILD = rpmbuild
-TCL_PATH = tclsh
-TCLTK_PATH = wish
+CC ?= gcc
+AR ?= ar
+TAR ?= tar
+INSTALL ?= install
+RPMBUILD ?= rpmbuild
+TCL_PATH ?= tclsh
+TCLTK_PATH ?= wish
 
 export TCL_PATH TCLTK_PATH
 
-- 
1.5.2.1
Junio C Hamano· Jun 13, 2007, 06:07 UTC · re: Eygene Ryabinkin · lore

Re: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

I run "make CFLAGS=-O0 -g" all the time. Also "make CC=echo" seems to "work" as expected ;-).

Care to elaborate what problem you are trying to solve?
Eygene Ryabinkin· Jun 13, 2007, 07:15 UTC · re: Junio C Hamano · lore

Re: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

Junio, Sam, good day.
Tue, Jun 12, 2007 at 11:07:56PM -0700, Junio C Hamano wrote:
> I run "make CFLAGS=-O0 -g" all the time.  Also "make CC=echo"
> seems to "work" as expected ;-).
> 
> Care to elaborate what problem you are trying to solve?

As Sam Ravnborg kindly pointed out, you're using make variables and I am trying to give the respect to the environment variables.

And the real problem is that one (for example, me) can try to build Git with the different compiler than CC (gccX or icc, for example). And it is much better for lazy people to do 'export CC=whatever' once and then fire make any number of times ;))

Answering Sam: yes, with my patch it is easier to inherit the variables from the environment. But it is not clear if it is good or bad ;))

But anyway, this patch is only my suggestion, and it can be thrown away :)

-- 
Eygene
Junio C Hamano· Jun 13, 2007, 07:39 UTC · re: Eygene Ryabinkin · lore

Re: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

Eygene Ryabinkin <rea-git@codelabs.ru> writes:
Show 22 quoted lines
> Junio, Sam, good day.
>
> Tue, Jun 12, 2007 at 11:07:56PM -0700, Junio C Hamano wrote:
>> I run "make CFLAGS=-O0 -g" all the time.  Also "make CC=echo"
>> seems to "work" as expected ;-).
>> 
>> Care to elaborate what problem you are trying to solve?
>
> As Sam Ravnborg kindly pointed out, you're using make variables
> and I am trying to give the respect to the environment variables.
>
> And the real problem is that one (for example, me) can try to
> build Git with the different compiler than CC (gccX or icc, for
> example).  And it is much better for lazy people to do 'export
> CC=whatever' once and then fire make any number of times ;))
>
> Answering Sam: yes, with my patch it is easier to inherit the
> variables from the environment.  But it is not clear if it is
> good or bad ;))
>
> But anyway, this patch is only my suggestion, and it can be
> thrown away :)

Oh, I will, very gladly ;-), as it is obviously inferior than how we currently do our build.

I would personally hate environment affecting build (or anything for that matter), as it makes it unnecessarily difficult to diagnose when something goes wrong. I consider that it is a beautiful thing that make can take explicit override from the command line.

Lazy people like me can always have a make wrapper. E.g. I have a checkout of my 'todo' branch at Meta in git.git repository, so I would say

	$ Meta/Make -pedantic

to ask for specific set of CFLAGS. If something goes wrong and I need to ask for help from other people, it is crystal clear to them that I am using something "customized" from the above command line.

If you modify Makefile to allow the build procedure to be easily contaminated with stray environment, and when your build breaks, you would answer that your command line is:

	$ make

when asked how you tried to build things -- and leave people who try to help you scratching their head, wasting their time.

Eygene Ryabinkin· Jun 13, 2007, 07:53 UTC · re: Junio C Hamano · lore

Re: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

Junio,
Wed, Jun 13, 2007 at 12:39:28AM -0700, Junio C Hamano wrote:
Show 5 quoted lines
> > But anyway, this patch is only my suggestion, and it can be
> > thrown away :)
> 
> Oh, I will, very gladly ;-), as it is obviously inferior than
> how we currently do our build.
OK, then this topic can be closed ;))
Thank you!
-- 
Eygene
Matthias Lederhofer· Jun 13, 2007, 07:42 UTC · re: Eygene Ryabinkin · lore

Re: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

Eygene Ryabinkin <rea-git@codelabs.ru> wrote:
Show 22 quoted lines
> Junio, Sam, good day.
> 
> Tue, Jun 12, 2007 at 11:07:56PM -0700, Junio C Hamano wrote:
> > I run "make CFLAGS=-O0 -g" all the time.  Also "make CC=echo"
> > seems to "work" as expected ;-).
> > 
> > Care to elaborate what problem you are trying to solve?
> 
> As Sam Ravnborg kindly pointed out, you're using make variables
> and I am trying to give the respect to the environment variables.
> 
> And the real problem is that one (for example, me) can try to
> build Git with the different compiler than CC (gccX or icc, for
> example).  And it is much better for lazy people to do 'export
> CC=whatever' once and then fire make any number of times ;))
> 
> Answering Sam: yes, with my patch it is easier to inherit the
> variables from the environment.  But it is not clear if it is
> good or bad ;))
> 
> But anyway, this patch is only my suggestion, and it can be
> thrown away :)

If you want to fix it for your own checkout of git just put whatever you like in config.mak. For example I add -ggdb3 to CFLAGS, set the prefix variable and add some custom make targets in this file.

Sam Ravnborg· Jun 13, 2007, 06:12 UTC · re: Eygene Ryabinkin · lore

Re: [PATCH] Teach Makefile to respect external variables: CFLAGS and others.

On Wed, Jun 13, 2007 at 09:42:30AM +0400, Eygene Ryabinkin wrote:
> If one is not using the configure script, then there is no way to
> redefine variables CFLAGS, LFLAGS, CC, AR, TAR, INSTALL, RPMBUILD,
> TCL_PATCH and TCLTK_PATH.  This shouldn't be so, since these variables
> can be manually set by user and we should respect them.

make distingush between environment variables and make variables. So for make there is a big difference between:

export FOO=foobar make

and make FOO=foobar

The latter will work as expected without your changes. And the good part about this is that some random environment variables does not influence the build.

	Sam

← back to recent threads