I'm rather proud of this one (can you tell I'm overhauling sawsim's Makefile ;).
$ cat Makefile FILES = a b DS = src DT = targ all : $(FILES:%=$(DT)/%) @echo "got $^" @echo "done" clean : rm -rf $(DT) .SECONDEXPANSION: #$(FILES:%=$(DT)/%) : $$($$@:$(DT)/%=$(DS)/%) $(DT) # This colon --^ produces: "target pattern contains no `%'." # Instead use this idom --v $(FILES:%=$(DT)/%) : $$(subst $(DT),$(DS),$$@) $(DT) @echo "looking for $< for $@" $(DT) : mkdir $@ % : @echo "missing rule for $@" $ make looking for src/a for targ/a looking for src/b for targ/b got targ/a targ/b done
Of course you could accomplish the same effect with
$(DT)/% : $(SRC)/% @echo "looking for $< for %@"
but what fun is that? ;)