81 lines
1.5 KiB
Makefile
81 lines
1.5 KiB
Makefile
OPTIMIZE = -O2
|
|
CPPFLAGS += -DF_CPU=$(MCU_FREQ)
|
|
override CFLAGS = -g --std=c99 -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
|
|
override LDFLAGS =
|
|
AVRDUDE_ARGS =
|
|
|
|
# programs we are gonna use
|
|
CC = avr-gcc
|
|
OBJCOPY = avr-objcopy
|
|
OBJDUMP = avr-objdump
|
|
SIZE = avr-size
|
|
AVRDUDE = avrdude
|
|
|
|
ifdef BOARD
|
|
include boards/$(BOARD).mk
|
|
endif
|
|
|
|
ifdef BAUDRATE
|
|
CPPFLAGS += -DBAUDRATE=$(BAUDRATE)
|
|
endif
|
|
|
|
default: $(PROG).hex
|
|
|
|
clean:
|
|
rm -rf *.o drivers/*.o *.elf *.lst *.hex *.bin *.asm
|
|
|
|
# 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
|
|
|
|
# generic rules
|
|
%.o: %.c
|
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
|
|
|
|
%.elf: %.o $(DRIVER_OBJ:.c=.o)
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
|
$(SIZE) $@
|
|
|
|
%.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
|
|
reset:
|
|
$(AVRDUDE) $(AVRDUDE_ARGS)
|
|
|
|
flash: $(PROG).hex
|
|
$(AVRDUDE) $(AVRDUDE_ARGS) -U flash:w:$(PROG).hex
|
|
endif
|
|
|
|
# serial console
|
|
ifeq ($(COM),picocom)
|
|
serial:
|
|
$(COM) -b $(BAUDRATE) $(AVRDUDE_TTY)
|
|
endif
|
|
ifeq ($(COM),screen)
|
|
serial:
|
|
$(COM) $(AVRDUDE_TTY) $(BAUDRATE)
|
|
endif
|