Change a make variable, and call another rule, from a recipe in same Makefile?

后端 未结 2 1867
深忆病人
深忆病人 2020-12-29 22:44

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 t

2条回答
  •  太阳男子
    2020-12-29 22:49

    Well, I managed to get to a sort of a workaround, but I don't exactly understand it much - so a more learned answer will be appreciated. For me here, these links helped:

    • Set a variable from within a rule
    • make : rule call rule
    • Passing additional variables from command line to make

    So here is the example modified - apparently, to call a rule from a rule afterwards (not as a prerequisite, rather, as a postrequisite), I can only recursively call make, while having the new variable value specified on its command line:

    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
    

    The output is somewhat more verbose than I'd like it, but it works:

    $ 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'
    

    ... which is what I wanted purely command-line interaction-wise, but I know is not the best solution (see @JonathanWakely's comment below)

提交回复
热议问题