Re: setting CFLAGS in /etc/make.conf

From: horio shoichi <bugsgrief_at_bugsgrief.net>
Date: Sat, 21 Aug 2004 12:26:06 +0900
On Fri, 20 Aug 2004 15:36:05 +0300
Ruslan Ermilov <ru_at_FreeBSD.org> wrote:

> Facts:
> 
> 1. In FreeBSD, CFLAGS (if not explicitly set, or set in /etc/make.conf)
>    is the global make(1) variable.
> 
> 2. FreeBSD make(1) knows about environment and global variables, and
>    global variables take precedence over environment variables.
> 
> 3. If CFLAGS is not explicitly set in /etc/make.conf, and CFLAGS is
>    set in environment instead, its value becomes a value of the CFLAGS
>    make(1) global variable:
> 
> : $ cat makefile
> : FOO+=   bar
> : 
> : all:
> :         _at_echo global FOO: ${FOO}
> :         _at_echo env FOO: $${FOO}
> : $ FOO=foo make
> : global FOO: foo bar
> : env FOO: foo
> 
> So, if you need to change another makefile's idea of the initial value
> of CFLAGS, you basically have two reliable choices:
> 
> a) Don't use /etc/make.conf to avoid the possibility of setting
>    CFLAGS in /etc/make.conf.
> 
> b) Modify this another makefile to add things you want to CFLAGS;
>    the modification may be either hardcoded, or using another
>    macro whose value you can then pass as environment variable.
> 
> There's no other reliable way, and FreeBSD make(1) doesn't provide
> you a way to initialize a variable in the global context on the
> command line or from environment, except for -D which would set it
> to "1".  You can only modify global variables from makefile or
> from its included sources.
> 
> P.S.  I start to hate command-line variable in make(1).  ;)
> 
> 
> Cheers,
> -- 
> Ruslan Ermilov
> ru_at_FreeBSD.org
> FreeBSD committer
> 
I think following way is "reliable". No ?

% grep CFLAGS /etc/make.conf
CFLAGS	?= -O -pipe
%

or equivalently, (more polite and maybe more robust)

% grep CFLAGS /etc/make.conf
.if defined(ENV_CFLAGS) && !empty(ENV_CFLAGS)
CFLAGS	= ${ENV_CFLAGS}
.else	# CFLAGS
CFLAGS	= -O -pipe
.endif	# CFLAGS
%

I myself is using a variation of the latter for ports,
to occasionally set -fno-stack-protector.


horio shoichi
Received on Sat Aug 21 2004 - 01:32:44 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:07 UTC