Makefile variable initialization and export

后端 未结 4 1772
野趣味
野趣味 2021-02-02 08:00
somevar := apple
export somevar
update := $(shell echo \"v=$$somevar\")

all:
    @echo $(update)

I was hoping to apple as output of command, however i

4条回答
  •  时光说笑
    2021-02-02 08:47

    Running the makefile

    foo:=apple
    export foo
    all:
            @echo ">"$(shell echo "$$foo")
            @echo ">""$$foo"
    

    gives for me (with foo undefined in the environment)

    $ make
    >
    >apple
    
    $ make foo=bar
    >
    >apple
    
    $ export foo=bar; make
    >bar
    >apple
    
    $ export foo=bar; make foo=bar
    >bar
    >bar
    

    Try using the quoted form (update := "v=$$somevar") and let the shell handle expansion when a command is run (you'll still need the export)

提交回复
热议问题