bbefb78a创建于 2012年9月8日历史提交
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# TODO(polina): for Mac build check if no longer need .r files and/or document
# target browsers for each bundle target.

Import('env')

if not env.Bit('mac'):
  env['COMPONENT_STATIC'] = False


plugin_env = env.Clone()
if env.Bit('linux'):
    plugin_env.Append(
        CCFLAGS=['-fPIC', '-Wno-long-long',],
        CPPDEFINES = ['XP_UNIX', 'MOZ_X11'],
        )
    if not env.Bit('asan'):
      plugin_env.Append(
          # Catch unresolved symbols in libraries.
          LINKFLAGS=['-Wl,-z,defs'],
          )

    # We usually try to build things statically, but the plugin is a .so
    plugin_env.FilterOut(LINKFLAGS=['-static'])

if env.Bit('mac'):
    plugin_env.Append(
        CCFLAGS=['-Wno-long-long',
                 # warning: Basically all of our 2d Mac stuff is deprecated.
                 '-Wno-deprecated',
                 '-Wno-deprecated-declarations'],
        CPPDEFINES = [
            'XP_MACOSX',
            'XP_UNIX',
            ['TARGET_API_MAC_CARBON', '1'],
            # TODO(robertm): NO_X11 may be obsolete
            'NO_X11',
            'USE_SYSTEM_CONSOLE',
        ],
        FRAMEWORKS = ['Carbon'],
        # TODO(jrg): it's a little awkward to, when you want a bundle:
        #  1) add -bundle to your LINKFLAGS
        #  2) create a "program" (which shows up in all_programs target)
        #  3) create a bundle out of it, specifying the bundle extension
        # Ideally that all happens inside a CompleteBundlePseudoBuilder().
        LINKFLAGS = ['-bundle', '-framework', 'Foundation']
    )

if env.Bit('windows'):
    plugin_env.Append(
        CPPDEFINES = ['XP_WIN', 'WIN32', '_WINDOWS'],
    )

common_inputs = [
    'file_downloader.cc',
    'json_manifest.cc',
    'local_temp_file.cc',
    'module_ppapi.cc',
    'nacl_subprocess.cc',
    'nexe_arch.cc',
    'plugin.cc',
    'pnacl_coordinator.cc',
    'pnacl_resources.cc',
    'pnacl_translate_thread.cc',
    'scriptable_plugin.cc',
    'sel_ldr_launcher_chrome.cc',
    'service_runtime.cc',
    'srpc_client.cc',
    'srpc_params.cc',
    'temporary_file.cc',
    'utility.cc',
]

if env.Bit('target_x86'):
  common_inputs += ['arch_x86/sandbox_isa.cc']
elif env.Bit('target_arm'):
  common_inputs += ['arch_arm/sandbox_isa.cc']
else:
  # Unrecognized architecture - this is a build failure.
  print "Unrecognized architecture: %s" % env['TARGET_ARCHITECTURE']
  Return()

# The libraries used by both the PPAPI plugin.  They and the PPAPI specific
# libraries must come before OS libraries, because they may generate references
# that are resolved by the OS libraries.  E.g., libimc.a contains
# references to symbols from librt.so.
common_libs = [
    'nonnacl_util',
    'nonnacl_srpc',
    'gio_wrapped_desc',
    'nrd_xfer',
    'nacl_perf_counter',
    'nacl_base',
    'imc',
    'weak_ref',
    'platform',
    'platform_qual_lib',
    'reverse_service',
    'gio',
    'jsoncpp',
    'sel',
    'simple_service',
    'thread_interface',
    'env_cleanser',
    'nacl_error_code',
]

os_libs = [ ]
if plugin_env.Bit('linux'):
  os_libs += ['dl', 'rt']

if plugin_env.Bit('windows'):
  os_libs += ['gdi32', 'user32', ]


###############################################################################
# PPAPI Plugin Build
###############################################################################

