android.gypi 9.4 KB
Newer Older
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
# Copyright 2012 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#     * Neither the name of Google Inc. nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Definitions for building standalone V8 binaries to run on Android.
# This is mostly excerpted from:
# http://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi

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