makefile - 如何在makefile中做条件语句

标签 makefile gnu-make

我正在尝试使用命令行 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的值一直是空的。我稍微改变了代码。现在的问题是 make 抛出错误
../makefile-includes/ARM-compiler.inc:10: *** commands commence before first target

在这一行:
ifeq ($(TOOLKIT), 1)

有人有什么想法吗?
谢谢

最佳答案

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

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

但是您可以在规则之外设置变量:只需从上面的条件语句中删除所有前导选项卡。这将适用于除 PATH 之外的所有内容和 LD_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根本。

关于makefile - 如何在makefile中做条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10883836/

相关文章:

makefile - 制作更好的 Makefile

bash - Makefile 错误退出并显示一条消息

makefile - 何时应该在 make recipe 中评估对 *eval* 的调用

c++ - 编译器标志更改时自动重新编译

具有两个同名目标的 Makefile

c - 仅适用于 C 的 Eclipse makefile(Windows 版本)

c - Msys 在 Powershell 中生成 - 没有这样的文件或目录

c - GNU Makefile并行执行两个文件

makefile - 仅在成功时保留中间文件

c++ - Makefile 说变量是空的,但它不是