示例#1
0
文件: config.py 项目: wobakj/avango
 def get_libraries(self):
     if oshelper.os_is_mac():
         # FIXME find proper way to detect this
         return ['Python']
     env = scons.Environment()
     flags = env.ParseFlags(
         distutils.sysconfig.get_config_var('BLDLIBRARY'))
     return flags['LIBS']
示例#2
0
def NaClEnvironment(use_c_plus_plus_libs=False,
                    nacl_platform=None,
                    toolchain_arch=None,
                    toolchain_variant=None,
                    use_ppapi=True,
                    install_subdir=None,
                    lib_prefix=None):
    '''Make an Environment that uses the NaCl toolchain to build sources.

  This modifies a default construction Environment to point the compilers and
  other bintools at the NaCl-specific versions, adds some tools that set certain
  build flags needed by the NaCl-specific tools, and adds a custom Builder that
  generates .nmf files.

  Args:
    use_c_plus_plus_libs: Indicate whether to insert the C++ NaCl libs at the
        right place in the list of LIBS.
    nacl_platform: The target NaCl/Chrome/Papper platform for which the
        environment, e.g. 'pepper_14'.
    toolchain_arch: The target architecture of the toolchain (e.g., x86, pnacl)
    toolchain_variant: The libc of the toolchain (e.g., newlib, glibc)
    use_ppapi: flag indicating whether to compile again ppapi libraries
    install_subdir: subdirectory within the NACL_INSTALL_ROOT for this project.
    lib_prefix: an optional list of path components to prepend to the library
        path.  These components are joined with appropriate path separators
        Examples: ['..', '..'], ['..', 'peer_directory'].
  Returns:
    A SCons Environment with all the various Tool and keywords set to build
    NaCl modules.
  '''
    def GetCommandLineOption(option_name, option_value, option_default):
        '''Small helper function to get a command line option.

    Returns a command-line option value, which can be overridden.  If the
    option is set on the command line, then that value is favoured over the
    internally set value.  If option is neither set on the command line nor
    given a value, its default is used.

    Args:
      option_name: The name of the command line option, e.g. "variant".
      option_value: The initial value of the option. This value is used if the
          its not set via the command line.  Can be None.
      option_default: If the option value hasn't been set via the command line
          nor via an internal value, then this default value is used.  Can be
          None.

    Returns:
      The value of the command-line option, according to the override rules
          described above.
    '''
        cmd_line_value = Script.GetOption(option_name)
        if not cmd_line_value and not option_value:
            cmd_line_value = option_default
        return cmd_line_value or option_value

    nacl_utils.AddCommandLineOptions()
    env = Script.Environment()

    # We must have a nacl_platform, either as argument to this function or from
    # the command line. However, if we're cleaning we can relax this requirement.
    # (And our build bots will be much happier that way.)
    nacl_platform_from_option = Script.GetOption('nacl_platform')
    if not nacl_platform_from_option and not nacl_platform:
        if Script.GetOption('clean'):
            nacl_platform_from_option = '.'
        else:
            raise ValueError('NaCl platform not specified')

    # Setup the base dir for tools, etc. Favor the nacl platform specified on
    # the command line if there's a conflict.
    nacl_platform_to_use = nacl_platform_from_option or nacl_platform

    toolchain_variant = GetCommandLineOption(
        'variant', toolchain_variant, nacl_utils.DEFAULT_TOOLCHAIN_VARIANT)
    toolchain_arch = GetCommandLineOption('architecture', toolchain_arch,
                                          nacl_utils.DEFAULT_TOOLCHAIN_ARCH)

    base_dir = os.getenv('NACL_SDK_ROOT', '')
    base_dir = os.path.join(base_dir, nacl_platform_to_use)
    toolchain = nacl_utils.ToolchainPath(base_dir=base_dir,
                                         arch=toolchain_arch,
                                         variant=toolchain_variant)
    if (toolchain is None):
        raise ValueError('Cannot find a NaCl toolchain')

    tool_bin_path = os.path.join(toolchain, 'bin')
    tool_runtime_path = os.path.join(toolchain, 'runtime')
    staging_dir = os.path.abspath(
        os.getenv('NACL_INSTALL_ROOT',
                  os.path.join(os.getenv('NACL_SDK_ROOT', '.'), 'staging')))
    if install_subdir:
        staging_dir = os.path.join(staging_dir, install_subdir)
    lib_prefix = lib_prefix or []
    if type(lib_prefix) is not list:
        # Break path down into list of directory components
        lib_prefix = filter(lambda x: x, lib_prefix.split('/'))

    # Invoke the various *nix tools that the NativeClient SDK resembles.  This
    # is done so that SCons doesn't try to invoke cl.exe on Windows in the
    # Object builder.
    env.Tool('g++')
    env.Tool('gcc')
    env.Tool('gnulink')
    env.Tool('ar')
    env.Tool('as')

    env.Tool('nacl_tools')
    # TODO(dspringer): Figure out how to make this dynamic and then compute it
    # based on the desired target arch.
    env.Replace(
        tools=['nacl_tools'],
        # Replace the normal unix tools with the NaCl ones.  Note the
        # use of the NACL_ARCHITECTURE prefix for the tools.  This
        # Environment variable is set in nacl_tools.py; it has no
        # default value.
        CC=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}gcc'),
        CXX=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}g++'),
        AR=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}ar'),
        AS=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}as'),
        GDB=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}gdb'),
        # NOTE: use g++ for linking so we can handle C AND C++.
        LINK=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}g++'),
        LD=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}ld'),
        STRIP=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}strip'),
        NACL_SEL_LDR32=os.path.join(tool_bin_path, 'sel_ldr_x86_32'),
        NACL_IRT_CORE32=os.path.join(tool_runtime_path,
                                     'irt_core_x86_32.nexe'),
        NACL_SEL_LDR64=os.path.join(tool_bin_path, 'sel_ldr_x86_64'),
        NACL_IRT_CORE64=os.path.join(tool_runtime_path,
                                     'irt_core_x86_64.nexe'),
        RANLIB=os.path.join(tool_bin_path, '${NACL_ARCHITECTURE}ranlib'),
        ASFLAGS=[
            '${EXTRA_ASFLAGS}',
        ],
        # c specific
        EXTRA_CFLAGS=[],
        CFLAGS=[
            '${EXTRA_CFLAGS}',
            '-std=gnu99',
        ],
        # c++ specific
        EXTRA_CXXFLAGS=[],
        CXXFLAGS=[
            '${EXTRA_CXXFLAGS}',
            '-std=gnu++98',
            '-Wno-long-long',
        ],
        # Both C and C++
        CCFLAGS=[
            '${EXTRA_CCFLAGS}',
            '-Wall',
            '-Wswitch-enum',
            '-pthread',
        ],
        CPPDEFINES=[  # _GNU_SOURCE ensures that strtof() gets declared.
            ('_GNU_SOURCE', 1),
            # This ensures that PRId64 etc. get defined.
            ('__STDC_FORMAT_MACROS', '1'),
            # strdup, and other common stuff
            ('_BSD_SOURCE', '1'),
            ('_POSIX_C_SOURCE', '199506'),
            ('_XOPEN_SOURCE', '600'),
        ],
        CPPPATH=[],
        LINKFLAGS=[
            '${EXTRA_LINKFLAGS}',
        ],
        # The NaCl environment makes '.nexe' executables.  If this is
        # not explicitly set, then SCons on Windows doesn't understand
        # how to construct a Program builder properly.
        PROGSUFFIX='.nexe',
        # Target NaCl platform info.
        TARGET_NACL_PLATFORM=nacl_platform_to_use,
        NACL_TOOLCHAIN_VARIANT=toolchain_variant,
        NACL_TOOLCHAIN_ROOT=toolchain,
        NACL_INSTALL_ROOT=staging_dir,
        NACL_LIB_PREFIX=lib_prefix,
    )
    # This supresses the "MS_DOS style path" warnings on Windows.  It's benign on
    # all other platforms.
    env['ENV']['CYGWIN'] = 'nodosfilewarning'

    # Append the common NaCl libs.
    if use_ppapi:
        common_nacl_libs = ['ppapi']
        if use_c_plus_plus_libs:
            common_nacl_libs.extend(['ppapi_cpp'])
        env.Append(LIBS=common_nacl_libs)

    gen_nmf_builder = env.Builder(suffix='.nmf', action=nacl_utils.GenerateNmf)
    env.Append(BUILDERS={'GenerateNmf': gen_nmf_builder})

    return env
