[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: variables-as-targets driving me insane
From: |
Iwan Aucamp |
Subject: |
Re: variables-as-targets driving me insane |
Date: |
Fri, 01 Oct 2010 04:41:42 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100713 Lightning/1.0b2 Thunderbird/3.1.1 |
On 10/01/2010 02:46 AM, address@hidden wrote:
Hi All:
I have a problem with my Makefile, where I'm trying to change the destination
directory of the objects/output depending on the target selected.
Here's the snippet that is giving me grief:
...
# AVR Static library:
avrlib avrtest: PLATFORM=avr
...
dylib : PLATFORM=osx
#Let's make a default PLATFORM:
PLATFORM ?= osx
...
So it seems that the PLATFORM variable is picked up incorrectly early on, but
later it is correct.
Quoted from make manual:
3.9 How make Reads a Makefile
GNU make does its work in two distinct phases. During the first
phase it reads all the make-
files, included makefiles, etc. and internalizes all the variables
and their values, implicit and
explicit rules, and constructs a dependency graph of all the targets
and their prerequisites.
During the second phase, make uses these internal structures to
determine what targets will
need to be rebuilt and to invoke the rules necessary to do so.
Because of this target specific variables cannot affect targets ... only
the recipe/commands for the target and dependencies.
You might want to rather create a macro that automatically expands to
all platform specific targets - and then set up correct dependencies.
This behaviour is exhibited under both GNU Make v3.81 as shipped with OSX snow
leapord and also GNU Make 3.81 under cygwin.
Note that the build happens correctly, just in the wrong directory. Also the osx platform
is built in the correct directory. Another clue is that removing the "PLATFORM ?=
osx" line results in a BLANK $(PLATFORM) for the avrlib target (so it seems that's
where the problem lies). Finally, I have also tried other methods of defining a default
$(PLATFORM), all to no avail.
Any help will be appreciated; this is driving me wild.