blob: 0b1851c3650e652a0cd141b3aea805f55dd90388 [file] [log] [blame]
Andrew Walbran40a33682018-11-30 11:58:36 +00001# Copyright 2018 Google LLC
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
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 Scullb401ba32018-11-09 10:30:54 +000022# Select the project to build.
23PROJECT ?= reference
24
Andrew Scull58de5c32018-08-15 17:20:02 +010025OUT ?= out
Andrew Scull23e93a82018-10-26 14:56:04 +010026OUT_DIR = out
Andrew Scull114096b2018-07-31 14:42:16 +010027
Andrew Scullbe199df2018-08-07 17:42:31 +010028.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010029all: $(OUT_DIR)/build.ninja
30 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010031
Andrew Scull23e93a82018-10-26 14:56:04 +010032$(OUT_DIR)/build.ninja:
Andrew Scullb401ba32018-11-09 10:30:54 +000033 @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010034
Andrew Scullbe199df2018-08-07 17:42:31 +010035.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010036clean:
Andrew Scull58de5c32018-08-15 17:20:02 +010037 @$(NINJA) -C $(OUT_DIR) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010038
Andrew Scullbe199df2018-08-07 17:42:31 +010039.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010040clobber:
41 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010042
Andrew Scullbf570f22018-08-08 15:35:54 +010043# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010044.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010045format:
Andrew Scull80871322018-08-06 12:04:09 +010046 @echo "Formatting..."
Andrew Sculle9827712018-10-19 14:54:20 +010047 @find src/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
48 @find inc/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
49 @find test/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
Andrew Scullb401ba32018-11-09 10:30:54 +000050 @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
Andrew Sculle9827712018-10-19 14:54:20 +010051 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
Andrew Scull4f170f52018-07-19 12:58:20 +010052
Andrew Scullbf570f22018-08-08 15:35:54 +010053# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +010054.PHONY: tidy
Andrew Scull58de5c32018-08-15 17:20:02 +010055tidy: $(OUT_DIR)/build.ninja
56 @$(NINJA) -C $(OUT_DIR)
Andrew Scullbe199df2018-08-07 17:42:31 +010057 @echo "Tidying..."
Andrew Scull93753872018-11-16 16:47:57 +000058 # TODO: enable readability-magic-numbers once there are fewer violations.
59 # TODO: enable for c++ tests as it currently gives spurious errors.
60 @find src/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
61 @find test/ \( -name \*.c \) | xargs clang-tidy -p $(OUT_DIR) -fix
Andrew Scull2a495c22018-08-12 23:07:30 +010062
63.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +010064check: $(OUT_DIR)/build.ninja
65 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +010066 @echo "Checking..."
Andrew Scull93753872018-11-16 16:47:57 +000067 # TODO: enable for c++ tests as it currently gives spurious errors.
68 @find src/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
69 @find test/ \( -name \*.c \) | xargs clang-check -p $(OUT_DIR) -analyze -fix-what-you-can
Andrew Scull18834872018-10-12 11:48:09 +010070
71.PHONY: license
72license:
Andrew Scull4c86ff52018-10-29 11:22:28 +000073 @find src/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h | xargs -n1 python build/license.py --style c
74 @find inc/ -name \*.S -o -name \*.c -o -name \*.cc -o -name \*.h | xargs -n1 python build/license.py --style c
75 @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 +010076 @find build/ -name \*.py| xargs -n1 python build/license.py --style hash
77 @find test/ -name \*.py| xargs -n1 python build/license.py --style hash
78 @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 python build/license.py --style hash