有一个小需求,将一个目录包括子目录中的coffee文件批量转换到另一个指定的目录中,同时保挂子目录的结构。改了一个类似的Makefile。发一下备忘:
coffeeBaseDir=coffee/ coffeeDir=$(abspath $(coffeeBaseDir)) jsBaseDir=js/ jsDir=$(abspath $(jsBaseDir)) jsFile=$(shell find $(coffeeBaseDir) -type f -name *.coffee | sed 's@^$(coffeeBaseDir)@$(jsDir)/@g' | sed 's@\.coffee$$@\.js@g') jsDeploy: $(jsFile) $(jsDir)/%.js: $(coffeeDir)/%.coffee @mkdir -p `sed 's@/[^/]\+$$@/@g' <<< '$@'` coffee -bp $< > $@ test: @echo $(jsFile) clean: @rm js -fr @echo 'clean success!'
测试结果:
>find coffee -type f coffee/abc.coffee/3.coffee coffee/abc.coffee/1.coffee coffee/abc.coffee/2.coffee coffee/p1/3.coffee coffee/p1/1.coffee coffee/p1/2.coffee coffee/p2/3.coffee coffee/p2/1.coffee coffee/p2/2.coffee coffee/p3/3.coffee coffee/p3/1.coffee coffee/p3/2.coffee >find js -type f js/abc.coffee/2.js js/abc.coffee/1.js js/abc.coffee/3.js js/p1/2.js js/p1/1.js js/p1/3.js js/p2/2.js js/p2/1.js js/p2/3.js js/p3/2.js js/p3/1.js js/p3/3.js