blob: 73e84216b4d9c470b6e9bcadfd7ea7b7af53a651 [file] [log] [blame]
Ben Murdochc7cc0282012-03-05 14:35:55 +00001# Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002# 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.
Ben Murdoch592a9fc2012-03-05 11:04:45 +000030CXX ?= g++
31LINK ?= g++
Ben Murdoch69a99ed2011-11-30 16:03:39 +000032OUTDIR ?= out
33TESTJOBS ?= -j16
34GYPFLAGS ?=
Ben Murdoch592a9fc2012-03-05 11:04:45 +000035TESTFLAGS ?=
Ben Murdochc7cc0282012-03-05 14:35:55 +000036ANDROID_NDK_ROOT ?=
37ANDROID_TOOL_PREFIX = $(ANDROID_NDK_ROOT)/toolchain/bin/arm-linux-androideabi
Ben Murdoch69a99ed2011-11-30 16:03:39 +000038
39# Special build flags. Use them like this: "make library=shared"
40
41# library=shared || component=shared_library
42ifeq ($(library), shared)
43 GYPFLAGS += -Dcomponent=shared_library
44endif
45ifdef component
46 GYPFLAGS += -Dcomponent=$(component)
47endif
48# console=readline
49ifdef console
50 GYPFLAGS += -Dconsole=$(console)
51endif
52# disassembler=on
53ifeq ($(disassembler), on)
54 GYPFLAGS += -Dv8_enable_disassembler=1
55endif
Ben Murdoch592a9fc2012-03-05 11:04:45 +000056# objectprint=on
57ifeq ($(objectprint), on)
58 GYPFLAGS += -Dv8_object_print=1
59endif
Ben Murdoch69a99ed2011-11-30 16:03:39 +000060# snapshot=off
61ifeq ($(snapshot), off)
62 GYPFLAGS += -Dv8_use_snapshot='false'
63endif
64# gdbjit=on
65ifeq ($(gdbjit), on)
66 GYPFLAGS += -Dv8_enable_gdbjit=1
67endif
68# liveobjectlist=on
69ifeq ($(liveobjectlist), on)
70 GYPFLAGS += -Dv8_use_liveobjectlist=true
71endif
72# vfp3=off
73ifeq ($(vfp3), off)
74 GYPFLAGS += -Dv8_can_use_vfp_instructions=false
75else
76 GYPFLAGS += -Dv8_can_use_vfp_instructions=true
77endif
Ben Murdoch589d6972011-11-30 16:04:58 +000078# soname_version=1.2.3
79ifdef soname_version
80 GYPFLAGS += -Dsoname_version=$(soname_version)
81endif
Ben Murdoch592a9fc2012-03-05 11:04:45 +000082# werror=no
83ifeq ($(werror), no)
84 GYPFLAGS += -Dwerror=''
85endif
86# presubmit=no
87ifeq ($(presubmit), no)
88 TESTFLAGS += --no-presubmit
89endif
Ben Murdochc7cc0282012-03-05 14:35:55 +000090# strictaliasing=off (workaround for GCC-4.5)
91ifeq ($(strictaliasing), off)
92 GYPFLAGS += -Dv8_no_strict_aliasing=1
93endif
Ben Murdoch69a99ed2011-11-30 16:03:39 +000094
95# ----------------- available targets: --------------------
Ben Murdoch589d6972011-11-30 16:04:58 +000096# - "dependencies": pulls in external dependencies (currently: GYP)
Ben Murdoch69a99ed2011-11-30 16:03:39 +000097# - any arch listed in ARCHES (see below)
98# - any mode listed in MODES
99# - every combination <arch>.<mode>, e.g. "ia32.release"
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000100# - "native": current host's architecture, release mode
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000101# - any of the above with .check appended, e.g. "ia32.release.check"
Ben Murdochc7cc0282012-03-05 14:35:55 +0000102# - "android": cross-compile for Android/ARM (release mode)
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000103# - default (no target specified): build all DEFAULT_ARCHES and MODES
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000104# - "check": build all targets and run all tests
105# - "<arch>.clean" for any <arch> in ARCHES
106# - "clean": clean all ARCHES
107
108# ----------------- internal stuff ------------------------
109
110# Architectures and modes to be compiled. Consider these to be internal
111# variables, don't override them (use the targets instead).
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000112ARCHES = ia32 x64 arm mips
113DEFAULT_ARCHES = ia32 x64 arm
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000114MODES = release debug
115
116# List of files that trigger Makefile regeneration:
117GYPFILES = build/all.gyp build/common.gypi build/standalone.gypi \
118 preparser/preparser.gyp samples/samples.gyp src/d8.gyp \
119 test/cctest/cctest.gyp tools/gyp/v8.gyp
120
121# Generates all combinations of ARCHES and MODES, e.g. "ia32.release".
122BUILDS = $(foreach mode,$(MODES),$(addsuffix .$(mode),$(ARCHES)))
123# Generates corresponding test targets, e.g. "ia32.release.check".
124CHECKS = $(addsuffix .check,$(BUILDS))
125# File where previously used GYPFLAGS are stored.
126ENVFILE = $(OUTDIR)/environment
127
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000128.PHONY: all check clean dependencies $(ENVFILE).new native \
Ben Murdoch589d6972011-11-30 16:04:58 +0000129 $(ARCHES) $(MODES) $(BUILDS) $(CHECKS) $(addsuffix .clean,$(ARCHES)) \
Ben Murdochc7cc0282012-03-05 14:35:55 +0000130 $(addsuffix .check,$(MODES)) $(addsuffix .check,$(ARCHES)) \
131 must-set-ANDROID_NDK_ROOT
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000132
133# Target definitions. "all" is the default.
134all: $(MODES)
135
136# Compile targets. MODES and ARCHES are convenience targets.
137.SECONDEXPANSION:
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000138$(MODES): $(addsuffix .$$@,$(DEFAULT_ARCHES))
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000139
140$(ARCHES): $(addprefix $$@.,$(MODES))
141
142# Defines how to build a particular target (e.g. ia32.release).
143$(BUILDS): $(OUTDIR)/Makefile-$$(basename $$@)
144 @$(MAKE) -C "$(OUTDIR)" -f Makefile-$(basename $@) \
145 CXX="$(CXX)" LINK="$(LINK)" \
146 BUILDTYPE=$(shell echo $(subst .,,$(suffix $@)) | \
147 python -c "print raw_input().capitalize()") \
148 builddir="$(shell pwd)/$(OUTDIR)/$@"
149
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000150native: $(OUTDIR)/Makefile-native
151 @$(MAKE) -C "$(OUTDIR)" -f Makefile-native \
152 CXX="$(CXX)" LINK="$(LINK)" BUILDTYPE=Release \
153 builddir="$(shell pwd)/$(OUTDIR)/$@"
154
Ben Murdochc7cc0282012-03-05 14:35:55 +0000155# TODO(jkummerow): add "android.debug" when we need it.
156android android.release: $(OUTDIR)/Makefile-android
157 @$(MAKE) -C "$(OUTDIR)" -f Makefile-android \
158 CXX="$(ANDROID_TOOL_PREFIX)-g++" \
159 AR="$(ANDROID_TOOL_PREFIX)-ar" \
160 RANLIB="$(ANDROID_TOOL_PREFIX)-ranlib" \
161 CC="$(ANDROID_TOOL_PREFIX)-gcc" \
162 LD="$(ANDROID_TOOL_PREFIX)-ld" \
163 LINK="$(ANDROID_TOOL_PREFIX)-g++" \
164 BUILDTYPE=Release \
165 builddir="$(shell pwd)/$(OUTDIR)/android.release"
166
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000167# Test targets.
168check: all
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000169 @tools/test-wrapper-gypbuild.py $(TESTJOBS) --outdir=$(OUTDIR) \
170 --arch=$(shell echo $(DEFAULT_ARCHES) | sed -e 's/ /,/g') \
171 $(TESTFLAGS)
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000172
173$(addsuffix .check,$(MODES)): $$(basename $$@)
174 @tools/test-wrapper-gypbuild.py $(TESTJOBS) --outdir=$(OUTDIR) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000175 --mode=$(basename $@) $(TESTFLAGS)
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000176
177$(addsuffix .check,$(ARCHES)): $$(basename $$@)
178 @tools/test-wrapper-gypbuild.py $(TESTJOBS) --outdir=$(OUTDIR) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000179 --arch=$(basename $@) $(TESTFLAGS)
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000180
181$(CHECKS): $$(basename $$@)
182 @tools/test-wrapper-gypbuild.py $(TESTJOBS) --outdir=$(OUTDIR) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000183 --arch-and-mode=$(basename $@) $(TESTFLAGS)
184
185native.check: native
186 @tools/test-wrapper-gypbuild.py $(TESTJOBS) --outdir=$(OUTDIR)/native \
187 --arch-and-mode=. $(TESTFLAGS)
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000188
189# Clean targets. You can clean each architecture individually, or everything.
190$(addsuffix .clean,$(ARCHES)):
191 rm -f $(OUTDIR)/Makefile-$(basename $@)
192 rm -rf $(OUTDIR)/$(basename $@).release
193 rm -rf $(OUTDIR)/$(basename $@).debug
194 find $(OUTDIR) -regex '.*\(host\|target\)-$(basename $@)\.mk' -delete
195
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000196native.clean:
197 rm -f $(OUTDIR)/Makefile-native
198 rm -rf $(OUTDIR)/native
199 find $(OUTDIR) -regex '.*\(host\|target\)-native\.mk' -delete
200
Ben Murdochc7cc0282012-03-05 14:35:55 +0000201android.clean:
202 rm -f $(OUTDIR)/Makefile-android
203 rm -rf $(OUTDIR)/android.release
204 find $(OUTDIR) -regex '.*\(host\|target\)-android\.mk' -delete
205
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000206clean: $(addsuffix .clean,$(ARCHES)) native.clean
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000207
208# GYP file generation targets.
209$(OUTDIR)/Makefile-ia32: $(GYPFILES) $(ENVFILE)
210 build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
211 -Ibuild/standalone.gypi --depth=. -Dtarget_arch=ia32 \
212 -S-ia32 $(GYPFLAGS)
213
214$(OUTDIR)/Makefile-x64: $(GYPFILES) $(ENVFILE)
215 build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
216 -Ibuild/standalone.gypi --depth=. -Dtarget_arch=x64 \
217 -S-x64 $(GYPFLAGS)
218
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000219$(OUTDIR)/Makefile-arm: $(GYPFILES) $(ENVFILE) build/armu.gypi
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000220 build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
221 -Ibuild/standalone.gypi --depth=. -Ibuild/armu.gypi \
222 -S-arm $(GYPFLAGS)
223
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000224$(OUTDIR)/Makefile-mips: $(GYPFILES) $(ENVFILE) build/mipsu.gypi
225 build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
226 -Ibuild/standalone.gypi --depth=. -Ibuild/mipsu.gypi \
227 -S-mips $(GYPFLAGS)
228
229$(OUTDIR)/Makefile-native: $(GYPFILES) $(ENVFILE)
230 build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
231 -Ibuild/standalone.gypi --depth=. -S-native $(GYPFLAGS)
232
Ben Murdochc7cc0282012-03-05 14:35:55 +0000233$(OUTDIR)/Makefile-android: $(GYPFILES) $(ENVFILE) build/android.gypi \
234 must-set-ANDROID_NDK_ROOT
235 CC="${ANDROID_TOOL_PREFIX}-gcc" \
236 build/gyp/gyp --generator-output="$(OUTDIR)" build/all.gyp \
237 -Ibuild/standalone.gypi --depth=. -Ibuild/android.gypi \
238 -S-android $(GYPFLAGS)
239
240must-set-ANDROID_NDK_ROOT:
241ifndef ANDROID_NDK_ROOT
242 $(error ANDROID_NDK_ROOT is not set)
243endif
244
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000245# Replaces the old with the new environment file if they're different, which
246# will trigger GYP to regenerate Makefiles.
247$(ENVFILE): $(ENVFILE).new
248 @if test -r $(ENVFILE) && cmp $(ENVFILE).new $(ENVFILE) >/dev/null; \
249 then rm $(ENVFILE).new; \
250 else mv $(ENVFILE).new $(ENVFILE); fi
251
252# Stores current GYPFLAGS in a file.
253$(ENVFILE).new:
254 @mkdir -p $(OUTDIR); echo "GYPFLAGS=$(GYPFLAGS)" > $(ENVFILE).new;
Ben Murdoch589d6972011-11-30 16:04:58 +0000255
256# Dependencies.
257dependencies:
258 svn checkout --force http://gyp.googlecode.com/svn/trunk build/gyp \
259 --revision 1026