[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 13:57:57 -0800 |
User-agent: |
G2/0.2 |
Thanks. This seesm to work as well.
P = pp qq
T = pp rr
CFLAGS = -c
CFLAGS += $(shell [ $(foreach f,$(P),$(filter $(f),$@)) ] && echo -g)
.PHONY: $(T)
all: $(T)
$(T):
@echo $@ $(CFLAGS)
James
Paul D. Smith wrote:
> %% "James" <hslee@ind.alcatel.com> writes:
>
> j> P = pp qq
> j> T = pp rr
> j> CFLAGS = -c
> j> ifneq ($(strip $(foreach f,$(P),$(findstring $(f),$@))),)
> j> CFLAGS += -g
> j> endif
>
> j> .PHONY: $(T)
> j> all: $(T)
> j> $(T):
> j> @echo $@ $(CFLAGS)
>
> Well, you haven't used any target-specific variable settings here so... ??
>
> This makefile is confused. You cannot have a line like this:
>
> j> ifneq ($(strip $(foreach f,$(P),$(findstring $(f),$@))),)
>
> and have it make any sense. The value $@ is an automatic variable: it
> has a value ONLY in the context of running a particular rule, but here
> you're using it in a preprocessor statement (ifneq), which is expanded
> as the makefile is read in... at that time $@ has no value and so it's
> replaced with the empty string. Thus, your test will never be true as
> it's looking for $(f) in a constant empty string.
>
> Not to mention you don't want to use findstring here, since this:
>
> $(findstring foo.o,barfoo.o)
>
> will return true (or, really, "foo.o") when you expect it to return
> false (empty). You should be using filter and/or filter-out here, as
> those test entire words not just substrings.
>
>
> Why don't you just say:
> P = pp qq
> T = pp rr
> CFLAGS = -c
>
> .PHONY: $(T)
> all: $(T)
> $(P): CFLAGS += -g
> $(T):
> @echo $@ $(CFLAGS)
>
> That gives a rule for all targets in variable T, and it sets all targets
> in variable P to have a target-specific variable "CFLAGS += -g", which
> is I think what you wanted.
>
> --
> -------------------------------------------------------------------------------
> 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