示例#3
0
    def __init__(self, target, machine, build, toolchain, available_features=[]):
        self.available_features = available_features
        self.host_platform = self.detect_platform()
        self.host_machine = self.detect_machine()
        self.flags = {}

        if target is None:
            target = self.host_platform

        if machine is None:
            machine = self.host_machine

        if toolchain is None:
            if self.host_platform == 'windows':
                raise Exception(
                    'must specify toolchain on Windows (msvs or gnu)')
            else:
                toolchain = 'gnu'

        if build is None:
            build = 'debug'

        if not build in ['debug', 'release']:
            raise Exception("invalid build type")

        if target not in ['windows', 'osx', 'linux', 'bsd']:
            raise Exception("invalid target platform")

        if machine.lower() not in ['x86_64', 'x86', 'i686', 'i586',
                                   'alpha', 'hppa', 'mips', 'mipsel', 's390',
                                   'sparc', 'ia64', 'armel', 'armhf', 'hurd-i386',
                                   'sh3', 'sh4',
                                   'kfreebsd-amd64', 'kfreebsd-i386',
                                   'i486', 'i386', 'ppc', 'ppc64', 'powerpc',
                                   'powerpc64', 'powerpcspe', 's390x',
                                   'amd64', 'em64t', 'intel64', 'arm64',
                                   'ppc64el']:
            raise Exception("invalid machine type")

        if toolchain not in ['gnu', 'msvs']:
            raise Exception('invalid toolchain type')

        if toolchain == 'msvs' and self.host_platform != 'windows':
            raise Exception(
                'cannot use msvs toolchain on non-windows platform')

        self.platform = target
        self.platform_is_posix = self.platform in ['linux', 'osx', 'bsd']
        self.platform_is_linux = self.platform == 'linux'
        self.platform_is_osx = self.platform == 'osx'
        self.platform_is_bsd = self.platform == 'bsd'
        self.platform_is_windows = self.platform == 'windows'

        self.machine = machine
        self.build = build
        self.build_is_debug = build == 'debug'
        self.build_is_release = build == 'release'

        self.toolchain = toolchain
        self.toolchain_is_gnu = self.toolchain == 'gnu'
        self.toolchain_is_msvs = self.toolchain == 'msvs'

        self.crosscompile = self.host_platform != self.platform

        flags_force32 = int(Script.ARGUMENTS.get('force32', 0))
        flags_force64 = int(Script.ARGUMENTS.get('force64', 0))
        if flags_force32 and flags_force64:
            logging.error('Both force32 and force64 cannot be enabled at once')
            Script.Exit(1)

        if flags_force32:
            if self.machine in ['powerpc', 'powerpc64', 'ppc', 'ppc64']:
                self.machine = 'powerpc'
            else:
                self.machine = 'x86'
        elif flags_force64:
            if self.machine in ['powerpc', 'powerpc64', 'ppc', 'ppc64']:
                self.machine = 'powerpc64'
            else:
                self.machine = 'x86_64'
        self.machine_is_64bit = self.machine.lower(
            ) in ['x86_64', 'powerpc64', 'ppc64', 'amd64', 'em64t', 'intel64']
        self.bitwidth = 64 if self.machine_is_64bit else 32
        self.architecture_is_x86 = self.machine.lower(
            ) in ['x86', 'x86_64', 'i386', 'i486', 'i586', 'i686', 'em64t',
                  'intel64', 'amd64']
        self.architecture_is_powerpc = self.machine.lower(
            ) in ['powerpc', 'powerpc64', 'ppc', 'ppc64']
        self.architecture_is_arm = self.machine.lower().startswith('arm')

        self.build_dir = util.get_build_dir(self.platform, self.bitwidth)

        # Currently this only works for Windows
        self.static_dependencies = int(Script.ARGUMENTS.get('staticlibs', 0))

        logging.info("Target Platform: %s" % self.platform)
        logging.info("Target Machine: %s" % self.machine)
        logging.info("Build: %s" % self.build)
        logging.info("Toolchain: %s" % self.toolchain)
        logging.info(
            "Crosscompile: %s" % ("YES" if self.crosscompile else "NO"))
        if self.platform_is_windows:
            logging.info("Static dependencies: %s" % (
                "YES" if self.static_dependencies else "NO"))

        if self.crosscompile:
            logging.info("Host Platform: %s" % self.host_platform)
            logging.info("Host Machine: %s" % self.host_machine)

        if self.crosscompile and self.host_platform != 'linux':
            raise Exception(
                'Cross-compiling on a non-Linux host not currently supported')

        tools = ['default']
        toolpath = ['#build/']
        extra_arguments = {}
        import depends
        if int(Script.ARGUMENTS.get('qt5', 0)):
            tools.append('qt5')
            if self.machine_is_64bit:
                default_qtdir = depends.Qt.DEFAULT_QT5DIRS64.get(
                    self.platform, '')
            else:
                default_qtdir = depends.Qt.DEFAULT_QT5DIRS32.get(
                    self.platform, '')
        else:
            tools.append('qt4')
            default_qtdir = depends.Qt.DEFAULT_QT4DIRS.get(self.platform, '')
        tools.append('protoc')

        # Ugly hack to check the qtdir argument
        qtdir = Script.ARGUMENTS.get('qtdir',
                                     os.environ.get('QTDIR', default_qtdir))

        # Validate the specified qtdir exists
        if not os.path.exists(qtdir):
            logging.error("QT path does not exist or QT4 is not installed.")
            logging.error(
                "Please specify your QT path by running 'scons qtdir=[path]'")
            Script.Exit(1)
        # And that it doesn't contain qt3
        elif qtdir.find("qt3") != -1 or qtdir.find("qt/3") != -1:
            logging.error("Mixxx now requires QT4 instead of QT3 - please use your QT4 path with the qtdir build flag.")
            Script.Exit(1)
        logging.info("Qt path: %s" % qtdir)

        # Previously this wasn't done for OSX, but I'm not sure why
        # -- rryan 6/8/2011
        extra_arguments['QTDIR'] = qtdir

        if self.platform_is_osx:
            tools.append('OSConsX')
            toolpath.append('#/build/osx/')
        if self.platform_is_windows and self.toolchain_is_msvs:
            # NOTE(rryan): Don't use the SCons mssdk tool since it does not
            # support x64.
            # In SConscript.env we use the MSVS tool to let you generate a
            # Visual Studio solution. Consider removing this.
            tools.extend(['msvs'])
            # SCons's built-in Qt tool attempts to link 'qt' into your binary if
            # you don't do this.
            extra_arguments['QT_LIB'] = ''
            # Causes SCons to bypass MSVC environment detection altogether
            # and depend on environment variables.
            # TODO(rryan): Expose SCons MSVC auto-detection options.
            extra_arguments['MSVC_USE_SCRIPT'] = None

        # Setup the appropriate toolchains for cross-compiling
        if self.crosscompile:
            if self.platform_is_windows:
                tools.append('crossmingw')
            if self.platform_is_osx:
                tools.append('crossosx')

        self.env = Script.Environment(
            tools=tools, toolpath=toolpath, ENV=os.environ,
            **extra_arguments)
        self.read_environment_variables()

        # Now that environment variables have been read, we can detect the compiler.
        self.compiler_is_gcc = 'gcc' in self.env['CC']
        self.compiler_is_clang = 'clang' in self.env['CC']

        self.virtualize_build_dir()

        if self.toolchain_is_gnu:
            if flags_force32:
                self.env.Append(CCFLAGS='-m32')
            elif flags_force64:
                self.env.Append(CCFLAGS='-m64')

        self.setup_platform_sdk()

        if self.platform_is_osx:
            if self.architecture_is_powerpc:
                self.env.Append(CCFLAGS='-arch ppc')
                self.env.Append(LINKFLAGS='-arch ppc')
            else:
                if self.bitwidth == 32:
                    self.env.Append(CCFLAGS='-arch i386')
                    self.env.Append(LINKFLAGS='-arch i386')
                elif self.bitwidth == 64:
                    self.env.Append(CCFLAGS='-arch x86_64')
                    self.env.Append(LINKFLAGS='-arch x86_64')

        if self.crosscompile:
            crosscompile_root = Script.ARGUMENTS.get('crosscompile_root', '')

            if crosscompile_root == '':
                print "Your build setup indicates this is a cross-compile, but you did not specify 'crosscompile_root', which is required."
                Script.Exit(1)

            crosscompile_root = os.path.abspath(crosscompile_root)
            self.env.Append(CPPPATH=os.path.join(crosscompile_root, 'include'))
            self.env.Append(LIBPATH=os.path.join(crosscompile_root, 'lib'))
            self.env.Append(LIBPATH=os.path.join(crosscompile_root, 'bin'))

        self.install_options()