# We build a shared library with this build script to allow easier build
# testing. This library can also be loaded into Chrome using --no-sandbox
# --register-pepper-plugins="path/to/library;application/x-nacl".
#
# The .gyp files include rules used to link the plugin statically into Chrome.
# (This is still work in progress as of mid-Nov 2010.)
#

ppNaClPlugin = 'ppNaClPlugin'

ppapi_libs = common_libs + [ 'ppapi_cpp', 'ppapi_browser', 'nonnacl_srpc' ]
if plugin_env['SHARED_LIBS_SPECIAL']:
  plugin_env.Append(LIBS=[l + '_shared' for l in ppapi_libs] + os_libs)
else:
  plugin_env.Append(LIBS=ppapi_libs + os_libs)

if not env.Bit('mac'):  # linux, windows, arm
  # This builds with
  #   MODE=... ppNaClPlugin sel_ldr
  # with the output going to
  #   scons-out/.../staging/libppNaClPlugin.so on Linux and
  #   scons-out/.../staging/ppNaClPlugin.dll on Windows.
  ppapi_plugin = plugin_env.ComponentLibrary(ppNaClPlugin,
                                             common_inputs,
                                             no_import_lib=True)
else:  # mac
  # This builds with
  #   MODE=... scons-out/.../staging/ppNaClPlugin.bundle sel_ldr
  # This places both ppNaClPlugin.bundle/ and sel_ldr into staging/.
  # One must either set $NACL_SEL_LDR=path/to/sel_ldr or manually
  # copy sel_ldr to path/to/ppNaClPlugin.bundle/Contents/Resources/.
  # (the 2nd option has been disabled:
  # see ../nonnacl_util/osx/get_plugin_dirname.mm).
  REZ = '/Developer/Tools/Rez'
  plugin_env.Command(target='ppNaClPlugin.rsrc',
                     source='osx_ppapi/ppNaClPlugin.r',
                     action=[Action(REZ + ' -o ${TARGET} ${SOURCE} -useDF')])
  ppapi_plugin = plugin_env.ComponentProgram(ppNaClPlugin,
                                             common_inputs,
                                             no_import_lib=True)
  # Bundle pattern can be found in
  # site_scons/site_tools/target_platform_mac.py
  bundle_name = '${STAGING_DIR}/' + ppNaClPlugin + '.bundle'
  plugin_env.Bundle(bundle_name,
                    BUNDLE_EXE = ppapi_plugin,
                    BUNDLE_PKGINFO_FILENAME = 0,
                    BUNDLE_RESOURCES = 'ppNaClPlugin.rsrc',
                    BUNDLE_INFO_PLIST = 'osx_ppapi/Info.plist')

plugin_env.Alias('plugin', plugin_env.GetPPAPIPluginPath(False))


###############################################################################
# PPAPI Plugin Test
###############################################################################

# Rather than link ppNaClPlugin statically, this unittest uses the dynamic
# library.  Note that these tests do not yet run on ARM.
unittest_sources = ['dylib_unittest.cc', 'plugin_unittest.cc']
if env.Bit('target_x86'):
  if env.Bit('linux'):
    unittest = env.ComponentProgram('ppapi_plugin_unittest',
                                    unittest_sources,
                                    no_import_lib=True,
                                    EXTRA_LIBS=['dl'])
  elif env.Bit('mac'):
    unittest = env.ComponentProgram('ppapi_plugin_unittest', unittest_sources)
  elif env.Bit('windows'):
    unittest = env.ComponentProgram('ppapi_plugin_unittest',
                                    unittest_sources,
                                    no_import_lib=True)
  node = env.CommandTest('ppapi_plugin_unittest.out',
                         command=[unittest,
                                  ppapi_plugin,
                                  env['BUILD_ISA_NAME']])
  env.AddNodeToTestSuite(node, ['small_tests'], 'run_ppapi_plugin_unittest')


# TODO(polina,sehr): add a test for the PPAPI plugin on ARM.