Re: setting CFLAGS in /etc/make.conf

From: Harti Brandt <harti_at_freebsd.org>
Date: Fri, 20 Aug 2004 15:17:46 +0200 (CEST)
On Fri, 20 Aug 2004, Ruslan Ermilov wrote:

RE>On Fri, Aug 20, 2004 at 02:08:33PM +0200, Oliver Eikemeier wrote:
RE>> I run into this recently with mail/exim. Of course it was possible to 
RE>> work around this too, but it happened only when certain configuration 
RE>> options where given *and* CFLAGS was set in /etc/make.conf. There must
RE>> be a better way to deal with this.
RE>> 
RE>Facts:
RE>
RE>1. In FreeBSD, CFLAGS (if not explicitly set, or set in /etc/make.conf)
RE>   is the global make(1) variable.
RE>
RE>2. FreeBSD make(1) knows about environment and global variables, and
RE>   global variables take precedence over environment variables.
RE>
RE>3. If CFLAGS is not explicitly set in /etc/make.conf, and CFLAGS is
RE>   set in environment instead, its value becomes a value of the CFLAGS
RE>   make(1) global variable:
RE>
RE>: $ cat makefile
RE>: FOO+=   bar
RE>: 
RE>: all:
RE>:         _at_echo global FOO: ${FOO}
RE>:         _at_echo env FOO: $${FOO}
RE>: $ FOO=foo make
RE>: global FOO: foo bar
RE>: env FOO: foo
RE>
RE>So, if you need to change another makefile's idea of the initial value
RE>of CFLAGS, you basically have two reliable choices:
RE>
RE>a) Don't use /etc/make.conf to avoid the possibility of setting
RE>   CFLAGS in /etc/make.conf.
RE>
RE>b) Modify this another makefile to add things you want to CFLAGS;
RE>   the modification may be either hardcoded, or using another
RE>   macro whose value you can then pass as environment variable.
RE>
RE>There's no other reliable way, and FreeBSD make(1) doesn't provide
RE>you a way to initialize a variable in the global context on the
RE>command line or from environment, except for -D which would set it
RE>to "1".  You can only modify global variables from makefile or
RE>from its included sources.
RE>
RE>P.S.  I start to hate command-line variable in make(1).  ;)

They have their place so you could do make CC=icc without caring what
Makefile does try to set CC. You just need to use them for the things they
are intended for.

The problem with CFLAGS is that it is overloaded to be a variable that 
should be twiddled by the user, by make (via .mk and make.conf) and by 
individual makefiles. This is normally (read on other systems) not the 
case - CFLAGS used to be a variable used by makefiles. I think setting 
CFLAGS from make.conf is bad.

<THINKING LOUD>

make.conf should probably have a different variable (something like 
CFLAGS_DEFAULT or whatever) that just gets applied at the places where 
CFLAGS is used to pass them to a command. This would somewhat (but not 
entirely) decouple the different CFLAGS uses. Another step would be to 
have CFLAGS_SYS (or whatever) that gets set in *.mk. So we would end up 
with

	${CC} ${CFLAGS} ${CFLAGS_DEFAULT} ${CFLAGS_SYS} ...

and everybody could do with CFLAGS whatever he needs to do.

</THINKING LOUD>

harti
Received on Fri Aug 20 2004 - 11:17:56 UTC

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