blob: 619ac1c9c5f7bd11ecb06af6a1deef0cb63f4dc5 [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
Andrew Scullbf570f22018-08-08 15:35:54 +010015# Set path to prebuilts used in the build.
Andrew Scull49a8e832018-08-03 13:02:09 +010016UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Andrew Scullbf570f22018-08-08 15:35:54 +010017PREBUILTS := $(PWD)/prebuilts/$(UNNAME_S)-x64
Andrew Scull49a8e832018-08-03 13:02:09 +010018GN ?= $(PREBUILTS)/gn/gn
19NINJA ?= $(PREBUILTS)/ninja/ninja
Andrew Scullbf570f22018-08-08 15:35:54 +010020export PATH := $(PREBUILTS)/clang/bin:$(PATH)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010021
Andrew Scullcbefbdb2019-01-11 16:36:26 +000022CHECKPATCH := $(PWD)/third_party/linux/scripts/checkpatch.pl \
23 --ignore BRACES,SPDX_LICENSE_TAG,VOLATILE,SPLIT_STRING,AVOID_EXTERNS,USE_SPINLOCK_T,NEW_TYPEDEFS,INITIALISED_STATIC,FILE_PATH_CHANGES,EMBEDDED_FUNCTION_NAME --quiet
24
Andrew Scullb401ba32018-11-09 10:30:54 +000025# Select the project to build.
26PROJECT ?= reference
27
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000028OUT ?= out/$(PROJECT)
29OUT_DIR = out/$(PROJECT)
Andrew Scull114096b2018-07-31 14:42:16 +010030
Andrew Scullbe199df2018-08-07 17:42:31 +010031.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010032all: $(OUT_DIR)/build.ninja
33 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010034
Andrew Scull23e93a82018-10-26 14:56:04 +010035$(OUT_DIR)/build.ninja:
Andrew Scullb401ba32018-11-09 10:30:54 +000036 @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010037
Andrew Scullbe199df2018-08-07 17:42:31 +010038.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010039clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010040 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010041
Andrew Scullbe199df2018-08-07 17:42:31 +010042.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010043clobber:
44 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010045
Andrew Scullbf570f22018-08-08 15:35:54 +010046# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010047.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010048format:
Andrew Scull80871322018-08-06 12:04:09 +010049 @echo "Formatting..."
Andrew Sculle9827712018-10-19 14:54:20 +010050 @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
51 @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
52 @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
Andrew Scullb401ba32018-11-09 10:30:54 +000053 @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010054 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010055
Andrew Scullcbefbdb2019-01-11 16:36:26 +000056.PHONY: checkpatch
57checkpatch:
58 @find src/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
59 @find inc/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
60 # TODO: enable for test/
61 @find project/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
62
Andrew Scullbf570f22018-08-08 15:35:54 +010063# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +010064.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +010065tidy: $(OUT_DIR)/build.ninja
66 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +010067 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +000068 # TODO: enable readability-magic-numbers once there are fewer violations.
69 # TODO: enable for c++ tests as it currently gives spurious errors.
70 @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
71 @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
Andrew Scull2a495c22018-08-12 23:07:30 +010072
73.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +010074check: $(OUT_DIR)/build.ninja
75 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +010076 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +000077 # TODO: enable for c++ tests as it currently gives spurious errors.
78 @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
79 @find test/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
Andrew Scull18834872018-10-12 11:48:09 +010080
81.PHONY: license
82license:
Andrew Scull4c86ff52018-10-29 11:22:28 +000083 @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h | xargs -n1 python build/license.py --style c
84 @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h | xargs -n1 python build/license.py --style c
85 @find test/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h | xargs -n1 python build/license.py --style c
Andrew Sculle9827712018-10-19 14:54:20 +010086 @find build/ -name \*.py| xargs -n1 python build/license.py --style hash
87 @find test/ -name \*.py| xargs -n1 python build/license.py --style hash
88 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 python build/license.py --style hash
Andrew Walbranbc342d42019-02-05 16:56:02 +000089
90.PHONY: update-prebuilts
91update-prebuilts: prebuilts/linux-aarch64/linux/vmlinuz
92
93prebuilts/linux-aarch64/linux/vmlinuz: $(OUT_DIR)/build.ninja
94 @$(NINJA) -C $(OUT_DIR) "third_party:linux"
95 cp out/reference/obj/third_party/linux.bin $@