gpt4 book ai didi

c++ - GNU 使 ifeq 比较不起作用

转载 作者:行者123 更新时间:2023-11-28 02:36:27 24 4
gpt4 key购买 nike

我试图在执行另一个 makefile 之前根据目标列表中的当前目标执行命令(当前只有该列表中的一个条目)。

我有这个:

$(LIBS):            
ifeq ($@,libname)
my command here
endif
$(MAKE) -C ./lib/$@

问题是,即使目标名称正确,ifeq 也不会执行。使用 $(info $@) 准确显示 libname,但表达式未被评估为 true。我认为在条件条件下扩展自动变量可能存在问题,所以我尝试使用这样的 eval:

$(LIBS):
$(eval CURRENT_LIB := $@)
ifeq ($(CURRENT_LIB),libname)
my command here
endif
$(MAKE) -C ./lib/$@

info 显示变量现在正好等于 libname 但 ifeq 没有​​被执行。当我输入类似 ifeq (libname,libname) 的内容时,它可以正常工作,因此语句可以正常工作,但是变量和文本之间的比较不会计算为真,即使两者相等并且它应该可以工作。GNU make 版本为 4.1

我在这里错过了什么?

完整的生成文件:

CC := g++
CFLAGS := -v -std=c++0x -pthread -Wall -g -O3

OBJ := mycode.o
OBJ += moreobjects.o
#more objects in here

LIBS = libname

.PHONY: libs $(LIBS)

SRC = $(OBJ:%.o=%.cpp)
DEPFILE := .depend

mytarget: libs $(OBJ)
$(CC) $(CFLAGS) -o $@ $(OBJ)

-include $(DEPFILE)

%.o: %.cpp
$(CC) $(CFLAGS) -c $<
$(CC) -MM -std=c++11 $(SRC) > $(DEPFILE)

libs: $(LIBS)

$(LIBS):
$(eval CURRENT_LIB := $@)
ifeq ($(CURRENT_LIB),libname)
./lib/$(CURRENT_LIB)/configure
endif
$(MAKE) -C ./lib/$@

.PHONY: clean_all
clean_all: clean
$(foreach dir,$(LIBS),$(MAKE) clean -C ./lib/$(dir))


.PHONY: clean
clean:
rm -rf mytarget $(OBJ) $(DEPFILE)

非常感谢!

最佳答案

你正在尝试做的事情是行不通的。来自documentation :

Conditionals control what 'make' actually "sees" in the makefile, so they cannot be used to control recipes at the time of execution.

我的意思是,在读取 Makefile 时评估条件。所以 make 读取你的 Makefile,你的条件是假的,它被删除了。

关于c++ - GNU 使 ifeq 比较不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27268450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com