blob: 2d3a8858e85ac58f774e9f115a1332ccc69dc115 [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 Brazdil5ecf75f2019-07-21 10:39:47 +020015# 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.
18ifeq ($(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.
25all:
26 @$(PWD)/build/run_in_container.sh make $@
27
28# Catch-all target.
29.DEFAULT:
30 @$(PWD)/build/run_in_container.sh make $@
31
32else # HAFNIUM_HERMETIC_BUILD
33
Andrew Scullbf570f22018-08-08 15:35:54 +010034# Set path to prebuilts used in the build.
Andrew Scull49a8e832018-08-03 13:02:09 +010035UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Andrew Scullbf570f22018-08-08 15:35:54 +010036PREBUILTS := $(PWD)/prebuilts/$(UNNAME_S)-x64
Andrew Scull49a8e832018-08-03 13:02:09 +010037GN ?= $(PREBUILTS)/gn/gn
38NINJA ?= $(PREBUILTS)/ninja/ninja
Andrew Scullbf570f22018-08-08 15:35:54 +010039export PATH := $(PREBUILTS)/clang/bin:$(PATH)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010040
Andrew Scullcbefbdb2019-01-11 16:36:26 +000041CHECKPATCH := $(PWD)/third_party/linux/scripts/checkpatch.pl \
David Brazdil7a462ec2019-08-15 12:27:47 +010042 --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 Scullcbefbdb2019-01-11 16:36:26 +000043
Andrew Scullb401ba32018-11-09 10:30:54 +000044# Select the project to build.
45PROJECT ?= reference
46
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000047OUT ?= out/$(PROJECT)
48OUT_DIR = out/$(PROJECT)
Andrew Scull114096b2018-07-31 14:42:16 +010049
Andrew Scullbe199df2018-08-07 17:42:31 +010050.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010051all: $(OUT_DIR)/build.ninja
52 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010053
Andrew Scull23e93a82018-10-26 14:56:04 +010054$(OUT_DIR)/build.ninja:
Andrew Scullb401ba32018-11-09 10:30:54 +000055 @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010056
Andrew Scullbe199df2018-08-07 17:42:31 +010057.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010058clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010059 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010060
Andrew Scullbe199df2018-08-07 17:42:31 +010061.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010062clobber:
63 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010064
Andrew Scullbf570f22018-08-08 15:35:54 +010065# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010066.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010067format:
Andrew Scull80871322018-08-06 12:04:09 +010068 @echo "Formatting..."
Andrew Sculle9827712018-10-19 14:54:20 +010069 @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
70 @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
71 @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
Andrew Scullb401ba32018-11-09 10:30:54 +000072 @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010073 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010074
Andrew Scullcbefbdb2019-01-11 16:36:26 +000075.PHONY: checkpatch
76checkpatch:
77 @find src/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
78 @find inc/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
79 # TODO: enable for test/
80 @find project/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
81
Andrew Scullbf570f22018-08-08 15:35:54 +010082# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +010083.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +010084tidy: $(OUT_DIR)/build.ninja
85 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +010086 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +000087 # TODO: enable readability-magic-numbers once there are fewer violations.
88 # TODO: enable for c++ tests as it currently gives spurious errors.
89 @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
90 @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
Andrew Scull2a495c22018-08-12 23:07:30 +010091
92.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +010093check: $(OUT_DIR)/build.ninja
94 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +010095 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +000096 # TODO: enable for c++ tests as it currently gives spurious errors.
97 @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
98 @find test/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
Andrew Scull18834872018-10-12 11:48:09 +010099
100.PHONY: license
101license:
David Brazdil7a462ec2019-08-15 12:27:47 +0100102 @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
103 @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.dts | xargs -n1 python build/license.py --style c
104 @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 +0100105 @find build/ -name \*.py| xargs -n1 python build/license.py --style hash
106 @find test/ -name \*.py| xargs -n1 python build/license.py --style hash
107 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 python build/license.py --style hash
Andrew Walbranbc342d42019-02-05 16:56:02 +0000108
109.PHONY: update-prebuilts
110update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz
111
112prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja
113 @$(NINJA) -C $(OUT_DIR) "third_party:linux"
114 cp out/reference/obj/third_party/linux.bin $@
David Brazdil5ecf75f2019-07-21 10:39:47 +0200115
116endif # HAFNIUM_HERMETIC_BUILD