-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
403 lines (324 loc) Β· 12.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# Leka - LekaOS
# Copyright 2020 APF France handicap
# 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
MCUBOOT_DIR := $(ROOT_DIR)/extern/mcuboot
#
# MARK: - Config
#
MBED_GIT_URL ?= $(shell cat $(ROOT_DIR)/config/mbed_git_url)
MBED_BRANCH ?= $(shell cat $(ROOT_DIR)/config/mbed_version)
MBED_VERSION ?= $(shell cat $(ROOT_DIR)/config/mbed_version)
MCUBOOT_GIT_URL ?= $(shell cat $(ROOT_DIR)/config/mcuboot_git_url)
MCUBOOT_VERSION ?= $(shell cat $(ROOT_DIR)/config/mcuboot_version)
OS_VERSION ?= $(shell cat $(ROOT_DIR)/config/os_version)
#
# MARK: - Options
#
# build
BUILD_TYPE ?= Release
TARGET_BOARD ?= LEKA_V1_2_DEV
# tests
COVERAGE ?= ON
SANITIZERS ?= OFF
UT_LITE ?= OFF
GCOV_EXEC ?= ""
CI_UT_OPTIMIZATION_LEVEL ?= ""
# os
ENABLE_LOG_DEBUG ?= ON
ENABLE_SYSTEM_STATS ?= ON
ENABLE_FAST_SLEEP ?= OFF
# bootloader
BUILD_TARGETS_TO_USE_WITH_BOOTLOADER ?= OFF
#
# MARK: - Build dirs
#
# Global - os + bootloader + spikes + functional tests
GLOBAL_BUILD_DIR := $(ROOT_DIR)/_build
TARGET_BOARD_BUILD_DIR := $(GLOBAL_BUILD_DIR)/${TARGET_BOARD}
TARGET_BOARD_CMAKE_CONFIG_DIR := $(TARGET_BOARD_BUILD_DIR)/cmake_config
# Firmware = os + bootloader
FIRMWARE_BUILD_DIR := $(ROOT_DIR)/_build_firmware
FIRMWARE_CONFIG_DIR := $(FIRMWARE_BUILD_DIR)/cmake_config
# Unit tests
UNIT_TESTS_BUILD_DIR := $(ROOT_DIR)/_build_unit_tests
UNIT_TESTS_COVERAGE_DIR := $(UNIT_TESTS_BUILD_DIR)/_coverage
#
# MARK: - VSCode CMake Tools
#
CMAKE_TOOLS_BUILD_DIR := $(ROOT_DIR)/_build_cmake_tools
CMAKE_TOOLS_CONFIG_DIR := $(CMAKE_TOOLS_BUILD_DIR)/cmake_config
#
# MARK: - Coverage exclusions
#
EXCLUDE_FROM_GCOVR_COVERAGE = -e '.*Xcode.*' -e '.*_build.*' -e '.*extern.*' -e '.*tests/unit.*' -e '.*tests/mocks.*' -e '.*_test.*\..*' -e '.*include/boost.*' -e '.*include/semver.*' -e '.*include/interface.*' -e '.*CoreSTM32Hal.*'
EXCLUDE_FROM_LCOV_COVERAGE = '*Xcode*' '*_build*' '*extern*' '*tests/unit*' '*tests/mocks*' '*_test*.*' '*include/boost*' '*include/semver*' '*include/interface*' '*CoreSTM32Hal*'
#
# MARK: - .bin path
#
LEKA_OS_BIN_PATH := $(TARGET_BOARD_BUILD_DIR)/app/os/LekaOS.bin
BIN_PATH ?= $(LEKA_OS_BIN_PATH)
#
# MARK: - Build targets
#
.PHONY: spikes tests config build_unit_tests
all:
@echo ""
@echo "ποΈ Building everything! π"
cmake --build $(TARGET_BOARD_BUILD_DIR)
os:
@echo ""
@echo "ποΈ Building LekaOS π€"
cmake --build $(TARGET_BOARD_BUILD_DIR) -t LekaOS
bootloader:
@echo ""
@echo "ποΈ Building Bootloader π€"
cmake --build $(TARGET_BOARD_BUILD_DIR) -t bootloader
spikes:
@echo ""
@echo "ποΈ Building spikes π±"
cmake --build $(TARGET_BOARD_BUILD_DIR) -t spikes
tests_functional:
@echo ""
@echo "ποΈ Building functional tests βοΈ"
cmake --build $(TARGET_BOARD_BUILD_DIR) -t tests_functional
firmware: bootloader
@echo ""
@echo "ποΈ Building Firmware = LekaOS + Bootloader π€"
cmake --build $(FIRMWARE_BUILD_DIR) -t LekaOS
@echo ""
@echo "π Check os version"
@echo ""
@python3 tools/check_version.py ./config/os_version
@echo ""
@echo "π§βπ¬ Generate firmware + os images"
@bash ./tools/generate_firmware.sh
#
# MARK: - Config targets
#
config_all:
@$(MAKE) config
@$(MAKE) config_firmware
@$(MAKE) config_unit_tests_lite COVERAGE=ON
# Global config
config:
@$(MAKE) config_cmake_target
@$(MAKE) config_cmake_build
config_cmake_target: mkdir_cmake_config
@echo ""
@echo "π Running configuration script for target $(TARGET_BOARD) π"
python3 $(CMAKE_DIR)/scripts/configure_cmake_for_target.py $(TARGET_BOARD) -p $(TARGET_BOARD_CMAKE_CONFIG_DIR) -a $(ROOT_DIR)/config/mbed_app.json
config_cmake_build: mkdir_cmake_config
@echo ""
@echo "π Running cmake configuration script for target $(TARGET_BOARD) π"
@cmake -S . -B $(TARGET_BOARD_BUILD_DIR) -GNinja -DCMAKE_CONFIG_DIR="$(TARGET_BOARD_CMAKE_CONFIG_DIR)" -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_LOG_DEBUG=$(ENABLE_LOG_DEBUG) -DENABLE_FAST_SLEEP=$(ENABLE_FAST_SLEEP) -DENABLE_SYSTEM_STATS=$(ENABLE_SYSTEM_STATS) -DBUILD_TARGETS_TO_USE_WITH_BOOTLOADER=$(BUILD_TARGETS_TO_USE_WITH_BOOTLOADER)
# Firmware config
config_firmware: config
@$(MAKE) config_firmware_target
@$(MAKE) config_firmware_build
config_firmware_target: mkdir_firmware_config
@echo ""
@echo "π Running configuration script for firmware (os + bootloader) π"
python3 $(CMAKE_DIR)/scripts/configure_cmake_for_target.py $(TARGET_BOARD) -p $(FIRMWARE_CONFIG_DIR) -a $(ROOT_DIR)/config/mbed_app.json
config_firmware_build: mkdir_firmware_config
@echo ""
@echo "π Running cmake configuration script for firmware (os + bootloader) π"
@cmake -S . -B $(FIRMWARE_BUILD_DIR) -GNinja -DCMAKE_CONFIG_DIR="$(FIRMWARE_CONFIG_DIR)" -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_LOG_DEBUG=$(ENABLE_LOG_DEBUG) -DENABLE_FAST_SLEEP=$(ENABLE_FAST_SLEEP) -DENABLE_SYSTEM_STATS=$(ENABLE_SYSTEM_STATS) -DBUILD_TARGETS_TO_USE_WITH_BOOTLOADER=ON
# Tools
config_tools:
@$(MAKE) config_tools_target
config_tools_target: mkdir_tools_config
@echo ""
@echo "π Running configuration script for VSCode CMake Tools π"
python3 $(CMAKE_DIR)/scripts/configure_cmake_for_target.py $(TARGET_BOARD) -p $(CMAKE_TOOLS_CONFIG_DIR) -a $(ROOT_DIR)/config/mbed_app.json
config_tools_build: mkdir_tools_config
@echo ""
@echo "π Running cmake configuration script for target $(TARGET_BOARD) π"
@cmake -S . -B $(CMAKE_TOOLS_BUILD_DIR) -GNinja -DCMAKE_CONFIG_DIR="$(CMAKE_TOOLS_CONFIG_DIR)" -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_LOG_DEBUG=ON -DENABLE_FAST_SLEEP=$(ENABLE_FAST_SLEEP) -DENABLE_SYSTEM_STATS=ON
#
# MARK: - Tests targets
#
ut:
@$(MAKE) unit_tests
utc:
@$(MAKE) unit_tests
@$(MAKE) coverage
unit_tests:
@$(MAKE) build_unit_tests
@$(MAKE) run_unit_tests
coverage:
@echo ""
@echo "π¬ Generating code coverage π"
@echo ""
@gcovr --root . $(EXCLUDE_FROM_GCOVR_COVERAGE) --exclude-throw-branches --exclude-unreachable-branches
@gcovr --root . $(EXCLUDE_FROM_GCOVR_COVERAGE) --exclude-throw-branches --exclude-unreachable-branches --html-details $(UNIT_TESTS_COVERAGE_DIR)/coverage.html
@echo ""
@echo "π Html report can be viewed with:"
@echo " open $(UNIT_TESTS_COVERAGE_DIR)/coverage.html\n"
coverage_json:
@echo ""
@echo "π¬ Generating code coverage in json π"
@gcovr --root . -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_sonarqube:
@echo ""
@echo "π¬ Generating code coverage π"
@echo ""
@gcovr --root . $(EXCLUDE_FROM_GCOVR_COVERAGE) --gcov-executable $(GCOV_EXEC)
@gcovr --root . $(EXCLUDE_FROM_GCOVR_COVERAGE) --gcov-executable $(GCOV_EXEC) --exclude-throw-branches --exclude-unreachable-branches --sonarqube $(UNIT_TESTS_COVERAGE_DIR)/coverage.xml
@echo ""
@echo "π SonarQube XML report can be viewed with:"
@echo " open $(UNIT_TESTS_COVERAGE_DIR)/coverage.xml\n"
coverage_lcov:
@echo ""
@echo "π¬ Generating code coverage using lcov π"
@which lcov
@lcov --version
@mkdir -p $(UNIT_TESTS_COVERAGE_DIR)
@lcov --capture --directory . --output-file $(UNIT_TESTS_COVERAGE_DIR)/_tmp_coverage.info --gcov-tool $(GCOV_EXEC)
@lcov --remove $(UNIT_TESTS_COVERAGE_DIR)/_tmp_coverage.info $(EXCLUDE_FROM_LCOV_COVERAGE) -o $(UNIT_TESTS_COVERAGE_DIR)/coverage.info
@lcov --list $(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)/LekaOSUnitTestsExec --gtest_color=yes --gtest_output=xml:$(UNIT_TESTS_COVERAGE_DIR)/google_test_detail.xml
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=$(COVERAGE) -DSANITIZERS=$(SANITIZERS) -DUT_LITE=$(UT_LITE) -DCI_UT_OPTIMIZATION_LEVEL=$(CI_UT_OPTIMIZATION_LEVEL)
@mkdir -p $(CMAKE_TOOLS_BUILD_DIR)/unit_tests
@ln -sf $(UNIT_TESTS_BUILD_DIR)/compile_commands.json $(CMAKE_TOOLS_BUILD_DIR)/unit_tests/compile_commands.json
config_unit_tests_asan:
@$(MAKE) config_unit_tests SANITIZERS=ON
config_unit_tests_lite:
@$(MAKE) config_unit_tests SANITIZERS=ON UT_LITE=ON
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
clang_tidy_diff:
@echo ""
@echo "πββοΈ Running clang-tidy on modified files π§Ή"
@echo ""
@git diff --name-status develop \
| grep -E -v "_test" \
| grep -E -v "extern" \
| grep -E -v "gtest" \
| grep -E -v "gmock" \
| grep -E -v "mocks" \
| grep -E -v "stubs" \
| grep -E "^A|^M" | sed "s/^[AM]\t//g" \
| grep -E "\.h\$$|\.cpp\$$" \
|| echo "No files added nor modified!"
@echo ""
@git diff --name-status develop \
| grep -E -v "_test" \
| grep -E -v "extern" \
| grep -E -v "gtest" \
| grep -E -v "gmock" \
| grep -E -v "mocks" \
| grep -E -v "stubs" \
| grep -E "^A|^M" | sed "s/^[AM]\t//g" \
| grep -E "\.h\$$|\.cpp\$$" \
| xargs --no-run-if-empty ruby tools/run-clang-tidy.rb $(CMAKE_TOOLS_BUILD_DIR)
#
# MARK: - Mbed targets
#
pull_deps:
@$(MAKE) mbed_clone
@$(MAKE) mcuboot_clone
mbed_clone:
@echo ""
@echo "𧬠Cloning Mbed OS π¦"
@rm -rf $(MBED_OS_DIR)
git clone --depth=1 --branch=$(MBED_BRANCH) $(MBED_GIT_URL) $(MBED_OS_DIR)
@$(MAKE) mbed_symlink_files
mbed_symlink_files:
@echo ""
@echo "π Symlinking templates to Mbed OS directory ποΈ"
ln -srf $(CMAKE_DIR)/templates/mbed/CMakeLists.txt $(MBED_OS_DIR)/CMakeLists.txt
ln -srf $(CMAKE_DIR)/templates/mbed/.mbedignore $(MBED_OS_DIR)/.mbedignore
#
# MARK: - Mcuboot targets
#
mcuboot_clone:
@echo ""
@echo "𧬠Cloning MCUBoot π¦"
@rm -rf $(MCUBOOT_DIR)
git clone --depth=1 --branch=$(MCUBOOT_VERSION) $(MCUBOOT_GIT_URL) $(MCUBOOT_DIR)
@$(MAKE) mcuboot_symlink_files
mcuboot_symlink_files:
@echo ""
@echo "π Symlinking CMakeLists.txt to MCUBoot directory ποΈ"
ln -srf $(CMAKE_DIR)/templates/mcuboot/boot.cmake $(MCUBOOT_DIR)/boot/CMakeLists.txt
ln -srf $(CMAKE_DIR)/templates/mcuboot/mbed.cmake $(MCUBOOT_DIR)/boot/mbed/CMakeLists.txt
#
# MARK: - Utils targets
#
mkdir_cmake_config:
@mkdir -p $(TARGET_BOARD_CMAKE_CONFIG_DIR)
mkdir_firmware_config:
@mkdir -p $(FIRMWARE_CONFIG_DIR)
mkdir_tools_config:
@mkdir -p $(CMAKE_TOOLS_CONFIG_DIR)
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_BOARD_BUILD_DIR)
rm_build_all:
@echo ""
@echo "β οΈ Cleaning up all build directories π§Ή"
rm -rf $(GLOBAL_BUILD_DIR)
rm -rf $(FIRMWARE_BUILD_DIR)
rm -rf $(CMAKE_TOOLS_BUILD_DIR)
rm -rf ./compile_commands.json
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 -v
@ccache -z
ccache_postbuild:
@echo ""
@echo "πͺ Ccache post build stats π"
@ccache -s -v
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