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 | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 22 | CHECKPATCH := $(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 Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 25 | # Select the project to build. |
| 26 | PROJECT ?= reference |
| 27 | |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame^] | 28 | OUT ?= out/$(PROJECT) |
| 29 | OUT_DIR = out/$(PROJECT) |
Andrew Scull | 114096b | 2018-07-31 14:42:16 +0100 | [diff] [blame] | 30 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 31 | .PHONY: all |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 32 | all: $(OUT_DIR)/build.ninja |
| 33 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 34 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 35 | $(OUT_DIR)/build.ninja: |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 36 | @$(GN) --export-compile-commands gen --args='project="$(PROJECT)"' $(OUT_DIR) |
Andrew Scull | 5e96ef7 | 2018-07-18 10:46:26 +0100 | [diff] [blame] | 37 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 38 | .PHONY: clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 39 | clean: |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 40 | @$(NINJA) -C $(OUT_DIR) -t clean |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 41 | |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 42 | .PHONY: clobber |
Andrew Scull | a158e91 | 2018-07-16 11:32:13 +0100 | [diff] [blame] | 43 | clobber: |
| 44 | rm -rf $(OUT) |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 45 | |
Andrew Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 46 | # see .clang-format. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 47 | .PHONY: format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 48 | format: |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 49 | @echo "Formatting..." |
Andrew Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 50 | @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 Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 53 | @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] | 54 | @find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 55 | |
Andrew Scull | cbefbdb | 2019-01-11 16:36:26 +0000 | [diff] [blame] | 56 | .PHONY: checkpatch |
| 57 | checkpatch: |
| 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 Scull | bf570f2 | 2018-08-08 15:35:54 +0100 | [diff] [blame] | 63 | # see .clang-tidy. |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 64 | .PHONY: tidy |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 65 | tidy: $(OUT_DIR)/build.ninja |
| 66 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | be199df | 2018-08-07 17:42:31 +0100 | [diff] [blame] | 67 | @echo "Tidying..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 68 | # 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 Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 72 | |
| 73 | .PHONY: check |
Andrew Scull | 58de5c3 | 2018-08-15 17:20:02 +0100 | [diff] [blame] | 74 | check: $(OUT_DIR)/build.ninja |
| 75 | @$(NINJA) -C $(OUT_DIR) |
Andrew Scull | 2a495c2 | 2018-08-12 23:07:30 +0100 | [diff] [blame] | 76 | @echo "Checking..." |
Andrew Scull | 9375387 | 2018-11-16 16:47:57 +0000 | [diff] [blame] | 77 | # 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 Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 80 | |
| 81 | .PHONY: license |
| 82 | license: |
Andrew Scull | 4c86ff5 | 2018-10-29 11:22:28 +0000 | [diff] [blame] | 83 | @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 Scull | e982771 | 2018-10-19 14:54:20 +0100 | [diff] [blame] | 86 | @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 |