setting CFLAGS in /etc/make.conf
horio shoichi
bugsgrief at bugsgrief.net
Fri Aug 20 20:32:44 PDT 2004
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:
> : @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 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
More information about the freebsd-current
mailing list