blob: 8ad1562097bb2ac49be86ac933a3bf3adb400596 [file] [log] [blame]
Andrew Sculla158e912018-07-16 11:32:13 +01001OUT ?= out
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01002
Andrew Scullbf570f22018-08-08 15:35:54 +01003# Set path to prebuilts used in the build.
Andrew Scull49a8e832018-08-03 13:02:09 +01004UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Andrew Scullbf570f22018-08-08 15:35:54 +01005PREBUILTS := $(PWD)/prebuilts/$(UNNAME_S)-x64
Andrew Scull49a8e832018-08-03 13:02:09 +01006GN ?= $(PREBUILTS)/gn/gn
7NINJA ?= $(PREBUILTS)/ninja/ninja
Andrew Scullbf570f22018-08-08 15:35:54 +01008export PATH := $(PREBUILTS)/clang/bin:$(PATH)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01009
Andrew Scullbf570f22018-08-08 15:35:54 +010010# Configure the build arguments.
Andrew Scull114096b2018-07-31 14:42:16 +010011GCC ?= false
12ARCH ?= aarch64
13PLATFORM ?= qemu
14
Andrew Scullbe199df2018-08-07 17:42:31 +010015.PHONY: all
Andrew Sculla158e912018-07-16 11:32:13 +010016all: $(OUT)/build.ninja
17 @$(NINJA) -C $(OUT)
Andrew Scull5e96ef72018-07-18 10:46:26 +010018
Andrew Scull49a8e832018-08-03 13:02:09 +010019$(OUT)/build.ninja: $(OUT)/args.gn
Andrew Scullbe199df2018-08-07 17:42:31 +010020 @$(GN) --export-compile-commands gen $(OUT)
Andrew Scull5e96ef72018-07-18 10:46:26 +010021
Andrew Scull114096b2018-07-31 14:42:16 +010022# Configure the build by loading the configuration arguments for the
Andrew Scullbf570f22018-08-08 15:35:54 +010023# architecture and platform.
Andrew Scull114096b2018-07-31 14:42:16 +010024$(OUT)/args.gn: build/arch/$(ARCH)/$(PLATFORM).args
25 @echo Copying config for $(ARCH) on $(PLATFORM)
26 @mkdir -p $(OUT)
27 @echo "arch = \"$(ARCH)\"" >> $@
28 @echo "use_gcc = $(GCC)" >> $@
29 @echo >> $@
30 @cat $< >> $@
31
Andrew Scullbe199df2018-08-07 17:42:31 +010032.PHONY: clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010033clean:
Andrew Sculla158e912018-07-16 11:32:13 +010034 @$(NINJA) -C $(OUT) -t clean
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010035
Andrew Scullbe199df2018-08-07 17:42:31 +010036.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010037clobber:
38 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010039
Andrew Scullbf570f22018-08-08 15:35:54 +010040# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010041.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010042format:
Andrew Scull80871322018-08-06 12:04:09 +010043 @echo "Formatting..."
Andrew Sculla158e912018-07-16 11:32:13 +010044 @find src/ -name *.c -o -name *.h | xargs clang-format -style file -i
45 @find inc/ -name *.c -o -name *.h | xargs clang-format -style file -i
Andrew Scullaf5e53e2018-07-23 19:19:46 +010046 @find test/ -name *.c -o -name *.h | xargs clang-format -style file -i
Andrew Sculla158e912018-07-16 11:32:13 +010047 @find . -name *.gn -o -name *.gni -exec $(GN) format {} \;
Andrew Scull4f170f52018-07-19 12:58:20 +010048
Andrew Scullbf570f22018-08-08 15:35:54 +010049# see .clang-tidy.
Andrew Scullbe199df2018-08-07 17:42:31 +010050.PHONY: tidy
51tidy: $(OUT)/build.ninja
52 @$(NINJA) -C $(OUT)
53 @echo "Tidying..."
54 @find src/ -name *.c -exec clang-tidy -p $(OUT) -fix {} \;
55 @find test/ -name *.c -exec clang-tidy -p $(OUT) -fix {} \;
Andrew Scull2a495c22018-08-12 23:07:30 +010056
57.PHONY: check
58check: $(OUT)/build.ninja
59 @$(NINJA) -C $(OUT)
60 @echo "Checking..."
61 @find src/ -name *.c -exec clang-check -p $(OUT) -analyze {} \;
62 @find test/ -name *.c -exec clang-check -p $(OUT) -analyze {} \;