-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
292 lines (230 loc) · 11.8 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#******************************************************************************
# Generated by VisualTeensy V1.5.0 on 12.05.2022 at 15:24
#
# Board Teensy 4.0
# USB Type Serial + MIDIx16 + Audio
# CPU Speed 600 MHz
# Optimize Faster
# Keyboard Layout US English
#
# https://github.com/luni64/VisualTeensy
#******************************************************************************
SHELL := cmd.exe
export SHELL
TARGET_NAME := Control-S1
BOARD_ID := TEENSY40
MCU := imxrt1062
LIBS_SHARED_BASE := C:\Users\Mirek\Documents\Arduino\libraries
LIBS_SHARED := Adafruit_GFX_Library Adafruit_BusIO
LIBS_LOCAL_BASE := lib
LIBS_LOCAL := Adafruit_SSD1306 SD Encoder FastLED SdFat SerialFlash SPI Wire Audio Control-Surface
CORE_BASE := cores/teensy4
GCC_BASE := C:\PROGRA~2\Arduino\hardware\tools\arm\bin
UPL_PJRC_B := C:\PROGRA~2\Arduino\hardware\tools
UPL_TYCMD_B := C:\PROGRA~1\TyTools
#******************************************************************************
# Flags and Defines
#******************************************************************************
FLAGS_CPU := -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16
FLAGS_OPT := -O2
FLAGS_COM := -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD
FLAGS_LSP :=
FLAGS_CPP := -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing
FLAGS_C :=
FLAGS_S := -x assembler-with-cpp
FLAGS_LD := -Wl,--print-memory-usage,--gc-sections,--relax -T$(CORE_BASE)/imxrt1062.ld
LIBS := -larm_cortexM7lfsp_math -lm -lstdc++
DEFINES := -D__IMXRT1062__ -DTEENSYDUINO=156 -DARDUINO_TEENSY40 -DARDUINO=10813
DEFINES += -DF_CPU=600000000 -DLAYOUT_US_ENGLISH
ifeq ($(teensyconfig),)
$(warning No Teensy config specified)
$(info Usage: >> make teensyconfig={config})
endif
ifeq ($(teensyconfig), Serial_MIDIx16_Audio)
DEFINES += -DUSB_MIDI16_AUDIO_SERIAL
endif
ifeq ($(teensyconfig), Serial_MIDIx16)
DEFINES += -DUSB_MIDI16_SERIAL
endif
ifeq ($(teensyconfig), Serial_MIDIx4)
DEFINES += -DUSB_MIDI4_SERIAL
endif
ifeq ($(teensyconfig), Serial_MIDI)
DEFINES += -DUSB_MIDI_SERIAL
endif
CPP_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_CPP)
C_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_C)
S_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_S)
LD_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_LSP) $(FLAGS_LD)
AR_FLAGS := rcs
NM_FLAGS := --numeric-sort --defined-only --demangle --print-size
#******************************************************************************
# Colors
#******************************************************************************
COL_CORE := [38;2;187;206;251m
COL_LIB := [38;2;206;244;253m
COL_SRC := [38;2;100;149;237m
COL_LINK := [38;2;255;255;202m
COL_ERR := [38;2;255;159;159m
COL_OK := [38;2;179;255;179m
COL_RESET := [0m
#******************************************************************************
# Folders and Files
#******************************************************************************
USR_SRC := src
LIB_SRC := lib
CORE_SRC := $(CORE_BASE)
BIN := .vsteensy/build
USR_BIN := $(BIN)/src
CORE_BIN := $(BIN)/core
LIB_BIN := $(BIN)/lib
CORE_LIB := $(BIN)/core.a
TARGET_HEX := $(BIN)/$(TARGET_NAME).hex
TARGET_ELF := $(BIN)/$(TARGET_NAME).elf
TARGET_LST := $(BIN)/$(TARGET_NAME).lst
TARGET_SYM := $(BIN)/$(TARGET_NAME).sym
#******************************************************************************
# BINARIES
#******************************************************************************
CC := $(GCC_BASE)/arm-none-eabi-gcc
CXX := $(GCC_BASE)/arm-none-eabi-g++
AR := $(GCC_BASE)/arm-none-eabi-gcc-ar
NM := $(GCC_BASE)/arm-none-eabi-gcc-nm
SIZE := $(GCC_BASE)/arm-none-eabi-size
OBJDUMP := $(GCC_BASE)/arm-none-eabi-objdump
OBJCOPY := $(GCC_BASE)/arm-none-eabi-objcopy
UPL_PJRC := "$(UPL_PJRC_B)/teensy_post_compile" -test -file=$(TARGET_NAME) -path=$(BIN) -tools="$(UPL_PJRC_B)" -board=$(BOARD_ID) -reboot
UPL_TYCMD := $(UPL_TYCMD_B)/tyCommanderC upload $(TARGET_HEX) --autostart --wait --multi
UPL_CLICMD := $(UPL_CLICMD_B)/teensy_loader_cli -mmcu=$(MCU) -v $(TARGET_HEX)
UPL_JLINK := $(UPL_JLINK_B)/jlink -commanderscript .vsteensy/flash.jlink
#******************************************************************************
# Source and Include Files
#******************************************************************************
# Recursively create list of source and object files in USR_SRC and CORE_SRC
# and corresponding subdirectories.
# The function rwildcard is taken from http://stackoverflow.com/a/12959694)
rwildcard =$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
#User Sources -----------------------------------------------------------------
USR_C_FILES := $(call rwildcard,$(USR_SRC)/,*.c)
USR_CPP_FILES := $(call rwildcard,$(USR_SRC)/,*.cpp)
USR_S_FILES := $(call rwildcard,$(USR_SRC)/,*.S)
USR_OBJ := $(USR_S_FILES:$(USR_SRC)/%.S=$(USR_BIN)/%.s.o) $(USR_C_FILES:$(USR_SRC)/%.c=$(USR_BIN)/%.c.o) $(USR_CPP_FILES:$(USR_SRC)/%.cpp=$(USR_BIN)/%.cpp.o)
# Core library sources --------------------------------------------------------
CORE_CPP_FILES := $(call rwildcard,$(CORE_SRC)/,*.cpp)
CORE_C_FILES := $(call rwildcard,$(CORE_SRC)/,*.c)
CORE_S_FILES := $(call rwildcard,$(CORE_SRC)/,*.S)
CORE_OBJ := $(CORE_S_FILES:$(CORE_SRC)/%.S=$(CORE_BIN)/%.s.o) $(CORE_C_FILES:$(CORE_SRC)/%.c=$(CORE_BIN)/%.c.o) $(CORE_CPP_FILES:$(CORE_SRC)/%.cpp=$(CORE_BIN)/%.cpp.o)
# User library sources (see https://github.com/arduino/arduino/wiki/arduino-ide-1.5:-library-specification)
LIB_DIRS_SHARED := $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/ $(LIBS_SHARED_BASE)/$d/utility/) # base and /utility
LIB_DIRS_SHARED += $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_SHARED_BASE)/$d/src/,*/.))) # src and all subdirs of base
LIB_DIRS_LOCAL := $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/ $(LIBS_LOCAL_BASE)/$d/utility/ ) # base and /utility
LIB_DIRS_LOCAL += $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_LOCAL_BASE)/$d/src/,*/.))) # src and all subdirs of base
LIB_CPP_SHARED := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.cpp))
LIB_C_SHARED := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.c))
LIB_S_SHARED := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.S))
LIB_CPP_LOCAL := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.cpp))
LIB_C_LOCAL := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.c))
LIB_S_LOCAL := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.S))
LIB_OBJ := $(LIB_CPP_SHARED:$(LIBS_SHARED_BASE)/%.cpp=$(LIB_BIN)/%.cpp.o) $(LIB_CPP_LOCAL:$(LIBS_LOCAL_BASE)/%.cpp=$(LIB_BIN)/%.cpp.o)
LIB_OBJ += $(LIB_C_SHARED:$(LIBS_SHARED_BASE)/%.c=$(LIB_BIN)/%.c.o) $(LIB_C_LOCAL:$(LIBS_LOCAL_BASE)/%.c=$(LIB_BIN)/%.c.o)
LIB_OBJ += $(LIB_S_SHARED:$(LIBS_SHARED_BASE)/%.S=$(LIB_BIN)/%.s.o) $(LIB_S_LOCAL:$(LIBS_LOCAL_BASE)/%.S=$(LIB_BIN)/%.s.o)
# Includes -------------------------------------------------------------
INCLUDE := -I./include -I./$(USR_SRC) -I$(CORE_SRC)
INCLUDE += $(foreach d, $(LIBS_LOCAL),-I$(LIBS_LOCAL_BASE)/$d/ -I$(LIBS_LOCAL_BASE)/$d/src -I$(LIBS_LOCAL_BASE)/$d/utility/)
INCLUDE += $(foreach d, $(LIBS_SHARED), -I$(LIBS_SHARED_BASE)/$d/ -I$(LIBS_SHARED_BASE)/$d/src -I$(LIBS_SHARED_BASE)/$d/utility/)
# Generate directories --------------------------------------------------------
DIRECTORIES := $(sort $(dir $(CORE_OBJ) $(USR_OBJ) $(LIB_OBJ)))
generateDirs := $(foreach d, $(DIRECTORIES), $(shell if not exist "$d" mkdir "$d"))
#$(info dirs: $(DIRECTORIES))
#******************************************************************************
# Rules:
#******************************************************************************
.PHONY: directories all rebuild upload uploadTy uploadCLI clean cleanUser cleanCore
all: $(TARGET_LST) $(TARGET_SYM) $(TARGET_HEX)
rebuild: cleanUser all
clean: cleanUser cleanCore cleanLib
@echo $(COL_OK)cleaning done$(COL_RESET)
upload: all
@$(UPL_PJRC)
uploadTy: all
@$(UPL_TYCMD)
uploadCLI: all
@$(UPL_CLICMD)
uploadJLink: all
@$(UPL_JLINK)
# Core library ----------------------------------------------------------------
$(CORE_BIN)/%.s.o: $(CORE_SRC)/%.S
@echo $(COL_CORE)CORE [ASM] $(notdir $<) $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(CORE_BIN)/%.c.o: $(CORE_SRC)/%.c
@echo $(COL_CORE)CORE [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<
$(CORE_BIN)/%.cpp.o: $(CORE_SRC)/%.cpp
@echo $(COL_CORE)CORE [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<
$(CORE_LIB) : $(CORE_OBJ)
@echo $(COL_LINK)CORE [AR] $@ $(COL_ERR)
@$(AR) $(AR_FLAGS) $@ $^
@echo $(COL_OK)Teensy core built successfully &&echo.
# Shared Libraries ------------------------------------------------------------
$(LIB_BIN)/%.s.o: $(LIBS_SHARED_BASE)/%.S
@echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.cpp.o: $(LIBS_SHARED_BASE)/%.cpp
@echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.c.o: $(LIBS_SHARED_BASE)/%.c
@echo $(COL_LIB)LIB [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<
# Local Libraries -------------------------------------------------------------
$(LIB_BIN)/%.s.o: $(LIBS_LOCAL_BASE)/%.S
@echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.cpp.o: $(LIBS_LOCAL_BASE)/%.cpp
@echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.c.o: $(LIBS_LOCAL_BASE)/%.c
@echo $(COL_LIB)LIB [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<
# Handle user sources ---------------------------------------------------------
$(USR_BIN)/%.s.o: $(USR_SRC)/%.S
@echo $(COL_SRC)USER [ASM] $< $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o "$@" -c $<
$(USR_BIN)/%.c.o: $(USR_SRC)/%.c
@echo $(COL_SRC)USER [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o "$@" -c $<
$(USR_BIN)/%.cpp.o: $(USR_SRC)/%.cpp
@echo $(COL_SRC)USER [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o "$@" -c $<
# Linking ---------------------------------------------------------------------
$(TARGET_ELF): $(CORE_LIB) $(LIB_OBJ) $(USR_OBJ)
@echo $(COL_LINK)
@echo [LD] $@ $(COL_ERR)
@$(CC) $(LD_FLAGS) -o "$@" $(USR_OBJ) $(LIB_OBJ) $(CORE_LIB) $(LIBS)
@echo $(COL_OK)User code built and linked to libraries &&echo.
%.lst: %.elf
@echo [LST] $@
@$(OBJDUMP) -d -S --demangle --no-show-raw-insn "$<" > "$@"
@echo $(COL_OK)Sucessfully built project$(COL_RESET) &&echo.
%.sym: %.elf
@echo [SYM] $@
@$(NM) $(NM_FLAGS) "$<" > "$@"
%.hex: %.elf
@echo $(COL_LINK)[HEX] $@
@$(OBJCOPY) -O ihex -R.eeprom "$<" "$@"
# Cleaning --------------------------------------------------------------------
cleanUser:
@echo $(COL_LINK)Cleaning user binaries...$(COL_RESET)
@if exist $(USR_BIN) rd /s/q "$(USR_BIN)"
@if exist "$(TARGET_LST)" del $(subst /,\,$(TARGET_LST))
cleanCore:
@echo $(COL_LINK)Cleaning core binaries...$(COL_RESET)
@if exist $(CORE_BIN) rd /s/q "$(CORE_BIN)"
@if exist $(CORE_LIB) del $(subst /,\,$(CORE_LIB))
cleanLib:
@echo $(COL_LINK)Cleaning user library binaries...$(COL_RESET)
@if exist $(LIB_BIN) rd /s/q "$(LIB_BIN)"
# compiler generated dependency info ------------------------------------------
-include $(CORE_OBJ:.o=.d)
-include $(USR_OBJ:.o=.d)
-include $(LIB_OBJ:.o=.d)