-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile.common
129 lines (98 loc) · 3.67 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
PRG ?= main
MACHINE ?= uno
SATS = $(wildcard SATS/*.sats)
DATS = $(wildcard DATS/*.dats)
DATSC = $(patsubst %.dats,%_dats.c,$(DATS))
DATSOBJ = $(patsubst %.dats,%_dats.o,$(DATS))
SATS_ATSDUINO = $(wildcard $(TOP)/SATS/*.sats)
DATS_ATSDUINO = $(wildcard $(TOP)/DATS/*.dats)
C_ATSDUINO = $(patsubst %.dats,%_dats.c,$(notdir $(DATS_ATSDUINO)))
OBJ_ATSDUINO = $(patsubst %.dats,%_dats.o,$(notdir $(DATS_ATSDUINO)))
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
ATS = patsopt
ATSCFLAGS = -std=c99 -D_XOPEN_SOURCE
ATSCFLAGS += -D_ATSTYPE_VAR_SIZE_=0X000F -D_ATS_CCOMP_EXCEPTION_NONE_ -D_ATS_CCOMP_RUNTIME_NONE_ -D_ATS_CCOMP_PRELUDE_NONE_ -D_ATS_CCOMP_PRELUDE_USER_=\"$(TOP)/avr_prelude/kernel_prelude.cats\"
ATSCFLAGS += -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable
ATSCFLAGS += -I. -I${PATSHOME} -I${PATSHOME}/ccomp/runtime -I$(TOP)/_arduino -I$(TOP)/_dummy -I$(TOP)
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU) -DF_CPU=$(F_CPU) $(DEFS) $(ATSCFLAGS)
override LDFLAGS = -Wl,-Map,$(PRG).map
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: $(PRG).elf lst text eeprom
$(PRG).elf: libarduino.a libatsduino.a $(DATSOBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(DATSOBJ) -L. -latsduino -larduino $(LIBS)
# dependency:
$(DATSOBJ): %_dats.o: %_dats.c
$(CC) $(CFLAGS) -c -o $@ $<
$(DATSC): %_dats.c: %.dats $(SATS) $(SATS_ATSDUINO)
$(ATS) -o [email protected] -d $<
mv [email protected] $@
libatsduino.a: $(OBJ_ATSDUINO)
avr-ar -r $@ $^
$(OBJ_ATSDUINO): %_dats.o: %_dats.c
$(CC) $(CFLAGS) -c -o $@ $<
$(C_ATSDUINO): %_dats.c: $(TOP)/DATS/%.dats $(SATS_ATSDUINO)
$(ATS) -o [email protected] -d $<
mv [email protected] $@
libarduino.a: $(OBJ_ARDUINO)
avr-ar -r $@ $^
$(OBJ_ARDUINO): %.o: $(TOP)/_arduino/%.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak *.a
rm -rf *.lst *.map DATS/*.c DATS/*.o *_dats.c *.tmp $(EXTRA_CLEAN_FILES)
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:$<