更改一个make变量,并从同一Makefile中的配方调用另一个规则? [英] Change a make variable, and call another rule, from a recipe in same Makefile?

查看:94
本文介绍了更改一个make变量,并从同一Makefile中的配方调用另一个规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过如何手动是从make目标中调用另一个目标吗?,但是我的问题有点不同;考虑以下示例(请注意,stackoverflow.com将选项卡更改为显示中的空格;但是,如果您尝试编辑,则选项卡将保留在源代码中):

I have already seen How to manually call another target from a make target?, but my question is a bit different; consider this example (note, stackoverflow.com changes the tabs to spaces in display; but tabs are preserved in source, if you try to edit):

TEXENGINE=pdflatex

pdflatex:
    echo the engine is $(TEXENGINE)

lualatex:
    TEXENGINE=lualatex
    echo Here I want to call the pdflatex rule, to check $(TEXENGINE) there!

在这里,如果我运行默认目标(pdflatex),则会得到预期的输出:

Here, if I run the default target (pdflatex), I get the expected output:

$ make pdflatex 
echo the engine is pdflatex
the engine is pdflatex

但是,对于目标lualatex,我想要:

But, with the target lualatex, I want to:

  • make变量TEXENGINE更改为lualatex,然后
  • 调用与pdflatex中相同的代码(使用它).
  • change the make variable TEXENGINE to lualatex, and then
  • call the same code as in pdflatex (which uses it).

我该怎么做?

很明显,在我的lualatex规则中,我什至没有设法更改TEXENGINE变量,因为尝试时会得到它:

Clearly, in my lualatex rule I don't even manage to change the TEXENGINE variable, because I get this when I try it:

$ 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中是否可以进行这样的事情.

... so I would really like to know if something like this is possible in 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).

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!

输出为:

$ 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变量,并从同一Makefile中的配方调用另一个规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