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 | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 15 | # 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. |
| 18 | ifeq ($(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. |
| 25 | all: |
| 26 | @$(PWD)/build/run_in_container.sh make $@ |
| 27 | |
| 28 | # Catch-all target. |
| 29 | .DEFAULT: |
| 30 | @$(PWD)/build/run_in_container.sh make $@ |
| 31 | |
| 32 | else # HAFNIUM_HERMETIC_BUILD |
| 33 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 34 | # Set path to prebuilts used in the build. |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 35 | UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 36 | PREBUILTS := $(PWD)/prebuilts/$(UNNAME_S)-x64 |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 37 | GN ?= $(PREBUILTS)/gn/gn |
| 38 | NINJA ?= $(PREBUILTS)/ninja/ninja |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 39 | export PATH := $(PREBUILTS)/clang/bin:$(PATH) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 40 | |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 41 | |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 42 | CHECKPATCH := $(PWD)/third_party/linux/scripts/checkpatch.pl \ |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 43 | --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 --quiet |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 44 | |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 45 | # Specifies the grep pattern for ignoring specific files in checkpatch. |
| 46 | # Separate the different items in the list with a grep or (\|). |
| 47 | # debug_el1.c : uses XMACROS, which checkpatch doesn't understand. |
| 48 | CHECKPATCH_IGNORE := "src/arch/aarch64/hypervisor/debug_el1.c" |
| 49 | |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 50 | # Select the project to build. |
| 51 | PROJECT ?= reference |
| 52 | |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 53 | OUT ?= out/$(PROJECT) |
| 54 | OUT_DIR = out/$(PROJECT) |
Andrew Scull | 114096b | 2018-07-31 14:42:16 +0100 | [diff] [blame] | 55 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 56 | .PHONY: all |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 57 | all: $(OUT_DIR)/build.ninja |
| 58 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 59 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 60 | $(OUT_DIR)/build.ninja: |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 61 | @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 62 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 63 | .PHONY: clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 64 | clean: |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 65 | @$(NINJA) -C $(OUT_DIR) -t clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 66 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 67 | .PHONY: clobber |
Andrew Scull | a158e91 | 2018-07-16 11:32:13 +0100 | [diff] [blame] | 68 | clobber: |
| 69 | rm -rf $(OUT) |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 70 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 71 | # see .clang-format. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 72 | .PHONY: format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 73 | format: |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 74 | @echo "Formatting..." |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame^] | 75 | @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
| 76 | @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
| 77 | @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i |
| 78 | @find project/ -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] | 79 | @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 80 | |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 81 | .PHONY: checkpatch |
| 82 | checkpatch: |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 83 | @find src/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f |
| 84 | @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] | 85 | # TODO: enable for test/ |
Fuad Tabba | c76466d | 2019-09-06 10:42:12 +0100 | [diff] [blame] | 86 | @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] | 87 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 88 | # see .clang-tidy. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 89 | .PHONY: tidy |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 90 | tidy: $(OUT_DIR)/build.ninja |
| 91 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 92 | @echo "Tidying..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 93 | # TODO: enable readability-magic-numbers once there are fewer violations. |
| 94 | # TODO: enable for c++ tests as it currently gives spurious errors. |
| 95 | @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix |
| 96 | @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 97 | |
| 98 | .PHONY: check |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 99 | check: $(OUT_DIR)/build.ninja |
| 100 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 101 | @echo "Checking..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 102 | # TODO: enable for c++ tests as it currently gives spurious errors. |
| 103 | @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can |
| 104 | @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] | 105 | |
| 106 | .PHONY: license |
| 107 | license: |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 108 | @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c |
| 109 | @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c |
| 110 | @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] | 111 | @find build/ -name \*.py| xargs -n1 python build/license.py --style hash |
| 112 | @find test/ -name \*.py| xargs -n1 python build/license.py --style hash |
| 113 | @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] | 114 | |
| 115 | .PHONY: update-prebuilts |
| 116 | update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz |
| 117 | |
| 118 | prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja |
| 119 | @$(NINJA) -C $(OUT_DIR) "third_party:linux" |
| 120 | cp out/reference/obj/third_party/linux.bin $@ |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 121 | |
| 122 | endif # HAFNIUM_HERMETIC_BUILD |