Home | History | Annotate | Download | only in build
      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       'variables': {
     37         'android_ndk_root%': '<!(/bin/echo -n $ANDROID_NDK_ROOT)',
     38         'android_target_arch%': 'arm',  # target_arch in android terms.
     39 
     40         # Switch between different build types, currently only '0' is
     41         # supported.
     42         'android_build_type%': 0,
     43       },
     44       'android_ndk_root%': '<(android_ndk_root)',
     45       'android_ndk_sysroot': '<(android_ndk_root)/platforms/android-9/arch-<(android_target_arch)',
     46       'android_build_type%': '<(android_build_type)',
     47     },
     48     'android_ndk_root%': '<(android_ndk_root)',
     49     'android_ndk_sysroot': '<(android_ndk_sysroot)',
     50     'android_ndk_include': '<(android_ndk_sysroot)/usr/include',
     51     'android_ndk_lib': '<(android_ndk_sysroot)/usr/lib',
     52     # Enable to use the system stlport, otherwise statically
     53     # link the NDK one?
     54     'use_system_stlport%': '<(android_build_type)',
     55     'android_stlport_library': 'stlport_static',
     56     # Copy it out one scope.
     57     'android_build_type%': '<(android_build_type)',
     58 
     59     'OS': 'android',
     60     'target_arch': 'arm',
     61     'v8_target_arch': 'arm',
     62     'armv7': 1,
     63     'arm_neon': 0,
     64     'arm_fpu': 'vfpv3',
     65   },  # variables
     66   'target_defaults': {
     67     'defines': [
     68       'ANDROID',
     69       'V8_ANDROID_LOG_STDOUT',
     70     ],
     71     'configurations': {
     72       'Release': {
     73         'cflags!': [
     74           '-O2',
     75           '-Os',
     76         ],
     77         'cflags': [
     78           '-fdata-sections',
     79           '-ffunction-sections',
     80           '-fomit-frame-pointer',
     81           '-O3',
     82         ],
     83       },  # Release
     84     },  # configurations
     85     'cflags': [ '-Wno-abi', '-Wall', '-W', '-Wno-unused-parameter',
     86                 '-Wnon-virtual-dtor', '-fno-rtti', '-fno-exceptions', ],
     87     'target_conditions': [
     88       ['_toolset=="target"', {
     89         'cflags!': [
     90           '-pthread',  # Not supported by Android toolchain.
     91         ],
     92         'cflags': [
     93           '-U__linux__',  # Don't allow toolchain to claim -D__linux__
     94           '-ffunction-sections',
     95           '-funwind-tables',
     96           '-fstack-protector',
     97           '-fno-short-enums',
     98           '-finline-limit=64',
     99           '-Wa,--noexecstack',
    100           '-Wno-error=non-virtual-dtor',  # TODO(michaelbai): Fix warnings.
    101           # Note: This include is in cflags to ensure that it comes after
    102           # all of the includes.
    103           '-I<(android_ndk_include)',
    104           '-march=armv7-a',
    105           '-mtune=cortex-a8',
    106           '-mfpu=vfp3',
    107         ],
    108         'defines': [
    109           'ANDROID',
    110           #'__GNU_SOURCE=1',  # Necessary for clone()
    111           'USE_STLPORT=1',
    112           '_STLP_USE_PTR_SPECIALIZATIONS=1',
    113           'HAVE_OFF64_T',
    114           'HAVE_SYS_UIO_H',
    115           'ANDROID_BINSIZE_HACK', # Enable temporary hacks to reduce binsize.
    116         ],
    117         'ldflags!': [
    118           '-pthread',  # Not supported by Android toolchain.
    119         ],
    120         'ldflags': [
    121           '-nostdlib',
    122           '-Wl,--no-undefined',
    123           '-Wl,--icf=safe',  # Enable identical code folding to reduce size
    124           # Don't export symbols from statically linked libraries.
    125           '-Wl,--exclude-libs=ALL',
    126         ],
    127         'libraries!': [
    128             '-lrt',  # librt is built into Bionic.
    129             # Not supported by Android toolchain.
    130             # Where do these come from?  Can't find references in
    131             # any Chromium gyp or gypi file.  Maybe they come from
    132             # gyp itself?
    133             '-lpthread', '-lnss3', '-lnssutil3', '-lsmime3', '-lplds4', '-lplc4', '-lnspr4',
    134           ],
    135           'libraries': [
    136             '-l<(android_stlport_library)',
    137             # Manually link the libgcc.a that the cross compiler uses.
    138             '<!($CC -print-libgcc-file-name)',
    139             '-lc',
    140             '-ldl',
    141             '-lstdc++',
    142             '-lm',
    143         ],
    144         'conditions': [
    145           ['android_build_type==0', {
    146             'ldflags': [
    147               '-Wl,-rpath-link=<(android_ndk_lib)',
    148               '-L<(android_ndk_lib)',
    149             ],
    150           }],
    151           # NOTE: The stlport header include paths below are specified in
    152           # cflags rather than include_dirs because they need to come
    153           # after include_dirs. Think of them like system headers, but
    154           # don't use '-isystem' because the arm-linux-androideabi-4.4.3
    155           # toolchain (circa Gingerbread) will exhibit strange errors.
    156           # The include ordering here is important; change with caution.
    157           ['use_system_stlport==0', {
    158             'cflags': [
    159               '-I<(android_ndk_root)/sources/cxx-stl/stlport/stlport',
    160             ],
    161             'conditions': [
    162               ['target_arch=="arm" and armv7==1', {
    163                 'ldflags': [
    164                   '-L<(android_ndk_root)/sources/cxx-stl/stlport/libs/armeabi-v7a',
    165                 ],
    166               }],
    167               ['target_arch=="arm" and armv7==0', {
    168                 'ldflags': [
    169                   '-L<(android_ndk_root)/sources/cxx-stl/stlport/libs/armeabi',
    170                 ],
    171               }],
    172               ['target_arch=="ia32"', {
    173                 'ldflags': [
    174                   '-L<(android_ndk_root)/sources/cxx-stl/stlport/libs/x86',
    175                 ],
    176               }],
    177             ],
    178           }],
    179           ['target_arch=="ia32"', {
    180             # The x86 toolchain currently has problems with stack-protector.
    181             'cflags!': [
    182               '-fstack-protector',
    183             ],
    184             'cflags': [
    185               '-fno-stack-protector',
    186             ],
    187           }],
    188         ],
    189         'target_conditions': [
    190           ['_type=="executable"', {
    191             'ldflags': [
    192               '-Bdynamic',
    193               '-Wl,-dynamic-linker,/system/bin/linker',
    194               '-Wl,--gc-sections',
    195               '-Wl,-z,nocopyreloc',
    196               # crtbegin_dynamic.o should be the last item in ldflags.
    197               '<(android_ndk_lib)/crtbegin_dynamic.o',
    198             ],
    199             'libraries': [
    200               # crtend_android.o needs to be the last item in libraries.
    201               # Do not add any libraries after this!
    202               '<(android_ndk_lib)/crtend_android.o',
    203             ],
    204           }],
    205           ['_type=="shared_library"', {
    206             'ldflags': [
    207               '-Wl,-shared,-Bsymbolic',
    208             ],
    209           }],
    210         ],
    211       }],  # _toolset=="target"
    212       # Settings for building host targets using the system toolchain.
    213       ['_toolset=="host"', {
    214         'cflags': [ '-m32', '-pthread' ],
    215         'ldflags': [ '-m32', '-pthread' ],
    216         'ldflags!': [
    217           '-Wl,-z,noexecstack',
    218           '-Wl,--gc-sections',
    219           '-Wl,-O1',
    220           '-Wl,--as-needed',
    221         ],
    222       }],
    223     ],  # target_conditions
    224   },  # target_defaults
    225 }