Make: Filtering prerequisites

Smirnov Dmitry Dmitry.Smirnov@tlmcom.ru
Mon Apr 3 05:43:00 GMT 2006


Hi,

I'm trying to implement the following in the make file:
Suppose I have few source files. I can create the list of targets corresponding to each source. 
I need to create the rule which builds the targets from sources.
Here is the example:
SOURCES := \
  dir1/subdir1/file1 \
  dir2/subdir2/file2 

TEST:=file3

TARGETS = $(addprefix dir3/subdir3/, $(notdir $(SOURCES)))

$(TARGETS): dir3/subdir3/% : $(foreach src,$(SOURCES),$(if $(findstring $(notdir $(src)),%),$(src),$(dir $(src))%))
            echo 'target: $@, source: $<'

all: $(TARGETS)

Do not be surprised with the rule: I've tried a lot of versions (much simpler than this one) but no one works. It looks that if I use the stem (%) or even the SysV $$(@F) neither $(filter) nor $(findstring) works.

For example, if I write 

$(TARGETS): $(filter %$$(@F), anystring/$$(@F)  anystring2/$$(@F)  ) it works, make produses the following:
make -k all 
make: *** No rule to make target `anystring/file1', needed by `dir3/subdir3/file1'.
make: *** No rule to make target `anystring2/file1', needed by `dir3/subdir3/file1'.
make: *** No rule to make target `anystring/file2', needed by `dir3/subdir3/file2'.
make: *** No rule to make target `anystring2/file2', needed by `dir3/subdir3/file2'.
make: Target `all' not remade because of errors.

But it fails if I replace it with 

$(TARGETS): $(filter %$$(@F), $(SOURCES) )

make -k all 
echo 'target: dir3/subdir3/file1, source: '
target: dir3/subdir3/file1, source: 
echo 'target: dir3/subdir3/file2, source: '
target: dir3/subdir3/file2, source:

Why it is so???!!!

Dmitry



More information about the Gcc-help mailing list