示例#4
0
    def __init__(self, target, machine, build, toolchain, available_features):
        self.available_features = available_features
        self.host_platform = self.detect_platform()
        self.host_machine = self.detect_machine()
        self.flags = {}

        if target is None:
            target = self.host_platform

        if machine is None:
            machine = self.host_machine

        if toolchain is None:
            if self.host_platform == 'windows':
                raise Exception(
                    'must specify toolchain on Windows (msvs or gnu)')
            else:
                toolchain = 'gnu'

        if build is None:
            build = 'debug'

        if not build in ['debug', 'release']:
            raise Exception("invalid build type")

        if target not in ['windows', 'osx', 'linux', 'bsd']:
            raise Exception("invalid target platform")

        if machine.lower() not in [
                'x86_64', 'x86', 'i686', 'i586', 'alpha', 'hppa', 's390',
                'sparc', 'ia64', 'armel', 'armhf', 'hurd-i386', 'armv5tel',
                'armv5tejl', 'armv6l', 'armv6hl', 'armv7l', 'armv7hl',
                'armv7hnl', 'sh3', 'sh4', 'kfreebsd-amd64', 'kfreebsd-i386',
                'i486', 'i386', 'ppc', 'ppc64', 'powerpc', 'powerpc64',
                'powerpcspe', 's390x', 'amd64', 'em64t', 'intel64', 'arm64',
                'ppc64el', 'ppc64le', 'm68k', 'mips', 'mipsel', 'mipsr6',
                'mipsr6el', 'mips64', 'mips64r6', 'mips64el', 'mips64r6el',
                'mipsn32', 'mipsn32el', 'mipsn32r6', 'mipsn32r6el',
                'mipsisa32r6', 'mipsisa32r6el', 'mipsisa64r6', 'mipsisa64r6el',
                'aarch64'
        ]:
            raise Exception("invalid machine type")

        if toolchain not in ['gnu', 'msvs']:
            raise Exception('invalid toolchain type')

        if toolchain == 'msvs' and self.host_platform != 'windows':
            raise Exception(
                'cannot use msvs toolchain on non-windows platform')

        self.platform = target
        self.platform_is_posix = self.platform in ['linux', 'osx', 'bsd']
        self.platform_is_linux = self.platform == 'linux'
        self.platform_is_osx = self.platform == 'osx'
        self.platform_is_bsd = self.platform == 'bsd'
        self.platform_is_windows = self.platform == 'windows'

        self.machine = machine
        self.build = build
        self.build_is_debug = build == 'debug'
        self.build_is_release = build == 'release'

        self.toolchain = toolchain
        self.toolchain_is_gnu = self.toolchain == 'gnu'
        self.toolchain_is_msvs = self.toolchain == 'msvs'

        self.crosscompile = self.host_platform != self.platform

        flags_force32 = int(Script.ARGUMENTS.get('force32', 0))
        flags_force64 = int(Script.ARGUMENTS.get('force64', 0))
        if flags_force32 and flags_force64:
            logging.error('Both force32 and force64 cannot be enabled at once')
            Script.Exit(1)

        if flags_force32:
            if self.machine in ['powerpc', 'powerpc64', 'ppc', 'ppc64']:
                self.machine = 'powerpc'
            else:
                self.machine = 'x86'
        elif flags_force64:
            if self.machine in ['powerpc', 'powerpc64', 'ppc', 'ppc64']:
                self.machine = 'powerpc64'
            else:
                self.machine = 'x86_64'
        self.machine_is_64bit = self.machine.lower() in [
            'x86_64', 'powerpc64', 'ppc64', 'amd64', 'em64t', 'intel64'
        ]
        self.bitwidth = 64 if self.machine_is_64bit else 32
        self.architecture_is_x86 = self.machine.lower() in [
            'x86', 'x86_64', 'i386', 'i486', 'i586', 'i686', 'em64t',
            'intel64', 'amd64'
        ]
        self.architecture_is_powerpc = self.machine.lower() in [
            'powerpc', 'powerpc64', 'ppc', 'ppc64'
        ]
        self.architecture_is_arm = self.machine.lower().startswith('arm')

        self.build_dir = util.get_build_dir(self.platform, self.bitwidth)

        # Currently this only works for Windows
        self.static_dependencies = int(Script.ARGUMENTS.get('staticlibs', 0))
        self.static_qt = int(Script.ARGUMENTS.get('staticqt', 0))

        self.bundle_pdbs = self.platform_is_windows and (
            self.build_is_debug
            or Script.ARGUMENTS.get('bundle_pdbs', '') in ('yes', 'y', '1'))

        self.scons_version = ('unknown'
                              if SCons.__version__.startswith('__VERSION') else
                              '%s (%s, %s)' % (
                                  SCons.__version__,
                                  SCons.__build__,
                                  SCons.__date__,
                              ))
        logging.info("SCons version: %s" % self.scons_version)
        logging.info("Python version: %s" % sys.version.replace('\n', ''))
        logging.info("Target Platform: %s" % self.platform)
        logging.info("Target Machine: %s" % self.machine)
        logging.info("Build: %s" % self.build)
        logging.info("Toolchain: %s" % self.toolchain)
        logging.info("Crosscompile: %s" %
                     ("YES" if self.crosscompile else "NO"))
        if self.platform_is_windows:
            self.winlib_path = Script.ARGUMENTS.get('winlib', '')
            logging.info("Winlib Path: %s" % self.winlib_path)
            logging.info("Static dependencies: %s" %
                         ("YES" if self.static_dependencies else "NO"))
            logging.info("Static Qt: %s" % ("YES" if self.static_qt else "NO"))

        if self.crosscompile:
            logging.info("Host Platform: %s" % self.host_platform)
            logging.info("Host Machine: %s" % self.host_machine)

        if self.crosscompile and self.host_platform != 'linux':
            raise Exception(
                'Cross-compiling on a non-Linux host not currently supported')

        tools = ['default', 'qt5', 'protoc']
        toolpath = ['#build/']
        extra_arguments = {}
        from . import depends
        if self.machine_is_64bit:
            default_qtdir = depends.Qt.DEFAULT_QT5DIRS64.get(self.platform, '')
        else:
            default_qtdir = depends.Qt.DEFAULT_QT5DIRS32.get(self.platform, '')

        # Try fallback to pkg-config on Linux
        if not os.path.isdir(default_qtdir) and self.platform == 'linux':
            pkg_config_cmd = ['pkg-config', '--variable=includedir', 'Qt5Core']
            try:
                output = subprocess.check_output(pkg_config_cmd)
            except OSError:
                # pkg-config is not installed
                pass
            except subprocess.CalledProcessError:
                # pkg-config failed to find Qt5Core
                pass
            else:
                default_qtdir = output.decode('utf-8').rstrip()

        # Ugly hack to check the qtdir argument
        qtdir = Script.ARGUMENTS.get('qtdir',
                                     os.environ.get('QTDIR',
                                                    default_qtdir)).rstrip()

        # Validate the specified qtdir exists
        if not os.path.isdir(qtdir):
            logging.error(
                "Qt path (%s) does not exist or Qt is not installed." % qtdir)
            logging.error(
                "Please specify your Qt path by running 'scons qtdir=[path]'")
            Script.Exit(1)
        # And that it doesn't contain qt3 or qt4
        elif 'qt3' in qtdir or 'qt/3' in qtdir or 'qt4' in qtdir:
            logging.error(
                "Mixxx now requires Qt 5. Please set the qtdir build flag to the path to your Qt 5 installation."
            )
            Script.Exit(1)
        logging.info("Qt path: %s" % qtdir)
        extra_arguments['QTDIR'] = qtdir

        if self.platform_is_osx:
            tools.append('OSConsX')
            toolpath.append('#/build/osx/')
        if self.platform_is_windows and self.toolchain_is_msvs:
            # NOTE(rryan): Don't use the SCons mssdk tool since it does not
            # support x64.
            # In SConscript.env we use the MSVS tool to let you generate a
            # Visual Studio solution. Consider removing this.
            tools.extend(['msvs', 'signtool'])
            toolpath.append('#/build/windows/')
            # SCons's built-in Qt tool attempts to link 'qt' into your binary if
            # you don't do this.
            extra_arguments['QT_LIB'] = ''
            # Causes SCons to bypass MSVC environment detection altogether
            # and depend on environment variables.
            # TODO(rryan): Expose SCons MSVC auto-detection options.
            extra_arguments['MSVC_USE_SCRIPT'] = None

        # Setup the appropriate toolchains for cross-compiling
        if self.crosscompile:
            if self.platform_is_windows:
                tools.append('crossmingw')
            if self.platform_is_osx:
                tools.append('crossosx')

        self.env = Script.Environment(tools=tools,
                                      toolpath=toolpath,
                                      ENV=os.environ,
                                      **extra_arguments)
        self.read_environment_variables()

        # Now that environment variables have been read, we can detect the compiler.
        if self.toolchain_is_msvs:
            self.compiler_is_gcc = False
            self.compiler_is_clang = False
        else:
            cc_version_cmd = shlex.split(self.env['CC']) + ['--version']
            cc_version = subprocess.check_output(cc_version_cmd).decode(
                'utf-8')
            self.compiler_is_gcc = 'gcc' in cc_version.lower()
            self.compiler_is_clang = 'clang' in cc_version.lower()

            # Determine the major compiler version (only GCC)
            if self.compiler_is_gcc:
                self.gcc_major_version = None
                gcc_version_cmd = shlex.split(
                    self.env['CC']) + ['-dumpversion']
                gcc_version = subprocess.check_output(gcc_version_cmd).decode(
                    'utf-8')
                # If match is None we don't know the version.
                if not gcc_version is None:
                    version_split = gcc_version.split('.')
                    if version_split:
                        self.gcc_major_version = int(version_split[0])

        self.virtualize_build_dir()

        if self.toolchain_is_gnu:
            if flags_force32:
                self.env.Append(CCFLAGS='-m32')
            elif flags_force64:
                self.env.Append(CCFLAGS='-m64')

        self.setup_platform_sdk()

        if self.platform_is_osx:
            if self.architecture_is_powerpc:
                self.env.Append(CCFLAGS='-arch ppc')
                self.env.Append(LINKFLAGS='-arch ppc')
            else:
                if self.bitwidth == 32:
                    self.env.Append(CCFLAGS='-arch i386')
                    self.env.Append(LINKFLAGS='-arch i386')
                elif self.bitwidth == 64:
                    self.env.Append(CCFLAGS='-arch x86_64')
                    self.env.Append(LINKFLAGS='-arch x86_64')

        if self.crosscompile:
            crosscompile_root = Script.ARGUMENTS.get('crosscompile_root', '')

            if crosscompile_root == '':
                print(
                    "Your build setup indicates this is a cross-compile, but you did not specify 'crosscompile_root', which is required."
                )
                Script.Exit(1)

            crosscompile_root = os.path.abspath(crosscompile_root)
            self.env.Append(CPPPATH=os.path.join(crosscompile_root, 'include'))
            self.env.Append(LIBPATH=os.path.join(crosscompile_root, 'lib'))
            self.env.Append(LIBPATH=os.path.join(crosscompile_root, 'bin'))

        self.install_options()
