How can i pass ENV variables between make targets

情到浓时终转凉″ 提交于 2019-12-04 04:37:30

By default make invokes a new shell environment for each recipe, the exported variable on the first line isn't in scope for the second.

You can fix this in multiple ways:

Export the variable with make's export directive

target1: export var1 := test
target1:
    $(MAKE) target2

Use make's command line variable assignment

target1:
    $(MAKE) target2 var1=test

Use shell command variable assignment

target1:
    var1=test $(MAKE) target2

Combine the two commands in a single recipe

target1:
    export var1=test; $(MAKE) target2

Force make to pass all recipes to the same shell instance

.ONESHELL:

target1:
    export var1=test
    $(make) target2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!