Convert to tags from "*" to "tags/*".
[blog.git] / posts / More_make_idoms.mdwn
1 [[!meta  title="More make idoms"]]
2 [[!meta  date="2008-08-31 20:27:09"]]
3 I'm rather proud of this one (can you tell I'm overhauling sawsim's
4 Makefile ;).
5
6     $ cat Makefile
7     FILES = a b
8     DS = src
9     DT = targ
10
11     all : $(FILES:%=$(DT)/%)
12             @echo "got $^"
13             @echo "done"
14
15     clean :
16             rm -rf $(DT)
17
18     .SECONDEXPANSION:
19     #$(FILES:%=$(DT)/%) : $$($$@:$(DT)/%=$(DS)/%) $(DT)
20     #              This colon --^ produces: "target pattern contains no `%'."
21     # Instead use this idom --v
22     $(FILES:%=$(DT)/%) : $$(subst $(DT),$(DS),$$@) $(DT)
23             @echo "looking for $< for $@"
24
25     $(DT) :
26             mkdir $@
27     % :
28             @echo "missing rule for $@"
29
30     $ make
31     looking for src/a for targ/a
32     looking for src/b for targ/b
33     got targ/a targ/b
34     done
35
36 Of course you could accomplish the same effect with
37
38    $(DT)/% : $(SRC)/%
39            @echo "looking for $< for %@"
40
41 but what fun is that? ;)
42
43 [[!tag tags/programming]]