help-gnu-utils
[Top][All Lists]
Advanced

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

Re: make question (target dependent variable)


From: James
Subject: Re: make question (target dependent variable)
Date: 13 Jan 2006 15:57:43 -0800
User-agent: G2/0.2

The real-life problem is something like

P = pp qq
T = pp/obj/p.o rr/obj/r.o

CFLAGS = -c
CFLAGS += $(if $(filter $(@D:/obj=),$(P)),-g)

all: $(T)
$(T):
        @echo $@ $(CFLAGS)

$ make -f test-2.mk
pp/obj/p.o -c -g
rr/obj/r.o -c

Many thanks.
James

Paul D. Smith wrote:
> %% "James" <hslee@ind.alcatel.com> writes:
>
>   j> Thanks. This seesm to work as well.
>
>   j> CFLAGS = -c
>   j> CFLAGS += $(shell [ $(foreach f,$(P),$(filter $(f),$@)) ] && echo -g)
>
> Well... yeah.  But... ugh! :-|
>
> You're invoking that shell EVERY TIME you evaluate CFLAGS; and I mean
> _in addition to_ the shell that's actually doing the echo.
>
> If you're going to do this you might as well use make's builtin $(if
> ...)  function instead of calling out to the shell:
>
>     CFLAGS += $(if $(filter $@,$(P)),-g)
>
> Note that (a) you don't need the foreach even the way you wrote it
> originally because filter tests _each_ of its arguments against each of
> the possibilities; there can be more than one, and (b) if you swap them
> (since $@ is only one item) you'll get better performance.
>
>
> If it were me, I'd still probably use target-specific variables rather
> than something like the above.  Seems cleaner to me.
>
> But, either of these is better than using $(shell ...), IMO.
>
> Cheers!
>
> --
> -------------------------------------------------------------------------------
>  Paul D. Smith <psmith@gnu.org>          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]