help-make
[Top][All Lists]
Advanced

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

Re: Gmake problem when including sub makefiles


From: Martin Gaarde Lund
Subject: Re: Gmake problem when including sub makefiles
Date: Thu, 17 Aug 2006 09:23:15 +0200

Thanks alot for the hints guys - problem solved. I got it right when I read the excellent documentation about target-specific variables once more ;)

It feels like every day I learn important details on how make operates ;)

Im going to a large extend to make a well structured non-recursive make build system. In my experience this is not a trivial task and I keep stumbling into small challenges like this. There is alot of hype about the shortcomings of make but I learn every day the opposite and that this is indeed a strong tool and until now I have been able to implement all non recursively with the help from you guys.

Again thanks for the help.

Br, Martin
On 8/17/06, Paul D. Smith <address@hidden> wrote:
On Wednesday, 16 August, Martin Gaarde Lund (address@hidden) wrote:

> ERRORFILE = $(PROJECT).err
>
> PROJECT = project
>
> test.o:
>     armcc test.c -o test.o --errors $(ERRORFILE)
>
> PROJECT = project1
>
> test1.o:
>     armcc test1.c -o test1.o --errors $(ERRORFILE)

> From this example I would have expected make to assemble the following
> target commands:
> armcc test.c -o test.o --errors project.err
> armcc test1.c -o test1.o --errors project1.err

> Is it possible to make a construction which works as I intended it to?
>
> Please note that I can not depend on the target rule for defining my error
> output.

One solution has already been provided: using target-specific variables.
However, the syntax given was incorrect: you can't put a target-specific
variable setting into a command rule.  You need to write them separately:

    CC = armcc
    ERRORFILE = $(PROJECT).err

    test.o: PROJECT = project
    test.o:
            $(CC) $< -o $@ --errors $(ERRORFILE)

    test1.o: PROJECT = project1
    test1.o:
            $(CC) $< -o $@ --errors $(ERRORFILE)


Alternatively you can do a similar thing with constructed variable names;
this is portable to other versions of make (including older versions of GNU
make that didn't support target-specific variable settings) if you care
about that:

    CC = armcc
    ERRORFILE = $(PROJECT-$@).err

    PROJECT-test.o = project
    test.o:
            $(CC) $< -o $@ --errors $(ERRORFILE)

    PROJECT-test1.o = project1
    test1.o:
            $(CC) $< -o $@ --errors $(ERRORFILE)

--
-------------------------------------------------------------------------------
Paul D. Smith < address@hidden>          Find some GNU make tips at:
http://www.gnu.org                      http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist


reply via email to

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