我正在使用类似于此处介绍的非递归 make 的实现:http: //evbergen.home.xs4all.nl/nonrecursive-make.html
这是问题的一个例子。
主要Makefile
包括foo/Rules.mk
. foo/Rules.mk
包含片段:
# Here, d is bound to foo, the path to the current directory
$(d)/foo.zip: $(d)/bar
zip -r $@ $^
# This expands to the recipe: zip -r foo/foo.zip foo/bar
不幸的是,这会创建一个包含 的 zip 存档foo/bar
,但我需要它包含bar
,也就是说,使存档相对于给定目录。cd
不起作用。
# DOES NOT WORK
$(d)/foo.zip: d := $(d) # this makes the variable d work in the recipe
$(d)/foo.zip: $(d)/bar
cd $(d); zip -r $@ $^
# This expands to the recipe: cd foo; zip -r foo/foo.zip foo/bar
在一般情况下如何使这项工作(d 可以是任何路径,zip 包含任意选择的文件和子目录)?