makefile - 使用定义、foreach 和调用的动态 Gnu Makefile 规则
问题描述
我想定义很多这样的规则:
x-9: y-9 z-9 x-8
python gen-files.py --out-x=x-9 --out-y=y-9 --in-x=x-8
x-8: y-8 z-8 x-7
python gen-files.py --out-x=x-8 --out-y=y-8 --in-x=x-7
x-7: y-7 z-7 x-6
python gen-files.py --out-x=x-7 --out-y=y-7 --in-x=x-6
x-6: y-6 z-6 x-5
python gen-files.py --out-x=x-6 --out-y=y-6 --in-x=x-5
x-5: y-5 z-5 x-4
python gen-files.py --out-x=x-5 --out-y=y-5 --in-x=x-4
x-4:
touch x-4
如您所见,基本思想是我有一个目标
输出文件编号:
它有几个依赖项,要么包含NUMBER
在它们的名称中,要么包含在它们NUMBER-MINUS-ONE
的名称中。
我的目标是,当我尝试x-9
自动构建最终目标时x-8
,x-7
...下降到x-4
.
我尝试了类似的东西
define oprule
x-$(1): x-$(1) y-$(1) z-$(1) x-$(2)
python gen-files.py --out-x=x-$(1) --out-y=y-$(1) --in-x=x-$(2)
endef
ttt = 9 8 7 6 5
$(foreach now, $(ttt), \
$(call oprule, $(now), $(shell $$(( $(now)-1 )) ) ) )
我认为这会生成 5 条规则,但是当我尝试
make x-9
我收到消息
Makefile:93: *** multiple target patterns. Stop.
我不知道会发生什么。
解决方案
它应该是
define oprule
x-$(1): y-$(1) z-$(1) x-$(2)
python gen-files.py --out-x=x-$(1) --out-y=y-$(1) --in-x=x-$(2)
endef
前面的最后一个换行endef
总是被吃掉(就像后面的第一个换行一样define
)。所以你必须再有一个来生成正确的行拆分(或在调用 oprule 后foreach
添加某种宏)。$(nl)
PS 而且逗号后面也不要加空格。虽然在这种特殊情况下它不会受到伤害,但总的来说,这些空间对于制作来说很重要。
推荐阅读
- jquery - 如何在 1 个 div 中分别使用 2 个 jQuery checkboxradio 组?
- python - 在 VS Code 中调试 youtube-dl 时导入错误
- javascript - 网站背景有时无法播放音频 .mp3 文件
- julia - 获取文件/复杂代码的整个 AST
- c++ - 使用 Qt5 的 C++ 中出现意外的“多重定义”错误
- linux - 如何将字节间延迟超时设置为毫秒?
- php - 为什么会话变量为空?
- flutter - flutter_bloc - 每个 Bloc 有多个存储库,还是只有一个?
- python - Python - 删除在加法期间给出不同结果的按位移位运算符周围的括号
- node.js - 如何从我的 react-app 启动节点脚本?