-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
253 lines (201 loc) Β· 6.68 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
# Mbed CMake Template
# Copyright 2020 Ladislas de Toldi (ladislas [at] detoldi.me)
# SPDX-License-Identifier: Apache-2.0
#
# MARK: - Constants
#
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CMAKE_DIR := $(ROOT_DIR)/cmake
MBED_OS_DIR := $(ROOT_DIR)/extern/mbed-os
PROJECT_BUILD_DIR := $(ROOT_DIR)/_build
#
# MARK: - Arguments
#
PORT ?= /dev/tty.usbmodem14303
BRANCH ?= $(shell cat $(ROOT_DIR)/.mbed_version)
VERSION ?= $(shell cat $(ROOT_DIR)/.mbed_version)
BAUDRATE ?= 115200
BUILD_TYPE ?= Release
TARGET_BOARD ?= DISCO_F769NI
CODE_ANALYSIS ?= OFF
#
# MARK: - Build dirs
#
CMAKE_CONFIG_DIR := $(PROJECT_BUILD_DIR)/cmake_config
TARGET_BUILD_DIR := $(PROJECT_BUILD_DIR)/${TARGET_BOARD}
UNIT_TESTS_BUILD_DIR := $(ROOT_DIR)/_build_unit_tests
UNIT_TESTS_COVERAGE_DIR := $(UNIT_TESTS_BUILD_DIR)/_coverage
#
# MARK: - .bin path
#
BIN_PATH ?= $(TARGET_BUILD_DIR)/src/main_project.bin
#
# MARK: - Build targets
#
.PHONY: spikes tests config
all:
@echo ""
@echo "ποΈ Building everything! π"
cmake --build $(TARGET_BUILD_DIR)
spikes:
@echo ""
@echo "ποΈ Building spikes π±"
cmake --build $(TARGET_BUILD_DIR) -t spikes
tests_functional:
@echo ""
@echo "ποΈ Building functional tests βοΈ"
cmake --build $(TARGET_BUILD_DIR) -t tests_functional
#
# MARK: - Config targets
#
config:
@$(MAKE) config_target
@$(MAKE) config_cmake
clean:
@$(MAKE) rm_build
clean_config:
@$(MAKE) rm_build
@$(MAKE) rm_config
@$(MAKE) config
config_target: mkdir_config
@echo ""
@echo "π Running configuration script for target $(TARGET_BOARD) π"
python3 $(CMAKE_DIR)/scripts/configure_cmake_for_target.py $(TARGET_BOARD) -p $(PROJECT_BUILD_DIR)/cmake_config/$(TARGET_BOARD) -a $(ROOT_DIR)/mbed_app.json
config_cmake: mkdir_build
@echo ""
@echo "π Running cmake configuration script for target $(TARGET_BOARD) π"
@cmake -S . -B $(TARGET_BUILD_DIR) -GNinja -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_CODE_ANALYSIS=$(CODE_ANALYSIS)
#
# MARK: - Tests targets
#
ut:
@$(MAKE) unit_tests
@$(MAKE) coverage
unit_tests:
@$(MAKE) build_unit_tests
@$(MAKE) run_unit_tests
coverage:
@echo ""
@echo "π¬ Generating code coverage π"
@gcovr -r . -e tests/unit/mbed-os -e googletest -e $(UNIT_TESTS_BUILD_DIR) --html-details $(UNIT_TESTS_COVERAGE_DIR)/coverage.html
@echo "π Html report can be viewed with:"
@echo " open $(UNIT_TESTS_COVERAGE_DIR)/coverage.html\n"
@gcovr -r . --exclude-directories '.*googletest.*' --exclude-directories '.*mbed-os.*' --exclude-directories '.*template.*' -e '.*gtest.*'
coverage_json:
@echo ""
@echo "π¬ Generating code coverage in json π"
@gcovr -r . -e tests/unit/mbed-os -e googletest -e $(UNIT_TESTS_BUILD_DIR) --json > $(UNIT_TESTS_COVERAGE_DIR)/coverage.json
@echo "π Json report is available at: $(UNIT_TESTS_COVERAGE_DIR)/coverage.json π"
coverage_lcov:
@echo ""
@echo "π¬ Generating code coverage using lcov π"
@mkdir -p $(UNIT_TESTS_COVERAGE_DIR)
@lcov --capture --directory . --output-file $(UNIT_TESTS_COVERAGE_DIR)/_tmp_coverage.info
@lcov --remove $(UNIT_TESTS_COVERAGE_DIR)/_tmp_coverage.info '*googletest*' '*v1*' '*Xcode*' '*CommandLineTools*' '*tests/unit*' -o $(UNIT_TESTS_COVERAGE_DIR)/coverage.info
view_coverage:
@echo ""
@echo "π¬ Opening code coverage in browser π"
@open $(UNIT_TESTS_COVERAGE_DIR)/coverage.html
build_unit_tests:
@echo ""
@echo "ποΈ Building unit tests π§ͺ"
cmake --build $(UNIT_TESTS_BUILD_DIR)
run_unit_tests:
@echo ""
@echo "πββοΈ Running unit tests π§ͺ"
@$(UNIT_TESTS_BUILD_DIR)/MbedCMakeTemplateUnitTestsExec
config_unit_tests: mkdir_build_unit_tests
@echo ""
@echo "π Running unit tests cmake configuration script π"
cmake -S ./tests/unit -B $(UNIT_TESTS_BUILD_DIR) -GNinja -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=True
clean_unit_tests:
@$(MAKE) rm_unit_tests
rm_unit_tests:
@echo ""
@echo "β οΈ Cleaning up unit tests build directories π§Ή"
rm -rf $(UNIT_TESTS_BUILD_DIR)
#
# MARK: - Tools targets
#
clang_format:
@echo ""
@echo "πββοΈ Running clang-format π¨"
python3 tools/run-clang-format.py -r --extension=h,c,cpp --color=always --style=file .
clang_format_fix:
@echo ""
@echo "πββοΈ Running clang-format & fixing files π¨"
python3 tools/run-clang-format.py -r --extension=h,c,cpp --color=always --style=file . -i
code_analysis: mkdir_build
@echo ""
@echo "πββοΈ Running cppcheck code analysis π¬"
@mkdir -p $(PROJECT_BUILD_DIR)/cppcheck
cmake -S . -B $(PROJECT_BUILD_DIR)/cppcheck -GNinja -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_CODE_ANALYSIS=ON
cmake --build $(PROJECT_BUILD_DIR)/cppcheck
#
# MARK: - Mbed targets
#
mbed_clone:
@echo ""
@echo "𧬠Cloning Mbed OS π¦"
@rm -rf $(MBED_OS_DIR)
git clone --depth=1 --branch=$(BRANCH) https://github.com/ARMmbed/mbed-os $(MBED_OS_DIR)
@$(MAKE) mbed_symlink_files
mbed_curl:
@echo ""
@echo "𧬠Curling Mbed OS π¦"
@rm -rf $(MBED_OS_DIR)
@mkdir -p $(MBED_OS_DIR)
curl -O -L https://github.com/ARMmbed/mbed-os/archive/$(VERSION).tar.gz
tar -xzf $(VERSION).tar.gz --strip-components=1 -C extern/mbed-os
rm -rf $(VERSION).tar.gz
@$(MAKE) mbed_symlink_files
mbed_symlink_files:
@echo ""
@echo "π Symlinking templates to Mbed OS directory ποΈ"
ln -srf $(CMAKE_DIR)/templates/Template_MbedOS_CMakelists.txt $(MBED_OS_DIR)/CMakeLists.txt
ln -srf $(CMAKE_DIR)/templates/Template_MbedOS_mbedignore.txt $(MBED_OS_DIR)/.mbedignore
#
# MARK: - Utils targets
#
mkdir_build:
@mkdir -p $(TARGET_BUILD_DIR)
mkdir_config:
@mkdir -p $(CMAKE_CONFIG_DIR)/$(TARGET_BOARD)
mkdir_build_unit_tests:
@mkdir -p $(UNIT_TESTS_BUILD_DIR)
@mkdir -p $(UNIT_TESTS_COVERAGE_DIR)
rm_build:
@echo ""
@echo "β οΈ Cleaning up $(TARGET_BOARD) build directory π§Ή"
rm -rf $(TARGET_BUILD_DIR)
rm_build_all:
@echo ""
@echo "β οΈ Cleaning up all build directories π§Ή"
rm -rf $(PROJECT_BUILD_DIR)
rm_config:
@echo ""
@echo "β οΈ Cleaning up $(TARGET_BOARD) cmake_config directory π§Ή"
rm -rf $(CMAKE_CONFIG_DIR)/$(TARGET_BOARD)
deep_clean:
@$(MAKE) rm_build_all
@$(MAKE) rm_unit_tests
ccache_prebuild:
@echo ""
@echo "πͺ Ccache config βοΈ"
@ccache -p
@echo ""
@echo "πͺ Ccache pre build stats π"
@ccache -s
@ccache -z
ccache_postbuild:
@echo ""
@echo "πͺ Ccache post build stats π"
@ccache -s
flash:
openocd -f interface/stlink.cfg -c 'transport select hla_swd' -f target/stm32f7x.cfg -c 'program $(BIN_PATH) 0x08000000' -c exit
sleep 1
@$(MAKE) reset
reset:
openocd -f interface/stlink.cfg -c 'transport select hla_swd' -f target/stm32f7x.cfg -c init -c 'reset run' -c exit
term:
mbed sterm -b $(BAUDRATE) -p $(PORT)