blob: 01627c56bd00aa28ed5b656a0315c1fb8876109c [file] [log] [blame]
Andrew Walbran692b3252019-03-07 15:51:31 +00001# Copyright 2018 The Hafnium Authors.
Andrew Walbran40a33682018-11-30 11:58:36 +00002#
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 Brazdilac4024a2019-10-01 11:19:43 +010015# Select the project to build.
16PROJECT ?= reference
17
David Brazdil5ecf75f2019-07-21 10:39:47 +020018# 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.
21ifeq ($(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.
28all:
Andrew Walbran3586d832019-10-17 19:14:22 +010029 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020030
31# Catch-all target.
32.DEFAULT:
Andrew Walbran3586d832019-10-17 19:14:22 +010033 @$(CURDIR)/build/run_in_container.sh make PROJECT=$(PROJECT) $@
David Brazdil5ecf75f2019-07-21 10:39:47 +020034
35else # HAFNIUM_HERMETIC_BUILD
36
Andrew Scullbf570f22018-08-08 15:35:54 +010037# Set path to prebuilts used in the build.
Andrew Scull49a8e832018-08-03 13:02:09 +010038UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Andrew Walbran3586d832019-10-17 19:14:22 +010039PREBUILTS := $(CURDIR)/prebuilts/$(UNNAME_S)-x64
Andrew Scull49a8e832018-08-03 13:02:09 +010040GN ?= $(PREBUILTS)/gn/gn
41NINJA ?= $(PREBUILTS)/ninja/ninja
Andrew Scullbf570f22018-08-08 15:35:54 +010042export PATH := $(PREBUILTS)/clang/bin:$(PATH)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010043
Fuad Tabbac76466d2019-09-06 10:42:12 +010044
Andrew Walbran3586d832019-10-17 19:14:22 +010045CHECKPATCH := $(CURDIR)/third_party/linux/scripts/checkpatch.pl \
Andrew Walbrand88ee922020-01-15 18:13:21 +000046 --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 Scullcbefbdb2019-01-11 16:36:26 +000047
Fuad Tabbac76466d2019-09-06 10:42:12 +010048# Specifies the grep pattern for ignoring specific files in checkpatch.
Andrew Scull3c257452019-11-26 13:32:50 +000049# C++ headers, *.hh, are automatically excluded.
Fuad Tabbac76466d2019-09-06 10:42:12 +010050# Separate the different items in the list with a grep or (\|).
51# debug_el1.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabbaf1d6dc52019-09-18 17:33:14 +010052# perfmon.c : uses XMACROS, which checkpatch doesn't understand.
Fuad Tabba77a4b012019-11-15 12:13:08 +000053# feature_id.c : uses XMACROS, which checkpatch doesn't understand.
54CHECKPATCH_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 +010055
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000056OUT ?= out/$(PROJECT)
57OUT_DIR = out/$(PROJECT)
Andrew Scull114096b2018-07-31 14:42:16 +010058
Andrew Scullbe199df2018-08-07 17:42:31 +010059.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010060all: $(OUT_DIR)/build.ninja
61 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010062
Andrew Scull23e93a82018-10-26 14:56:04 +010063$(OUT_DIR)/build.ninja:
Andrew Scullb401ba32018-11-09 10:30:54 +000064 @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010065
Andrew Scullbe199df2018-08-07 17:42:31 +010066.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010067clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010068 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010069
Andrew Scullbe199df2018-08-07 17:42:31 +010070.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010071clobber:
72 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010073
Andrew Scullbf570f22018-08-08 15:35:54 +010074# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010075.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010076format:
Andrew Scull80871322018-08-06 12:04:09 +010077 @echo "Formatting..."
David Brazdil0dbb41f2019-09-09 18:03:35 +010078 @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 Walbranf61ae3e2020-02-12 17:06:35 +000082 @find vmlib/ -name \*.c -o -name \*.cc -o -name \*.h | xargs -r clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010083 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010084
Andrew Scullcbefbdb2019-01-11 16:36:26 +000085.PHONY: checkpatch
86checkpatch:
Fuad Tabbac76466d2019-09-06 10:42:12 +010087 @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 Scullcbefbdb2019-01-11 16:36:26 +000089 # TODO: enable for test/
Fuad Tabbac76466d2019-09-06 10:42:12 +010090 @find project/ -name \*.c -o -name \*.h | grep -v $(CHECKPATCH_IGNORE) | xargs $(CHECKPATCH) -f
Andrew Scullcbefbdb2019-01-11 16:36:26 +000091
Andrew Scullbf570f22018-08-08 15:35:54 +010092# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +010093.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +010094tidy: $(OUT_DIR)/build.ninja
95 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +010096 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +000097 # 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 Scull2a495c22018-08-12 23:07:30 +0100101
102.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +0100103check: $(OUT_DIR)/build.ninja
104 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +0100105 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +0000106 # 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 Scull18834872018-10-12 11:48:09 +0100109
110.PHONY: license
111license:
David Brazdil7a462ec2019-08-15 12:27:47 +0100112 @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 Sculle9827712018-10-19 14:54:20 +0100115 @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 Walbranbc342d42019-02-05 16:56:02 +0000118
119.PHONY: update-prebuilts
120update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz
121
122prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja
David Brazdil33cc5c02019-12-10 10:44:14 +0000123 @$(NINJA) -C $(OUT_DIR) "third_party/linux"
124 cp out/reference/obj/third_party/linux/linux.bin $@
David Brazdil5ecf75f2019-07-21 10:39:47 +0200125
126endif # HAFNIUM_HERMETIC_BUILD