Makefile:$(CC)不能与ifeq一起使用

时间:2012-03-30 08:03:20

标签: makefile gnu-make cc

所以,这很奇怪。在我的makefile中我有

CC:=icc
ifeq ($(CC),icc)
CFLAGS := $(ICCFLAGS)
LIBS := $(LIBS) -openmp
else
CFLAGS := $(GCCFLAGS)
LIBS := $(LIBS) -fopenmp
endif

对于make,条件为false但是

CCC:=icc
ifeq ($(CCC),icc)
CFLAGS := $(ICCFLAGS)
LIBS := $(LIBS) -openmp
else
CFLAGS := $(GCCFLAGS)
LIBS := $(LIBS) -fopenmp
endif

这里条件为真,

CC:=icc
CCC:=$(CC)
ifeq ($(CCC),icc)
CFLAGS := $(ICCFLAGS)
LIBS := $(LIBS) -openmp
else
CFLAGS := $(GCCFLAGS)
LIBS := $(LIBS) -fopenmp
endif

此处条件再次为假。到底是怎么回事?

1 个答案:

答案 0 :(得分:1)

您似乎要将CC作为命令行选项传递,例如:

make CC=...

...或使用-e开关调用make,这会强制环境变量优先于Makefile中定义的变量。

您可以使用origin function检查变量的定义方式:

CC := icc
$(error CC comes from $(origin CC))

如果打印command lineenvironment override,则解决方法是使用override directive

override CC := icc

即使命令行或环境中有另一个变量,也会设置CC变量。