makefile - Does Make expand recursive-variables before exporting them? -




given makefile:

ifeq "$(makelevel)" "0"   0 ::     @$(make)   else   1 ::     @echo 'foo is: "$(foo)"'   endif 



and executing, get:

$ make foo='$@' make[1]: entering directory '/home/myname' foo is: "1" make[1]: leaving directory '/home/myname'   $ make foo='$@' --environment-overrides make[1]: entering directory '/home/myname' foo is: "0" make[1]: leaving directory '/home/myname' 



have here recursive variable foo value: $@, - of course - expands name of target. now, have 2 options here:

  1. either, make expands first variable, , export variable sub-make.

    "logic", when make runs first makefile (makelevel = 0), build target 0, hence: expand variable foo(and value:$@) 0, , export - expanded value - sub-make.

    result, sub-make running makefile, variable foo has simple value: 0.

    in-fact case, when run make --environment-overrides, can see in second run of makefile, in example above.

  2. another "logic" is, make pass value "verbatim". means, no expansion!


    hence recursive variables still intact, when passed second make.

    logic, only sub-make allowed expand variables recursively, hence: recursive-expansion done in context of sub-make.

    in our example above, had foo value $@, if follow logic, make pass value $@ "verbatim", no expansion @ all, sub-make see value $@ foo variable, hence: when expanding in context of its target, happens 1, recursively expand foo(and value: $@) 1.

    actually, "normal" behaviour evident in first run of makefile, evident in example above.

so, lack of clear methodology, left conclude, behaviour of either expand , export or export , expand inconsistent.

that is, make choose first method, chose second.

in our example, command-line option (--environment--overrides), acted deciding factor, method make has choose.

but, can justify, these - seemingly - unrelated features (i.e export/recursive vs. environment-overrides), end have such dramatic effect on each-other?



(versions note: 4.0 , up).

make export foo in expanded form, can seen here:

target:     @echo "'$$foo'" 

output:

$make foo='$@' 'target' 

however, pass argument sub-makes, not use environment directly -- instead stuffs variable makeflags. , there passes foo unexpanded:

target:     @echo "'$$makeflags'" 

output:

$make foo='$@' ' -- foo=$$@' 

to clear: sub-make import foo environment, overridden setting makeflags.

when specify --environment--overrides, means environment variables take precedence on settings in makefile. gnu make documentation not explicitly specify happens variables passed in via makeflags in presence of --environment--overrides, apparently overridden too.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -