avr-firmwares/Makefile

68 lines
1.3 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 =
2018-10-06 16:28:24 +02:00
AVRDUDE_ARGS =
# programs we are gonna use
2018-01-28 20:40:35 +01:00
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
2018-01-30 00:12:22 +01:00
SIZE = avr-size
2018-10-06 16:28:24 +02:00
AVRDUDE = avrdude
2018-01-28 20:40:35 +01:00
ifdef BOARD
include boards/$(BOARD).mk
endif
2018-01-30 00:02:06 +01:00
ifdef BAUDRATE
CPPFLAGS += -DBAUDRATE=$(BAUDRATE)
endif
2018-01-28 20:40:35 +01:00
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 $@ $^
2018-10-03 02:52:05 +02:00
%.elf: %.o $(DRIVER_OBJ:.c=.o)
2018-01-28 20:40:35 +01:00
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
2018-01-30 00:12:22 +01:00
$(SIZE) $@
2018-01-28 20:40:35 +01:00
%.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)
2018-04-02 13:03:48 +02:00
2018-01-28 20:40:35 +01:00
ifdef AVRDUDE_TTY
AVRDUDE_ARGS += -P$(AVRDUDE_TTY)
endif
2018-04-02 13:03:48 +02:00
2018-01-28 20:40:35 +01:00
ifdef AVRDUDE_BAUD
AVRDUDE_ARGS += -b$(AVRDUDE_BAUD)
endif
ifdef AVRDUDE_TYPE
flash: $(PROG).hex
2018-10-06 16:28:24 +02:00
$(AVRDUDE) $(AVRDUDE_ARGS) -U flash:w:$(PROG).hex
2018-01-28 20:40:35 +01:00
endif