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