variables - Makefile 变量初始化和导出

标签 variables makefile export

somevar := apple
export somevar
update := $(shell echo "v=$$somevar")

all:
    @echo $(update)

我希望苹果作为命令的输出,但是它是空的,这让我想到了 export 和 :=发生在不同阶段的可变膨胀。如何克服这个?

最佳答案

问题是export将变量导出到命令使用的子shell;它不可用于其他作业中的扩展。所以不要试图从规则之外的环境中获取它。

somevar := apple
export somevar

update1 := $(shell perl -e 'print "method 1 $$ENV{somevar}\n"')
# Make runs the shell command, the shell does not know somevar, so update1 is "method 1 ".

update2 := perl -e 'print "method 2 $$ENV{somevar}\n"'
# Now update2 is perl -e 'print "method 2 $$ENV{somevar}\n"'

# Lest we forget:
update3 := method 3 $(somevar)

all:
    echo $(update1)
    $(update2)
    echo $(update3)
    perl -e 'print method 4 "$$ENV{somevar}\n"'

关于variables - Makefile 变量初始化和导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2838715/

相关文章:

c++ - 如何独立检查多个变量?

javascript - JS 全局和局部变量

linux - 用于 aws-iot-device-sdk-cpp 的 Buildroot MakeFile

excel - 使用 VBA 从 Excel 2003 导入/导出工作表

mysql - 出现错误 : 2003: Can't connect to MySQL server while taking dump from RDS

variables - 替换变量中的 "%"

java图形变量给出错误的值

c - main.c :(. text+0x25): 未定义对 `reciprocal' 的引用

macos - 在 Mac OSX 上安装 flite 时出错

java - Richfaces 数据表 PDF 导出