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" <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>          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

_______________________________________________
help-gnu-utils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gnu-utils

Reply via email to