[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem using -R in MAKEFLAGS
From: |
John Graham-Cumming |
Subject: |
Re: Problem using -R in MAKEFLAGS |
Date: |
Mon, 06 Nov 2006 17:17:01 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
Philip Guenther wrote:
You can't affect how make processes a makefile by setting MAKEFLAGS in
the makefile itself. Currently, make sets all the built-in variables
and rules before parsing the makefile, and that can be tested by the
makefile itself, so changing it would create all sorts of problems.
That's not actually totally true. Page 50 of the GNU Make manual
states: 'You can also set MAKEFLAGS in a makefile, to specify additional
flags that should be in effect for that makefile.'
For example,
MAKEFLAGS += -n
.PHONY: all
all:
@echo Doing all
will print 'echo Doing all' because the -n is in effect for that
Makefile. Unfortunately, as you do state, there are some flags that
will not work when MAKEFLAGS is set inside a Makefile. The source of
GNU Make shows that MAKEFLAGS is actually parsed twice: once before
handling the Makefile and once after:
/* Decode switches again, in case the variables were set by the
makefile. */
decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
The flag you want to set for no built in rules is -r (note that the
original message errorneously talked about -R which is for built in
variables although it does force -r). This translates to the
no_builtin_rules_flag variable in GNU Make's source.
Unfortunately, this flag is used to control the setting up of the built
in rules BEFORE the Makefiles are parsed (as you state) and hence you
can't add -r to MAKEFLAGS in a Makefile and have it affect that
Makefile. This is done so that new rules in the Makefile can override
the default rules as necessary.
Most of the command-line switches will work if specified in MAKEFLAGS in
the Makefile and affect that Makefile (you can try out silly examples
like -v and -p to see the effect).
Now, to actually solve your problem (disabling default rules in a
Makefile), there's a simple technique: you clear the default suffix list
for built-in rules. This will prevent any of the built-in rules from
being searched and you can go ahead and define your own pattern rules.
So simply write:
.SUFFIXES:
in the Makefile where you want to disable built-in rules. This won't
kill the built-in variables, but they are probably less of a worry.
John.
--
John Graham-Cumming
address@hidden
Home: http://www.jgc.org/
Blog: http://www.jgc.org/blog/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/
GNU Make Debugger: http://gmd.sf.net/
Fast, Parallel Builds: http://www.electric-cloud.com/