blob: ed91a5817d8c8026292ee0d0fb087037d89061d3 [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
Daniel Boulby6530adf2021-11-26 09:54:01 +00009GN_ARGS := project="$(PROJECT)"
10# Include assertions in the build
11ifneq (${ENABLE_ASSERTIONS},)
12 GN_ARGS += enable_assertions="$(ENABLE_ASSERTIONS)"
13endif
David Brazdilac4024a2019-10-01 11:19:43 +010014
David Brazdil5ecf75f2019-07-21 10:39:47 +020015# If HAFNIUM_HERMETIC_BUILD is "true" (not default), invoke `make` inside
16# a container. The 'run_in_container.sh' script will set the variable value to
17# 'inside' to avoid recursion.
18ifeq ($(HAFNIUM_HERMETIC_BUILD),true)
19
20# TODO: This is not ideal as (a) we invoke the container once per command-line
21# target, and (b) we cannot pass `make` arguments to the script. We could
22# consider creating a bash alias for `make` to invoke the script directly.
23
24# Need to define at least one non-default target.
25all:
Daniel Boulby6530adf2021-11-26 09:54:01 +000026 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \
27 ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020028
29# Catch-all target.
30.DEFAULT:
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
34else # HAFNIUM_HERMETIC_BUILD
35
Andrew Scullbf570f22018-08-08 15:35:54 +010036# Set path to prebuilts used in the build.
Andrew Scull49a8e832018-08-03 13:02:09 +010037UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Andrew Walbran3586d832019-10-17 19:14:22 +010038PREBUILTS := $(CURDIR)/prebuilts/$(UNNAME_S)-x64
Andrew Scull49a8e832018-08-03 13:02:09 +010039GN ?= $(PREBUILTS)/gn/gn
40NINJA ?= $(PREBUILTS)/ninja/ninja
Andrew Scullbf570f22018-08-08 15:35:54 +010041export PATH := $(PREBUILTS)/clang/bin:$(PATH)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010042
Fuad Tabbac76466d2019-09-06 10:42:12 +010043
Andrew Walbran3586d832019-10-17 19:14:22 +010044CHECKPATCH := $(CURDIR)/third_party/linux/scripts/checkpatch.pl \
Andrew Walbrana65a1322020-04-06 19:32:32 +010045 --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 +000046
Fuad Tabbac76466d2019-09-06 10:42:12 +010047# Specifies the grep pattern for ignoring specific files in checkpatch.
Andrew Scull3c257452019-11-26 13:32:50 +000048# C++ headers, *.hh, are automatically excluded.
Fuad Tabbac76466d2019-09-06 10:42:12 +010049# Separate the different items in the list with a grep or (\|).
50# debug_el1.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabbaf1d6dc52019-09-18 17:33:14 +010051# perfmon.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabba77a4b012019-11-15 12:13:08 +000052# feature_id.c : uses XMACROS, which checkpatch doesn't understand.
53CHECKPATCH_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 +010054
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000055OUT ?= out/$(PROJECT)
56OUT_DIR = out/$(PROJECT)
Andrew Scull114096b2018-07-31 14:42:16 +010057
Andrew Scullbe199df2018-08-07 17:42:31 +010058.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010059all: $(OUT_DIR)/build.ninja
60 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010061
Andrew Scull23e93a82018-10-26 14:56:04 +010062$(OUT_DIR)/build.ninja:
Daniel Boulby6530adf2021-11-26 09:54:01 +000063 @$(GN) --export-compile-commands gen --args='$(GN_ARGS)' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010064
Andrew Scullbe199df2018-08-07 17:42:31 +010065.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010066clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010067 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010068
Andrew Scullbe199df2018-08-07 17:42:31 +010069.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010070clobber:
71 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010072
Andrew Scullbf570f22018-08-08 15:35:54 +010073# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010074.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010075format:
Andrew Scull80871322018-08-06 12:04:09 +010076 @echo "Formatting..."
David Brazdil0dbb41f2019-09-09 18:03:35 +010077 @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
78 @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
79 @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
80 @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Walbranf61ae3e2020-02-12 17:06:35 +000081 @find vmlib/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010082 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010083
Andrew Scullcbefbdb2019-01-11 16:36:26 +000084.PHONY: checkpatch
85checkpatch:
Fuad Tabbac76466d2019-09-06 10:42:12 +010086 @find src/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
87 @find inc/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +000088 # TODO: enable for test/
Fuad Tabbac76466d2019-09-06 10:42:12 +010089 @find project/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +000090
Andrew Scullbf570f22018-08-08 15:35:54 +010091# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +010092.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +010093tidy: $(OUT_DIR)/build.ninja
94 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +010095 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +000096 # TODO: enable readability-magic-numbers once there are fewer violations.
97 # TODO: enable for c++ tests as it currently gives spurious errors.
Andrew Walbran287cdf62020-04-08 20:48:51 +010098 @find src/ \( -name \*.c \) | xargs prebuilts/linux-x64/clang/bin/clang-tidy -p $(OUT_DIR) -fix
99 @find test/ \( -name \*.c \) | xargs prebuilts/linux-x64/clang/bin/clang-tidy -p $(OUT_DIR) -fix
Andrew Scull2a495c22018-08-12 23:07:30 +0100100
101.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +0100102check: $(OUT_DIR)/build.ninja
103 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +0100104 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +0000105 # TODO: enable for c++ tests as it currently gives spurious errors.
Andrew Walbran287cdf62020-04-08 20:48:51 +0100106 @find src/ \( -name \*.c \) | xargs prebuilts/linux-x64/clang/bin/clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
107 @find test/ \( -name \*.c \) | xargs prebuilts/linux-x64/clang/bin/clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
Andrew Scull18834872018-10-12 11:48:09 +0100108
109.PHONY: license
110license:
Andrew Walbran5e71e9b2020-06-17 15:44:49 +0100111 @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 +0100112 @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 +0100113 @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 +0100114 @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 +0100115 @find vmlib/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
116 @find build/ -name \*.py -o -name \*.sh -o -name \*.inc -o -name Dockerfile* | xargs -n1 python build/license.py --style hash
117 @find kokoro/ -name \*.sh -o -name \*.cfg | xargs -n1 python build/license.py --style hash
Andrew Sculle9827712018-10-19 14:54:20 +0100118 @find test/ -name \*.py| xargs -n1 python build/license.py --style hash
Andrew Walbran5e71e9b2020-06-17 15:44:49 +0100119 @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 +0000120
121.PHONY: update-prebuilts
122update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz
123
124prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja
David Brazdil33cc5c02019-12-10 10:44:14 +0000125 @$(NINJA) -C $(OUT_DIR) "third_party/linux"
126 cp out/reference/obj/third_party/linux/linux.bin $@
David Brazdil5ecf75f2019-07-21 10:39:47 +0200127
128endif # HAFNIUM_HERMETIC_BUILD