示例#5
0
文件: __init__.py 项目: wobakj/avango
def _build_environment():
    result = scons.Environment(options=options)
    result.Tool('subst', toolpath=[os.path.dirname(__file__) + '/tools'])

    if 'icpc' in result['CXX']:
        result.Append(CCFLAGS='-wd177,383,424,810,981,1418,1419,1572')
        result.Append(LINKFLAGS='-static-intel')

    if oshelper.os_is_windows():
        if result.get('OPENSCENEGRAPH_DEBUG',
                      None):  # FIXME move this elswhere
            result.Append(
                CXXFLAGS=
                '/EHsc /W3 /MDd /wd4099 /wd4244 /wd4800 /wd4996 /wd4251 /wd4661'
            )  # FIXME remove deactivation of warnings
        else:
            result.Append(CXXFLAGS=[
                '/EHsc', '/W3', '/MD', '/wd4099', '/wd4244', '/wd4800',
                '/wd4996', '/wd4251', '/wd4661'
            ])  # FIXME remove deactivation of warnings

        result.Append(CPPDEFINES=['AV_INSTANTIATE_FIELD_TEMPLATES'])

        result.Append(CCFLAGS='/bigobj')
        result.Append(LINKFLAGS=['/MANIFEST'])
        result['SHLINKCOM'] = [
            result['SHLINKCOM'],
            'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'
        ]
    else:
        result.Append(CCFLAGS='-ansi -Wall')

    if result['DEBUG']:
        if oshelper.os_is_windows():
            result.Append(CCFLAGS='/DEBUG /Zi /D_DEBUG /Ob0 /Od /RTC1')
        else:
            result.Append(CCFLAGS='-g')
    else:
        if not oshelper.os_is_windows():
            result.Append(CCFLAGS='-O2 -DNDEBUG')
            if result['CXX'] == 'g++':
                result.Append(CCFLAGS='-fno-strict-aliasing')

    if result['TRACE_LOGGING']:
        result.Append(CPPDEFINES='TRACE_LOGGING')

    if result['BUILD_32']:
        #linux or mac
        if not oshelper.os_is_windows():
            result.Append(CCFLAGS='-m32')
            result.Append(LINKFLAGS='-m32')
        #windows
        else:
            result.Append(CPPDEFINES=['WIN32'])
    else:
        if oshelper.os_is_windows():
            result.Append(CPPDEFINES=['WIN32'])
            result.Append(LINKFLAGS='/MACHINE:X64')

    result.PrependENVPath('PATH', result['BINARY_PATH'])
    result.Prepend(CPPPATH=result['INCLUDE_PATH'].split(os.pathsep))
    result.Prepend(LIBPATH=result['LIBRARY_PATH'].split(os.pathsep))
    result.PrependENVPath(oshelper.get_library_search_path_env(),
                          result['LIBRARY_PATH'])
    result.PrependENVPath('PYTHONPATH', result['PYTHON_PATH'])
    result.PrependENVPath('PKG_CONFIG_PATH', result['PKG_CONFIG_PATH'])
    os.environ['PKG_CONFIG_PATH'] = result['PKG_CONFIG_PATH']
    return result
