【问题标题】:With EXPORT_ALL_VARIABLES make does not export variables with dot使用 EXPORT_ALL_VARIABLES make 不会导出带点的变量
【发布时间】:2013-06-02 08:13:46
【问题描述】:

以下内容已使用 MinGW msys 和 Cygwin 进行了测试。
在 makefile 中定义虚假目标 EXPORT_ALL_VARIABLES 然后执行子 make 时,不会导出带点的变量。
所以 CFLAGS 被导出,但 CFLAGS.cppCFLAGS.c 不是。

这是一个记录在案的功能吗?什么是理性?
有没有办法导出所有变量?

例子:

test1.mak

CFLAGS=-O2
CFLAGS.cpp=-O2 -fno-rtti
all:
    $(MAKE) -f test2.mak
.EXPORT_ALL_VARIABLES:

test2.mak

$(info CFLAGS='$(CFLAGS)')
$(info CFLAGS.cpp='$(CFLAGS.cpp)')
all:
    @echo Done

输出:

make -f test1.mak 
CFLAGS='-O2'
CFLAGS.cpp=''
Done

【问题讨论】:

    标签: makefile cygwin mingw


    【解决方案1】:

    POSIX sh 中的环境变量不能包含“.”;试试看:

    $ FOO.BAR=foobar
    FOO.BAR=foobar: command not found
    

    Make 只会导出对 shell 有效的变量。

    GNU make 手册说:

    If you use export by itself to export variables by
    default, variables whose names contain characters other than
    alphanumerics and underscores will not be exported unless specifically
    mentioned in an export directive.
    

    然后:

    you can write a rule for the special target
    .EXPORT_ALL_VARIABLES instead of using the export directive.
    

    因此,该目标与单独使用export 相同,并且具有相同的限制。

    【讨论】:

    • 如果您提供一个如何为 .EXPORT_ALL_VARIABLES 编写规则的示例,将会更有帮助
    • 我不明白你的意思。 .EXPORT_ALL_VARIABLES 是一个内置的伪目标:见gnu.org/software/make/manual/html_node/… 除了问题中已经显示的内容外,无需为其编写规则。
    猜你喜欢
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多