Date: Sat, 21 Aug 2004 12:26:06 +0900 From: horio shoichi <bugsgrief@bugsgrief.net> To: freebsd-current@freebsd.org Subject: Re: setting CFLAGS in /etc/make.conf Message-ID: <20040821.033233.eb441d09555a849b.10.0.3.20@bugsgrief.net> In-Reply-To: <20040820123605.GD29568@ip.net.ua> References: <p06110400bd4b837282da@[128.113.24.47]> <A8718F96-F2A1-11D8-A951-00039312D914@fillmore-labs.com> <20040820123605.GD29568@ip.net.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 20 Aug 2004 15:36:05 +0300
Ruslan Ermilov <ru@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:
> : @echo global FOO: ${FOO}
> : @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@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040821.033233.eb441d09555a849b.10.0.3.20>
