summaryrefslogtreecommitdiff
path: root/scripts/main.mk
blob: cf062afc739e75f91f45458b64e6858d8ab39303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
ifeq ($(shell uname -s), Darwin)
  HOST_PLATFORM = osx
else
  HOST_PLATFORM = linux
endif

PLATFORM ?= $(HOST_PLATFORM)

ifeq ($(PLATFORM),android)
  CONFIGURE_PLATFORM = android
  CONFIGURE_SUBPLATFORM = $(firstword $(SUBPLATFORM) arm-v7)
  CONFIGURE_INPUT = platform/android/scripts/configure.sh
  PLATFORM_OUTPUT = ./build/android-$(CONFIGURE_SUBPLATFORM)

  GYP_FLAVOR_SUFFIX = -android
  ENV = $(shell MASON_ANDROID_ABI=$(CONFIGURE_SUBPLATFORM) ./platform/android/scripts/toolchain.sh)

else ifeq ($(PLATFORM),qt)
  CONFIGURE_PLATFORM = $(HOST_PLATFORM)
  CONFIGURE_SUBPLATFORM = $(shell uname -m)
  CONFIGURE_INPUT = platform/qt/scripts/configure.sh
  PLATFORM_OUTPUT = ./build/qt-$(HOST_PLATFORM)-$(CONFIGURE_SUBPLATFORM)

  # Cross compilation support
  ENV = $(shell MASON_PLATFORM_VERSION=$(CONFIGURE_SUBPLATFORM) ./platform/qt/scripts/toolchain.sh)

else ifeq ($(PLATFORM),node)
  CONFIGURE_PLATFORM = $(HOST_PLATFORM)
  CONFIGURE_SUBPLATFORM = $(shell uname -m)
  CONFIGURE_INPUT = platform/$(HOST_PLATFORM)/scripts/configure.sh
  PLATFORM_OUTPUT = ./build/node-$(HOST_PLATFORM)-$(CONFIGURE_SUBPLATFORM)

else
  CONFIGURE_PLATFORM = $(PLATFORM)
  CONFIGURE_SUBPLATFORM = $(shell uname -m)
  CONFIGURE_INPUT = platform/$(CONFIGURE_PLATFORM)/scripts/configure.sh
  PLATFORM_OUTPUT = ./build/$(PLATFORM)-$(CONFIGURE_SUBPLATFORM)
endif

ifneq (,$(findstring clang,$(CXX)))
	CXX_HOST = "clang"
else ifneq (,$(findstring g++,$(CXX)))
	CXX_HOST = "g++"
endif

