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 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
David Brazdil | ac4024a | 2019-10-01 11:19:43 +0100 | [diff] [blame] | 15 | # Select the project to build. |
| 16 | PROJECT ?= reference |
| 17 | |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 18 | # If HAFNIUM_HERMETIC_BUILD is "true" (not default), invoke `make` inside |
| 19 | # a container. The 'run_in_container.sh' script will set the variable value to |
| 20 | # 'inside' to avoid recursion. |
| 21 | ifeq ($(HAFNIUM_HERMETIC_BUILD),true) |
| 22 | |
| 23 | # TODO: This is not ideal as (a) we invoke the container once per command-line |
| 24 | # target, and (b) we cannot pass `make` arguments to the script. We could |
| 25 | # consider creating a bash alias for `make` to invoke the script directly. |
| 26 | |
| 27 | # Need to define at least one non-default target. |
| 28 | all: |
Andrew Walbran | 3586d83 | 2019-10-17 19:14:22 +0100 | [diff] [blame] | 29 | @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 30 | |
| 31 | # Catch-all target. |
| 32 | .DEFAULT: |
Andrew Walbran | 3586d83 | 2019-10-17 19:14:22 +0100 | [diff] [blame] | 33 | @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 34 | |
| 35 | else # HAFNIUM_HERMETIC_BUILD |
| 36 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 37 | # Set path to prebuilts used in the build. |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 38 | UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
Andrew Walbran | 3586d83 | 2019-10-17 19:14:22 +0100 | [diff] [blame] | 39 | PREBUILTS := $(CURDIR)/prebuilts/$(UNNAME_S)-x64 |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 40 | GN ?= $(PREBUILTS)/gn/gn |
| 41 | NINJA ?= $(PREBUILTS)/ninja/ninja |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 42 | export PATH := $(PREBUILTS)/clang/bin:$(PATH) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 43 | |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 44 | |
Andrew Walbran | 3586d83 | 2019-10-17 19:14:22 +0100 | [diff] [blame] | 45 | CHECKPATCH := $(CURDIR)/third_party/linux/scripts/checkpatch.pl \ |
Andrew Walbran | d88ee92 | 2020-01-15 18:13:21 +0000 | [diff] [blame] | 46 | --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 --quiet |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 47 | |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 48 | # Specifies the grep pattern for ignoring specific files in checkpatch. |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 49 | # C++ headers, *.hh, are automatically excluded. |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 50 | # Separate the different items in the list with a grep or (\|). |
| 51 | # debug_el1.c : uses XMACROS, which checkpatch doesn't understand. |
Fuad Tabba | f1d6dc5 | 2019-09-18 17:33:14 +0100 | [diff] [blame] | 52 | # perfmon.c : uses XMACROS, which checkpatch doesn't understand. |
Fuad Tabba | 77a4b01 | 2019-11-15 12:13:08 +0000 | [diff] [blame] | 53 | # feature_id.c : uses XMACROS, which checkpatch doesn't understand. |
| 54 | 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] | 55 | |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 56 | OUT ?= out/$(PROJECT) |
| 57 | OUT_DIR = out/$(PROJECT) |
Andrew Scull | 114096b | 2018-07-31 14:42:16 +0100 | [diff] [blame] | 58 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 59 | .PHONY: all |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 60 | all: $(OUT_DIR)/build.ninja |
| 61 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 62 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 63 | $(OUT_DIR)/build.ninja: |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 64 | @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 65 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 66 | .PHONY: clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 67 | clean: |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 68 | @$(NINJA) -C $(OUT_DIR) -t clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 69 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 70 | .PHONY: clobber |
Andrew Scull | a158e91 | 2018-07-16 11:32:13 +0100 | [diff] [blame] | 71 | clobber: |
| 72 | rm -rf $(OUT) |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 73 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 74 | # see .clang-format. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 75 | .PHONY: format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 76 | format: |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 77 | @echo "Formatting..." |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 78 | @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
| 79 | @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
| 80 | @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
| 81 | @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^] | 82 | @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] | 83 | @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 84 | |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 85 | .PHONY: checkpatch |
| 86 | checkpatch: |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 87 | @find src/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f |
| 88 | @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] | 89 | # TODO: enable for test/ |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 90 | @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] | 91 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 92 | # see .clang-tidy. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 93 | .PHONY: tidy |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 94 | tidy: $(OUT_DIR)/build.ninja |
| 95 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 96 | @echo "Tidying..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 97 | # TODO: enable readability-magic-numbers once there are fewer violations. |
| 98 | # TODO: enable for c++ tests as it currently gives spurious errors. |
| 99 | @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix |
| 100 | @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 101 | |
| 102 | .PHONY: check |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 103 | check: $(OUT_DIR)/build.ninja |
| 104 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 105 | @echo "Checking..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 106 | # TODO: enable for c++ tests as it currently gives spurious errors. |
| 107 | @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can |
| 108 | @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] | 109 | |
| 110 | .PHONY: license |
| 111 | license: |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 112 | @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c |
| 113 | @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c |
| 114 | @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 Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 115 | @find build/ -name \*.py| xargs -n1 python build/license.py --style hash |
| 116 | @find test/ -name \*.py| xargs -n1 python build/license.py --style hash |
| 117 | @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 python build/license.py --style hash |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 118 | |
| 119 | .PHONY: update-prebuilts |
| 120 | update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz |
| 121 | |
| 122 | prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja |
David Brazdil | 33cc5c0 | 2019-12-10 10:44:14 +0000 | [diff] [blame] | 123 | @$(NINJA) -C $(OUT_DIR) "third_party/linux" |
| 124 | cp out/reference/obj/third_party/linux/linux.bin $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 125 | |
| 126 | endif # HAFNIUM_HERMETIC_BUILD |