summaryrefslogtreecommitdiff
path: root/Makefile
blob: bf5d3555a0d6484237af1ac86bbf40502a1a2a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
.PHONY: flash love

TARGETS=door lightctrl lightctrl_v2

CFLAGS_OPT=-Os \
	-fpredictive-commoning -fmerge-all-constants -fmodulo-sched -fmodulo-sched-allow-regmoves \
	-fgcse-sm -fgcse-las -fgcse-after-reload -fconserve-stack \
	-fwhole-program
CFLAGS_WARN=-std=gnu99 -Wall -Wextra -Wno-unused -pedantic
CFLAGS_LD=-Wl,-T,avr4-signature.x 
CFLAGS_=${CFLAGS_WARN} ${CFLAGS_OPT} ${CFLAGS_LD} ${CFLAGS}
MCU_door=48
MCU_lightctrl=88
MCU_lightctrl_v2=88
AVRDUDE=avrdude

love: $(foreach target,$(TARGETS),$(target).elf)
	avr-size $^

ifdef TARGET
flash: ${TARGET}.flash
#	$(AVRDUDE) -p m$(MCU_$(basename $<)) -c stk500v2 -P avrdoper -y \
#		-U eeprom:r:eeprom:r
	$(AVRDUDE) -p m$(MCU_$(basename $<)) -c stk500v2 -P avrdoper -y \
		-U flash:w:$< \
		-U eeprom:w:eeprom:r
else
flash:
	@echo the flash target is available only with TARGET set to something. use e.g. \"make flash TARGET=door\" >&2
	@false
endif

%.flash: %.elf Makefile
	avr-objcopy -j .text -j .data -O ihex $< $@
%.elf: %.c *.c *.x Makefile
	avr-gcc -mmcu=atmega$(MCU_$(basename $@)) ${CFLAGS_} -o $@ $<