# Text formatting
TEXT_BOLD = \033[1m
COLOR_GREEN = \033[32m
COLOR_CYAN = \033[36m
COLOR_PINK = \033[35m
FORMAT_END = \033[0m

# Never remove intermediate files
.SECONDARY:

#### Dependencies ##############################################################

ifneq (,$(wildcard .git/.))
.mason:
	git submodule update --init
else
.mason: ;
endif

CONFIGURE_OUTPUT = $(PLATFORM_OUTPUT)/config.gypi
.NOTPARALLEL: $(CONFIGURE_OUTPUT)
$(CONFIGURE_OUTPUT): $(CONFIGURE_INPUT) .mason configure
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Running configure...$(FORMAT_END)\n"
	$(ENV) ./configure $< $@ $(CONFIGURE_PLATFORM) $(CONFIGURE_SUBPLATFORM)

#### Build files ###############################################################

GYP_FLAGS += -I$(CONFIGURE_OUTPUT)
GYP_FLAGS += -Dcoverage=$(ENABLE_COVERAGE)
GYP_FLAGS += -Dcxx_host=$(CXX_HOST)
GYP_FLAGS += -Goutput_dir=.
GYP_FLAGS += --depth=.
GYP_FLAGS += --generator-output=$(PLATFORM_OUTPUT)

.PHONY: Makefile/__project__
Makefile/__project__: $(CONFIGURE_OUTPUT)
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Recreating project...$(FORMAT_END)\n"
	$(ENV) deps/run_gyp platform/$(PLATFORM)/platform.gyp $(GYP_FLAGS) -f make$(GYP_FLAVOR_SUFFIX)

.PHONY: Ninja/__project__
Ninja/__project__: $(CONFIGURE_OUTPUT)
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Recreating project...$(FORMAT_END)\n"
	$(ENV) deps/run_gyp platform/$(PLATFORM)/platform.gyp $(GYP_FLAGS) -f ninja

#### Node targets ##############################################################

NODE_PRE_GYP = $(shell npm bin)/node-pre-gyp

Makefile/node: $(CONFIGURE_OUTPUT)
	$(NODE_PRE_GYP) configure --clang -- $(GYP_FLAGS) \
	  -Dlibuv_cflags= -Dlibuv_ldflags= -Dlibuv_static_libs=
	$(NODE_PRE_GYP) build --clang

Xcode/node: $(CONFIGURE_OUTPUT)
	$(NODE_PRE_GYP) configure --clang -- $(GYP_FLAGS) -f xcode \
	  -Dlibuv_cflags= -Dlibuv_ldflags= -Dlibuv_static_libs=

#### Build individual targets ##################################################

Makefile/%: Makefile/__project__
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Building target $*...$(FORMAT_END)\n"
	$(ENV) $(MAKE) -j$(JOBS) -C $(PLATFORM_OUTPUT) BUILDTYPE=$(BUILDTYPE) $*

Ninja/%: Ninja/__project__
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Building target $*...$(FORMAT_END)\n"
	$(ENV) deps/ninja/ninja-$(PLATFORM) -C $(PLATFORM_OUTPUT)/$(BUILDTYPE) $*

#### Tidy ######################################################################

Ninja/compdb: OUTPUT=$(PLATFORM_OUTPUT)/$(BUILDTYPE)/compile_commands.json
Ninja/compdb: Ninja/__project__
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Writing to $(OUTPUT)$(FORMAT_END)\n"
	$(ENV) deps/ninja/ninja-$(PLATFORM) -C $(PLATFORM_OUTPUT)/$(BUILDTYPE) \
		-t compdb cc cc_s cxx objc objcxx > $(OUTPUT)

tidy: Ninja/compdb
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Generating header files...$(FORMAT_END)\n"
	$(ENV) deps/ninja/ninja-$(PLATFORM) -C $(PLATFORM_OUTPUT)/$(BUILDTYPE) version shaders
	@printf "$(TEXT_BOLD)$(COLOR_GREEN)* Running tidy...$(FORMAT_END)\n"
	@./scripts/clang-tidy.sh $(PLATFORM_OUTPUT)/$(BUILDTYPE)

#### Run tests #################################################################

run-glfw-app:
	cd $(PLATFORM_OUTPUT)/$(BUILDTYPE) && ./mapbox-glfw

run-qt-app:
	cd $(PLATFORM_OUTPUT)/$(BUILDTYPE) && ./qmapboxgl

run-qt-qml-app:
	cd $(PLATFORM_OUTPUT)/$(BUILDTYPE) && ./qquickmapboxgl

run-valgrind-glfw-app:
	cd $(PLATFORM_OUTPUT)/$(BUILDTYPE) && valgrind --leak-check=full --suppressions=../../../scripts/valgrind.sup ./mapbox-glfw

ifneq (,$(shell which gdb))
  GDB = gdb -batch -return-child-result -ex 'set print thread-events off' -ex 'run' -ex 'thread apply all bt' --args
endif

test-%: Makefile/test
	$(GDB) $(PLATFORM_OUTPUT)/$(BUILDTYPE)/test --gtest_catch_exceptions=0 --gtest_filter=$*

check: Makefile/test
	./scripts/collect-coverage.sh $(PLATFORM_OUTPUT)/$(BUILDTYPE)