Makefile:在先决条件中使用目标文件路径
我有以下项目结构:
+-Makefile
+-src/
+-a/
| +-foo.py
+-b/
| +-foo.py
+-c/
| +-foo.py
每个 foo.py 文件都是一个具有完全相同名称的不同文件(即它们具有不同的索引节点,但字面上都称为“foo.py” - 当然实际上是这样)名称不是 foo.py,这只是一个示例)。
我希望创建一个 GNU Makefile 规则,该规则在运行时会创建以下结构:
+-Makefile
+-src/
+-a/
| +-foo.py
| +-a.zip
+-b/
| +-foo.py
| +-b.zip
+-c/
| +-foo.py
| +-c.zip
这是我能够弄清楚的最接近的结构,尽管它当然会由于在似乎不允许的先决条件:
SRCDIR = src/
PRJ_DIRS = a b c
SRC_FILE = foo.py
# This next rather nasty line turns PRJ_DIRS in to, e.g., src/a/a.zip etc.
ZIP_FILES = $(addprefix $(SRCDIR),$(join $(PRJ_DIRS),$(PRJ_DIRS:%=/%.zip)))'
build: $(ZIP_FILES)
# Next line crashes because we can't use $@ in the prereq
$(ZIP_FILES): $(addprefix $(dir $@), $(SRC_FILE))
touch $@
所以提出问题的一种方法是: 如何编写一条规则,使用每个相应的 foo.py
文件作为构建适当的 .zip 文件的先决条件?
或者,一个可能实际上正在寻找的更直接的问题从错误的角度来看: 如何引用先决条件中构建的特定目标?
I have the following project structure:
+-Makefile
+-src/
+-a/
| +-foo.py
+-b/
| +-foo.py
+-c/
| +-foo.py
Each foo.py
file is a different file with exactly the same name (ie they have different inodes but are all literally called 'foo.py' - although of course in reality the name is not foo.py, which is just an example).
I wish to create a GNU Makefile rule which, when run, creates the following structure:
+-Makefile
+-src/
+-a/
| +-foo.py
| +-a.zip
+-b/
| +-foo.py
| +-b.zip
+-c/
| +-foo.py
| +-c.zip
This is the closest I have been able to figure out, although of course it fails due to using a target variable in the prereqs which doesn't seem to be allowed:
SRCDIR = src/
PRJ_DIRS = a b c
SRC_FILE = foo.py
# This next rather nasty line turns PRJ_DIRS in to, e.g., src/a/a.zip etc.
ZIP_FILES = $(addprefix $(SRCDIR),$(join $(PRJ_DIRS),$(PRJ_DIRS:%=/%.zip)))'
build: $(ZIP_FILES)
# Next line crashes because we can't use $@ in the prereq
$(ZIP_FILES): $(addprefix $(dir $@), $(SRC_FILE))
touch $@
So one way to put the question:
How can I write a rule the uses each corresponding foo.py
file as a prereq to build the appropriate .zip file?
Or, a more direct question that might actually be looking at this from the wrong angle:
How can I refer to the specific target that's being built in the prereqs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,既然你认为二次扩展是一种拼凑,那么
$(foreach ...)
和$(eval ...)
再次可以拯救你(一个非常强大的组合) 。将您的规则替换为以下内容,您应该得到您想要的。
Okay, since you consider secondary expansion a kludge, it's
$(foreach ...)
and$(eval ...)
to the rescue again (a very powerful combination).Replace your rule with the following and you should get what you want.