avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Make question (how to)


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Make question (how to)
Date: Fri, 6 May 2005 19:54:40 +0200 (MET DST)

"Larry Barello" <address@hidden> wrote:

> target1:
>       MCU=mega128
>       SRC="this.c that.c ..."
>       ASRC="this.S that.S ..."

> target2:
>       MCU=mega16
>       ... etc.

> But this doesn't work.

That cannot work that way.  Makefiles do only parse *all* their macro
definitions first, then evaluate the macros, and only then start to
consider which targets to make.  Thus, you cannot create
target-dependant macros.  Also, make macros must start right at the
beginning of a line.  They might be preceded by spaces but must *not*
by a TAB (thus adding spaces before a macro name is not really
recommendable, as it might heavily confuse the occasional reader of
your Makefile).  [It's perhaps possible that GNU make even allows a
TAB in front of a macro definition, and then decides whether this is
going to be a macro definition or a shell command to produce a target
based on the context -- but using that feature is even more
confusing.]

What you did was creating shell (environmental) variables for each
target whose lifetime was only a single shell command (i.e. one line
of your Makefile) inside that target's sequence of commands.  A rather
expensive NOP, I'd say. ;-)

That order of evaluating macros also explains why you cannot create
recursive macros like that:

FOO= bar
FOO= $(FOO) mumble

Everything is only sucked into memory while parsing the Makefile, and
FOO is going to be evaluated after everything has been read
(considering macros imported from the environment as well as specified
on the command-line).  Evaluating FOO above would then cause an
infinite self-recursion.  That's why more modern make utilities (BSD,
GNU, Solaris >= 9) support a += operator:

FOO= bar
FOO+= mumble

For backwards compatibility to all dialects, you need to express that
using different macro names:

FOO1= bar
FOO2= mumble
FOO= $(FOO1) $(FOO2)


Of course, Rich's suggestion of recursively calling "make" with a
different actual target name, passing new macro values from the
command-line, will work as expected.  It's probably the best solution
you could get for your problem.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]