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