blob: 8e9de498b4eb295a54c20e489d376dfc9a7b486c [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 Boulbyf06ecc72022-04-25 16:42:18 +010012ENABLE_ASSERTIONS ?= 1
13
Daniel Boulby6530adf2021-11-26 09:54:01 +000014GN_ARGS := project="$(PROJECT)"
Olivier Deprez9fa36962021-09-20 14:32:14 +010015GN_ARGS += toolchain_lib="$(TOOLCHAIN_LIB)"
Daniel Boulbyf06ecc72022-04-25 16:42:18 +010016ifeq ($(filter $(ENABLE_ASSERTIONS), 1 0),)
17 $(error invalid value for ENABLE_ASSERTIONS, should be 1 or 0)
Daniel Boulby6530adf2021-11-26 09:54:01 +000018endif
Daniel Boulbyf06ecc72022-04-25 16:42:18 +010019GN_ARGS += enable_assertions="$(ENABLE_ASSERTIONS)"
David Brazdilac4024a2019-10-01 11:19:43 +010020
David Brazdil5ecf75f2019-07-21 10:39:47 +020021# If HAFNIUM_HERMETIC_BUILD is "true" (not default), invoke `make` inside
22# a container. The 'run_in_container.sh' script will set the variable value to
23# 'inside' to avoid recursion.
24ifeq ($(HAFNIUM_HERMETIC_BUILD),true)
25
26# TODO: This is not ideal as (a) we invoke the container once per command-line
27# target, and (b) we cannot pass `make` arguments to the script. We could
28# consider creating a bash alias for `make` to invoke the script directly.
29
30# Need to define at least one non-default target.
31all:
Daniel Boulby6530adf2021-11-26 09:54:01 +000032 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \
33 ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020034
35# Catch-all target.
36.DEFAULT:
Daniel Boulby6530adf2021-11-26 09:54:01 +000037 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \
38 ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020039
40else # HAFNIUM_HERMETIC_BUILD
41
Andrew Scullbf570f22018-08-08 15:35:54 +010042# Set path to prebuilts used in the build.
Olivier Deprez9fa36962021-09-20 14:32:14 +010043UNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
44UNAME_M := $(shell uname -m)
45
46ifeq ($(UNAME_M),x86_64)
47UNAME_M := x64
48endif
49
50PREBUILTS := $(CURDIR)/prebuilts/$(UNAME_S)-$(UNAME_M)
Andrew Scull49a8e832018-08-03 13:02:09 +010051GN ?= $(PREBUILTS)/gn/gn
52NINJA ?= $(PREBUILTS)/ninja/ninja
Fuad Tabbac76466d2019-09-06 10:42:12 +010053
Andrew Walbran3586d832019-10-17 19:14:22 +010054CHECKPATCH := $(CURDIR)/third_party/linux/scripts/checkpatch.pl \
Andrew Walbrana65a1322020-04-06 19:32:32 +010055 --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 +000056
Fuad Tabbac76466d2019-09-06 10:42:12 +010057# Specifies the grep pattern for ignoring specific files in checkpatch.
Andrew Scull3c257452019-11-26 13:32:50 +000058# C++ headers, *.hh, are automatically excluded.
Fuad Tabbac76466d2019-09-06 10:42:12 +010059# Separate the different items in the list with a grep or (\|).
60# debug_el1.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabbaf1d6dc52019-09-18 17:33:14 +010061# perfmon.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabba77a4b012019-11-15 12:13:08 +000062# feature_id.c : uses XMACROS, which checkpatch doesn't understand.
63CHECKPATCH_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 +010064
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000065OUT ?= out/$(PROJECT)
66OUT_DIR = out/$(PROJECT)
Andrew Scull114096b2018-07-31 14:42:16 +010067
Andrew Scullbe199df2018-08-07 17:42:31 +010068.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010069all: $(OUT_DIR)/build.ninja
70 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010071
Andrew Scull23e93a82018-10-26 14:56:04 +010072$(OUT_DIR)/build.ninja:
Daniel Boulby6530adf2021-11-26 09:54:01 +000073 @$(GN) --export-compile-commands gen --args='$(GN_ARGS)' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010074
Andrew Scullbe199df2018-08-07 17:42:31 +010075.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010076clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010077 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010078
Andrew Scullbe199df2018-08-07 17:42:31 +010079.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010080clobber:
81 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010082
Andrew Scullbf570f22018-08-08 15:35:54 +010083# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010084.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010085format:
Andrew Scull80871322018-08-06 12:04:09 +010086 @echo "Formatting..."
David Brazdil0dbb41f2019-09-09 18:03:35 +010087 @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
88 @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
89 @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
90 @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Walbranf61ae3e2020-02-12 17:06:35 +000091 @find vmlib/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010092 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010093
Andrew Scullcbefbdb2019-01-11 16:36:26 +000094.PHONY: checkpatch
95checkpatch:
Fuad Tabbac76466d2019-09-06 10:42:12 +010096 @find src/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
97 @find inc/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +000098 # TODO: enable for test/
Fuad Tabbac76466d2019-09-06 10:42:12 +010099 @find project/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +0000100
Andrew Scullbf570f22018-08-08 15:35:54 +0100101# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +0100102.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +0100103tidy: $(OUT_DIR)/build.ninja
104 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +0100105 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +0000106 # TODO: enable readability-magic-numbers once there are fewer violations.
107 # TODO: enable for c++ tests as it currently gives spurious errors.
Olivier Deprez9fa36962021-09-20 14:32:14 +0100108 @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
109 @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
Andrew Scull2a495c22018-08-12 23:07:30 +0100110
111.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +0100112check: $(OUT_DIR)/build.ninja
113 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +0100114 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +0000115 # TODO: enable for c++ tests as it currently gives spurious errors.
Olivier Deprez9fa36962021-09-20 14:32:14 +0100116 @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
117 @find test/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
Andrew Scull18834872018-10-12 11:48:09 +0100118
119.PHONY: license
120license:
Olivier Deprez21f625b2023-02-02 14:02:56 +0000121 @find build/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts -o -name \*.ld | xargs -n1 python3 build/license.py --style c
122 @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python3 build/license.py --style c
123 @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python3 build/license.py --style c
124 @find test/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python3 build/license.py --style c
125 @find vmlib/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python3 build/license.py --style c
126 @find build/ -name \*.py -o -name \*.sh -o -name \*.inc -o -name Dockerfile* | xargs -n1 python3 build/license.py --style hash
127 @find kokoro/ -name \*.sh -o -name \*.cfg | xargs -n1 python3 build/license.py --style hash
128 @find test/ -name \*.py| xargs -n1 python3 build/license.py --style hash
129 @find . \( -path ./driver/linux -o -path ./third_party \) -prune -o \( -name \*.gn -o -name \*.gni \) -print | xargs -n1 python3 build/license.py --style hash
Andrew Walbranbc342d42019-02-05 16:56:02 +0000130
131.PHONY: update-prebuilts
132update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz
133
134prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja
David Brazdil33cc5c02019-12-10 10:44:14 +0000135 @$(NINJA) -C $(OUT_DIR) "third_party/linux"
136 cp out/reference/obj/third_party/linux/linux.bin $@
David Brazdil5ecf75f2019-07-21 10:39:47 +0200137
138endif # HAFNIUM_HERMETIC_BUILD