blob: c9fb16fb2b028c64417fa6c3df9156149fe39acd [file] [log] [blame]
Andrew Walbran692b3252019-03-07 15:51:31 +00001# Copyright 2018 The Hafnium Authors.
Andrew Walbran40a33682018-11-30 11:58:36 +00002#
Andrew Walbrane959ec12020-06-17 15:01:09 +01003# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file or at
5# https://opensource.org/licenses/BSD-3-Clause.
Andrew Walbran40a33682018-11-30 11:58:36 +00006
David Brazdilac4024a2019-10-01 11:19:43 +01007# Select the project to build.
8PROJECT ?= reference
Olivier Deprez9fa36962021-09-20 14:32:14 +01009
10TOOLCHAIN_LIB := $(shell clang --print-resource-dir)
11
Daniel Boulby6530adf2021-11-26 09:54:01 +000012GN_ARGS := project="$(PROJECT)"
Olivier Deprez9fa36962021-09-20 14:32:14 +010013GN_ARGS += toolchain_lib="$(TOOLCHAIN_LIB)"
14
Daniel Boulby6530adf2021-11-26 09:54:01 +000015# Include assertions in the build
16ifneq (${ENABLE_ASSERTIONS},)
17 GN_ARGS += enable_assertions="$(ENABLE_ASSERTIONS)"
18endif
David Brazdilac4024a2019-10-01 11:19:43 +010019
David Brazdil5ecf75f2019-07-21 10:39:47 +020020# If HAFNIUM_HERMETIC_BUILD is "true" (not default), invoke `make` inside
21# a container. The 'run_in_container.sh' script will set the variable value to
22# 'inside' to avoid recursion.
23ifeq ($(HAFNIUM_HERMETIC_BUILD),true)
24
25# TODO: This is not ideal as (a) we invoke the container once per command-line
26# target, and (b) we cannot pass `make` arguments to the script. We could
27# consider creating a bash alias for `make` to invoke the script directly.
28
29# Need to define at least one non-default target.
30all:
Daniel Boulby6530adf2021-11-26 09:54:01 +000031 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \
32 ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020033
34# Catch-all target.
35.DEFAULT:
Daniel Boulby6530adf2021-11-26 09:54:01 +000036 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \
37 ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020038
39else # HAFNIUM_HERMETIC_BUILD
40
Andrew Scullbf570f22018-08-08 15:35:54 +010041# Set path to prebuilts used in the build.
Olivier Deprez9fa36962021-09-20 14:32:14 +010042UNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
43UNAME_M := $(shell uname -m)
44
45ifeq ($(UNAME_M),x86_64)
46UNAME_M := x64
47endif
48
49PREBUILTS := $(CURDIR)/prebuilts/$(UNAME_S)-$(UNAME_M)
Andrew Scull49a8e832018-08-03 13:02:09 +010050GN ?= $(PREBUILTS)/gn/gn
51NINJA ?= $(PREBUILTS)/ninja/ninja
Fuad Tabbac76466d2019-09-06 10:42:12 +010052
Andrew Walbran3586d832019-10-17 19:14:22 +010053CHECKPATCH := $(CURDIR)/third_party/linux/scripts/checkpatch.pl \
Andrew Walbrana65a1322020-04-06 19:32:32 +010054 --ignore BRACES,SPDX_LICENSE_TAG,VOLATILE,SPLIT_STRING,AVOID_EXTERNS,USE_SPINLOCK_T,NEW_TYPEDEFS,INITIALISED_STATIC,FILE_PATH_CHANGES,EMBEDDED_FUNCTION_NAME,SINGLE_STATEMENT_DO_WHILE_MACRO,MACRO_WITH_FLOW_CONTROL,PREFER_PACKED,PREFER_ALIGNED,INDENTED_LABEL,SPACING --quiet
Andrew Scullcbefbdb2019-01-11 16:36:26 +000055
Fuad Tabbac76466d2019-09-06 10:42:12 +010056# Specifies the grep pattern for ignoring specific files in checkpatch.
Andrew Scull3c257452019-11-26 13:32:50 +000057# C++ headers, *.hh, are automatically excluded.
Fuad Tabbac76466d2019-09-06 10:42:12 +010058# Separate the different items in the list with a grep or (\|).
59# debug_el1.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabbaf1d6dc52019-09-18 17:33:14 +010060# perfmon.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabba77a4b012019-11-15 12:13:08 +000061# feature_id.c : uses XMACROS, which checkpatch doesn't understand.
62CHECKPATCH_IGNORE := "src/arch/aarch64/hypervisor/debug_el1.c\|src/arch/aarch64/hypervisor/perfmon.c\|src/arch/aarch64/hypervisor/feature_id.c"
Fuad Tabbac76466d2019-09-06 10:42:12 +010063
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000064OUT ?= out/$(PROJECT)
65OUT_DIR = out/$(PROJECT)
Andrew Scull114096b2018-07-31 14:42:16 +010066
Andrew Scullbe199df2018-08-07 17:42:31 +010067.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010068all: $(OUT_DIR)/build.ninja
69 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010070
Andrew Scull23e93a82018-10-26 14:56:04 +010071$(OUT_DIR)/build.ninja:
Daniel Boulby6530adf2021-11-26 09:54:01 +000072 @$(GN) --export-compile-commands gen --args='$(GN_ARGS)' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010073
Andrew Scullbe199df2018-08-07 17:42:31 +010074.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010075clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010076 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010077
Andrew Scullbe199df2018-08-07 17:42:31 +010078.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010079clobber:
80 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010081
Andrew Scullbf570f22018-08-08 15:35:54 +010082# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010083.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010084format:
Andrew Scull80871322018-08-06 12:04:09 +010085 @echo "Formatting..."
David Brazdil0dbb41f2019-09-09 18:03:35 +010086 @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
87 @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
88 @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
89 @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Walbranf61ae3e2020-02-12 17:06:35 +000090 @find vmlib/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010091 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010092
Andrew Scullcbefbdb2019-01-11 16:36:26 +000093.PHONY: checkpatch
94checkpatch:
Fuad Tabbac76466d2019-09-06 10:42:12 +010095 @find src/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
96 @find inc/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +000097 # TODO: enable for test/
Fuad Tabbac76466d2019-09-06 10:42:12 +010098 @find project/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +000099
Andrew Scullbf570f22018-08-08 15:35:54 +0100100# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +0100101.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +0100102tidy: $(OUT_DIR)/build.ninja
103 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +0100104 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +0000105 # TODO: enable readability-magic-numbers once there are fewer violations.
106 # TODO: enable for c++ tests as it currently gives spurious errors.
Olivier Deprez9fa36962021-09-20 14:32:14 +0100107 @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
108 @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
Andrew Scull2a495c22018-08-12 23:07:30 +0100109
110.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +0100111check: $(OUT_DIR)/build.ninja
112 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +0100113 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +0000114 # TODO: enable for c++ tests as it currently gives spurious errors.
Olivier Deprez9fa36962021-09-20 14:32:14 +0100115 @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
116 @find test/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
Andrew Scull18834872018-10-12 11:48:09 +0100117
118.PHONY: license
119license:
Andrew Walbran5e71e9b2020-06-17 15:44:49 +0100120 @find build/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts -o -name \*.ld | xargs -n1 python build/license.py --style c
David Brazdil7a462ec2019-08-15 12:27:47 +0100121 @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
Andrew Walbran5e71e9b2020-06-17 15:44:49 +0100122 @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
David Brazdil7a462ec2019-08-15 12:27:47 +0100123 @find test/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
Andrew Walbran5e71e9b2020-06-17 15:44:49 +0100124 @find vmlib/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
125 @find build/ -name \*.py -o -name \*.sh -o -name \*.inc -o -name Dockerfile* | xargs -n1 python build/license.py --style hash
126 @find kokoro/ -name \*.sh -o -name \*.cfg | xargs -n1 python build/license.py --style hash
Andrew Sculle9827712018-10-19 14:54:20 +0100127 @find test/ -name \*.py| xargs -n1 python build/license.py --style hash
Andrew Walbran5e71e9b2020-06-17 15:44:49 +0100128 @find . \( -path ./driver/linux -o -path ./third_party \) -prune -o \( -name \*.gn -o -name \*.gni \) -print | xargs -n1 python build/license.py --style hash
Andrew Walbranbc342d42019-02-05 16:56:02 +0000129
130.PHONY: update-prebuilts
131update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz
132
133prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja
David Brazdil33cc5c02019-12-10 10:44:14 +0000134 @$(NINJA) -C $(OUT_DIR) "third_party/linux"
135 cp out/reference/obj/third_party/linux/linux.bin $@
David Brazdil5ecf75f2019-07-21 10:39:47 +0200136
137endif # HAFNIUM_HERMETIC_BUILD