1# Copyright 2012 the V8 project authors. All rights reserved.
2# Redistribution and use in source and binary forms, with or without
3# modification, are permitted provided that the following conditions are
4# met:
5#
6#     * Redistributions of source code must retain the above copyright
7#       notice, this list of conditions and the following disclaimer.
8#     * Redistributions in binary form must reproduce the above
9#       copyright notice, this list of conditions and the following
10#       disclaimer in the documentation and/or other materials provided
11#       with the distribution.
12#     * Neither the name of Google Inc. nor the names of its
13#       contributors may be used to endorse or promote products derived
14#       from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
29# Variable default definitions. Override them by exporting them in your shell.
30CXX ?= g++
31LINK ?= g++
32OUTDIR ?= out
33TESTJOBS ?=
34GYPFLAGS ?=
35TESTFLAGS ?=
36ANDROID_NDK_ROOT ?=
37ANDROID_NDK_HOST_ARCH ?=
38ANDROID_TOOLCHAIN ?=
39ANDROID_V8 ?= /data/local/tmp/v8
40NACL_SDK_ROOT ?=
41
42# Special build flags. Use them like this: "make library=shared"
43
44# library=shared || component=shared_library
45ifeq ($(library), shared)
46  GYPFLAGS += -Dcomponent=shared_library
47endif
48ifdef component
49  GYPFLAGS += -Dcomponent=$(component)
50endif
51# console=readline
52ifdef console
53  GYPFLAGS += -Dconsole=$(console)
54endif
55# disassembler=on
56ifeq ($(disassembler), on)
57  GYPFLAGS += -Dv8_enable_disassembler=1
58endif
59# objectprint=on
60ifeq ($(objectprint), on)
61  GYPFLAGS += -Dv8_object_print=1
62endif
63# verifyheap=on
64ifeq ($(verifyheap), on)
65  GYPFLAGS += -Dv8_enable_verify_heap=1
66endif
67# backtrace=off
68ifeq ($(backtrace), off)
69  GYPFLAGS += -Dv8_enable_backtrace=0
70else
71  GYPFLAGS += -Dv8_enable_backtrace=1
72endif
73# snapshot=off
74ifeq ($(snapshot), off)
75  GYPFLAGS += -Dv8_use_snapshot='false'
76endif
77# extrachecks=on/off
78ifeq ($(extrachecks), on)
79  GYPFLAGS += -Dv8_enable_extra_checks=1
80endif
81ifeq ($(extrachecks), off)
82  GYPFLAGS += -Dv8_enable_extra_checks=0
83endif
84# gdbjit=on/off
85ifeq ($(gdbjit), on)
86  GYPFLAGS += -Dv8_enable_gdbjit=1
87endif
88ifeq ($(gdbjit), off)
89  GYPFLAGS += -Dv8_enable_gdbjit=0
90endif
91# vtunejit=on
92ifeq ($(vtunejit), on)
93  GYPFLAGS += -Dv8_enable_vtunejit=1
94endif
95# optdebug=on
96ifeq ($(optdebug), on)
97  GYPFLAGS += -Dv8_optimized_debug=1
98endif
99# debuggersupport=off
100ifeq ($(debuggersupport), off)
101  GYPFLAGS += -Dv8_enable_debugger_support=0
102endif
103# unalignedaccess=on
104ifeq ($(unalignedaccess), on)
105  GYPFLAGS += -Dv8_can_use_unaligned_accesses=true
106endif
107# soname_version=1.2.3
108ifdef soname_version
109  GYPFLAGS += -Dsoname_version=$(soname_version)
110endif
111# werror=no
112ifeq ($(werror), no)
113  GYPFLAGS += -Dwerror=''
114endif
115# presubmit=no
116ifeq ($(presubmit), no)
117  TESTFLAGS += --no-presubmit
118endif
119# strictaliasing=off (workaround for GCC-4.5)
120ifeq ($(strictaliasing), off)
121  GYPFLAGS += -Dv8_no_strict_aliasing=1
122endif
123# regexp=interpreted
124ifeq ($(regexp), interpreted)
125  GYPFLAGS += -Dv8_interpreted_regexp=1
126endif
127# i18nsupport=on
128ifeq ($(i18nsupport), on)
129  GYPFLAGS += -Dv8_enable_i18n_support=1
130endif
131# arm specific flags.
132# armv7=false/true
133ifeq ($(armv7), false)
134  GYPFLAGS += -Darmv7=0
135else
136ifeq ($(armv7), true)
137  GYPFLAGS += -Darmv7=1
138endif
139endif
140# vfp2=off. Deprecated, use armfpu=
141# vfp3=off. Deprecated, use armfpu=
142ifeq ($(vfp3), off)
143  GYPFLAGS += -Darm_fpu=vfp
144endif
145# hardfp=on/off. Deprecated, use armfloatabi
146ifeq ($(hardfp),on)
147  GYPFLAGS += -Darm_float_abi=hard
148else
149ifeq ($(hardfp),off)
150  GYPFLAGS += -Darm_float_abi=softfp
151endif
152endif
153# armneon=on/off
154ifeq ($(armneon), on)
155  GYPFLAGS += -Darm_neon=1
156endif
157# fpu: armfpu=xxx
158# xxx: vfp, vfpv3-d16, vfpv3, neon.
159ifeq ($(armfpu),)
160ifneq ($(vfp3), off)
161  GYPFLAGS += -Darm_fpu=default
162endif
163else
164  GYPFLAGS += -Darm_fpu=$(armfpu)
165endif
166# float abi: armfloatabi=softfp/hard
167ifeq ($(armfloatabi),)
168ifeq ($(hardfp),)
169  GYPFLAGS += -Darm_float_abi=default
170endif
171else
172  GYPFLAGS += -Darm_float_abi=$(armfloatabi)
173endif
174# armthumb=on/off
175ifeq ($(armthumb), off)
176  GYPFLAGS += -Darm_thumb=0
177else
178ifeq ($(armthumb), on)
179  GYPFLAGS += -Darm_thumb=1
180endif
181endif
182# armtest=on
183# With this flag set, by default v8 will only use features implied
184# by the compiler (no probe). This is done by modifying the default
185# values of enable_armv7, enable_vfp2, enable_vfp3 and enable_32dregs.
186# Modifying these flags when launching v8 will enable the probing for
187# the specified values.
188# When using the simulator, this flag is implied.
189ifeq ($(armtest), on)
190  GYPFLAGS += -Darm_test=on
191endif
192
193# ----------------- available targets: --------------------
194# - "dependencies": pulls in external dependencies (currently: GYP)
195# - "grokdump": rebuilds heap constants lists used by grokdump
196# - any arch listed in ARCHES (see below)
197# - any mode listed in MODES
198# - every combination <arch>.<mode>, e.g. "ia32.release"
199# - "native": current host's architecture, release mode
200# - any of the above with .check appended, e.g. "ia32.release.check"
201# - "android": cross-compile for Android/ARM
202# - "nacl" : cross-compile for Native Client (ia32 and x64)
203# - default (no target specified): build all DEFAULT_ARCHES and MODES
204# - "check": build all targets and run all tests
205# - "<arch>.clean" for any <arch> in ARCHES
206# - "clean": clean all ARCHES
207
208# ----------------- internal stuff ------------------------
209
210# Architectures and modes to be compiled. Consider these to be internal
211# variables, don't override them (use the targets instead).
212ARCHES = ia32 x64 arm mipsel
213DEFAULT_ARCHES = ia32 x64 arm
214MODES = release debug
215ANDROID_ARCHES = android_ia32 android_arm android_mipsel
216NACL_ARCHES = nacl_ia32 nacl_x64
217
218# List of files that trigger Makefile regeneration:
219GYPFILES = build/all.gyp build/features.gypi build/standalone.gypi \
220	   build/toolchain.gypi preparser/preparser.gyp samples/samples.gyp \
221	   src/d8.gyp test/cctest/cctest.gyp tools/gyp/v8.gyp
222
223# If vtunejit=on, the v8vtune.gyp will be appended.
224ifeq ($(vtunejit), on)
225  GYPFILES += src/third_party/vtune/v8vtune.gyp
226endif
227# Generates all combinations of ARCHES and MODES, e.g. "ia32.release".
228BUILDS = $(foreach mode,$(MODES),$(addsuffix .$(mode),$(ARCHES)))
229ANDROID_BUILDS = $(foreach mode,$(MODES), \
230                   $(addsuffix .$(mode),$(ANDROID_ARCHES)))
231NACL_BUILDS = $(foreach mode,$(MODES), \
232                   $(addsuffix .$(mode),$(NACL_ARCHES)))
233# Generates corresponding test targets, e.g. "ia32.release.check".
234CHECKS = $(addsuffix .check,$(BUILDS))
235ANDROID_CHECKS = $(addsuffix .check,$(ANDROID_BUILDS))
236NACL_CHECKS = $(addsuffix .check,$(NACL_BUILDS))
237# File where previously used GYPFLAGS are stored.
238ENVFILE = $(OUTDIR)/environment
239
240.PHONY: all check clean dependencies $(ENVFILE).new native \
241        $(ARCHES) $(MODES) $(BUILDS) $(CHECKS) $(addsuffix .clean,$(ARCHES)) \
242        $(addsuffix .check,$(MODES)) $(addsuffix .check,$(ARCHES)) \
243        $(ANDROID_ARCHES) $(ANDROID_BUILDS) $(ANDROID_CHECKS) \
244        must-set-ANDROID_NDK_ROOT_OR_TOOLCHAIN \
245        $(NACL_ARCHES) $(NACL_BUILDS) $(NACL_CHECKS) \
246        must-set-NACL_SDK_ROOT
247
248# Target definitions. "all" is the default.
249all: $(MODES)
250
251# Special target for the buildbots to use. Depends on $(OUTDIR)/Makefile
252# having been created before.
253buildbot:
254	$(MAKE) -C "$(OUTDIR)" BUILDTYPE=$(BUILDTYPE) \
255	        builddir="$(abspath $(OUTDIR))/$(BUILDTYPE)"
256
257mips mips.release mips.debug:
258	@echo "V8 does not support big-endian MIPS builds at the moment," \
259	      "please use little-endian builds (mipsel)."
260
261# Compile targets. MODES and ARCHES are convenience targets.
262.SECONDEXPANSION:
263$(MODES): $(addsuffix .$$@,$(DEFAULT_ARCHES))
264
265$(ARCHES): $(addprefix $$@.,$(MODES))
266
267# Defines how to build a particular target (e.g. ia32.release).
268$(BUILDS): $(OUTDIR)/Makefile.$$(basename $$@)
269	@$(MAKE) -C "$(OUTDIR)" -f Makefile.$(basename $@) \
270	         CXX="$(CXX)" LINK="$(LINK)" \
271	         BUILDTYPE=$(shell echo $(subst .,,$(suffix $@)) | \
272	                     python -c "print raw_input().capitalize()") \
273	         builddir="$(shell pwd)/$(OUTDIR)/$@"
274
275native: $(OUTDIR)/Makefile.native
276	@$(MAKE) -C "$(OUTDIR)" -f Makefile.native \
277	         CXX="$(CXX)" LINK="$(LINK)" BUILDTYPE=Release \
278	         builddir="$(shell pwd)/$(OUTDIR)/$@"
279
280$(ANDROID_ARCHES): $(addprefix $$@.,$(MODES))
281
282$(ANDROID_BUILDS): $(GYPFILES) $(ENVFILE) build/android.gypi \
283                   must-set-ANDROID_NDK_ROOT_OR_TOOLCHAIN Makefile.android
284	@$(MAKE) -f Makefile.android $@ \
285	        ARCH="$(basename $@)" \
286	        MODE="$(subst .,,$(suffix $@))" \
287	        OUTDIR="$(OUTDIR)" \
288	        GYPFLAGS="$(GYPFLAGS)"
289
290$(NACL_ARCHES): $(addprefix $$@.,$(MODES))
291
292$(NACL_BUILDS): $(GYPFILES) $(ENVFILE) \
293		   Makefile.nacl must-set-NACL_SDK_ROOT
294	@$(MAKE) -f Makefile.nacl $@ \
295	        ARCH="$(basename $@)" \
296	        MODE="$(subst .,,$(suffix $@))" \
297	        OUTDIR="$(OUTDIR)" \
298	        GYPFLAGS="$(GYPFLAGS)"
299
300# Test targets.
301check: all
302	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR) \
303	    --arch=$(shell echo $(DEFAULT_ARCHES) | sed -e 's/ /,/g') \
304	    $(TESTFLAGS)
305
306$(addsuffix .check,$(MODES)): $$(basename $$@)
307	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR) \
308	    --mode=$(basename $@) $(TESTFLAGS)
309
310$(addsuffix .check,$(ARCHES)): $$(basename $$@)
311	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR) \
312	    --arch=$(basename $@) $(TESTFLAGS)
313
314$(CHECKS): $$(basename $$@)
315	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR) \
316	    --arch-and-mode=$(basename $@) $(TESTFLAGS)
317
318$(addsuffix .sync, $(ANDROID_BUILDS)): $$(basename $$@)
319	@tools/android-sync.sh $(basename $@) $(OUTDIR) \
320	                       $(shell pwd) $(ANDROID_V8)
321
322$(addsuffix .check, $(ANDROID_BUILDS)): $$(basename $$@).sync
323	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR) \
324	     --arch-and-mode=$(basename $@) \
325	     --timeout=600 \
326	     --command-prefix="tools/android-run.py"
327
328$(addsuffix .check, $(ANDROID_ARCHES)): \
329                $(addprefix $$(basename $$@).,$(MODES)).check
330
331$(addsuffix .check, $(NACL_BUILDS)): $$(basename $$@)
332	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR) \
333	     --arch-and-mode=$(basename $@) \
334	     --timeout=600 --nopresubmit \
335	     --command-prefix="tools/nacl-run.py"
336
337$(addsuffix .check, $(NACL_ARCHES)): \
338                $(addprefix $$(basename $$@).,$(MODES)).check
339
340native.check: native
341	@tools/run-tests.py $(TESTJOBS) --outdir=$(OUTDIR)/native \
342	    --arch-and-mode=. $(TESTFLAGS)
343
344# Clean targets. You can clean each architecture individually, or everything.
345$(addsuffix .clean, $(ARCHES) $(ANDROID_ARCHES) $(NACL_ARCHES)):
346	rm -f $(OUTDIR)/Makefile.$(basename $@)
347	rm -rf $(OUTDIR)/$(basename $@).release
348	rm -rf $(OUTDIR)/$(basename $@).debug
349	find $(OUTDIR) -regex '.*\(host\|target\).$(basename $@)\.mk' -delete
350
351native.clean:
352	rm -f $(OUTDIR)/Makefile.native
353	rm -rf $(OUTDIR)/native
354	find $(OUTDIR) -regex '.*\(host\|target\).native\.mk' -delete
355
356clean: $(addsuffix .clean, $(ARCHES) $(ANDROID_ARCHES) $(NACL_ARCHES)) native.clean
357
358# GYP file generation targets.
359OUT_MAKEFILES = $(addprefix $(OUTDIR)/Makefile.,$(ARCHES))
360$(OUT_MAKEFILES): $(GYPFILES) $(ENVFILE)
361	PYTHONPATH="$(shell pwd)/tools/generate_shim_headers:$(PYTHONPATH)" \
362	GYP_GENERATORS=make \
363	build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
364	              -Ibuild/standalone.gypi --depth=. \
365	              -Dv8_target_arch=$(subst .,,$(suffix $@)) \
366	              -S.$(subst .,,$(suffix $@)) $(GYPFLAGS)
367
368$(OUTDIR)/Makefile.native: $(GYPFILES) $(ENVFILE)
369	PYTHONPATH="$(shell pwd)/tools/generate_shim_headers:$(PYTHONPATH)" \
370	GYP_GENERATORS=make \
371	build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
372	              -Ibuild/standalone.gypi --depth=. -S.native $(GYPFLAGS)
373
374must-set-ANDROID_NDK_ROOT_OR_TOOLCHAIN:
375ifndef ANDROID_NDK_ROOT
376ifndef ANDROID_TOOLCHAIN
377	  $(error ANDROID_NDK_ROOT or ANDROID_TOOLCHAIN must be set))
378endif
379endif
380
381# Note that NACL_SDK_ROOT must be set to point to an appropriate
382# Native Client SDK before using this makefile. You can download
383# an SDK here:
384#   https://developers.google.com/native-client/sdk/download
385# The path indicated by NACL_SDK_ROOT will typically end with
386# a folder for a pepper version such as "pepper_25" that should
387# have "tools" and "toolchain" subdirectories.
388must-set-NACL_SDK_ROOT:
389ifndef NACL_SDK_ROOT
390	  $(error NACL_SDK_ROOT must be set)
391endif
392
393# Replaces the old with the new environment file if they're different, which
394# will trigger GYP to regenerate Makefiles.
395$(ENVFILE): $(ENVFILE).new
396	@if test -r $(ENVFILE) && cmp $(ENVFILE).new $(ENVFILE) > /dev/null; \
397	    then rm $(ENVFILE).new; \
398	    else mv $(ENVFILE).new $(ENVFILE); fi
399
400# Stores current GYPFLAGS in a file.
401$(ENVFILE).new:
402	@mkdir -p $(OUTDIR); echo "GYPFLAGS=$(GYPFLAGS)" > $(ENVFILE).new; \
403	    echo "CXX=$(CXX)" >> $(ENVFILE).new
404
405# Heap constants for grokdump.
406DUMP_FILE = tools/v8heapconst.py
407grokdump: ia32.release
408	@cat $(DUMP_FILE).tmpl > $(DUMP_FILE)
409	@$(OUTDIR)/ia32.release/d8 --dump-heap-constants >> $(DUMP_FILE)
410
411# Dependencies.
412# Remember to keep these in sync with the DEPS file.
413dependencies:
414	svn checkout --force http://gyp.googlecode.com/svn/trunk build/gyp \
415	    --revision 1685
416	svn checkout --force \
417	    https://src.chromium.org/chrome/trunk/deps/third_party/icu46 \
418	    third_party/icu --revision 214189
419