This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
/
Makefile.cmake
363 lines (313 loc) · 12 KB
/
Makefile.cmake
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
#
# Arm SCP/MCP Software
# Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
#
# Directories
#
export TOP_DIR := $(shell pwd)
export ARCH_DIR := $(TOP_DIR)/arch
export FWK_DIR := $(TOP_DIR)/framework
export TOOLS_DIR := $(TOP_DIR)/tools
export PRODUCTS_DIR := $(TOP_DIR)/product
export MODULES_DIR := $(TOP_DIR)/module
export DOC_DIR := $(TOP_DIR)/doc
export MOD_TEST_DIR := $(TOP_DIR)/unit_test
export MOD_TEST_BUILD_DIR=$(BUILD_DIR)/module/test
export FWK_TEST_DIR=$(FWK_DIR)/test
export FWK_TEST_BUILD_DIR=$(BUILD_DIR)/framework/test
export PROD_TEST_DIR := $(TOP_DIR)/product/test
export PROD_TEST_BUILD_DIR=$(BUILD_DIR)/product/test
#
# Tools
#
export RM := rm -rf
export MD := mkdir -p
export CP := cp -r
export DOC := doxygen
export CMAKE := cmake
export CTEST := ctest
export CD := cd
export LCOV := lcov
export GENHTML := genhtml
export PYTHON := python3
#
# Documentation paths
#
export BUILD_STRING := $(shell $(TOOLS_DIR)/build_string.py 2>/dev/null)
export BUILD_DOC_DIR = $(BUILD_DIR)/doc
export MODULE_INCLUDES := $(shell ls -d $(MODULES_DIR)/*/include/ 2>/dev/null)
export MODULE_DOCS := $(shell ls -d $(MODULES_DIR)/*/doc/ 2>/dev/null)
export MODULE_DOCS += $(shell ls -d $(PRODUCTS_DIR)/*/module/*/doc/ 2>/dev/null)
#
# Default options
#
DEFAULT_MODE := release
DEFAULT_BUILD_PATH := $(TOP_DIR)/build
DEFAULT_VERBOSE := n
DEFAULT_DEBUGGER := n
DEFAULT_ENABLE_COVERAGE := n
DEFAULT_TOOLCHAIN := GNU
DEFAULT_BUILD_SYSTEM := Ninja
export CMSIS_DIR := $(TOP_DIR)/contrib/cmsis/git/CMSIS/Core
DEFAULT_LOG_LEVEL_debug := INFO
DEFAULT_LOG_LEVEL_release := WARN
DEFAULT_CMAKE_TOOL_LOG_LEVEL := NOTICE
#
# Top-level configuration
#
.DEFAULT_GOAL = all
# MAKECMDGOALS isn't set if there's no explicit goal in the
# command line, so set the default.
MAKECMDGOALS ?= $(.DEFAULT_GOAL)
# Mode
MODE ?= $(DEFAULT_MODE)
ifneq ($(filter-out debug release, $(MODE)),)
$(error "Invalid MODE parameter. Aborting...")
endif
# Build System
BUILD_SYSTEM ?= $(DEFAULT_BUILD_SYSTEM)
ifneq ($(filter-out Make Ninja, $(BUILD_SYSTEM)),)
$(error "Invalid BUILD_SYSTEM parameter. Aborting...")
endif
# Toolchain
TOOLCHAIN ?= $(DEFAULT_TOOLCHAIN)
ifneq ($(filter-out GNU ArmClang Clang, $(TOOLCHAIN)),)
$(error "Invalid TOOLCHAIN parameter. Aborting...")
endif
# Log level
LOG_LEVEL ?= $(DEFAULT_LOG_LEVEL_${MODE})
CMAKE_SCP_LOG_LEVEL_OPTION=-DSCP_LOG_LEVEL=$(LOG_LEVEL)
# Build directory
BUILD_PATH ?= $(DEFAULT_BUILD_PATH)
ifeq ($(BUILD_PATH),)
$(error "Invalid BUILD_PATH parameter. Aborting...")
endif
export BUILD_DIR = $(abspath $(BUILD_PATH))
# Verbose mode: y/n
export V ?= $(DEFAULT_VERBOSE)
ifneq ($(V),n)
CMAKE_TOOL_LOG_LEVEL := --log-level=VERBOSE
CMAKE_BUILD_VERBOSE_OPTION := -v
else
CMAKE_TOOL_LOG_LEVEL := --log-level=$(DEFAULT_CMAKE_TOOL_LOG_LEVEL)
MAKEFLAGS += --silent
MAKEFLAGS += --no-print-directory
endif
# Include debugger library: y/n
DEBUGGER ?= $(DEFAULT_DEBUGGER)
ifeq ($(DEBUGGER),y)
CMAKE_DEBUGGER_OPTION := -DSCP_ENABLE_DEBUGGER=ON
endif
ENABLE_COVERAGE ?= $(DEFAULT_ENABLE_COVERAGE)
#
# Products
#
PRODUCTS := $(sort $(shell find product -name "product.mk" -printf "%h\n" | cut -d'/' -f2-3))
#
# Deprecated Products/Platforms
#
DEPRECATED_PLATFORMS := none
PRODUCT_INDEPENDENT_GOALS := clean help test doc fwk_test mod_test prod_test
ifneq ($(filter-out $(PRODUCT_INDEPENDENT_GOALS), $(MAKECMDGOALS)),)
ifeq ($(PRODUCT),)
$(error "You must define PRODUCT. Aborting...")
endif
PRODUCT_DIR := $(PRODUCTS_DIR)/$(PRODUCT)
ifeq ($(wildcard $(PRODUCT_DIR)/product.mk),)
$(error "Missing product.mk in $(PRODUCT_DIR)")
endif
include $(PRODUCT_DIR)/product.mk
ifeq ($(BS_FIRMWARE_LIST),)
$(error "You must define BS_FIRMWARE_LIST in product.mk. Aborting...")
endif
# Terminate the build if the chosen platform is in the list of deprecated
# ones.
ifeq ($(filter-out $(DEPRECATED_PLATFORMS), $(PRODUCT)),)
$(error "$(PRODUCT) has been deprecated! Build terminated")
endif
FIRMWARE_TARGETS := $(addprefix firmware-, $(BS_FIRMWARE_LIST))
ifndef PLATFORM_VARIANT
PRODUCT_BUILD_PATH := $(BUILD_PATH)/$(BS_PRODUCT_NAME)/$(TOOLCHAIN)/$(MODE)
else
PRODUCT_BUILD_PATH := $(BUILD_PATH)/$(BS_PRODUCT_NAME)/platform_variant_$(PLATFORM_VARIANT)/$(TOOLCHAIN)/$(MODE)
endif
define msg_start
================================================================
Arm SCP/MCP Software build System
Platform : $(BS_PRODUCT_NAME)
Mode : $(MODE)
Firmware(s) : $(BS_FIRMWARE_LIST)
================================================================
endef
$(info $(msg_start))
endif
ifeq ($(MODE),debug)
CMAKE_BUILD_TYPE=-DCMAKE_BUILD_TYPE=Debug
endif
CMAKE_COMMAND_OPTION := $(CMAKE_BUILD_TYPE)
CMAKE_COMMAND_OPTION += -DSCP_TOOLCHAIN="$(TOOLCHAIN)"
CMAKE_COMMAND_OPTION += -DSCP_LLVM_SYSROOT_CC="$(LLVM_SYSROOT_CC)"
ifdef PLATFORM_VARIANT
CMAKE_COMMAND_OPTION += -DSCP_PLATFORM_VARIANT="$(PLATFORM_VARIANT)"
endif
ifdef CMAKE_BUILD_VERBOSE_OPTION
CMAKE_COMMAND_OPTION += -DCOMMAND_OUTPUT_VERBOSE=1
endif
ifeq ($(TEST_ON_TARGET),1)
CMAKE_COMMAND_OPTION += -DTEST_ON_TARGET=1
endif
ifeq ($(BUILD_SYSTEM), Ninja)
CMAKE_COMMAND_OPTION += -G $(BUILD_SYSTEM)
endif
CMAKE_COMMAND_OPTION += $(CMAKE_TOOL_LOG_LEVEL)
CMAKE_COMMAND_OPTION += $(CMAKE_SCP_LOG_LEVEL_OPTION)
CMAKE_COMMAND_OPTION += $(CMAKE_DEBUGGER_OPTION)
#
# Rules
#
.PHONY: help
help:
@echo "Arm SCP/MCP Software build system"
@echo ""
@echo "Usage: make -f Makefile.cmake [PRODUCT=<name>] [OPTIONS] [TARGET]"
@echo ""
@echo "--------------------------------------------------------------------"
@echo "| Available Targets |"
@echo "--------------------------------------------------------------------"
@echo " all Build all firmware defined by PRODUCT=<product>"
@echo " clean Remove all built products"
@echo " fwk_test Build and runs framework unit tests"
@echo " mod_test Build and runs module unit tests"
@echo " help Show this documentation"
@echo " doc Generate the documentation of this project with Doxygen"
@echo ""
@echo "--------------------------------------------------------------------"
@echo "| Product Selection |"
@echo "--------------------------------------------------------------------"
@echo " PRODUCT"
@echo " Available products: $(PRODUCTS)"
@echo " Select the target product to build. This is a required"
@echo " parameter."
@echo ""
@echo "--------------------------------------------------------------------"
@echo "| Options |"
@echo "--------------------------------------------------------------------"
@echo " BUILD_PATH"
@echo " Value: <Full, user provided path>"
@echo " Default: '$(DEFAULT_BUILD_PATH)'"
@echo " Set the base directory used during the build process."
@echo ""
@echo " MODE"
@echo " Value: <debug | release>"
@echo " Default: '$(DEFAULT_MODE)'"
@echo " Choose between release and debug mode."
@echo ""
@echo " O"
@echo " Value: <Compiler-specific optimization level>"
@echo " Default: <Compiler and MODE specific>"
@echo " Set the desired level of optimization the compiler will use."
@echo ""
@echo " V"
@echo " Value: <y|n>"
@echo " Default: $(DEFAULT_VERBOSE)"
@echo " Enable or disable verbose mode for the build system."
@echo ""
@echo " DEBUGGER"
@echo " Value: <y|n>"
@echo " Default: $(DEFAULT_DEBUGGER)"
@echo " Include the debugger library."
@echo ""
@echo " LOG_LEVEL"
@echo " Value: <DEBUG|INFO|WARN|ERROR|CRIT|DISABLED>"
@echo " Default: $(LOG_LEVEL)"
@echo " Filter log messages less important than this level."
@echo ""
@echo " BUILD_SYSTEM"
@echo " Value: <Make|Ninja>"
@echo " Default: $(DEFAULT_BUILD_SYSTEM)"
@echo " Specify CMake to generate GNU Make or Ninja build system."
@echo ""
@echo " TOOLCHAIN"
@echo " Value: <GNU|ArmClang|Clang>"
@echo " Default: $(DEFAULT_TOOLCHAIN)"
@echo " Specify Toolchain to build the firmware."
@echo ""
@echo " LLVM_SYSROOT_CC"
@echo " Value: <LLVM sysroot compiler path>"
@echo " Specify LLVM sysroot compiler path to build the firmware."
@echo ""
@echo " PLATFORM_VARIANT"
@echo " Value: <Platform variant>"
@echo " Specify Platform variant if it is required."
@echo ""
@echo " EXTRA_CONFIG_ARGS"
@echo " Value: <cmake configuration parameters>"
@echo " Default: "
@echo " Pass extra arguments directly to cmake configuration stage."
@echo " Multiplle extra args can be added with += or by passing the arguments as a string"
@echo ""
@echo " EXTRA_BUILD_ARGS"
@echo " Value: <cmake build parameters>"
@echo " Default: "
@echo " Pass extra arguments directly to cmake build stage."
@echo " Multiplle extra args can be added with += or by passing the arguments as a string"
@echo ""
@echo " ENABLE_COVERAGE"
@echo " Value: <y|n>"
@echo " Default: n"
@echo " Enable or disable generation of code coverage reports for unit tests."
@echo " Use ENABLE_COVERAGE=y to enable coverage for 'fwk_test' and 'mod_test' targets."
@echo ""
.SECONDEXPANSION:
.PHONY: all
all: $(FIRMWARE_TARGETS)
firmware-%: $(PRODUCT_BUILD_PATH)/$$@/CMakeCache.txt
$(CMAKE) --build $(<D)/ $(CMAKE_BUILD_VERBOSE_OPTION) $(EXTRA_BUILD_ARGS)
.PRECIOUS: $(PRODUCT_BUILD_PATH)/firmware-%/CMakeCache.txt
$(PRODUCT_BUILD_PATH)/firmware-%/CMakeCache.txt: $(PRODUCT_DIR)/%/Firmware.cmake
$(RM) $(@D)
$(CMAKE) -B $(@D) -DSCP_FIRMWARE_SOURCE_DIR:PATH=$(PRODUCT_DIR)/$* $(CMAKE_COMMAND_OPTION) $(EXTRA_CONFIG_ARGS)
.PHONY: clean
clean:
$(RM) $(BUILD_DIR)
.PHONY: doc
doc:
mkdir -p $(BUILD_DOC_DIR)
$(DOC) $(DOC_DIR)/Doxyfile
.PHONY: test
test : fwk_test mod_test
.PHONY: fwk_test
fwk_test:
$(CMAKE) -B $(FWK_TEST_BUILD_DIR) $(FWK_TEST_DIR) -G Ninja
$(CMAKE) --build ${BUILD_PATH}/framework/test
# --test-dir option of ctest is not available before ctest 3.20
# so use workaround to change the test dir and run the tests from there
${CD} $(FWK_TEST_BUILD_DIR) && ${CTEST} -V --output-junit Testing/TestResults.xml
ifeq ($(ENABLE_COVERAGE),y)
${CD} $(FWK_TEST_BUILD_DIR) && $(LCOV) --capture --directory . --output-file scp_v2_fwk_test_coverage.info
${CD} $(FWK_TEST_BUILD_DIR) && $(PYTHON) $(TOOLS_DIR)/filter_coverage_report.py --filename scp_v2_fwk_test_coverage.info
${CD} $(FWK_TEST_BUILD_DIR) && $(GENHTML) scp_v2_fwk_test_coverage_filtered.info --prefix "$(TOP_DIR)" --output-directory $(FWK_TEST_BUILD_DIR)/coverage_report
endif
.PHONY: mod_test
mod_test:
$(CMAKE) -B $(MOD_TEST_BUILD_DIR) $(MOD_TEST_DIR) -G Ninja
$(CMAKE) --build $(MOD_TEST_BUILD_DIR)
${CD} $(MOD_TEST_BUILD_DIR) && $(CTEST) -V --output-junit Testing/TestResults.xml
ifeq ($(ENABLE_COVERAGE),y)
${CD} $(MOD_TEST_BUILD_DIR) && $(LCOV) --capture --directory $(MOD_TEST_BUILD_DIR) --output-file scp_v2_unit_test_coverage.info
${CD} $(MOD_TEST_BUILD_DIR) && $(PYTHON) $(TOOLS_DIR)/filter_coverage_report.py --filename scp_v2_unit_test_coverage.info
${CD} $(MOD_TEST_BUILD_DIR) && $(GENHTML) scp_v2_unit_test_coverage_filtered.info --prefix "$(TOP_DIR)" --output-directory $(MOD_TEST_BUILD_DIR)/coverage_report
endif
.PHONY: prod_test
prod_test:
$(CMAKE) -B $(PROD_TEST_BUILD_DIR) $(PROD_TEST_DIR) -G Ninja
$(CMAKE) --build $(PROD_TEST_BUILD_DIR)
${CD} $(PROD_TEST_BUILD_DIR) && $(CTEST) -V --output-junit Testing/TestResults.xml
ifeq ($(ENABLE_COVERAGE),y)
${CD} $(PROD_TEST_BUILD_DIR) && $(LCOV) --capture --directory $(PROD_TEST_BUILD_DIR) --output-file scp_v2_product_test_coverage.info
${CD} $(PROD_TEST_BUILD_DIR) && $(PYTHON) $(TOOLS_DIR)/filter_coverage_report.py --filename scp_v2_product_test_coverage.info
${CD} $(PROD_TEST_BUILD_DIR) && $(GENHTML) scp_v2_product_test_coverage_filtered.info --prefix "$(TOP_DIR)" --output-directory $(PROD_TEST_BUILD_DIR)/coverage_report
endif