joeforker
joeforker

Reputation: 41757

How do I add an additional Makefile step for a single target?

I have a Makefile that looks like this, going from .o -> .bin -> .stub for most targets. But I have another more complicated target that I want to generate through .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 $< %@

How do I tell make that .o -> .bin is not a valid transition while building complex.stub, and also prevent it from going through .elf for the others?

Upvotes: 2

Views: 75

Answers (1)

user657267
user657267

Reputation: 21000

You need to tell make about the exception to the rule, and provide an alternative pattern rule as there are no built-in rules for %.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 isn't strictly necessary, it's just a useful auto cleanup seeing as it's unlikely you need to keep the intermediate files around.

Upvotes: 1

Related Questions