开发者

Conditional variable define in Makefile with ifeq

开发者 https://www.devze.com 2023-03-16 10:31 出处:网络
I am trying to define variables in a Makefile, according to conditions. As ifeq can be run only in rules, I have added an additional rule (def_rule) I refer to for each rule.

I am trying to define variables in a Makefile, according to conditions. As ifeq can be run only in rules, I have added an additional rule (def_rule) I refer to for each rule.

Example:

def_rule:
ifeq ($(TARGET), android)
    CC=arm-linux-androideabi-gcc
else
    echo "native build" 
endf

all:    def_rule tp xi_eid_chipset.o

Unfortunately, invoking make all returns this:

ifeq (linux, android)

/bin/sh: Syntax error: word unexpected (expecting ")")

make: *** [def_rule] Error 2

I cannot figure out why. I have just followed examples in GNU Make documentation.

Do you kno开发者_如何学Pythonw how to do conditional defines in Makefiles ?


Conditionals can be outside of rules:

ifeq ($(TARGET), android)
 $(info Android)
 CC=arm-linux-androideabi-gcc
else
 $(info native build)
 CC=something else
endif

(Note that I've tossed in a few leading spaces, just to make it easier to read-- they are neither necessary nor harmful.)

0

精彩评论

暂无评论...
验证码 换一张
取 消