使用.SECONDEXPANSION动态“创建”目标名称时遇到问题:
小Makefile重现问题:
CONFIGS = test1 test2 test3
.SECONDEXPANSION:
all: $(CONFIGS)
OBJECTS=$$(CFG_NAME)_OBJECTS
$(CONFIGS) : CFG_NAME=$@
$(CONFIGS) : $(OBJECTS)
@echo $(CFG_NAME) $@ from $^
$(OBJECTS):
@echo OBJECTS $@ from $^
@echo DO IT
它说:“没有规则来制作目标'test1_OBJECTS'。我该如何解决这个问题?
编辑:改变答案
非常感谢您的回答。这是我任务的简单变体。
所以我尝试用另一种方式来回答。
CONFIGS = test1 test2 test3
PLATFORMS = x86 ppc arm
#will be test1x86 test2x86 ... test1ppc ... test3arm,
#so it is long way to enumarate all variants
VARIANTS = $(foreach c, $(CONFIGS), $(foreach p, $(PLATFORMS), $(c)$(p)))
#C FILE LIST
CFILES:=$(shell /bin/find -name "*.c")
.SECONDEXPANSION:
all: $(VARIANTS)
#More Comlex Rule
#Want to corresponding objects be in bins/test1x86/
OBJECTS:=$(CFILES:%.c=bins/$$(CFGNAME)%.o)
$(CONFIGS) : CFG_NAME=$@
$(CONFIGS) : $(OBJECTS)
@echo $(CFG_NAME) $@ from $^
#More complex prerequisites
#I understand that $$(CFGNAME) will be resolve incorrect.
#For each *.c file in subdir I would have object in corresponding path.
#For example, '1/2/3/test.c' will use for generate
#object file 'bins/test1x86/1/2/3/test.o',
#when I call 'make testx86' or 'make all' (it will build all VARIANTS),
#in 'bins/test1x86/1/2/3/'.
#So what have I do?
$(OBJECTS): bins/$$(CFGNAME)_OBJECTS/%o : %.c
@echo OBJECTS $@ from $^
@echo DO IT
所以,我想避免递归调用。你能帮助我吗?谢谢你。