-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.common
113 lines (81 loc) · 2.62 KB
/
Makefile.common
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
PRG ?= main
MACHINE ?= uno
CSRC = $(wildcard *.c)
COBJ = $(patsubst %.c,%.o,$(CSRC))
C_ARDUINO = $(wildcard $(TOP)/_arduino/*.c)
OBJ_ARDUINO = $(patsubst %.c,%.o,$(notdir $(C_ARDUINO)))
OPTIMIZE = -Os
LOADER = avrdude
DEFS ?=
LIBS ?=
# Machine params
ifeq ($(MACHINE),mega2560)
# Arduino Mega 2560
MCU = atmega2560
F_CPU = 16000000UL
BAUD_RATE = 115200
LOADERFLAGS = -c stk500v2 -p $(MCU) -b $(BAUD_RATE) -P /dev/$(USB)
else
# Arduino Uno
MCU = atmega328p
F_CPU = 16000000UL
BAUD_RATE = 115200
LOADERFLAGS = -c arduino -p $(MCU) -b $(BAUD_RATE) -P /dev/$(USB)
endif
# You should not have to change anything below here.
CC = avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I$(TOP)/_arduino $(DEFS)
override LDFLAGS = -Wl,-Map,$(PRG).map
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: $(PRG).elf lst text eeprom
$(PRG).elf: libarduino.a $(COBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COBJ) -L. -larduino $(LIBS)
# dependency:
$(COBJ): %.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
libarduino.a: $(OBJ_ARDUINO)
avr-ar -r $@ $^
$(OBJ_ARDUINO): %.o: $(TOP)/_arduino/%.c
$(CC) $(CFLAGS) -c -o $@ $<
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for building the .text rom images
text: hex bin srec
hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
# Rules for building the .eeprom rom images
eeprom: ehex ebin esrec
ehex: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_eeprom.srec
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ \
|| { echo empty $@ not generated; exit 0; }
# Every thing below here is used by avr-libc's build system and can be ignored
# by the casual user.
EXTRA_CLEAN_FILES = *.hex *.bin *.srec
write: $(PRG).hex
$(LOADER) $(LOADERFLAGS) -U flash:w:$<
VERIFAST = verifast
VERIFAST_OPT = -c -I ../../_arduino4verifast
verify:
$(VERIFAST) $(VERIFAST_OPT) main.c
clean:
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak *.a
rm -rf *.lst *.map *.tmp $(EXTRA_CLEAN_FILES)