forked from kammce/SJSU-Dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
188 lines (157 loc) · 5.44 KB
/
makefile
File metadata and controls
188 lines (157 loc) · 5.44 KB
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
# Allow settiing a project name from the environment, default to firmware.
# Only affects the name of the generated binary.
# TODO: Set this from the directory this makefile is stored in
PROJ ?= firmware
# Affects what DBC is generated for SJSUOne board
ENTITY ?= DBG
# IMPORTANT: Must be accessible via the PATH variable!!!
CC = arm-none-eabi-gcc
CPPC = arm-none-eabi-g++
OBJDUMP = arm-none-eabi-objdump
SIZEC = arm-none-eabi-size
OBJCOPY = arm-none-eabi-objcopy
NM = arm-none-eabi-nm
# Internal build directories
OBJ_DIR = obj
BIN_DIR = bin
DBC_DIR = _can_dbc
define n
endef
ifndef SJSUONEDEV
$(error $n$n=============================================$nSJSUOne environment variables not set.$nPLEASE run "source env.sh"$n=============================================$n$n)
endif
CFLAGS = -mcpu=cortex-m3 \
-D DISABLE_WATCHDOG\
-mthumb -g -Os -fmessage-length=0 \
-ffunction-sections -fdata-sections \
-Wall -Wshadow -Wlogical-op \
-Wfloat-equal -DBUILD_CFG_MPU=0 \
-fabi-version=0 \
-fno-exceptions \
-I"$(LIB_DIR)/" \
-I"$(LIB_DIR)/newlib" \
-I"$(LIB_DIR)/L0_LowLevel" \
-I"$(LIB_DIR)/L1_FreeRTOS" \
-I"$(LIB_DIR)/L1_FreeRTOS/trace" \
-I"$(LIB_DIR)/L1_FreeRTOS/include" \
-I"$(LIB_DIR)/L1_FreeRTOS/portable" \
-I"$(LIB_DIR)/L1_FreeRTOS/portable/no_mpu" \
-I"$(LIB_DIR)/L2_Drivers" \
-I"$(LIB_DIR)/L2_Drivers/base" \
-I"$(LIB_DIR)/L3_Utils" \
-I"$(LIB_DIR)/L3_Utils/tlm" \
-I"$(LIB_DIR)/L4_IO" \
-I"$(LIB_DIR)/L4_IO/fat" \
-I"$(LIB_DIR)/L4_IO/wireless" \
-I"$(LIB_DIR)/L5_Application" \
-I"L2_Drivers" \
-I"L3_Utils" \
-I"L4_IO" \
-I"L5_Application" \
-I"$(DBC_DIR)" \
-MMD -MP -c
LINKFLAGS = -mcpu=cortex-m3 \
-Os -mthumb \
-fmessage-length=0 -ffunction-sections -fdata-sections \
-Wall -Wshadow -Wlogical-op -Wfloat-equal \
-T $(LIB_DIR)/loader.ld \
-nostartfiles \
-Xlinker \
--gc-sections -Wl,-Map,"$(MAP)" \
-specs=nano.specs
DBCBUILD = $(DBC_DIR)/generated_can.h
LIBRARIES = $(shell find "$(LIB_DIR)" -name '*.c' -o -name '*.cpp')
SOURCES = $(shell find . -name '*.c' -o -name '*.cpp' -not -path './test/*')
COMPILABLES = $(LIBRARIES) $(SOURCES)
# $(patsubst %.cpp,%.o, LIST) : Replace .cpp -> .o
# $(patsubst %.c,%.o, LIST) : Replace .c -> .o
# $(patsubst src/%,%, LIST) : Replace src/path/file.o -> path/file.o
# $(addprefix $(OBJ_DIR)/, LIST) : Add OBJ DIR to path (path/file.o -> obj/path/file.o)
OBJECT_FILES = $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(COMPILABLES))))
EXECUTABLE = $(BIN_DIR)/$(PROJ).elf
HEX = $(EXECUTABLE:.elf=.hex)
LIST = $(EXECUTABLE:.elf=.lst)
SIZE = $(EXECUTABLE:.elf=.siz)
MAP = $(EXECUTABLE:.elf=.map)
SYMBOLS = $(EXECUTABLE:.elf=.sym)
.PHONY: default build clean flash telemetry cleaninstall
default:
@echo "List of available targets:"
@echo " build - builds firmware project"
@echo " flash - builds and installs firmware on to SJOne board"
@echo " telemetry - will launch telemetry interface"
@echo " clean - cleans project folder"
@echo " cleaninstall - cleans, builds and installs firmware"
build: $(DBC_DIR) $(OBJ_DIR) $(BIN_DIR) $(SIZE) $(LIST) $(HEX) $(SYMBOLS)
cleaninstall: clean build flash
print-% : ; @echo $* = $($*)
$(SYMBOLS): $(EXECUTABLE)
@echo 'Invoking: Cross ARM GNU NM Generate Symbol Table'
@$(NM) -C "$<" > "$@"
@echo 'Finished building: $@'
@echo ' '
$(HEX): $(EXECUTABLE)
@echo 'Invoking: Cross ARM GNU Create Flash Image'
@$(OBJCOPY) -O ihex "$<" "$@"
@echo 'Finished building: $@'
@echo ' '
$(SIZE): $(EXECUTABLE)
@echo 'Invoking: Cross ARM GNU Print Size'
@$(SIZEC) --format=berkeley "$<"
@echo 'Finished building: $@'
@echo ' '
$(LIST): $(EXECUTABLE)
@echo 'Invoking: Cross ARM GNU Create Listing'
@$(OBJDUMP) --source --all-headers --demangle --line-numbers --wide "$<" > "$@"
@echo 'Finished building: $@'
@echo ' '
$(EXECUTABLE): $(DBCBUILD) $(OBJECT_FILES)
@echo 'Invoking: Cross ARM C++ Linker'
@mkdir -p "$(dir $@)"
@$(CPPC) $(LINKFLAGS) -o "$@" $(OBJECT_FILES)
@echo 'Finished building target: $@'
@echo ' '
$(OBJ_DIR)/%.o: %.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cross ARM C++ Compiler'
@mkdir -p "$(dir $@)"
@$(CPPC) $(CFLAGS) -std=gnu++17 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: %.c
@echo 'Building file: $<'
@echo 'Invoking: Cross ARM C Compiler'
@mkdir -p "$(dir $@)"
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cross ARM C++ Compiler'
@mkdir -p "$(dir $@)"
@$(CPPC) $(CFLAGS) -std=gnu++17 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.c
@echo 'Building file: $<'
@echo 'Invoking: Cross ARM C Compiler'
@mkdir -p "$(dir $@)"
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(DBCBUILD):
python "$(LIB_DIR)/$(DBC_DIR)/dbc_parse.py" -i "$(LIB_DIR)/$(DBC_DIR)/243.dbc" -s $(ENTITY) > $(DBCBUILD)
$(DBC_DIR):
mkdir -p $(DBC_DIR)
$(OBJ_DIR):
@echo 'Creating Objects Folder: $<'
mkdir $(OBJ_DIR)
$(BIN_DIR):
@echo 'Creating Binary Folder: $<'
mkdir $(BIN_DIR)
clean:
rm -fR $(OBJ_DIR) $(BIN_DIR) $(DBC_DIR)
flash: build
hyperload $(SJSUONEDEV) $(HEX)
telemetry:
@telemetry