blob: 467b068103281e8609ad1d242b11a537031c8d03 [file] [log] [blame]
Andrew Scullbf570f22018-08-08 15:35:54 +01001# Set path to prebuilts used in the build.
Andrew Scull49a8e832018-08-03 13:02:09 +01002UNNAME_S := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Andrew Scullbf570f22018-08-08 15:35:54 +01003PREBUILTS := $(PWD)/prebuilts/$(UNNAME_S)-x64
Andrew Scull49a8e832018-08-03 13:02:09 +01004GN ?= $(PREBUILTS)/gn/gn
5NINJA ?= $(PREBUILTS)/ninja/ninja
Andrew Scullbf570f22018-08-08 15:35:54 +01006export PATH := $(PREBUILTS)/clang/bin:$(PATH)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01007
Andrew Scullbf570f22018-08-08 15:35:54 +01008# Configure the build arguments.
Andrew Scull114096b2018-07-31 14:42:16 +01009ARCH ?= aarch64
10PLATFORM ?= qemu
Andrew Scull58de5c32018-08-15 17:20:02 +010011GCC ?= false
12
13# Place builds for different architectures and platforms in different
14# directories.
15OUT ?= out
16OUT_DIR = out/$(ARCH)/$(PLATFORM)
Andrew Scull114096b2018-07-31 14:42:16 +010017
Andrew Scullbe199df2018-08-07 17:42:31 +010018.PHONY: all
Andrew Scull58de5c32018-08-15 17:20:02 +010019all: $(OUT_DIR)/build.ninja
20 @$(NINJA) -C $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010021
Andrew Scull58de5c32018-08-15 17:20:02 +010022$(OUT_DIR)/build.ninja: $(OUT_DIR)/args.gn
23 @$(GN) --export-compile-commands gen $(OUT_DIR)
Andrew Scull5e96ef72018-07-18 10:46:26 +010024
Andrew Scull114096b2018-07-31 14:42:16 +010025# Configure the build by loading the configuration arguments for the
Andrew Scullbf570f22018-08-08 15:35:54 +010026# architecture and platform.
Andrew Scull58de5c32018-08-15 17:20:02 +010027$(OUT_DIR)/args.gn: build/arch/$(ARCH)/$(PLATFORM).args
Andrew Scull114096b2018-07-31 14:42:16 +010028 @echo Copying config for $(ARCH) on $(PLATFORM)
Andrew Scull58de5c32018-08-15 17:20:02 +010029 @mkdir -p $(OUT_DIR)
Andrew Scull114096b2018-07-31 14:42:16 +010030 @echo "arch = \"$(ARCH)\"" >> $@
31 @echo "use_gcc = $(GCC)" >> $@
32 @echo >> $@
33 @cat $< >> $@
34
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
38 rm -f $(OUT_DIR)/args.gn
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010039
Andrew Scullbe199df2018-08-07 17:42:31 +010040.PHONY: clobber
Andrew Sculla158e912018-07-16 11:32:13 +010041clobber:
42 rm -rf $(OUT)
Andrew Scull7364a8e2018-07-19 15:39:29 +010043
Andrew Scullbf570f22018-08-08 15:35:54 +010044# see .clang-format.
Andrew Scullbe199df2018-08-07 17:42:31 +010045.PHONY: format
Andrew Scull4f170f52018-07-19 12:58:20 +010046format:
Andrew Scull80871322018-08-06 12:04:09 +010047 @echo "Formatting..."
Andrew Scull04502e42018-09-03 14:54:52 +010048 @find src/ -name *.c -o -name *.cc -o -name *.h | xargs clang-format -style file -i
49 @find inc/ -name *.c -o -name *.cc -o -name *.h | xargs clang-format -style file -i
50 @find test/ -name *.c -o -name *.cc -o -name *.h | xargs clang-format -style file -i
Andrew Scullbac419c2018-08-15 15:48:44 +010051 @find . \( -name *.gn -o -name *.gni \) -exec $(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 Scull04502e42018-09-03 14:54:52 +010058 @find src/ \( -name *.c -o -name *.cc \) -exec clang-tidy -p $(OUT_DIR) -fix {} \;
59 @find test/ \( -name *.c -o -name *.cc \) -exec clang-tidy -p $(OUT_DIR) -fix {} \;
Andrew Scull2a495c22018-08-12 23:07:30 +010060
61.PHONY: check
Andrew Scull58de5c32018-08-15 17:20:02 +010062check: $(OUT_DIR)/build.ninja
63 @$(NINJA) -C $(OUT_DIR)
Andrew Scull2a495c22018-08-12 23:07:30 +010064 @echo "Checking..."
Andrew Scull04502e42018-09-03 14:54:52 +010065 @find src/ \( -name *.c -o -name *.cc \) -exec clang-check -p $(OUT_DIR) -analyze {} \;
66 @find test/ \( -name *.c -o -name *.cc \) -exec clang-check -p $(OUT_DIR) -analyze {} \;