-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
276 lines (215 loc) · 11.4 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
#******************************************************************************
# Generated by VisualTeensy (https://github.com/luni64/VisualTeensy)
#
# Board Teensy LC
# USB Type Serial
# CPU Speed 48 MHz
# Optimize Smallest Code
# Keyboard Layout German
#
#******************************************************************************
SHELL := cmd.exe
export SHELL
TARGET_NAME := Teensy-StackMat-LED
BOARD_ID := TEENSYLC
MCU := mkl26z64
LIBS_SHARED_BASE := C:\Users\mgr\Documents\Arduino\libraries
LIBS_SHARED :=
LIBS_LOCAL_BASE := lib
LIBS_LOCAL :=
CORE_BASE := C:\PROGRA~2\Arduino\hardware\teensy\avr\cores\teensy3
GCC_BASE := C:\PROGRA~2\Arduino\hardware\tools\arm\bin
UPL_PJRC_B := C:\PROGRA~2\Arduino\hardware\tools
UPL_TYCMD_B := C:\Hardware\Teensy\TyTools-0.9.2-win64
#******************************************************************************
# Flags and Defines
#******************************************************************************
FLAGS_CPU := -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant
FLAGS_OPT := -Os --specs=nano.specs
FLAGS_COM := -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD
FLAGS_LSP :=
FLAGS_CPP := -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti
FLAGS_C :=
FLAGS_S := -x assembler-with-cpp
FLAGS_LD := -Wl,--print-memory-usage,--gc-sections,--relax,--defsym=__rtc_localtime=$(shell powershell [int](Get-Date -UFormat +%s)[0]) -T$(CORE_BASE)/mkl26z64.ld
LIBS := -larm_cortexM0l_math -lm -lstdc++
DEFINES := -D__MKL26Z64__ -DTEENSYDUINO=153 -DARDUINO_TEENSYLC -DARDUINO=10807
DEFINES += -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_GERMAN
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
#******************************************************************************
# 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/$(TARGET_NAME)
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
#******************************************************************************
# BINARIES
#******************************************************************************
CC := $(GCC_BASE)/arm-none-eabi-gcc
CXX := $(GCC_BASE)/arm-none-eabi-g++
AR := $(GCC_BASE)/arm-none-eabi-gcc-ar
OBJCOPY := $(GCC_BASE)/arm-none-eabi-objcopy
SIZE := $(GCC_BASE)/arm-none-eabi-size
OBJDUMP := $(GCC_BASE)/arm-none-eabi-objdump
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_INO_FILES := $(call rwildcard,$(USR_SRC)/,*.ino)
USR_OBJ := $(USR_S_FILES:$(USR_SRC)/%.S=$(USR_BIN)/%.o) $(USR_C_FILES:$(USR_SRC)/%.c=$(USR_BIN)/%.o) $(USR_CPP_FILES:$(USR_SRC)/%.cpp=$(USR_BIN)/%.o)
USR_OBJ += $(USR_INO_FILES:$(USR_SRC)/%.ino=$(USR_BIN)/%.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)/%.o) $(CORE_C_FILES:$(CORE_SRC)/%.c=$(CORE_BIN)/%.o) $(CORE_CPP_FILES:$(CORE_SRC)/%.cpp=$(CORE_BIN)/%.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)/%.o) $(LIB_CPP_LOCAL:$(LIBS_LOCAL_BASE)/%.cpp=$(LIB_BIN)/%.o)
LIB_OBJ += $(LIB_C_SHARED:$(LIBS_SHARED_BASE)/%.c=$(LIB_BIN)/%.o) $(LIB_C_LOCAL:$(LIBS_LOCAL_BASE)/%.c=$(LIB_BIN)/%.o)
LIB_OBJ += $(LIB_S_SHARED:$(LIBS_SHARED_BASE)/%.S=$(LIB_BIN)/%.o) $(LIB_S_LOCAL:$(LIBS_LOCAL_BASE)/%.S=$(LIB_BIN)/%.o)
# Includes -------------------------------------------------------------
INCLUDE := -I./$(USR_SRC) -I$(CORE_SRC)
INCLUDE += $(foreach d, $(LIB_DIRS_SHARED), -I$d)
INCLUDE += $(foreach d, $(LIB_DIRS_LOCAL), -I$d)
# 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))
$(info$(COL_RESET))
#******************************************************************************
# Rules:
#******************************************************************************
.PHONY: directories all rebuild upload uploadTy uploadCLI clean cleanUser cleanCore
all: $(TARGET_LST) $(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)/%.o: $(CORE_SRC)/%.S
@echo $(COL_CORE)CORE [ASM] $(notdir $<) $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(CORE_BIN)/%.o: $(CORE_SRC)/%.c
@echo $(COL_CORE)CORE [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<
$(CORE_BIN)/%.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)/%.o: $(LIBS_SHARED_BASE)/%.S
@echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.cpp
@echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.c
@echo $(COL_LIB)LIB [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<
# Local Libraries -------------------------------------------------------------
$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.S
@echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.cpp
@echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<
$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.c
@echo $(COL_LIB)LIB [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<
# Handle user sources ---------------------------------------------------------
$(USR_BIN)/%.o: $(USR_SRC)/%.S
@echo $(COL_SRC)USER [ASM] $< $(COL_ERR)
@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<
$(USR_BIN)/%.o: $(USR_SRC)/%.c
@echo $(COL_SRC)USER [CC] $(notdir $<) $(COL_ERR)
@"$(CC)" $(C_FLAGS) $(INCLUDE) -o "$@" -c $<
$(USR_BIN)/%.o: $(USR_SRC)/%.cpp
@echo $(COL_SRC)USER [CPP] $(notdir $<) $(COL_ERR)
@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o "$@" -c $<
$(USR_BIN)/%.o: $(USR_SRC)/%.ino
@echo $(COL_SRC)USER [INO] $< $(COL_ERR)
@"$(CC)" $(CPP_FLAGS) $(INCLUDE) -x c++ -o $@ -c $< -x none
# 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 $(COL_LINK)
@echo [LST] $@ $(COL_ERR)
@$(OBJDUMP) -d -S --demangle --no-show-raw-insn --syms "$<" > "$@"
@echo $(COL_OK)Sucessfully built project$(COL_RESET) &&echo.
%.hex: %.elf
@echo $(COL_LINK)[HEX] $@
# @$(SIZE) "$<"
@$(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)