gpt4 book ai didi

makefile - 更改一个make变量,并从同一Makefile中的配方调用另一个规则?

转载 作者:行者123 更新时间:2023-12-03 10:39:27 24 4
gpt4 key购买 nike

我已经看过How to manually call another target from a make target?,但是我的问题有点不同。考虑以下示例(请注意,stackoverflow.com将选项卡更改为显示中的空格;但是,如果您尝试编辑,则选项卡将保留在源代码中):

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),则会得到预期的输出:
$ make pdflatex 
echo the engine is pdflatex
the engine is pdflatex

但是,使用目标 lualatex,我想要:
  • make变量TEXENGINE更改为lualatex,然后将
  • 更改为
  • 调用与pdflatex(使用它)相同的代码。

  • 我该怎么办?

    显然,在我的 lualatex规则中,我什至没有设法更改 TEXENGINE变量,因为尝试时会得到以下信息:
    $ 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中是否可以进行这样的操作。

    最佳答案

    使用target-specific variable

    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!

    关于makefile - 更改一个make变量,并从同一Makefile中的配方调用另一个规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26382846/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com