forked from pichenettes/avril
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.mk
192 lines (145 loc) · 6.51 KB
/
makefile.mk
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright 2009 Olivier Gillet.
#
# Author: Olivier Gillet ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AVRLIB_TOOLS_PATH = /usr/local/CrossPack-AVR/bin/
AVRLIB_ETC_PATH = /usr/local/CrossPack-AVR/etc/
# AVRLIB_TOOLS_PATH = /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/
# AVRLIB_ETC_PATH = /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/
BUILD_ROOT = build/
BUILD_DIR = $(BUILD_ROOT)$(TARGET)/
PROGRAMMER = avrispmkII
MCU = atmega$(MCU_NAME)p
DMCU = m$(MCU_NAME)p
MCU_DEFINE = ATMEGA$(MCU_NAME)P
F_CPU = 20000000
VPATH = $(PACKAGES)
CC_FILES = $(notdir $(wildcard $(patsubst %,%/*.cc,$(PACKAGES))))
AS_FILES = $(notdir $(wildcard $(patsubst %,%/*.as,$(PACKAGES))))
OBJ_FILES = $(CC_FILES:.cc=.o) $(AS_FILES:.S=.o)
OBJS = $(patsubst %,$(BUILD_DIR)%,$(OBJ_FILES))
DEPS = $(OBJS:.o=.d)
TARGET_HEX = $(BUILD_DIR)$(TARGET).hex
TARGET_ELF = $(BUILD_DIR)$(TARGET).elf
TARGETS = $(BUILD_DIR)$(TARGET).*
DEP_FILE = $(BUILD_DIR)depends.mk
CC = $(AVRLIB_TOOLS_PATH)avr-gcc
CXX = $(AVRLIB_TOOLS_PATH)avr-g++
OBJCOPY = $(AVRLIB_TOOLS_PATH)avr-objcopy
OBJDUMP = $(AVRLIB_TOOLS_PATH)avr-objdump
AR = $(AVRLIB_TOOLS_PATH)avr-ar
SIZE = $(AVRLIB_TOOLS_PATH)avr-size
NM = $(AVRLIB_TOOLS_PATH)avr-nm
AVRDUDE = $(AVRLIB_TOOLS_PATH)avrdude
REMOVE = rm -f
CAT = cat
CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. \
-g -Os -w -Wall \
-ffunction-sections -fdata-sections -D$(MCU_DEFINE) \
-DSERIAL_RX_0 -fno-move-loop-invariants \
-mcall-prologues
CXXFLAGS = -fno-exceptions
ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
LDFLAGS = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os
# ------------------------------------------------------------------------------
# Source compiling
# ------------------------------------------------------------------------------
$(BUILD_DIR)%.o: %.cc
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
$(BUILD_DIR)%.o: %.s
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
$(BUILD_DIR)%.d: %.cc
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
$(BUILD_DIR)%.d: %.s
$(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
# ------------------------------------------------------------------------------
# Object file conversion
# ------------------------------------------------------------------------------
$(BUILD_DIR)%.hex: $(BUILD_DIR)%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(BUILD_DIR)%.eep: $(BUILD_DIR)%.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex $< $@
$(BUILD_DIR)%.lss: $(BUILD_DIR)%.elf
$(OBJDUMP) -h -S $< > $@
$(BUILD_DIR)%.sym: $(BUILD_DIR)%.elf
$(NM) -n $< > $@
# ------------------------------------------------------------------------------
# AVRDude
# ------------------------------------------------------------------------------
AVRDUDE_CONF = $(AVRLIB_ETC_PATH)avrdude.conf
AVRDUDE_COM_OPTS = -V -p $(DMCU)
AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
AVRDUDE_ISP_OPTS = -c $(PROGRAMMER) -P usb
# ------------------------------------------------------------------------------
# Main targets
# ------------------------------------------------------------------------------
all: $(BUILD_DIR) $(TARGET_HEX)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(TARGET_ELF): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(SYS_OBJS)
$(DEP_FILE): $(BUILD_DIR) $(DEPS)
cat $(DEPS) > $(DEP_FILE)
upload: $(TARGET_HEX)
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
-U flash:w:$(TARGET_HEX):i
clean:
$(REMOVE) $(OBJS) $(TARGETS) $(DEP_FILE) $(DEPS)
depends: $(DEPS)
cat $(DEPS) > $(DEP_FILE)
$(TARGET).size: $(TARGET_ELF)
$(SIZE) $(TARGET_ELF) > $(TARGET).size
$(BUILD_DIR)$(TARGET).top_symbols: $(TARGET_ELF)
$(NM) $(TARGET_ELF) --size-sort -C -f bsd -r > $@
size: $(TARGET).size
cat $(TARGET).size | awk '{ print $$1+$$2 }' | tail -n1 | figlet | cowsay -n -f moose
size_report: build/$(TARGET)/$(TARGET).lss build/$(TARGET)/$(TARGET).top_symbols
.PHONY: all clean depends upload
include $(DEP_FILE)
# ------------------------------------------------------------------------------
# Midi files for firmware update
# ------------------------------------------------------------------------------
HEX2SYSEX = python tools/hex2sysex/hex2sysex.py
$(BUILD_DIR)%.mid: $(BUILD_DIR)%.hex
$(HEX2SYSEX) -o $@ $<
$(BUILD_DIR)%.syx: $(BUILD_DIR)%.hex
$(HEX2SYSEX) --syx -o $@ $<
midi: $(BUILD_DIR)$(TARGET).mid
syx: $(BUILD_DIR)$(TARGET).syx
# ------------------------------------------------------------------------------
# Resources
# ------------------------------------------------------------------------------
RESOURCE_COMPILER = avrlib/tools/resources_compiler.py
resources: $(wildcard $(RESOURCES)/*.py)
python $(RESOURCE_COMPILER) $(RESOURCES)/resources.py
# ------------------------------------------------------------------------------
# Publish a firmware version on the website
# ------------------------------------------------------------------------------
REMOTE_HOST = mutable-instruments.net
REMOTE_USER = shruti
REMOTE_PATH = public_html/static/firmware
publish: $(BUILD_DIR)$(TARGET).mid $(BUILD_DIR)$(TARGET).hex
scp $(BUILD_DIR)$(TARGET).mid $(REMOTE_USER)@$(REMOTE_HOST):$(REMOTE_PATH)/$(TARGET)_$(VERSION).mid
scp $(BUILD_DIR)$(TARGET).hex $(REMOTE_USER)@$(REMOTE_HOST):$(REMOTE_PATH)//$(TARGET)_$(VERSION).hex
scp $(BUILD_DIR)$(TARGET).syx $(REMOTE_USER)@$(REMOTE_HOST):$(REMOTE_PATH)//$(TARGET)_$(VERSION).syx
# ------------------------------------------------------------------------------
# Set fuses
# ------------------------------------------------------------------------------
fuses:
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e -u \
-U lock:w:0x3f:m \
-U efuse:w:0x$(EFUSE):m \
-U hfuse:w:0x$(HFUSE):m \
-U lfuse:w:0x$(LFUSE):m \
-Ulock:w:0x0F:m