-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
202 lines (155 loc) · 5.66 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
# Teensy 4.0
MCU = IMXRT1062
LOWER_MCU = imxrt1062
CPUARCH = cortex-m7
# project name for hex file
TARGET = main
# compiler OPTIONS
OPTIONS = -DF_CPU=600000000 # CPU Freq default
#OPTIONS = -DF_CPU=960000000 # OC, need heatsink
OPTIONS += -DUSB_HID -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE -DMOUSE_INTERFACE # -DUSB_SERIAL
# options needed by many Arduino libraries to configure for Teensy 4.0
OPTIONS += -D__$(MCU)__ -DARDUINO=10810 -DTEENSYDUINO=149 -DARDUINO_TEENSY40
# COMPILER PATHS
#************************************************************************
UNAME := $(shell uname)
# SET your own path or comment out
ARDUINOPATH ?= /home/ch/_el/arduino-1.8.19
ifdef ARDUINOPATH
# path location for Teensy Loader, teensy_post_compile and teensy_reboot (on Linux)
TOOLSPATH = $(abspath $(ARDUINOPATH)/hardware/tools)
# path location for Arduino libraries (currently not used)
LIBRARYPATH = $(abspath $(ARDUINOPATH)/libraries)
# path location for the arm-none-eabi compiler
COMPILERPATH = $(abspath $(ARDUINOPATH)/hardware/tools/arm/bin)
else
ifeq ($(UNAME), Linux)
COMPILERPATH ?= /usr/bin
E =
else # cygwin
COMPILERPATH ?= /usr/local/bin
E = -e
endif
endif
# PATHS
#************************************************************************
# source subdirs 3
SRCDIR = t4
SRCLIB = lib
SRCKC = kc
# output dirs
OBJDIR = obj
BINDIR = bin
PROJECT = main
INC = -I$(SRCDIR) -I$(SRCLIB) -I$(SRCKC)
MCU_LD = $(SRCDIR)/$(LOWER_MCU).ld
# FLAGS
#************************************************************************
WARN = -Wno-cpp -g
OPT = -O3 -ffunction-sections -fdata-sections -fno-exceptions
# Cortex M7 with single & double precision FPU
ARCH = -mcpu=$(CPUARCH) -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb
# compiler options for C only
CFLAGS = $(WARN) $(OPT) $(ARCH) $(OPTIONS) -std=gnu11
# compiler options for C++ only -Wno-error=narrowing
CXXFLAGS = $(WARN) $(OPT) $(ARCH) -MMD -std=gnu++14 -felide-constructors -fno-rtti $(OPTIONS)
# linker options --defsym=__rtc_localtime=0 --specs=nano.specs
LDFLAGS = -Os -Wl,--gc-sections,--relax --specs=nano.specs $(ARCH) -T$(MCU_LD)
LIBS = -larm_cortexM7lfsp_math -lm -lstdc++
# compiler programs
CC_ = $(COMPILERPATH)/arm-none-eabi-gcc
CXX_ = $(COMPILERPATH)/arm-none-eabi-g++
CC = @$(CC_)
CXX = @$(CC_)
OBJCOPY = @$(COMPILERPATH)/arm-none-eabi-objcopy
SIZE = $(COMPILERPATH)/arm-none-eabi-size
# auto create lists of sources and objects
C_FILES := $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCLIB)/*.c) $(wildcard $(SRCKC)/*.c)
CPP_FILES := $(wildcard $(SRCDIR)/*.cpp) $(wildcard $(SRCLIB)/*.cpp) $(wildcard $(SRCKC)/*.cpp)
OBJ_FILES := $(addprefix $(OBJDIR)/,$(notdir $(CPP_FILES:.cpp=.o))) $(addprefix $(OBJDIR)/,$(notdir $(C_FILES:.c=.o)))
# util, color errors and warnings
#************************************************************************
# "\e[38;5;27m 21 57v 63bv 27 33 39 45 bl 212 pink
# yl 226 220 or 166 196 red 40 grn 51 cy 90 154 ylgrn
# @mkdir -p $(dir $@) ?
CC_CLR = \e[38;5;33m
CXX_CLR = \e[38;5;39m
ERR_CLR = \e[38;5;202m
WARN_CLR = \e[33m
OBJ_CLR = \e[38;5;248m
NORM_CLR = \e[38;5;249m
NO_CLR = \033[m
ST_CLR = \e[38;5;51m
ifeq ($(UNAME), Linux)
COLOR_OUTPUT =
else
COLOR_OUTPUT = 2>&1 | \
while IFS='' read -r line; do \
if [[ $$line == *:[\ ]error:* ]]; then \
echo $(E) "$(ERR_CLR)$${line}$(NO_CLR)"; \
elif [[ $$line == *:[\ ]warning:* ]]; then \
echo $(E) "$(WARN_CLR)$${line}$(NO_CLR)"; \
else \
echo $(E) "$(NORM_CLR)$${line}$(NO_CLR)"; \
fi; \
done; exit $${PIPESTATUS[0]};
endif
# BUILD
#************************************************************************
# test
#phony:
# echo $(COMPILERPATH)
kc: $(BINDIR)/$(PROJECT).hex
# C compilation
$(OBJDIR)/%.o : $(SRCKC)/%.c
@echo $(E) "$(CC_CLR) CC\e[m" $<
$(CC) $(CFLAGS) $(INC) -c $< -o $@ $(COLOR_OUTPUT)
$(OBJDIR)/%.o : $(SRCLIB)/%.c
@echo $(E) "$(CC_CLR) CC\e[m" $<
$(CC) $(CFLAGS) $(INC) -c $< -o $@ $(COLOR_OUTPUT)
$(OBJDIR)/%.o : $(SRCDIR)/%.c
@echo $(E) "$(CC_CLR) CC\e[m" $<
$(CC) $(CFLAGS) $(INC) -c $< -o $@ $(COLOR_OUTPUT)
# C++ compilation
$(OBJDIR)/%.o : $(SRCKC)/%.cpp
@echo $(E) "$(CXX_CLR) CXX\e[m" $<
$(CXX) $(CXXFLAGS) $(INC) -c $< -o $@ $(COLOR_OUTPUT)
$(OBJDIR)/%.o : $(SRCLIB)/%.cpp
@echo $(E) "$(CXX_CLR) CXX\e[m" $<
$(CXX) $(CXXFLAGS) $(INC) -c $< -o $@ $(COLOR_OUTPUT)
$(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@echo $(E) "$(CXX_CLR) CXX\e[m" $<
$(CXX) $(CXXFLAGS) $(INC) -c $< -o $@ $(COLOR_OUTPUT)
# Linker invocation
$(BINDIR)/$(PROJECT).elf: $(OBJ_FILES) $(MCU_LD)
@echo $(E) "\e[38;5;154m Linking \e[m"
$(CC) $(LDFLAGS) -o $@ $(OBJ_FILES) $(LIBS)
# Hex, last
$(BINDIR)/$(PROJECT).hex : $(BINDIR)/$(PROJECT).elf
# $(SIZE) $<
@./sizeCalc $(SIZE) ram $< 524288 " SRAM"
@./sizeCalc $(SIZE) flash $< 2031616 Flash
$(OBJCOPY) -O ihex -R .eeprom $< $@
# Upload after build, good for one tennsy
# Comment out to use teensy loader and program button
@echo $(E) "$(ST_CLR)Upload$(NO_CLR)"
ifneq (,$(wildcard $(TOOLSPATH)))
@$(TOOLSPATH)/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(TOOLSPATH)
# Comment out if using only one Teensy, else have to press reset button to program
# @$(TOOLSPATH)/teensy_reboot
endif
@echo $(E) "$(ST_CLR) $(NO_CLR)"
# SHORTCUTS
#************************************************************************
#clean:
c:
@echo $(E) "$(ST_CLR)Clean$(NO_CLR)"
rm -f $(OBJDIR)/*.o $(OBJDIR)/*.d $(BINDIR)/$(PROJECT).elf $(BINDIR)/$(PROJECT).hex
#rebuild:
r:
@make c --no-print-directory
@echo $(E) "$(ST_CLR)Rebuild$(NO_CLR)"
@make m --no-print-directory
#make 8 threads
m:
@make -j8 --no-print-directory