From: W. Trevor King Date: Mon, 1 Sep 2008 00:27:09 +0000 (+0000) Subject: Importing NanoBlogger post "More make idoms" X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b15e9ddf46afb28e7cf49bdcd099ed8f60bd25f3;p=mw2txt.git Importing NanoBlogger post "More make idoms" --- diff --git a/posts/More_make_idoms.mdwn b/posts/More_make_idoms.mdwn new file mode 100644 index 0000000..814c15c --- /dev/null +++ b/posts/More_make_idoms.mdwn @@ -0,0 +1,43 @@ +[[!meta title="More make idoms"]] +[[!meta date="2008-08-31 20:27:09"]] +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? ;) + +[[!tag programming]]