Makefile:if语句工作的问题=(

时间:2011-04-28 15:36:34

标签: c++ makefile

MAC_BOOST_PATH = -L/opt/local/lib
LINUX_BOOST_PATH = -L/usr/lib/
DEFAULT_PATH = -L/usr/local/lib
BOOST_PATH = $(DEFAULT_PATH)

ifeq ($(UNAME), Darwin)
BOOST_PATH = MAC_BOOST_PATH
@echo Compiling for Mac OS X
@echo 
endif
ifeq ($(UNAME), Linux)
BOOST_PATH = LINUX_BOOST_PATH
@echo Compiling for Linux
@echo 
endif

echo不是打印,BOOST_PATH没有改变,我不认为......所以......我不确定我在这里做错了什么... = \

4 个答案:

答案 0 :(得分:3)

您没有在任何地方定义UNAME变量。你可能想要这样的东西:

UNAME = $(shell uname)

答案 1 :(得分:3)

您不能将命令放在Makefile中,与目标无关。您需要引入一个显示操作系统的目标。而且,你缺少'$()'。使用例如

UNAME=$(shell uname)
MAC_BOOST_PATH = -L/opt/local/lib
LINUX_BOOST_PATH = -L/usr/lib/
DEFAULT_PATH = -L/usr/local/lib
BOOST_PATH = $(DEFAULT_PATH)

ifeq ($(UNAME),Darwin)
BOOST_PATH=$(MAC_BOOST_PATH)
endif
ifeq ($(UNAME),Linux)
BOOST_PATH=$(LINUX_BOOST_PATH)
endif

all: showos

showos: 
  @echo compiling for $(UNAME)

答案 2 :(得分:0)

我认为您需要移除@符号才能显示回声

答案 3 :(得分:0)

正如Erik所指出的,Make不会执行独立于目标的命令。但它可以评估没有目标的函数:

UNAME = whatever

ifeq ($(UNAME), Darwin)
BOOST_PATH = MAC_BOOST_PATH
$(info Compiling for Mac OS X)
$(info )  # note the space
endif
ifeq ($(UNAME), Linux)
BOOST_PATH = LINUX_BOOST_PATH
$(info Compiling for Linux)
$(info )
endif