示例#6
0
文件: mixxx.py 项目: leo-combes/mixxx
    def __init__(self,
                 target,
                 machine,
                 build,
                 toolchain,
                 available_features=[]):
        self.available_features = available_features
        self.host_platform = self.detect_platform()
        self.host_machine = self.detect_machine()
        self.flags = {}

        if target is None:
            target = self.host_platform

        if machine is None:
            machine = self.host_machine

        if toolchain is None:
            if self.host_platform == 'windows':
                raise Exception(
                    'must specify toolchain on Windows (msvs or gnu)')
            else:
                toolchain = 'gnu'

        if build is None:
            build = 'debug'

        if not build in ['debug', 'release']:
            raise Exception("invalid build type")

        if target not in ['windows', 'osx', 'linux', 'bsd']:
            raise Exception("invalid target platform")

        if machine not in [
                'x86_64', 'x86', 'i686', 'i586', 'alpha', 'hppa', 'mips',
                'mipsel', 's390', 'sparc', 'ia64', 'armel', 'armhf',
                'hurd-i386', 'sh3', 'sh4', 'kfreebsd-amd64', 'kfreebsd-i386',
                'i486', 'i386', 'powerpc', 'powerpc64', 'powerpcspe', 's390x',
                'amd64', 'AMD64', 'EM64T', 'INTEL64'
        ]:
            raise Exception("invalid machine type")

        if toolchain not in ['gnu', 'msvs']:
            raise Exception('invalid toolchain type')

        if toolchain == 'msvs' and self.host_platform != 'windows':
            raise Exception(
                'cannot use msvs toolchain on non-windows platform')

        self.platform = target
        self.platform_is_posix = self.platform in ['linux', 'osx', 'bsd']
        self.platform_is_linux = self.platform == 'linux'
        self.platform_is_osx = self.platform == 'osx'
        self.platform_is_bsd = self.platform == 'bsd'
        self.platform_is_windows = self.platform == 'windows'

        self.machine = machine
        self.build = build
        self.build_is_debug = build == 'debug'
        self.build_is_release = build == 'release'

        self.toolchain = toolchain
        self.toolchain_is_gnu = self.toolchain == 'gnu'
        self.toolchain_is_msvs = self.toolchain == 'msvs'

        self.crosscompile = self.host_platform != self.platform

        flags_force32 = int(Script.ARGUMENTS.get('force32', 0))
        flags_force64 = int(Script.ARGUMENTS.get('force64', 0))
        if flags_force32 and flags_force64:
            logging.error('Both force32 and force64 cannot be enabled at once')
            Script.Exit(1)

        if flags_force32:
            if self.machine in ['powerpc', 'powerpc64']:
                self.machine = 'powerpc'
            else:
                self.machine = 'x86'
        elif flags_force64:
            if self.machine in ['powerpc', 'powerpc64']:
                self.machine = 'powerpc64'
            else:
                self.machine = 'x86_64'
        self.machine_is_64bit = self.machine in [
            'x86_64', 'powerpc64', 'AMD64', 'EM64T', 'INTEL64'
        ]
        self.bitwidth = 64 if self.machine_is_64bit else 32
        self.architecture_is_x86 = self.machine.lower() in [
            'x86', 'x86_64', 'i386', 'i486', 'i586', 'i686', 'EM64T', 'INTEL64'
        ]
        self.architecture_is_powerpc = self.machine.lower() in [
            'powerpc', 'powerpc64'
        ]

        self.build_dir = util.get_build_dir(self.platform, self.bitwidth)

        # Currently this only works for Windows
        self.static_dependencies = int(Script.ARGUMENTS.get('staticlibs', 0))
        self.msvcdebug = int(Script.ARGUMENTS.get('msvcdebug', 0))

        logging.info("Target Platform: %s" % self.platform)
        logging.info("Target Machine: %s" % self.machine)
        logging.info("Build: %s" % self.build)
        logging.info("Toolchain: %s" % self.toolchain)
        logging.info("Crosscompile: %s" %
                     ("YES" if self.crosscompile else "NO"))
        if self.platform_is_windows:
            logging.info("Static dependencies: %s" %
                         ("YES" if self.static_dependencies else "NO"))
            logging.info("MSVC Debug build: %s" %
                         ("YES" if self.msvcdebug else "NO"))

        if self.crosscompile:
            logging.info("Host Platform: %s" % self.host_platform)
            logging.info("Host Machine: %s" % self.host_machine)

        if self.crosscompile and self.host_platform != 'linux':
            raise Exception(
                'Cross-compiling on a non-Linux host not currently supported')

        tools = ['default']
        toolpath = ['#build/']
        extra_arguments = {}
        tools.append('qt4')
        tools.append('protoc')

        # Ugly hack to check the qtdir argument
        import depends
        default_qtdir = depends.Qt.DEFAULT_QTDIRS.get(self.platform, '')
        qtdir = Script.ARGUMENTS.get('qtdir',
                                     os.environ.get('QTDIR', default_qtdir))

        # Validate the specified qtdir exists
        if not os.path.exists(qtdir):
            logging.error("QT path does not exist or QT4 is not installed.")
            logging.error(
                "Please specify your QT path by running 'scons qtdir=[path]'")
            Script.Exit(1)
        # And that it doesn't contain qt3
        elif qtdir.find("qt3") != -1 or qtdir.find("qt/3") != -1:
            logging.error(
                "Mixxx now requires QT4 instead of QT3 - please use your QT4 path with the qtdir build flag."
            )
            Script.Exit(1)
        logging.info("Qt path: %s" % qtdir)

        # Previously this wasn't done for OSX, but I'm not sure why
        # -- rryan 6/8/2011
        extra_arguments['QTDIR'] = qtdir

        if self.platform == 'osx':
            tools.append('OSConsX')
            toolpath.append('#/build/osx/')
        if self.platform_is_windows and self.toolchain == 'msvs':
            toolpath.append('msvs')
            extra_arguments['VCINSTALLDIR'] = os.getenv(
                'VCInstallDir')  # TODO(XXX) Why?
            extra_arguments['QT_LIB'] = ''  # TODO(XXX) Why?

        # Setup the appropriate toolchains for cross-compiling
        if self.crosscompile:
            if self.platform_is_windows:
                tools.append('crossmingw')
            if self.platform == 'osx':
                tools.append('crossosx')

        self.env = Script.Environment(tools=tools,
                                      toolpath=toolpath,
                                      ENV=os.environ,
                                      **extra_arguments)
        self.read_environment_variables()
        self.virtualize_build_dir()

        if self.toolchain_is_gnu:
            if flags_force32:
                self.env.Append(CCFLAGS='-m32')
            elif flags_force64:
                self.env.Append(CCFLAGS='-m64')

        if self.platform == 'osx':
            if self.machine == 'powerpc':
                self.env.Append(CCFLAGS='-arch ppc')
                self.env.Append(LINKFLAGS='-arch ppc')
            else:
                if self.bitwidth == 32:
                    self.env.Append(CCFLAGS='-arch i386')
                    self.env.Append(LINKFLAGS='-arch i386')
                elif self.bitwidth == 64:
                    self.env.Append(CCFLAGS='-arch x86_64')
                    self.env.Append(LINKFLAGS='-arch x86_64')

        if self.crosscompile:
            crosscompile_root = Script.ARGUMENTS.get('crosscompile_root', '')

            if crosscompile_root == '':
                print "Your build setup indicates this is a cross-compile, but you did not specify 'crosscompile_root', which is required."
                Script.Exit(1)

            crosscompile_root = os.path.abspath(crosscompile_root)
            self.env.Append(CPPPATH=os.path.join(crosscompile_root, 'include'))
            self.env.Append(LIBPATH=os.path.join(crosscompile_root, 'lib'))
            self.env.Append(LIBPATH=os.path.join(crosscompile_root, 'bin'))

        self.install_options()