-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (50 loc) · 1.33 KB
/
Makefile
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
ELF=test_bufferedio.elf
BAUD?=9600
F_CPU=8000000
SERIAL_DEV=ttyS0
DEVICE=atmega16a
DUDE_DEVNAME=m16
DUDE_ISP=avrispmkII
BACKEND=poll
AVRDUDE=avrdude -c $(DUDE_ISP) -p $(DUDE_DEVNAME) -e
CC=avr-gcc
SIZE=avr-size
OBJDUMP=avr-objdump
OBJCOPY=avr-objcopy
CFLAGS=-std=gnu99 -Os -DBAUD=$(BAUD) -DF_CPU=$(F_CPU) -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=$(DEVICE)
LDFLAGS=-Wl,--gc-sections -mmcu=$(DEVICE)
SOURCES=uart_stdio_$(BACKEND).c example.c
OBJECTS=$(SOURCES:.c=.o)
HEX=$(ELF:.elf=.hex)
all: $(OBJECTS) $(HEX) size
size:
$(SIZE) -C --mcu=$(DEVICE) $(ELF)
prog: $(HEX).burned
reprog:
rm -f $(HEX.burned)
$(MAKE) prog
erase:
rm -f $(PROGRAM).burned
$(AVRDUDE) -e
$(HEX).burned: $(HEX)
$(AVRDUDE) -U flash:w:$(HEX)
date >$@
prun: prog size run
zero: clean erase close
reprun: clean prun
run:
screen -q -r $(SERIAL_DEV) || screen -S $(SERIAL_DEV) /dev/$(SERIAL_DEV) $(BAUD)
close:
screen -X -S $(SERIAL_DEV) kill || true
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.lss: %.elf
$(OBJDUMP) -h -S $< >$@
%.elf: $(OBJECTS)
$(CC) $^ -o $@ -Wl,-Map="$*.map" $(LDFLAGS)
%.hex: %.elf %.lss
$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user $< $@
clean: close
rm -f *.lss *.hex *.o *.elf *.map *.burned Makefile.bak
.PRECIOUS: %.o %.lss
.PHONY: clean