[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: confusing ifeq behavior
From: |
John Graham-Cumming |
Subject: |
Re: confusing ifeq behavior |
Date: |
Tue, 06 Sep 2005 20:04:39 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
address@hidden wrote:
ALL_BLOCKS := a b c d e
SOME_BLOCKS := c d
$(ALL_BLOCKS):
@echo "the target is ->$@<-"
ifeq ($@, $(filter $@, $(SOME_BLOCKS)))
@echo "yes ->$@<=>$(filter $@, $(SOME_BLOCKS))<-"
else
@echo "no ->$@<=>$(filter $@, $(SOME_BLOCKS))<-"
endif
That's not going to work because ifeq is handled when the Makefile is
parsed (not when the rule is when). While the Makefile is being parsed
$@ (and other automatic variables) are not set and hence you will not
get the result you expect.
I think you have two choice: replace your ifeq with $(if) or use $(eval)
(GNU Make 3.80 or above) to iterate through $(ALL_BLOCKS) and create
each rule with the appropriate body programmatically.
The $(if) variant would look something like this (I used the GNU Make
Standard Library to get its seq function):
include gmsl
ALL_BLOCKS := a b c d e
SOME_BLOCKS := c d
all: $(ALL_BLOCKS)
$(ALL_BLOCKS):
@echo "the target is ->$@<-"
$(if $(call seq,$@,$(filter $@,$(SOME_BLOCKS))), \
@echo "yes ->$@<=>$(filter $@, $(SOME_BLOCKS))<-", \
@echo "no ->$@<=>$(filter $@, $(SOME_BLOCKS))<-")
(You could in fact simplify $(call seq,$@,$(filter $@,$(SOME_BLOCKS)))
to just $(filter $@,$(SOME_BLOCKS)) and get the same result).
John.
--
John Graham-Cumming
address@hidden
Home: http://www.jgc.org/
POPFile: http://getpopfile.org/
Sign up for my Spam and Anti-spam Newsletter
at http://www.jgc.org/