如何在makefile中执行条件语句
我试图使用命令行变量来选择我们用来编译的工具包。在命令行中,我使用如下行:如何在makefile中执行条件语句,makefile,gnu-make,Makefile,Gnu Make,我试图使用命令行变量来选择我们用来编译的工具包。在命令行中,我使用如下行: make all-arm OUR_TOOLKIT=1 在每一个makefile中,我都包含了 include ARM_Compiler.inc 然后,在每个makefile中 all: setToolkit $(otherOperations) ARM_编译器的内容是选择编译器的逻辑: setToolkit: ifdef OUR_TOOLKIT TOOLKIT=1 endif ifdef CUSTOMER
make all-arm OUR_TOOLKIT=1
在每一个makefile中,我都包含了
include ARM_Compiler.inc
然后,在每个makefile中
all: setToolkit $(otherOperations)
ARM_编译器的内容是选择编译器的逻辑:
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的帮助,我发现工具箱的值总是空的。我对代码做了一点修改。现在的问题是make抛出了错误
../makefile-includes/ARM-compiler.inc:10: *** commands commence before first target
在这一行:
ifeq ($(TOOLKIT), 1)
有人知道吗?
谢谢这个问题的变体出现了很多 每个命令都在自己的子shell中执行;一个命令中设置的变量不能用于另一个命令。 但是您可以在规则之外设置变量:只需从上面的条件语句中删除所有前导选项卡。这将适用于除
PATH
和LD\u LIBRARY\u PATH
之外的所有内容。在我看来,这两种方法都不应该弄糟,但是有办法达到你想要的效果。您可以像这样处理PATH
:
ifeq ($(TOOLKIT), 1)
TOOLKITPATH = /path/to/our/toolkit
endif
...
sometarget:
$(TOOLKITPATH)/sometool somearg
all:
export PATH=$$PATH:$(TOOLKITPATH) ; $(MAKE) $(otherOperations)
或者像这样:
ifeq ($(TOOLKIT), 1)
TOOLKITPATH = /path/to/our/toolkit
endif
...
sometarget:
$(TOOLKITPATH)/sometool somearg
all:
export PATH=$$PATH:$(TOOLKITPATH) ; $(MAKE) $(otherOperations)
您可能根本不应该使用LD\u LIBRARY\u PATH
。类似: