[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: --no-builtin-variables then assign to a builtin variable
From: |
Paul Smith |
Subject: |
Re: --no-builtin-variables then assign to a builtin variable |
Date: |
Sat, 25 Jul 2015 15:26:20 -0400 |
On Sat, 2015-07-25 at 08:55 -0700, John Reiser wrote:
> The workaround in GNU Make 4.0 is to use a different name
> because it looks like --no-builtin-variables permanently disables
> those names.
That's not what's happening. You can see that by using a different
makefile:
$ cat Makefile
MAKEFLAGS += -R
CC = foobar
all: ; @echo '$(CC)'
$ make
foobar
The thing that's confusing you is that make doesn't interpret changes to
the MAKEFLAGS variable immediately every time that variable is reset in
the makefile. Instead it reads all the makefiles, then after it's done
with all makefiles it re-interprets the MAKEFLAGS variable one time and
sets things up to align with the flags it finds.
So in your makefile when make checks this:
ifeq ($(CC),)
the variable CC still has its built-in value and so this statement is
not true, and so your local value of CC is never set and the built-in
value is preserved. Then later when make unsets built-in values, the
built-in value for CC is removed and now the variable is empty.
Another way to see this:
$ cat Makefile
MAKEFLAGS += -R
$(info CC=$(CC))
ifeq ($(CC),)
CC = foobar
endif
$(info CC=$(CC))
all: ; @echo 'CC=$(CC)'
Gives:
CC=cc
CC=cc
CC=