forked from jerryscript-project/jerryscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
346 lines (289 loc) · 14.7 KB
/
Makefile
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# Copyright 2014-2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Target naming scheme
#
# Main targets: {debug,release}.{linux,darwin,stm32f{4}}[.flash]
#
# Target mode part (before dot):
# debug: - JERRY_NDEBUG; - optimizations; + debug symbols; + -Werror | debug build
# release: + JERRY_NDEBUG; + optimizations; - debug symbols; + -Werror | release build
#
# Target system and modifiers part (after first dot):
# linux - target system is linux
# darwin - target system is Mac OS X
# mcu_stm32f{3,4} - target is STM32F{3,4} board
#
# Modifiers can be added after '-' sign.
# For list of modifiers for NATIVE target - see TARGET_NATIVE_MODS, for MCU target - TARGET_MCU_MODS.
#
# Target action part (optional, after second dot):
# flash - flash specified mcu target binary
#
# Unit test target: unittests_run
#
# Parallel run
# To build all targets in parallel, please, use make build -j
# To run precommit in parallel mode, please, use make precommit -j
#
# Parallel build of several selected targets started manually is not supported.
#
export TARGET_NATIVE_SYSTEMS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
# Options
# Valgrind
VALGRIND ?= OFF
ifneq ($(VALGRIND),ON)
VALGRIND := OFF
endif
# Valgrind Freya
VALGRIND_FREYA ?= OFF
ifneq ($(VALGRIND_FREYA),ON)
VALGRIND_FREYA := OFF
endif
# Static checkers
STATIC_CHECK ?= OFF
ifneq ($(STATIC_CHECK),ON)
STATIC_CHECK := OFF
endif
# LTO
ifeq ($(TARGET_NATIVE_SYSTEMS),darwin)
LTO ?= OFF
else
LTO ?= ON
endif
ifneq ($(LTO),ON)
LTO := OFF
endif
# LOG
LOG ?= OFF
ifneq ($(LOG),ON)
LOG := OFF
endif
# All-in-one build
ifeq ($(TARGET_NATIVE_SYSTEMS),darwin)
ALL_IN_ONE ?= ON
else
ALL_IN_ONE ?= OFF
endif
ifneq ($(ALL_IN_ONE),ON)
ALL_IN_ONE := OFF
endif
# Verbosity
ifdef VERBOSE
Q :=
QLOG :=
else
Q := @
QLOG := >/dev/null
endif
# External build configuration
# Flag, indicating whether to use compiler's default libc (YES / NO)
USE_COMPILER_DEFAULT_LIBC ?= NO
# List of include paths for external libraries (semicolon-separated)
EXTERNAL_LIBS_INTERFACE ?=
# External libc interface
ifeq ($(USE_COMPILER_DEFAULT_LIBC),YES)
ifneq ($(EXTERNAL_LIBC_INTERFACE),)
$(error EXTERNAL_LIBC_INTERFACE should not be specified in case compiler's default libc is used)
endif
endif
# Compiler to use for external build
EXTERNAL_C_COMPILER ?= arm-none-eabi-gcc
EXTERNAL_CXX_COMPILER ?= arm-none-eabi-g++
export TARGET_DEBUG_MODES = debug
export TARGET_RELEASE_MODES = release
export TARGET_NATIVE_MODS = cp cp_minimal mem_stats mem_stress_test
export TARGET_MCU_MODS = cp cp_minimal
export TARGET_NATIVE_SYSTEMS_MODS = $(TARGET_NATIVE_SYSTEMS) \
$(foreach __MOD,$(TARGET_NATIVE_MODS),$(foreach __SYSTEM,$(TARGET_NATIVE_SYSTEMS),$(__SYSTEM)-$(__MOD)))
export TARGET_STM32F3_MODS = $(foreach __MOD,$(TARGET_MCU_MODS),mcu_stm32f3-$(__MOD))
export TARGET_STM32F4_MODS = $(foreach __MOD,$(TARGET_MCU_MODS),mcu_stm32f4-$(__MOD))
# Target list
export JERRY_NATIVE_TARGETS = $(foreach __MODE,$(TARGET_DEBUG_MODES),$(foreach __SYSTEM,$(TARGET_NATIVE_SYSTEMS_MODS),$(__MODE).$(__SYSTEM))) \
$(foreach __MODE,$(TARGET_RELEASE_MODES),$(foreach __SYSTEM,$(TARGET_NATIVE_SYSTEMS_MODS),$(__MODE).$(__SYSTEM)))
export JERRY_STM32F3_TARGETS = $(foreach __MODE,$(TARGET_RELEASE_MODES),$(foreach __SYSTEM,$(TARGET_STM32F3_MODS),$(__MODE).$(__SYSTEM)))
export JERRY_STM32F4_TARGETS = $(foreach __MODE,$(TARGET_DEBUG_MODES),$(foreach __SYSTEM,$(TARGET_STM32F4_MODS),$(__MODE).$(__SYSTEM))) \
$(foreach __MODE,$(TARGET_RELEASE_MODES),$(foreach __SYSTEM,$(TARGET_STM32F4_MODS),$(__MODE).$(__SYSTEM)))
export JERRY_TARGETS = $(JERRY_NATIVE_TARGETS) $(JERRY_STM32F3_TARGETS) $(JERRY_STM32F4_TARGETS) unittests
export CHECK_TARGETS = $(foreach __TARGET,$(JERRY_NATIVE_TARGETS),$(__TARGET).check)
export FLASH_TARGETS = $(foreach __TARGET,$(JERRY_STM32F3_TARGETS) $(JERRY_STM32F4_TARGETS),$(__TARGET).flash)
export OUT_DIR = ./build/bin
export PREREQUISITES_STATE_DIR = ./build/prerequisites
export SHELL=/bin/bash
# Precommit check targets
PRECOMMIT_CHECK_TARGETS_LIST := debug.$(TARGET_NATIVE_SYSTEMS) release.$(TARGET_NATIVE_SYSTEMS)
# Building all options combinations
OPTIONS_COMBINATIONS := $(foreach __OPTION,ON OFF,$(__COMBINATION)-VALGRIND-$(__OPTION))
OPTIONS_COMBINATIONS := $(foreach __COMBINATION,$(OPTIONS_COMBINATIONS),$(foreach __OPTION,ON OFF,$(__COMBINATION)-VALGRIND_FREYA-$(__OPTION)))
OPTIONS_COMBINATIONS := $(foreach __COMBINATION,$(OPTIONS_COMBINATIONS),$(foreach __OPTION,ON OFF,$(__COMBINATION)-LTO-$(__OPTION)))
OPTIONS_COMBINATIONS := $(foreach __COMBINATION,$(OPTIONS_COMBINATIONS),$(foreach __OPTION,ON OFF,$(__COMBINATION)-ALL_IN_ONE-$(__OPTION)))
# Building current options string
OPTIONS_STRING := -VALGRIND-$(VALGRIND)-VALGRIND_FREYA-$(VALGRIND_FREYA)-LTO-$(LTO)-ALL_IN_ONE-$(ALL_IN_ONE)
# Build directories
BUILD_DIR_PREFIX := ./build/obj
# Native
BUILD_DIRS_NATIVE := $(foreach _OPTIONS_COMBINATION,$(OPTIONS_COMBINATIONS),$(BUILD_DIR_PREFIX)$(_OPTIONS_COMBINATION)/native)
# stm32f3
BUILD_DIRS_STM32F3 := $(foreach _OPTIONS_COMBINATION,$(OPTIONS_COMBINATIONS),$(BUILD_DIR_PREFIX)$(_OPTIONS_COMBINATION)/stm32f3)
# stm32f4
BUILD_DIRS_STM32F4 := $(foreach _OPTIONS_COMBINATION,$(OPTIONS_COMBINATIONS),$(BUILD_DIR_PREFIX)$(_OPTIONS_COMBINATION)/stm32f4)
# All together
BUILD_DIRS_ALL := $(BUILD_DIRS_NATIVE) $(BUILD_DIRS_STM32F3) $(BUILD_DIRS_STM32F4)
# Current
BUILD_DIR := ./build/obj$(OPTIONS_STRING)
# "Build all" targets prefix
BUILD_ALL := build_all
.PHONY: all
all: precommit
.PHONY: $(BUILD_DIRS_NATIVE)
$(BUILD_DIRS_NATIVE):
$(Q) if [ "$$TOOLCHAIN" == "" ]; \
then \
arch=`uname -m`; \
if [ "$$arch" == "armv7l" ]; \
then \
readelf -A /proc/self/exe | grep Tag_ABI_VFP_args && arch=$$arch"-hf" || arch=$$arch"-el"; \
fi; \
TOOLCHAIN="build/configs/toolchain_$(TARGET_NATIVE_SYSTEMS)_$$arch.cmake"; \
fi; \
if [ -d "$@" ]; \
then \
grep -s -q "$$TOOLCHAIN" $@/toolchain.config || rm -rf $@ ; \
fi; \
mkdir -p $@; \
echo "$$TOOLCHAIN" > $@/toolchain.config
$(Q) cd $@ && \
(cmake \
-DENABLE_VALGRIND=$(VALGRIND) \
-DENABLE_VALGRIND_FREYA=$(VALGRIND_FREYA) \
-DENABLE_LOG=$(LOG) \
-DENABLE_LTO=$(LTO) \
-DENABLE_ALL_IN_ONE=$(ALL_IN_ONE) \
-DUSE_COMPILER_DEFAULT_LIBC=$(USE_COMPILER_DEFAULT_LIBC) \
-DCMAKE_TOOLCHAIN_FILE=`cat toolchain.config` ../../.. 2>&1 | tee cmake.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "CMake run failed. See "`pwd`"/cmake.log for details."; exit 1;); \
.PHONY: $(BUILD_DIRS_STM32F3)
$(BUILD_DIRS_STM32F3): prerequisites
$(Q) mkdir -p $@
$(Q) cd $@ && \
(cmake -DENABLE_VALGRIND=$(VALGRIND) -DENABLE_VALGRIND_FREYA=$(VALGRIND_FREYA) -DENABLE_LTO=$(LTO) -DENABLE_ALL_IN_ONE=$(ALL_IN_ONE) -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_mcu_stm32f3.cmake ../../.. 2>&1 | tee cmake.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "CMake run failed. See "`pwd`"/cmake.log for details."; exit 1;)
.PHONY: $(BUILD_DIRS_STM32F4)
$(BUILD_DIRS_STM32F4): prerequisites
$(Q) mkdir -p $@
$(Q) cd $@ && \
(cmake -DENABLE_VALGRIND=$(VALGRIND) -DENABLE_VALGRIND_FREYA=$(VALGRIND_FREYA) -DENABLE_LTO=$(LTO) -DENABLE_ALL_IN_ONE=$(ALL_IN_ONE) -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_mcu_stm32f4.cmake ../../.. 2>&1 | tee cmake.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "CMake run failed. See "`pwd`"/cmake.log for details."; exit 1;)
.PHONY: $(JERRY_NATIVE_TARGETS)
$(JERRY_NATIVE_TARGETS): $(BUILD_DIR)/native
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) [ "$(STATIC_CHECK)" = "OFF" ] || ($(MAKE) -C $(BUILD_DIR)/native VERBOSE=1 cppcheck.$@ 2>&1 | tee $(OUT_DIR)/$@/cppcheck.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "cppcheck run failed. See $(OUT_DIR)/$@/cppcheck.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/native VERBOSE=1 $@ 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) cp $(BUILD_DIR)/native/$@ $(OUT_DIR)/$@/jerry
.PHONY: unittests
unittests: $(BUILD_DIR)/native
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) [ "$(STATIC_CHECK)" = "OFF" ] || ($(MAKE) -C $(BUILD_DIR)/native VERBOSE=1 cppcheck.$@ 2>&1 | tee $(OUT_DIR)/$@/cppcheck.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "cppcheck run failed. See $(OUT_DIR)/$@/cppcheck.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/native VERBOSE=1 $@ 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) cp $(BUILD_DIR)/native/unit-test-* $(OUT_DIR)/$@
.PHONY: $(BUILD_ALL)_native
$(BUILD_ALL)_native: $(BUILD_DIRS_NATIVE)
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) [ "$(USE_COMPILER_DEFAULT_LIBC)" = "YES" ] || ($(MAKE) -C $(BUILD_DIR)/native jerry-libc-all VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/native jerry-fdlibm-all VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/native $(JERRY_NATIVE_TARGETS) unittests VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
.PHONY: $(JERRY_STM32F3_TARGETS)
$(JERRY_STM32F3_TARGETS): $(BUILD_DIR)/stm32f3
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) [ "$(STATIC_CHECK)" = "OFF" ] || ($(MAKE) -C $(BUILD_DIR)/stm32f3 VERBOSE=1 cppcheck.$@ 2>&1 | tee $(OUT_DIR)/$@/cppcheck.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "cppcheck run failed. See $(OUT_DIR)/$@/cppcheck.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/stm32f3 VERBOSE=1 [email protected] 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) cp $(BUILD_DIR)/stm32f3/$@ $(OUT_DIR)/$@/jerry
$(Q) cp $(BUILD_DIR)/stm32f3/[email protected] $(OUT_DIR)/$@/jerry.bin
.PHONY: $(BUILD_ALL)_stm32f3
$(BUILD_ALL)_stm32f3: $(BUILD_DIRS_STM32F3)
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) ($(MAKE) -C $(BUILD_DIR)/stm32f3 jerry-libc-all VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/stm32f3 $(JERRY_STM32F3_TARGETS) VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
.PHONY: $(JERRY_STM32F4_TARGETS)
$(JERRY_STM32F4_TARGETS): $(BUILD_DIR)/stm32f4
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) [ "$(STATIC_CHECK)" = "OFF" ] || ($(MAKE) -C $(BUILD_DIR)/stm32f4 VERBOSE=1 cppcheck.$@ 2>&1 | tee $(OUT_DIR)/$@/cppcheck.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "cppcheck run failed. See $(OUT_DIR)/$@/cppcheck.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/stm32f4 VERBOSE=1 [email protected] 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) cp $(BUILD_DIR)/stm32f4/$@ $(OUT_DIR)/$@/jerry
$(Q) cp $(BUILD_DIR)/stm32f4/[email protected] $(OUT_DIR)/$@/jerry.bin
.PHONY: $(BUILD_ALL)_stm32f4
$(BUILD_ALL)_stm32f4: $(BUILD_DIRS_STM32F4)
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) ($(MAKE) -C $(BUILD_DIR)/stm32f4 jerry-libc-all VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) ($(MAKE) -C $(BUILD_DIR)/stm32f4 $(JERRY_STM32F4_TARGETS) VERBOSE=1 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
.PHONY: $(BUILD_ALL)
$(BUILD_ALL): $(BUILD_ALL)_native $(BUILD_ALL)_stm32f3 $(BUILD_ALL)_stm32f4
#
# build - build_all, then run cppcheck and copy output to OUT_DIR
# Prebuild is needed to avoid race conditions between make instances running in parallel
#
.PHONY: build
build: $(BUILD_ALL)
$(Q) mkdir -p $(OUT_DIR)/$@
$(Q) ($(MAKE) VERBOSE=1 $(JERRY_TARGETS) 2>&1 | tee $(OUT_DIR)/$@/make.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Build failed. See $(OUT_DIR)/$@/make.log for details."; exit 1;)
$(Q) rm -rf $(OUT_DIR)/$(BUILD_ALL)* $(OUT_DIR)/$@
.PHONY: $(FLASH_TARGETS)
$(FLASH_TARGETS): $(BUILD_DIR)/mcu
$(Q) $(MAKE) -C $(BUILD_DIR)/mcu VERBOSE=1 $@ $(QLOG)
.PHONY: push
push: ./tools/git-scripts/push.sh
$(Q) ./tools/git-scripts/push.sh
.PHONY: pull
pull: ./tools/git-scripts/pull.sh
$(Q) ./tools/git-scripts/pull.sh
.PHONY: log
log: ./tools/git-scripts/log.sh
$(Q) ./tools/git-scripts/log.sh
.PHONY: precommit
precommit: clean prerequisites
$(Q) ./tools/precommit.sh "$(MAKE)" "$(OUT_DIR)" "$(PRECOMMIT_CHECK_TARGETS_LIST)"
.PHONY: unittests_run
unittests_run: unittests
$(Q) rm -rf $(OUT_DIR)/unittests/check
$(Q) mkdir -p $(OUT_DIR)/unittests/check
$(Q) ./tools/runners/run-unittests.sh $(OUT_DIR)/unittests || \
(echo "Unit tests run failed. See $(OUT_DIR)/unittests/unit_tests_run.log for details."; exit 1;)
.PHONY: clean
clean:
$(Q) rm -rf $(BUILD_DIR_PREFIX)* $(OUT_DIR)
.PHONY: prerequisites
prerequisites:
$(Q) mkdir -p $(PREREQUISITES_STATE_DIR)
$(Q) (./tools/prerequisites.sh $(PREREQUISITES_STATE_DIR)/.prerequisites 2>&1 | tee $(PREREQUISITES_STATE_DIR)/prerequisites.log $(QLOG) ; ( exit $${PIPESTATUS[0]} ) ) || \
(echo "Prerequisites setup failed. See $(PREREQUISITES_STATE_DIR)/prerequisites.log for details."; exit 1;)
.PHONY: prerequisites_clean
prerequisites_clean:
$(Q) ./tools/prerequisites.sh $(PREREQUISITES_STATE_DIR)/.prerequisites clean
$(Q) rm -rf $(PREREQUISITES_STATE_DIR)