Andrew Walbran | 40a3368 | 2018-11-30 11:58:36 +0000 | [diff] [blame] | 1 | # 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 Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 15 | # Set path to prebuilts used in the build. |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 16 | UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 17 | PREBUILTS := $(PWD)/prebuilts/$(UNNAME_S)-x64 |
Andrew Scull | 49a8e83 | 2018-08-03 13:02:09 +0100 | [diff] [blame] | 18 | GN ?= $(PREBUILTS)/gn/gn |
| 19 | NINJA ?= $(PREBUILTS)/ninja/ninja |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 20 | export PATH := $(PREBUILTS)/clang/bin:$(PATH) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 21 | |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame^] | 22 | # Select the project to build. |
| 23 | PROJECT ?= reference |
| 24 | |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 25 | OUT ?= out |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 26 | OUT_DIR = out |
Andrew Scull | 114096b | 2018-07-31 14:42:16 +0100 | [diff] [blame] | 27 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 28 | .PHONY: all |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 29 | all: $(OUT_DIR)/build.ninja |
| 30 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 31 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 32 | $(OUT_DIR)/build.ninja: |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame^] | 33 | @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 34 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 35 | .PHONY: clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 36 | clean: |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 37 | @$(NINJA) -C $(OUT_DIR) -t clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 38 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 39 | .PHONY: clobber |
Andrew Scull | a158e91 | 2018-07-16 11:32:13 +0100 | [diff] [blame] | 40 | clobber: |
| 41 | rm -rf $(OUT) |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 42 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 43 | # see .clang-format. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 44 | .PHONY: format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 45 | format: |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 46 | @echo "Formatting..." |
Andrew Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 47 | @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 Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame^] | 50 | @find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i |
Andrew Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 51 | @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 52 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 53 | # see .clang-tidy. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 54 | .PHONY: tidy |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 55 | tidy: $(OUT_DIR)/build.ninja |
| 56 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 57 | @echo "Tidying..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 58 | # 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 Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 62 | |
| 63 | .PHONY: check |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 64 | check: $(OUT_DIR)/build.ninja |
| 65 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 66 | @echo "Checking..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 67 | # 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 Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 70 | |
| 71 | .PHONY: license |
| 72 | license: |
Andrew Scull | 4c86ff5 | 2018-10-29 11:22:28 +0000 | [diff] [blame] | 73 | @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 Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 76 | @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 |