Change a make variable, and call another rule, from a recipe in same Makefile?
我已经看到了如何从make目标手动调用另一个目标了?,但我的问题有点不同;请考虑这个示例(注意,stackoverflow.com将选项卡更改为显示中的空格;但如果尝试编辑,则选项卡保留在源中):
1 2 3 4 5 6 7 8 | TEXENGINE=pdflatex pdflatex: echo the engine is $(TEXENGINE) lualatex: TEXENGINE=lualatex echo Here I want to call the pdflatex rule, to check $(TEXENGINE) there! |
在这里,如果我运行缺省目标(
1 2 3 | $ make pdflatex echo the engine is pdflatex the engine is pdflatex |
但是,对于目标
- 将
make 变量TEXENGINE 改为lualatex ,然后 - 调用与
pdflatex 中相同的代码(使用它)。
我怎么能做到?
很明显,在我的
1 2 3 4 | $ make lualatex TEXENGINE=lualatex echo Here I want to call the pdflatex rule, to check pdflatex there! Here I want to call the pdflatex rule, to check pdflatex there! |
…所以我真的想知道makefiles中是否有这样的功能。
使用目标特定变量
There is one more special feature of target-specific variables: when you define a target-specific variable that variable value is also in effect for all prerequisites of this target, and all their prerequisites, etc. (unless those prerequisites override that variable with their own target-specific variable value).
1 2 3 4 5 6 7 8 | TEXENGINE=pdflatex pdflatex: echo the engine is $(TEXENGINE) lualatex: TEXENGINE=lualatex lualatex: pdflatex echo Here I want to call the pdflatex rule, to check $(TEXENGINE) there! |
输出是:
1 2 3 4 5 6 7 8 | $ make pdflatex echo the engine is pdflatex the engine is pdflatex $ make lualatex echo the engine is lualatex the engine is lualatex echo Here I want to call the pdflatex rule, to check lualatex there! Here I want to call the pdflatex rule, to check lualatex there! |
嗯,我设法找到了一种解决办法,但我不太明白,所以我会感激一个更有学问的答案。对于我来说,这些链接有助于:
- 从规则内设置变量
- make:规则调用规则
- 从命令行传递附加变量
下面是修改过的示例——显然,为了在以后从规则调用规则(不是作为先决条件,而是作为后决条件),我只能递归调用
1 2 3 4 5 6 7 8 | TEXENGINE=pdflatex pdflatex: echo the engine is $(TEXENGINE) lualatex: echo Here I want to call the pdflatex rule, to check $(TEXENGINE) there! $(MAKE) TEXENGINE=lualatex pdflatex |
输出比我想要的要详细一些,但是它可以工作:
1 2 3 4 5 6 7 8 | $ make lualatex echo Here I want to call the pdflatex rule, to check pdflatex there! Here I want to call the pdflatex rule, to check pdflatex there! make TEXENGINE=lualatex pdflatex make[1]: Entering directory `/tmp' echo the engine is lualatex the engine is lualatex make[1]: Leaving directory `/tmp' |
…这完全是我想要的命令行交互方式,但我知道这不是最好的解决方案(参见下面的@jonathanwakely的评论)