• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Definitions for building standalone V8 binaries to run on Android.
29# This is mostly excerpted from:
30# http://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi
31
32{
33  'variables': {
34    # Location of Android NDK.
35    'variables': {
36      'android_ndk_root%': '<!(/bin/echo -n $ANDROID_NDK_ROOT)',
37      'android_toolchain%': '<!(/bin/echo -n $ANDROID_TOOLCHAIN)',
38    },
39    'conditions': [
40      ['android_ndk_root==""', {
41        'variables': {
42          'android_sysroot': '<(android_toolchain)/sysroot/',
43          'android_stlport': '<(android_toolchain)/sources/cxx-stl/stlport/',
44        },
45        'android_include': '<(android_sysroot)/usr/include',
46        'android_lib': '<(android_sysroot)/usr/lib',
47        'android_stlport_include': '<(android_stlport)/stlport',
48        'android_stlport_libs': '<(android_stlport)/libs',
49      }, {
50        'variables': {
51          'android_sysroot': '<(android_ndk_root)/platforms/android-<(android_target_platform)/arch-<(android_target_arch)',
52          'android_stlport': '<(android_ndk_root)/sources/cxx-stl/stlport/',
53        },
54        'android_include': '<(android_sysroot)/usr/include',
55        'android_lib': '<(android_sysroot)/usr/lib',
56        'android_stlport_include': '<(android_stlport)/stlport',
57        'android_stlport_libs': '<(android_stlport)/libs',
58      }],
59    ],
60    # Enable to use the system stlport, otherwise statically
61    # link the NDK one?
62    'use_system_stlport%': '<(android_webview_build)',
63    'android_stlport_library': 'stlport_static',
64  },  # variables
65  'target_defaults': {
66    'defines': [
67      'ANDROID',
68      'V8_ANDROID_LOG_STDOUT',
69    ],
70    'configurations': {
71      'Release': {
72        'cflags': [
73          '-fomit-frame-pointer',
74        ],
75      },  # Release
76    },  # configurations
77    'cflags': [ '-Wno-abi', '-Wall', '-W', '-Wno-unused-parameter',
78                '-Wnon-virtual-dtor', '-fno-rtti', '-fno-exceptions',
79                # Note: Using -std=c++0x will define __STRICT_ANSI__, which in
80                # turn will leave out some template stuff for 'long long'. What
81                # we want is -std=c++11, but this is not supported by GCC 4.6 or
82                # Xcode 4.2
83                '-std=gnu++0x' ],
84    'target_conditions': [
85      ['_toolset=="target"', {
86        'cflags!': [
87          '-pthread',  # Not supported by Android toolchain.
88        ],
89        'cflags': [
90          '-ffunction-sections',
91          '-funwind-tables',
92          '-fstack-protector',
93          '-fno-short-enums',
94          '-finline-limit=64',
95          '-Wa,--noexecstack',
96          '-Wno-error=non-virtual-dtor',  # TODO(michaelbai): Fix warnings.
97          # Note: This include is in cflags to ensure that it comes after
98          # all of the includes.
99          '-I<(android_include)',
100        ],
101        'defines': [
102          'ANDROID',
103          #'__GNU_SOURCE=1',  # Necessary for clone()
104          'USE_STLPORT=1',
105          '_STLP_USE_PTR_SPECIALIZATIONS=1',
106          'HAVE_OFF64_T',
107          'HAVE_SYS_UIO_H',
108          'ANDROID_BINSIZE_HACK', # Enable temporary hacks to reduce binsize.
109        ],
110        'ldflags!': [
111          '-pthread',  # Not supported by Android toolchain.
112        ],
113        'ldflags': [
114          '-nostdlib',
115          '-Wl,--no-undefined',
116        ],
117        'libraries!': [
118            '-lrt',  # librt is built into Bionic.
119            # Not supported by Android toolchain.
120            # Where do these come from?  Can't find references in
121            # any Chromium gyp or gypi file.  Maybe they come from
122            # gyp itself?
123            '-lpthread', '-lnss3', '-lnssutil3', '-lsmime3', '-lplds4', '-lplc4', '-lnspr4',
124          ],
125          'libraries': [
126            '-l<(android_stlport_library)',
127            # Manually link the libgcc.a that the cross compiler uses.
128            '<!($CC -print-libgcc-file-name)',
129            '-lc',
130            '-ldl',
131            '-lstdc++',
132            '-lm',
133        ],
134        'conditions': [
135          ['android_webview_build==0', {
136            'ldflags': [
137              '-Wl,-rpath-link=<(android_lib)',
138              '-L<(android_lib)',
139            ],
140          }],
141          ['target_arch == "arm"', {
142            'ldflags': [
143              # Enable identical code folding to reduce size.
144              '-Wl,--icf=safe',
145            ],
146          }],
147          ['target_arch=="arm" and arm_version==7', {
148            'cflags': [
149              '-march=armv7-a',
150              '-mtune=cortex-a8',
151              '-mfpu=vfp3',
152            ],
153          }],
154          # NOTE: The stlport header include paths below are specified in
155          # cflags rather than include_dirs because they need to come
156          # after include_dirs. Think of them like system headers, but
157          # don't use '-isystem' because the arm-linux-androideabi-4.4.3
158          # toolchain (circa Gingerbread) will exhibit strange errors.
159          # The include ordering here is important; change with caution.
160          ['use_system_stlport==0', {
161            'cflags': [
162              '-I<(android_stlport_include)',
163            ],
164            'conditions': [
165              ['target_arch=="arm" and arm_version==7', {
166                'ldflags': [
167                  '-L<(android_stlport_libs)/armeabi-v7a',
168                ],
169              }],
170              ['target_arch=="arm" and arm_version < 7', {
171                'ldflags': [
172                  '-L<(android_stlport_libs)/armeabi',
173                ],
174              }],
175              ['target_arch=="mipsel"', {
176                'ldflags': [
177                  '-L<(android_stlport_libs)/mips',
178                ],
179              }],
180              ['target_arch=="ia32" or target_arch=="x87"', {
181                'ldflags': [
182                  '-L<(android_stlport_libs)/x86',
183                ],
184              }],
185              ['target_arch=="x64"', {
186                'ldflags': [
187                  '-L<(android_stlport_libs)/x86_64',
188                ],
189              }],
190              ['target_arch=="arm64"', {
191                'ldflags': [
192                  '-L<(android_stlport_libs)/arm64-v8a',
193                ],
194              }],
195            ],
196          }],
197          ['target_arch=="ia32" or target_arch=="x87"', {
198            # The x86 toolchain currently has problems with stack-protector.
199            'cflags!': [
200              '-fstack-protector',
201            ],
202            'cflags': [
203              '-fno-stack-protector',
204            ],
205          }],
206          ['target_arch=="mipsel"', {
207            # The mips toolchain currently has problems with stack-protector.
208            'cflags!': [
209              '-fstack-protector',
210              '-U__linux__'
211            ],
212            'cflags': [
213              '-fno-stack-protector',
214            ],
215          }],
216          ['target_arch=="arm64" or target_arch=="x64"', {
217            # TODO(ulan): Enable PIE for other architectures (crbug.com/373219).
218            'cflags': [
219              '-fPIE',
220            ],
221            'ldflags': [
222              '-pie',
223            ],
224          }],
225        ],
226        'target_conditions': [
227          ['_type=="executable"', {
228            'conditions': [
229              ['target_arch=="arm64"', {
230                'ldflags': [
231                  '-Wl,-dynamic-linker,/system/bin/linker64',
232                ],
233              }, {
234                'ldflags': [
235                  '-Wl,-dynamic-linker,/system/bin/linker',
236                ],
237              }]
238            ],
239            'ldflags': [
240              '-Bdynamic',
241              '-Wl,-z,nocopyreloc',
242              # crtbegin_dynamic.o should be the last item in ldflags.
243              '<(android_lib)/crtbegin_dynamic.o',
244            ],
245            'libraries': [
246              # crtend_android.o needs to be the last item in libraries.
247              # Do not add any libraries after this!
248              '<(android_lib)/crtend_android.o',
249            ],
250          }],
251          ['_type=="shared_library"', {
252            'ldflags': [
253              '-Wl,-shared,-Bsymbolic',
254              '<(android_lib)/crtbegin_so.o',
255            ],
256          }],
257          ['_type=="static_library"', {
258            'ldflags': [
259              # Don't export symbols from statically linked libraries.
260              '-Wl,--exclude-libs=ALL',
261            ],
262          }],
263        ],
264      }],  # _toolset=="target"
265      # Settings for building host targets using the system toolchain.
266      ['_toolset=="host"', {
267        'cflags': [ '-pthread' ],
268        'ldflags': [ '-pthread' ],
269        'ldflags!': [
270          '-Wl,-z,noexecstack',
271          '-Wl,--gc-sections',
272          '-Wl,-O1',
273          '-Wl,--as-needed',
274        ],
275      }],
276    ],  # target_conditions
277  },  # target_defaults
278}
279