2013-06-02 13 views
0

以下是使用MinGW msys和Cygwin進行測試的結果。
當在makefile中定義僞目標EXPORT_ALL_VARIABLES,然後執行子命令時,不會導出帶點的變量。
所以CFLAGS被導出,但是CFLAGS.cppCFLAGS.c沒有。使用EXPORT_ALL_VARIABLES make不會輸出帶點的變量

這是一個記錄的功能?什麼是理性?
有沒有辦法導出所有變量?

實施例:

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 

回答

2

POSIX sh中的環境變量不能包含「。」;試試吧:

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

Make只會導出對shell有效的變量。

的GNU使手冊說:

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本身,並具有相同的限制。