summaryrefslogtreecommitdiff
path: root/Makefile
blob: 7d24dc80ce5d2d2698b3481d63f21cbf77ab8ee0 (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
37
38
39
40
41
42
43
44
45
46
47
MCU=atmega48
AVRDUDE=avrdude
ACC=avr-gcc
AOBJCOPY=avr-objcopy
ALD=avr-ld
ASIZE=avr-size
CFLAGS=-Wall -Wextra -Wno-unused-parameter -pedantic -std=c99
ifdef PIN
DPIN=-DPIN=\"$(PIN)\"
endif

ifdef MASTER_PIN
DPIN+=-DMASTER_PIN=\"$(MASTER_PIN)\"
endif
ACFLAGS=-g -mmcu=$(MCU) $(CFLAGS) $(DPIN) -Os -mcall-prologues
# ALDFLAGS=-L/usr/avr/lib/avr4 -L/usr/lib/binutils/avr/2.18
LD=gcc
CC=gcc
CXX=g++ -g
LDXX=g++ -g

love: kbc.flash kbc.eeprom

%.flash: %.ld.o
	$(AOBJCOPY) -O binary $< $@

%.eeprom: %.ld.o
	$(AOBJCOPY) -j .eeprom -O binary $^ $@

%.ld.o: %.o
	$(ACC) $(ACFLAGS) $(ALDFLAGS) -Wl,-Map,$(patsubst %.ld.o,%.map,$@) -o $@ $<
	@$(ASIZE) $@

%.o: %.c
	$(ACC) $(ACFLAGS) -c -o $@ $<

flash: kbc.flash
	$(AVRDUDE) -y -p m48 -E noreset -U flash:w:$<:r
eeprom: kbc.eeprom
	$(AVRDUDE) -y -p m48 -E noreset -U eeprom:w:$<:r

clean:
	rm -f *.flash *.eeprom *.o

.PHONY: love flash eeprom clean
.SECONDARY: