avr-firmwares/Makefile

57 lines
1.1 KiB
Makefile
Raw Normal View History

2018-01-28 20:40:35 +01:00
OPTIMIZE = -O2
CPPFLAGS += -DF_CPU=$(MCU_FREQ)
override CFLAGS = -g --std=c99 -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
override LDFLAGS =
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRDUDE_ARGS =
ifdef BOARD
include boards/$(BOARD).mk
endif
default: $(PROG).hex
clean:
rm -rf *.o drivers/*.o *.elf *.lst *.hex *.bin *.asm
2018-01-29 01:48:12 +01:00
# automatic dependencies
include deps.mk
deps.mk: *.c drivers/*.c
for i in *.c; do echo $${i%.c}.elf: $$(./finddeps.sh "$$i"); echo; done > deps.mk
2018-01-28 20:40:35 +01:00
# generic rules
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
%.elf: %.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
%.asm: %.elf
$(OBJDUMP) -z -j .text -m avr5 -d $< > $@
# flashing definitions and helper target
AVRDUDE_ARGS += -p$(MCU_TARGET)
AVRDUDE_ARGS += -c$(AVRDUDE_TYPE)
ifdef AVRDUDE_TTY
AVRDUDE_ARGS += -P$(AVRDUDE_TTY)
endif
ifdef AVRDUDE_BAUD
AVRDUDE_ARGS += -b$(AVRDUDE_BAUD)
endif
ifdef AVRDUDE_TYPE
flash: $(PROG).hex
avrdude $(AVRDUDE_ARGS) -U flash:w:$(PROG).hex
endif