Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 1 | # Copyright 2018 The Hafnium Authors. |
Andrew Walbran | 40a3368 | 2018-11-30 11:58:36 +0000 | [diff] [blame] | 2 | # |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 3 | # 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 Walbran | 40a3368 | 2018-11-30 11:58:36 +0000 | [diff] [blame] | 6 | |
David Brazdil | ac4024a | 2019-10-01 11:19:43 +0100 | [diff] [blame] | 7 | # Select the project to build. |
| 8 | PROJECT ?= reference |
Olivier Deprez | 9fa3696 | 2021-09-20 14:32:14 +0100 | [diff] [blame] | 9 | |
| 10 | TOOLCHAIN_LIB := $(shell clang --print-resource-dir) |
| 11 | |
Daniel Boulby | f06ecc7 | 2022-04-25 16:42:18 +0100 | [diff] [blame] | 12 | ENABLE_ASSERTIONS ?= 1 |
| 13 | |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 14 | GN_ARGS := project="$(PROJECT)" |
Olivier Deprez | 9fa3696 | 2021-09-20 14:32:14 +0100 | [diff] [blame] | 15 | GN_ARGS += toolchain_lib="$(TOOLCHAIN_LIB)" |
Daniel Boulby | f06ecc7 | 2022-04-25 16:42:18 +0100 | [diff] [blame] | 16 | ifeq ($(filter $(ENABLE_ASSERTIONS), 1 0),) |
| 17 | $(error invalid value for ENABLE_ASSERTIONS, should be 1 or 0) |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 18 | endif |
Daniel Boulby | f06ecc7 | 2022-04-25 16:42:18 +0100 | [diff] [blame] | 19 | GN_ARGS += enable_assertions="$(ENABLE_ASSERTIONS)" |
David Brazdil | ac4024a | 2019-10-01 11:19:43 +0100 | [diff] [blame] | 20 | |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 21 | # 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. |
| 24 | ifeq ($(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. |
| 31 | all: |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 32 | @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \ |
| 33 | ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 34 | |
| 35 | # Catch-all target. |
| 36 | .DEFAULT: |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 37 | @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) \ |
| 38 | ENABLE_ASSERTIONS=$(ENABLE_ASSERTIONS) $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 39 | |
| 40 | else # HAFNIUM_HERMETIC_BUILD |
| 41 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 42 | # Set path to prebuilts used in the build. |
Olivier Deprez | 9fa3696 | 2021-09-20 14:32:14 +0100 | [diff] [blame] | 43 | UNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 44 | UNAME_M := $(shell uname -m) |
| 45 | |
| 46 | ifeq ($(UNAME_M),x86_64) |
| 47 | UNAME_M := x64 |
| 48 | endif |
| 49 | |
| 50 | PREBUILTS := $(CURDIR)/prebuilts/$(UNAME_S)-$(UNAME_M) |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 51 | GN ?= $(PREBUILTS)/gn/gn |
| 52 | NINJA ?= $(PREBUILTS)/ninja/ninja |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 53 | |
Andrew Walbran | 3586d83 | 2019-10-17 19:14:22 +0100 | [diff] [blame] | 54 | CHECKPATCH := $(CURDIR)/third_party/linux/scripts/checkpatch.pl \ |
Andrew Walbran | a65a132 | 2020-04-06 19:32:32 +0100 | [diff] [blame] | 55 | --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 Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 56 | |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 57 | # Specifies the grep pattern for ignoring specific files in checkpatch. |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 58 | # C++ headers, *.hh, are automatically excluded. |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 59 | # Separate the different items in the list with a grep or (\|). |
| 60 | # debug_el1.c : uses XMACROS, which checkpatch doesn't understand. |
Fuad Tabba | f1d6dc5 | 2019-09-18 17:33:14 +0100 | [diff] [blame] | 61 | # perfmon.c : uses XMACROS, which checkpatch doesn't understand. |
Fuad Tabba | 77a4b01 | 2019-11-15 12:13:08 +0000 | [diff] [blame] | 62 | # feature_id.c : uses XMACROS, which checkpatch doesn't understand. |
| 63 | CHECKPATCH_IGNORE := "src/arch/aarch64/hypervisor/debug_el1.c\|src/arch/aarch64/hypervisor/perfmon.c\|src/arch/aarch64/hypervisor/feature_id.c" |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 64 | |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 65 | OUT ?= out/$(PROJECT) |
| 66 | OUT_DIR = out/$(PROJECT) |
Andrew Scull | 114096b | 2018-07-31 14:42:16 +0100 | [diff] [blame] | 67 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 68 | .PHONY: all |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 69 | all: $(OUT_DIR)/build.ninja |
| 70 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 71 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 72 | $(OUT_DIR)/build.ninja: |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 73 | @$(GN) --export-compile-commands gen --args='$(GN_ARGS)' $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 74 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 75 | .PHONY: clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 76 | clean: |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 77 | @$(NINJA) -C $(OUT_DIR) -t clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 78 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 79 | .PHONY: clobber |
Andrew Scull | a158e91 | 2018-07-16 11:32:13 +0100 | [diff] [blame] | 80 | clobber: |
| 81 | rm -rf $(OUT) |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 82 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 83 | # see .clang-format. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 84 | .PHONY: format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 85 | format: |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 86 | @echo "Formatting..." |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 87 | @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 Walbran | f61ae3e | 2020-02-12 17:06:35 +0000 | [diff] [blame] | 91 | @find vmlib/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
Andrew Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 92 | @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 93 | |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 94 | .PHONY: checkpatch |
| 95 | checkpatch: |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 96 | @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 Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 98 | # TODO: enable for test/ |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 99 | @find project/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 100 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 101 | # see .clang-tidy. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 102 | .PHONY: tidy |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 103 | tidy: $(OUT_DIR)/build.ninja |
| 104 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 105 | @echo "Tidying..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 106 | # TODO: enable readability-magic-numbers once there are fewer violations. |
| 107 | # TODO: enable for c++ tests as it currently gives spurious errors. |
Olivier Deprez | 9fa3696 | 2021-09-20 14:32:14 +0100 | [diff] [blame] | 108 | @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix |
| 109 | @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 110 | |
| 111 | .PHONY: check |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 112 | check: $(OUT_DIR)/build.ninja |
| 113 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 114 | @echo "Checking..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 115 | # TODO: enable for c++ tests as it currently gives spurious errors. |
Olivier Deprez | 9fa3696 | 2021-09-20 14:32:14 +0100 | [diff] [blame] | 116 | @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 Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 118 | |
| 119 | .PHONY: license |
| 120 | license: |
Olivier Deprez | 21f625b | 2023-02-02 14:02:56 +0000 | [diff] [blame] | 121 | @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 Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 130 | |
| 131 | .PHONY: update-prebuilts |
| 132 | update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz |
| 133 | |
| 134 | prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja |
David Brazdil | 33cc5c0 | 2019-12-10 10:44:14 +0000 | [diff] [blame] | 135 | @$(NINJA) -C $(OUT_DIR) "third_party/linux" |
| 136 | cp out/reference/obj/third_party/linux/linux.bin $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 137 | |
| 138 | endif # HAFNIUM_HERMETIC_BUILD |