生成脚本到Makefile [英] Build script to Makefile
问题描述
我努力编写Makefile,现在建立一些示例可以学习.我想使用Makefile,因为它可以使构建并发,使项目更统一并且更易于管理.
I struggle to write Makefiles and I'm building up some examples to learn from. I want to use Makefiles since it makes builds concurrent, projects more uniform and easier to manage.
您有什么资源要分享吗?
Do you have any resources to share?
例如,我正在努力思考如何将这个简单的构建脚本转换成Makefile,以便仅在修改index.src.html时才构建index.html.
For example I am struggling to think how to turn this simple build script into a Makefile, so that index.html is only built when its index.src.html is modified.
for i in */index.src.html
do
anolis --max-depth=3 $i $(dirname $i)/index.html
done
推荐答案
尝试使用模式规则.从 GNU Makefile手册:
Try using a pattern rule. From the GNU Makefile manual:
因此,模式规则%.o:%.c"说明了如何从另一个文件stem.c中创建任何文件stem.o.
Thus, a pattern rule ‘%.o : %.c’ says how to make any file stem.o from another file stem.c.
所以,类似
INFILES = $(shell find . -name index.src.html)
OUTFILES = $(addsuffix .html, $(basename $(basename $(INFILES))))
default: $(OUTFILES)
%.html : %.src.html
anolis --max-depth=3 $< $@
clean:
rm -f $(OUTFILES)
然后,技巧就以一种可靠且安全的方式建立了INFILES
.
The trick then becomes building up INFILES
in a reliable and safe way.
这篇关于生成脚本到Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!