2012-06-04 45 views
4

我试图使用命令行var来选择我们用来编译的工具包。当在命令行中我用这样一行:如何在生成文件中执行条件语句

make all-arm OUR_TOOLKIT=1 

而且,在暗示每个Makefile,我把这个包括

include ARM_Compiler.inc 

然后,在每个Makefile,

all: setToolkit $(otherOperations) 

而ARM_Compiler的内容是选择编译器的逻辑:

setToolkit: 
ifdef OUR_TOOLKIT 
    TOOLKIT=1 
endif 
ifdef CUSTOMER_TOOLKIT 
    TOOLKIT=2 
endif 

ifeq ($(TOOLKIT), 1) 
    $(info "=========Our toolkit selected======================") 
    rm=/bin/rm -f 
    CC= arm-linux-c++ -fPIC 
    CXX= arm-linux-c++ -fPIC 
    LINK= arm-linux-c++ -shared -Wl 
    AR= ar cq 
    RANLIB= ranlib 
    STRIP=arm-linux-strip 

    # para que se utilicen las herramientas y librerias del cross compiler 
    PATH:=$(PATH):/path/to/our/toolkit 
    LD_LIBRAY_PATH:=$(LD_LIBRAY_PATH):/path/to/our/toolkit   
endif 

ifeq ($(TOOLKIT), 2) 
    $(info "================Customer toolkit selected====================") 
    rm=/bin/rm -f 
    CC= arm-none-linux-gnueabi-c++ -fPIC 
    CXX= arm-none-linux-gnueabi-c++ -fPIC 
    LINK= arm-none-linux-gnueabi-c++ -shared -Wl 
    AR= ar cq 
    RANLIB= ranlib 
    STRIP= arm-none-linux-gnueabi-strip 

    # para que se utilicen las herramientas y librerias del cross compiler 
    PATH:=$(PATH):/path/to/other/toolkit 
    LD_LIBRAY_PATH:=$(LD_LIBRAY_PATH):/path/to/other/toolkit 
endif 

感谢0A0D的帮助,我发现TOOLKIT值总是空的。我已经改变了一些代码。现在的问题是,使引发错误

../makefile-includes/ARM-compiler.inc:10: *** commands commence before first target 

在这一行:

ifeq ($(TOOLKIT), 1) 

任何人有一些想法? 谢谢

+2

类似:http://stackoverflow.com/questions/8811526/using-conditional-rules-in-a-makefile – 2012-06-04 15:28:05

回答

5

这个问题的变种出现了很多。

每个命令都在其自己的子shell中执行;一个命令中设置的变量不能在另一个命令中使用。

但是,您可以在规则外设置变量:只需从上面的条件语句中删除所有主要的TAB。这将适用于除PATHLD_LIBRARY_PATH之外的所有内容。在我看来,这些都不是Make应该搞砸的东西,但是有办法达到你想要的效果。你可以处理PATH这样的:

ifeq ($(TOOLKIT), 1) 
    TOOLKITPATH = /path/to/our/toolkit 
endif 
... 

sometarget: 
    $(TOOLKITPATH)/sometool somearg 

或者这样:

all: 
    export PATH=$$PATH:$(TOOLKITPATH) ; $(MAKE) $(otherOperations) 

而且你可能不应该使用LD_LIBRARY_PATH可言。