[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: make question (target dependent variable)
From: |
Paul D. Smith |
Subject: |
Re: make question (target dependent variable) |
Date: |
13 Jan 2006 14:26:08 -0500 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
%% "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