From owner-freebsd-current@FreeBSD.ORG Fri Aug 20 09:33:42 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC64916A4CE for ; Fri, 20 Aug 2004 09:33:42 +0000 (GMT) Received: from tigra.ip.net.ua (tigra.ip.net.ua [82.193.96.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id D79FF43D2D for ; Fri, 20 Aug 2004 09:33:41 +0000 (GMT) (envelope-from ru@ip.net.ua) Received: from heffalump.ip.net.ua (heffalump.ip.net.ua [82.193.96.213]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id i7K9WCpC049213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 20 Aug 2004 12:32:13 +0300 (EEST) (envelope-from ru@ip.net.ua) Received: (from ru@localhost) by heffalump.ip.net.ua (8.13.1/8.13.1) id i7K9WENl028256; Fri, 20 Aug 2004 12:32:14 +0300 (EEST) (envelope-from ru) Date: Fri, 20 Aug 2004 12:32:14 +0300 From: Ruslan Ermilov To: Oliver Eikemeier Message-ID: <20040820093214.GB27931@ip.net.ua> References: <377474F4-F285-11D8-A951-00039312D914@fillmore-labs.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="tjCHc7DPkfUGtrlw" Content-Disposition: inline In-Reply-To: <377474F4-F285-11D8-A951-00039312D914@fillmore-labs.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new cc: current@FreeBSD.org Subject: Re: setting CFLAGS in /etc/make.conf X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Aug 2004 09:33:42 -0000 --tjCHc7DPkfUGtrlw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 20, 2004 at 10:44:58AM +0200, Oliver Eikemeier wrote: > I have a problem with the following recommendation in=20 > src/share/examples/etc/make.conf: >=20 > # CFLAGS controls the compiler settings used when compiling C code. > # Note that optimization settings other than -O and -O2 are not=20 > recommended > # or supported for compiling the world or the kernel - please revert any > # nonstandard optimization settings to "-O" before submitting bug reports > # without patches to the developers. > # Note also that at this time the -O2 setting is known to expose bugs in > # libalias(3), and possibly other parts of the system. > # > #CFLAGS=3D -O -pipe >=20 > Basically, when a port tries to pass CFLAGS to the distribution=20 > Makefile, this is done by > env CFLAGS=3D"${CFLAGS}" make > which is effectively overwritten by users setting CFLAGS in=20 > make.conf(5). OTOH when +=3D is used, it inherits the previous values, so= =20 > when someone would do > CFLAGS+=3D -O -pipe > in make.conf(5) the effective value passed is "-O -pipe -O -pipe=20 > ${_CPUCFLAGS}", which is not harmful, but not good either. This is=20 > especially problematic when the port uses CFLAGS=3D"${PTHREAD_CFLAGS}" or= =20 > CFLAGS=3D"-DMY_OPTION", and a lot of ports use CFLAGS. This is no problem= =20 > when the port has USE_GMAKE, since gmake doesn't read make.conf(5). >=20 >=20 > The following Makefile illustrates the problem: >=20 > all: > @env CFLAGS=3D"${CFLAGS} -DFOO" ${MAKE} cflags >=20 > .ifmake cflags > CFLAGS+=3D -DBAR > .endif >=20 > cflags: > @${ECHO} "CFLAGS=3D${CFLAGS}" >=20 > with the output: >=20 > CFLAGS=3D-O -pipe ${_CPUCFLAGS} -DFOO ${_CPUCFLAGS} -DBAR >=20 > Basically this is the expected result, although the ${_CPUCFLAGS} is=20 > unfortunately doubled. >=20 No, this is an abuse of the intended CFLAGS usage. CFLAGS is the add-only variable by design. You shouldn't reuse its value to reinitialize it. > This is what a typical port would see. When I now=20 > set >=20 > CFLAGS=3D -O -pipe >=20 > in make.conf(5), which is the example given in=20 > share/examples/etc/make.conf, I get: >=20 > CFLAGS=3D-O -pipe ${_CPUCFLAGS} -DBAR >=20 > so I loose the settings done in the ports Makefile (-DFOO). >=20 Just to make the picture clear for the rest of the readers. This has nothing to do with recent changes to make(1), this behavior of CFLAGS was forever. Since global variables are of a higher precedence than envieronment variables, the unconditional CFLAGS setting from /etc/make.conf takes precedence of CFLAGS specified in environment. That explains what you're seeing (and you well understand it, I'm sure). > One solution would be to set __MAKE_CONF=3D/dev/null in bsd.port.mk,=20 > another solution is to deprecate setting CFLAGS in make.conf(5), or use= =20 > an alternate variable. >=20 Both aren't good. People may have something set in /etc/make.conf for a good reason, e.g. to influence the build of some ports, for example. Also, you cannot "deprecate" unconditional (with the `=3D' operator) setting of CFLAGS in /etc/make.conf, as this is a well established practice, so there will always be someone who sets it this way. > Generally I believe it is unexpected that an reexecution of make(1)=20 > overwrites CFLAGS explicitly passed in the environment, so deprecating=20 > its usage is my favorite option here. Btw, passing CFLAGS in the command= =20 > line is not an option, since Makefiles need to be able to add to the=20 > value. >=20 > Thoughs? >=20 I suggest another solution: modifying the distribution makefile when needed, by adding the CFLAGS+=3D-DFOO onto the top of it, or doing something equivalent. This works most reliable: Port's main makefile: : all: : # commands that modify the distribution makefile : @${MAKE} cflags Distribution makefile: : CFLAGS+=3D -DFOO # this line was added by the port's makefile : .ifmake cflags : CFLAGS+=3D -DBAR : .endif :=20 : cflags: : @${ECHO} "CFLAGS=3D${CFLAGS}" An equivalent thing that doesn't involve modifying the distribution makefile would be: Port's main makefile: : all: : @cd ${WRKDIR} && ${MAKE} -f Makefile.wrapper cflags Ports produced makefile (Makefile.wrapper) in WRKDIR: : CFLAGS+=3D -DFOO : .include "Makefile" Distribution's original makefile (Makefile): : .ifmake cflags : CFLAGS+=3D -DBAR : .endif :=20 : cflags: : @${ECHO} "CFLAGS=3D${CFLAGS}" Cheers, --=20 Ruslan Ermilov ru@FreeBSD.org FreeBSD committer --tjCHc7DPkfUGtrlw Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (FreeBSD) iD8DBQFBJcUeqRfpzJluFF4RAl1MAKCWlES3rZN/o47/2WED4Wmks8jKvwCfZ9yN 4/pWbUgQBEpfyiWPJGg9DT8= =Nes+ -----END PGP SIGNATURE----- --tjCHc7DPkfUGtrlw--