我有一个// "You have %d nickel"
"You have %d nickels"
看起来像这样,对于大多数目标都来自Makefile
。但我想通过.o -> .bin -> .stub
生成另一个更复杂的目标。
.o -> .elf -> .bin -> .stub
在构建all: simple.stub complex.stub
%.bin: %.o
$(Q)echo " OBJCOPY $@"
$(Q)$(OBJCOPY) -O binary $< $@
%.stub: %.bin
$(Q)echo " HEXDUMP $@"
$(Q)$(HEXDUMP) -v -e '/2 "0x%04X, "' $< > $@
%.elf: %.o
arm-none-eabi-gcc $< %@
时如何告诉make
.o -> .bin
不是有效的转换,并阻止其他人通过complex.stub
?
答案 0 :(得分:1)
您需要告知make
规则的例外情况,并提供备用模式规则,因为%.bin: %.elf
没有内置规则
.PHONY: all
all: simple.stub complex.stub
.INTERMEDIATE: complex.bin complex.elf
complex.bin: complex.elf
%.bin: %.o
@echo Making $@ from $^
@echo "test" > $@
%.bin: %.elf
@echo Making $@ from $^
@echo "test" > $@
%.stub: %.bin
@echo Making $@ from $^
@echo "test" > $@
%.elf: %.o
@echo Making $@ from $^
@echo "test" > $@
%.o:
@echo Making $@
@echo "test" > $@
.INTERMEDIATE
并非绝对必要,它只是一个有用的自动清理,因为它不太可能需要保留中间文件。