From owner-freebsd-current@FreeBSD.ORG Sat Aug 21 03:32:44 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 9370116A4CE for ; Sat, 21 Aug 2004 03:32:44 +0000 (GMT) Received: from dns12.mail.yahoo.co.jp (dns12.mail.yahoo.co.jp [210.81.151.145]) by mx1.FreeBSD.org (Postfix) with SMTP id A1BDF43D1D for ; Sat, 21 Aug 2004 03:32:43 +0000 (GMT) (envelope-from ayakokiko@ybb.ne.jp) Received: from unknown (HELO gorgon.near.this) (219.11.234.11 with poptime) by dns12.mail.yahoo.co.jp with SMTP; 21 Aug 2004 03:32:42 -0000 X-Apparently-From: Received: from hydra.near.this (hydra.near.this [10.0.3.20]) by gorgon.near.this (Postfix) with ESMTP id 5AF6A7F24 for ; Sat, 21 Aug 2004 12:32:34 +0900 (JST) Received: by hydra.near.this (Postfix, from userid 100) id AF1AA9845; Sat, 21 Aug 2004 12:32:33 +0900 (JST) Date: Sat, 21 Aug 2004 12:26:06 +0900 From: horio shoichi To: freebsd-current@freebsd.org In-Reply-To: <20040820123605.GD29568@ip.net.ua> References: <20040820123605.GD29568@ip.net.ua> X-Mailer: Sylpheed-Claws 0.9.12 (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20040821.033233.eb441d09555a849b.10.0.3.20@bugsgrief.net> 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: Sat, 21 Aug 2004 03:32:44 -0000 On Fri, 20 Aug 2004 15:36:05 +0300 Ruslan Ermilov 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