Friday, 15 July 2011

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



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

i have seen how manually phone call other target create target?, question bit different; consider illustration (note, stackoverflow.com changes tabs spaces in display; tabs preserved in source, if seek edit):

texengine=pdflatex pdflatex: echo engine $(texengine) lualatex: texengine=lualatex echo here want phone call pdflatex rule, check $(texengine) there!

here, if run default target (pdflatex), expected output:

$ create pdflatex echo engine pdflatex engine pdflatex

but, target lualatex, want to:

change make variable texengine lualatex, , call same code in pdflatex (which uses it).

how that?

clearly, in lualatex rule don't manage alter texengine variable, because when seek it:

$ create lualatex texengine=lualatex echo here want phone call pdflatex rule, check pdflatex there! here want phone call pdflatex rule, check pdflatex there!

... know if possible in makefiles.

use target-specific variable

there 1 more special feature of target-specific variables: when define target-specific variable variable value in effect prerequisites of target, , prerequisites, etc. (unless prerequisites override variable own target-specific variable value).

texengine=pdflatex pdflatex: echo engine $(texengine) lualatex: texengine=lualatex lualatex: pdflatex echo here want phone call pdflatex rule, check $(texengine) there!

the output is:

$ create pdflatex echo engine pdflatex engine pdflatex $ create lualatex echo engine lualatex engine lualatex echo here want phone call pdflatex rule, check lualatex there! here want phone call pdflatex rule, check lualatex there!

makefile make gnu-make

No comments:

Post a Comment