-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (134 loc) · 4.71 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
# Teensy 3.2
MCU = MK20DX256
LOWER_MCU = mk20dx256
CPUARCH = cortex-m4
# project name for hex file
TARGET = main
# configurable options + + +
#************************************************************************
#OPTIONS = -DF_CPU=144000000
OPTIONS = -DF_CPU=120000000
# usb_desc.h : USB_HID USB_KEYBOARDONLY
OPTIONS += -DUSB_HID -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE
# options needed by many Arduino libraries to configure for Teensy 3.x
OPTIONS += -D__$(MCU)__ -DARDUINO=10805 -DTEENSYDUINO=141
# PATHS
#************************************************************************
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
COMPILERPATH ?= /usr/bin
E =
else
COMPILERPATH ?= /usr/local/bin
E = -e
endif
# source subdirs 3
SRCDIR = t3
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
#************************************************************************
ARCH = -mcpu=$(CPUARCH) -mthumb -MMD
WARN = -Wall -g
OPT = -O3 -Wno-misleading-indentation
# compiler options for C only
CFLAGS = $(WARN) $(OPT) $(ARCH) $(OPTIONS)
# compiler options for C++ only
CXXFLAGS = $(WARN) $(OPT) $(ARCH) -std=gnu++14 -felide-constructors -fno-exceptions -fno-rtti $(OPTIONS)
# linker options
LDFLAGS = -Os -Wl,--gc-sections,--defsym=__rtc_localtime=0 --specs=nano.specs -mcpu=$(CPUARCH) -mthumb -T$(MCU_LD)
LIBS = -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)
fanc: $(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 $< 65536 " SRAM"
@./sizeCalc $(SIZE) flash $< 262144 Flash
$(OBJCOPY) -O ihex -R .eeprom $< $@
# 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 -j
m:
@make -j --no-print-directory