Exemple #1
0
def configure(env):
    platform = env["platform"]

    if platform not in supported_platforms:
        raise RuntimeError(
            "This module does not currently support building for this platform"
        )

    env.add_module_version_string("mono")

    from SCons.Script import BoolVariable, PathVariable, Variables, Help

    default_mono_static = platform in ["iphone", "javascript"]
    default_mono_bundles_zlib = platform in ["javascript"]

    envvars = Variables()
    envvars.Add(
        PathVariable(
            "mono_prefix",
            "Path to the Mono installation directory for the target platform and architecture",
            "",
            PathVariable.PathAccept,
        ))
    envvars.Add(
        PathVariable(
            "mono_bcl",
            "Path to a custom Mono BCL (Base Class Library) directory for the target platform",
            "",
            PathVariable.PathAccept,
        ))
    envvars.Add(
        BoolVariable("mono_static", "Statically link Mono",
                     default_mono_static))
    envvars.Add(
        BoolVariable("mono_glue", "Build with the Mono glue sources", True))
    envvars.Add(BoolVariable("build_cil", "Build C# solutions", True))
    envvars.Add(
        BoolVariable(
            "copy_mono_root",
            "Make a copy of the Mono installation directory to bundle with the editor",
            True))

    # TODO: It would be great if this could be detected automatically instead
    envvars.Add(
        BoolVariable(
            "mono_bundles_zlib",
            "Specify if the Mono runtime was built with bundled zlib",
            default_mono_bundles_zlib))

    envvars.Update(env)
    Help(envvars.GenerateHelpText(env))

    if env["mono_bundles_zlib"]:
        # Mono may come with zlib bundled for WASM or on newer version when built with MinGW.
        print(
            "This Mono runtime comes with zlib bundled. Disabling 'builtin_zlib'..."
        )
        env["builtin_zlib"] = False
        thirdparty_zlib_dir = "#thirdparty/zlib/"
        env.Prepend(CPPPATH=[thirdparty_zlib_dir])
def configure(env):
    platform = env['platform']

    if platform not in supported_platforms:
        raise RuntimeError(
            'This module does not currently support building for this platform'
        )

    env.use_ptrcall = True
    env.add_module_version_string('mono')

    from SCons.Script import BoolVariable, PathVariable, Variables, Help

    default_mono_static = platform in ['iphone', 'javascript']
    default_mono_bundles_zlib = platform in ['javascript']

    envvars = Variables()
    envvars.Add(
        PathVariable(
            'mono_prefix',
            'Path to the mono installation directory for the target platform and architecture',
            '', PathVariable.PathAccept))
    envvars.Add(
        BoolVariable('mono_static', 'Statically link mono',
                     default_mono_static))
    envvars.Add(
        BoolVariable('mono_glue', 'Build with the mono glue sources', True))
    envvars.Add(
        BoolVariable(
            'copy_mono_root',
            'Make a copy of the mono installation directory to bundle with the editor',
            False))
    envvars.Add(
        BoolVariable('xbuild_fallback',
                     'If MSBuild is not found, fallback to xbuild', False))

    # TODO: It would be great if this could be detected automatically instead
    envvars.Add(
        BoolVariable(
            'mono_bundles_zlib',
            'Specify if the Mono runtime was built with bundled zlib',
            default_mono_bundles_zlib))

    envvars.Update(env)
    Help(envvars.GenerateHelpText(env))

    if env['mono_bundles_zlib']:
        # Mono may come with zlib bundled for WASM or on newer version when built with MinGW.
        print(
            'This Mono runtime comes with zlib bundled. Disabling \'builtin_zlib\'...'
        )
        env['builtin_zlib'] = False
        thirdparty_zlib_dir = "#thirdparty/zlib/"
        env.Prepend(CPPPATH=[thirdparty_zlib_dir])
Exemple #3
0
    def AddVariables(self):
        defvars = SVariables(self.def_env_file, args=ARGUMENTS)
        defvars.AddVariables(
            BoolVariable('verbose', 'Increase verbosity', 0),
            EnumVariable('debug_mode',
                         'debug output and symbols',
                         'no',
                         allowed_values=('no', 'libs', 'tests', 'all'),
                         map={},
                         ignorecase=0),  # case sensitive
            # test abi makes tests to call out for given library call
            EnumVariable('libabi',
                         'Test ABI for library function calling',
                         'aocl',
                         allowed_values=('aocl', 'glibc', 'libm', 'acml',
                                         'amdlibm'),
                         map={},
                         ignorecase=2),  # lowercase always
            EnumVariable('developer',
                         'A developer friendly mode',
                         0,
                         allowed_values=('0', '1', '2', '3', '4'),
                         map={
                             '0': 0,
                             '1': 1,
                             '2': 2,
                             '3': 3,
                             '4': 4
                         }),
            EnumVariable('build',
                         'Build type shortcut',
                         'release',
                         allowed_values=('release', 'developer', 'debug'),
                         ignorecase=2),
            EnumVariable('compiler',
                         "Select compiler type",
                         'gcc',
                         allowed_values=('gcc', 'aocc', 'llvm', 'icc'),
                         ignorecase=2),
            PathVariable('toolchain_base', "Use this as toolchain prefix",
                         '/usr/bin'))

        self.defvars = defvars
Exemple #4
0
def configure(env):
    if env["platform"] not in [
            "windows", "osx", "linuxbsd", "server", "android", "haiku",
            "javascript"
    ]:
        raise RuntimeError(
            "This module does not currently support building for this platform"
        )

    env.use_ptrcall = True
    env.add_module_version_string("mono")

    from SCons.Script import BoolVariable, PathVariable, Variables, Help

    envvars = Variables()
    envvars.Add(
        PathVariable(
            "mono_prefix",
            "Path to the mono installation directory for the target platform and architecture",
            "",
            PathVariable.PathAccept,
        ))
    envvars.Add(BoolVariable("mono_static", "Statically link mono", False))
    envvars.Add(
        BoolVariable("mono_glue", "Build with the mono glue sources", True))
    envvars.Add(
        BoolVariable(
            "copy_mono_root",
            "Make a copy of the mono installation directory to bundle with the editor",
            False))
    envvars.Add(
        BoolVariable("xbuild_fallback",
                     "If MSBuild is not found, fallback to xbuild", False))
    envvars.Update(env)
    Help(envvars.GenerateHelpText(env))

    if env["platform"] == "javascript":
        # Mono wasm already has zlib builtin, so we need this workaround to avoid symbol collisions
        print("Compiling with Mono wasm disables 'builtin_zlib'")
        env["builtin_zlib"] = False
        thirdparty_zlib_dir = "#thirdparty/zlib/"
        env.Prepend(CPPPATH=[thirdparty_zlib_dir])
Exemple #5
0
def configure(env):
    if env['platform'] not in [
            'windows', 'osx', 'linuxbsd', 'server', 'android', 'haiku',
            'javascript'
    ]:
        raise RuntimeError(
            'This module does not currently support building for this platform'
        )

    env.use_ptrcall = True
    env.add_module_version_string('mono')

    from SCons.Script import BoolVariable, PathVariable, Variables, Help

    envvars = Variables()
    envvars.Add(
        PathVariable(
            'mono_prefix',
            'Path to the mono installation directory for the target platform and architecture',
            '', PathVariable.PathAccept))
    envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
    envvars.Add(
        BoolVariable('mono_glue', 'Build with the mono glue sources', True))
    envvars.Add(
        BoolVariable(
            'copy_mono_root',
            'Make a copy of the mono installation directory to bundle with the editor',
            False))
    envvars.Add(
        BoolVariable('xbuild_fallback',
                     'If MSBuild is not found, fallback to xbuild', False))
    envvars.Update(env)
    Help(envvars.GenerateHelpText(env))

    if env['platform'] == 'javascript':
        # Mono wasm already has zlib builtin, so we need this workaround to avoid symbol collisions
        print('Compiling with Mono wasm disables \'builtin_zlib\'')
        env['builtin_zlib'] = False
        thirdparty_zlib_dir = "#thirdparty/zlib/"
        env.Prepend(CPPPATH=[thirdparty_zlib_dir])
Exemple #6
0
def configure(env):
    env.use_ptrcall = True
    env.add_module_version_string('mono')

    from SCons.Script import BoolVariable, PathVariable, Variables

    envvars = Variables()
    envvars.Add(
        PathVariable(
            'mono_prefix',
            'Path to the mono installation directory for the target platform and architecture',
            '', PathVariable.PathAccept))
    envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
    envvars.Add(
        BoolVariable('mono_glue', 'Build with the mono glue sources', True))
    envvars.Add(
        BoolVariable(
            'copy_mono_root',
            'Make a copy of the mono installation directory to bundle with the editor',
            False))
    envvars.Add(
        BoolVariable('xbuild_fallback',
                     'If MSBuild is not found, fallback to xbuild', False))
    envvars.Update(env)
Exemple #7
0
def configure(env):
    env.use_ptrcall = True
    env.add_module_version_string('mono')

    envvars = Variables()
    envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
    envvars.Add(
        PathVariable('mono_assemblies_output_dir',
                     'Path to the assemblies output directory', '#bin',
                     custom_path_is_dir_create))
    envvars.Update(env)

    bits = env['bits']

    mono_static = env['mono_static']
    assemblies_output_dir = Dir(env['mono_assemblies_output_dir']).abspath

    mono_lib_names = ['mono-2.0-sgen', 'monosgen-2.0']

    if env['platform'] == 'windows':
        if bits == '32':
            if os.getenv('MONO32_PREFIX'):
                mono_root = os.getenv('MONO32_PREFIX')
            elif os.name == 'nt':
                mono_root = monoreg.find_mono_root_dir(bits)
        else:
            if os.getenv('MONO64_PREFIX'):
                mono_root = os.getenv('MONO64_PREFIX')
            elif os.name == 'nt':
                mono_root = monoreg.find_mono_root_dir(bits)

        if not mono_root:
            raise RuntimeError('Mono installation directory not found')

        mono_version = mono_root_try_find_mono_version(mono_root)
        configure_for_mono_version(env, mono_version)

        mono_lib_path = os.path.join(mono_root, 'lib')

        env.Append(LIBPATH=mono_lib_path)
        env.Append(CPPPATH=os.path.join(mono_root, 'include', 'mono-2.0'))

        if mono_static:
            lib_suffix = Environment()['LIBSUFFIX']

            if env.msvc:
                mono_static_lib_name = 'libmono-static-sgen'
            else:
                mono_static_lib_name = 'libmonosgen-2.0'

            if not os.path.isfile(
                    os.path.join(mono_lib_path,
                                 mono_static_lib_name + lib_suffix)):
                raise RuntimeError('Could not find static mono library in: ' +
                                   mono_lib_path)

            if env.msvc:
                env.Append(LINKFLAGS=mono_static_lib_name + lib_suffix)

                env.Append(LINKFLAGS='Mincore' + lib_suffix)
                env.Append(LINKFLAGS='msvcrt' + lib_suffix)
                env.Append(LINKFLAGS='LIBCMT' + lib_suffix)
                env.Append(LINKFLAGS='Psapi' + lib_suffix)
            else:
                env.Append(LINKFLAGS=os.path.join(
                    mono_lib_path, mono_static_lib_name + lib_suffix))

                env.Append(LIBS='psapi')
                env.Append(LIBS='version')
        else:
            mono_lib_name = find_file_in_dir(mono_lib_path,
                                             mono_lib_names,
                                             extension='.lib')

            if not mono_lib_name:
                raise RuntimeError('Could not find mono library in: ' +
                                   mono_lib_path)

            if env.msvc:
                env.Append(LINKFLAGS=mono_lib_name +
                           Environment()['LIBSUFFIX'])
            else:
                env.Append(LIBS=mono_lib_name)

            mono_bin_path = os.path.join(mono_root, 'bin')

            mono_dll_name = find_file_in_dir(mono_bin_path,
                                             mono_lib_names,
                                             extension='.dll')

            if not mono_dll_name:
                raise RuntimeError('Could not find mono shared library in: ' +
                                   mono_bin_path)

            copy_file(mono_bin_path, 'bin', mono_dll_name + '.dll')

        copy_file(os.path.join(mono_lib_path, 'mono', '4.5'),
                  assemblies_output_dir, 'mscorlib.dll')
    else:
        sharedlib_ext = '.dylib' if sys.platform == 'darwin' else '.so'

        mono_root = ''
        mono_lib_path = ''

        if bits == '32':
            if os.getenv('MONO32_PREFIX'):
                mono_root = os.getenv('MONO32_PREFIX')
        else:
            if os.getenv('MONO64_PREFIX'):
                mono_root = os.getenv('MONO64_PREFIX')

        # We can't use pkg-config to link mono statically,
        # but we can still use it to find the mono root directory
        if not mono_root and mono_static:
            mono_root = pkgconfig_try_find_mono_root(mono_lib_names,
                                                     sharedlib_ext)
            if not mono_root:
                raise RuntimeError(
                    'Building with mono_static=yes, but failed to find the mono prefix with pkg-config. Specify one manually'
                )

        if mono_root:
            mono_version = mono_root_try_find_mono_version(mono_root)
            configure_for_mono_version(env, mono_version)

            mono_lib_path = os.path.join(mono_root, 'lib')

            env.Append(LIBPATH=mono_lib_path)
            env.Append(CPPPATH=os.path.join(mono_root, 'include', 'mono-2.0'))

            mono_lib = find_file_in_dir(mono_lib_path,
                                        mono_lib_names,
                                        prefix='lib',
                                        extension='.a')

            if not mono_lib:
                raise RuntimeError('Could not find mono library in: ' +
                                   mono_lib_path)

            env.Append(CPPFLAGS=['-D_REENTRANT'])

            if mono_static:
                mono_lib_file = os.path.join(mono_lib_path,
                                             'lib' + mono_lib + '.a')

                if sys.platform == 'darwin':
                    env.Append(LINKFLAGS=['-Wl,-force_load,' + mono_lib_file])
                elif sys.platform == 'linux' or sys.platform == 'linux2':
                    env.Append(LINKFLAGS=[
                        '-Wl,-whole-archive', mono_lib_file,
                        '-Wl,-no-whole-archive'
                    ])
                else:
                    raise RuntimeError(
                        'mono-static: Not supported on this platform')
            else:
                env.Append(LIBS=[mono_lib])

            if sys.platform == 'darwin':
                env.Append(LIBS=['iconv', 'pthread'])
            elif sys.platform == 'linux' or sys.platform == 'linux2':
                env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])

            if not mono_static:
                mono_so_name = find_file_in_dir(mono_lib_path,
                                                mono_lib_names,
                                                prefix='lib',
                                                extension=sharedlib_ext)

                if not mono_so_name:
                    raise RuntimeError(
                        'Could not find mono shared library in: ' +
                        mono_lib_path)

                copy_file(mono_lib_path, 'bin',
                          'lib' + mono_so_name + sharedlib_ext)

            copy_file(os.path.join(mono_lib_path, 'mono', '4.5'),
                      assemblies_output_dir, 'mscorlib.dll')
        else:
            assert not mono_static

            mono_version = pkgconfig_try_find_mono_version()
            configure_for_mono_version(env, mono_version)

            env.ParseConfig('pkg-config monosgen-2 --cflags --libs')

            mono_lib_path = ''
            mono_so_name = ''
            mono_prefix = subprocess.check_output(
                ['pkg-config', 'mono-2',
                 '--variable=prefix']).decode('utf8').strip()

            tmpenv = Environment()
            tmpenv.AppendENVPath('PKG_CONFIG_PATH',
                                 os.getenv('PKG_CONFIG_PATH'))
            tmpenv.ParseConfig('pkg-config monosgen-2 --libs-only-L')

            for hint_dir in tmpenv['LIBPATH']:
                name_found = find_file_in_dir(hint_dir,
                                              mono_lib_names,
                                              prefix='lib',
                                              extension=sharedlib_ext)
                if name_found:
                    mono_lib_path = hint_dir
                    mono_so_name = name_found
                    break

            if not mono_so_name:
                raise RuntimeError('Could not find mono shared library in: ' +
                                   str(tmpenv['LIBPATH']))

            copy_file(mono_lib_path, 'bin',
                      'lib' + mono_so_name + sharedlib_ext)
            copy_file(os.path.join(mono_prefix, 'lib', 'mono', '4.5'),
                      assemblies_output_dir, 'mscorlib.dll')

        env.Append(LINKFLAGS='-rdynamic')
Exemple #8
0
def getvars(config, secnames, indir=None, outdir=None,
            fmt_in='%(sec)s-infiles', fmt_out='%(sec)s-outfiles',
            fmt_params='%(sec)s-params'):
    """
    Return a tuple of configuration variables that may be passed to
    vars.AddVariables().

    * config - an instance of ConfigParser.SafeConfigParser()
    * secnames - a list of section names from which to import variables
    * indir - path to a directory to prepend to filenames if not found in cwd
    * outdir - path to a directory to prepend to output files.
    * fmt_* - formatting string defining sections corresponding to infiles,
      outfiles, and params for each section

    Example::

      vars = Variables()
      varlist = utils.getvars(config, ['ncbi','placefiles'],
                              indir=output, outdir=output)
      vars.AddVariables(*varlist)
    """

    vars = []

    # values from defaults section
    defaults = [k for k,v in config.items('DEFAULT')]
    for varname, val in config.items('DEFAULT'):
        if os.path.isdir(val):
            vars.append(PathVariable(
                varname, '%s (DEFAULT)' % varname, val, PathVariable.PathIsDir))
        if os.path.isfile(val):
            vars.append(
                PathVariable(varname, '%s (DEFAULT)' % varname, val,
                             PathVariable.PathIsFile))
        else:
            vars.append((varname, val, val))

    for sec in secnames:
        # input files and directories
        for varname,pth in config.items(fmt_in % locals()):
            if varname in defaults:
                continue
            elif os.path.exists(pth):
                pth = os.path.abspath(pth)
            elif indir:
                pth = join(indir, pth)
            else:
                raise OSError(
                    'Error in [%(sec)s] %(varname)s = %(pth)s: specify either an existing path or provide a default input directory using `indir`' % \
                        locals())

            vars.append(PathVariable(varname, '', pth))

        # output files and directories
        for varname,pth in config.items(fmt_out % locals()):
            if varname in defaults:
                continue
            elif outdir and not (pth.startswith(outdir) or pth.startswith('.')):
                pth = join(outdir, pth)
            else:
                pth = os.path.abspath(pth)

            # TODO: document this behavior (assume var is a directory if ends with 'dir')
            if varname.endswith('dir') or os.path.isdir(pth):
                pvar = PathVariable.PathIsDirCreate
            else:
                pvar = PathVariable.PathAccept

            vars.append(PathVariable(varname, '', pth, pvar))

        # ordinary variables; no path checking or directory creation
        params = fmt_params % locals()
        for varname, val in config.items(params):
            if varname in defaults:
                continue
            vars.append(
                (varname, '%(varname)s: defined in [%(params)s]' % locals(), val))

    return tuple(vars)
Exemple #9
0
def configure(env):
    env.use_ptrcall = True
    env.add_module_version_string("mono")

    envvars = Variables()
    envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
    envvars.Add(
        PathVariable('mono_assemblies_output_dir',
                     'Path to the assemblies output directory', '#bin',
                     PathVariable.PathIsDirCreate))
    envvars.Update(env)

    bits = env['bits']

    mono_static = env['mono_static']
    assemblies_output_dir = Dir(env['mono_assemblies_output_dir']).abspath

    mono_lib_names = ['mono-2.0-sgen', 'monosgen-2.0']

    if env['platform'] == 'windows':
        if mono_static:
            raise RuntimeError('mono-static: Not supported on Windows')

        if bits == '32':
            if os.getenv('MONO32_PREFIX'):
                mono_root = os.getenv('MONO32_PREFIX')
            elif os.name == 'nt':
                mono_root = monoreg.find_mono_root_dir(bits)
        else:
            if os.getenv('MONO64_PREFIX'):
                mono_root = os.getenv('MONO64_PREFIX')
            elif os.name == 'nt':
                mono_root = monoreg.find_mono_root_dir(bits)

        if not mono_root:
            raise RuntimeError('Mono installation directory not found')

        mono_lib_path = os.path.join(mono_root, 'lib')

        env.Append(LIBPATH=mono_lib_path)
        env.Append(CPPPATH=os.path.join(mono_root, 'include', 'mono-2.0'))

        mono_lib_name = find_file_in_dir(mono_lib_path,
                                         mono_lib_names,
                                         extension='.lib')

        if not mono_lib_name:
            raise RuntimeError('Could not find mono library in: ' +
                               mono_lib_path)

        if os.getenv('VCINSTALLDIR'):
            env.Append(LINKFLAGS=mono_lib_name + Environment()['LIBSUFFIX'])
        else:
            env.Append(LIBS=mono_lib_name)

        mono_bin_path = os.path.join(mono_root, 'bin')

        mono_dll_name = find_file_in_dir(mono_bin_path,
                                         mono_lib_names,
                                         extension='.dll')

        if not mono_dll_name:
            raise RuntimeError('Could not find mono shared library in: ' +
                               mono_bin_path)

        copy_file(mono_bin_path, 'bin', mono_dll_name + '.dll')

        copy_file(os.path.join(mono_lib_path, 'mono', '4.5'),
                  assemblies_output_dir, 'mscorlib.dll')
    else:
        sharedlib_ext = '.dylib' if sys.platform == 'darwin' else '.so'

        mono_root = ''
        mono_lib_path = ''

        if bits == '32':
            if os.getenv('MONO32_PREFIX'):
                mono_root = os.getenv('MONO32_PREFIX')
        else:
            if os.getenv('MONO64_PREFIX'):
                mono_root = os.getenv('MONO64_PREFIX')

        if mono_root:
            mono_lib_path = os.path.join(mono_root, 'lib')

            env.Append(LIBPATH=mono_lib_path)
            env.Append(CPPPATH=os.path.join(mono_root, 'include', 'mono-2.0'))

            mono_lib = find_file_in_dir(mono_lib_path,
                                        mono_lib_names,
                                        prefix='lib',
                                        extension='.a')

            if not mono_lib:
                raise RuntimeError('Could not find mono library in: ' +
                                   mono_lib_path)

            env.Append(CPPFLAGS=['-D_REENTRANT'])

            if mono_static:
                mono_lib_file = os.path.join(mono_lib_path,
                                             'lib' + mono_lib + '.a')

                if sys.platform == "darwin":
                    env.Append(LINKFLAGS=['-Wl,-force_load,' + mono_lib_file])
                elif sys.platform == "linux" or sys.platform == "linux2":
                    env.Append(LINKFLAGS=[
                        '-Wl,-whole-archive', mono_lib_file,
                        '-Wl,-no-whole-archive'
                    ])
                else:
                    raise RuntimeError(
                        'mono-static: Not supported on this platform')
            else:
                env.Append(LIBS=[mono_lib])

            if sys.platform == "darwin":
                env.Append(LIBS=['iconv', 'pthread'])
            elif sys.platform == "linux" or sys.platform == "linux2":
                env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])

            if not mono_static:
                mono_so_name = find_file_in_dir(mono_lib_path,
                                                mono_lib_names,
                                                prefix='lib',
                                                extension=sharedlib_ext)

                if not mono_so_name:
                    raise RuntimeError(
                        'Could not find mono shared library in: ' +
                        mono_lib_path)

                copy_file(mono_lib_path, 'bin',
                          'lib' + mono_so_name + sharedlib_ext)

            copy_file(os.path.join(mono_lib_path, 'mono', '4.5'),
                      assemblies_output_dir, 'mscorlib.dll')
        else:
            if mono_static:
                raise RuntimeError(
                    'mono-static: Not supported with pkg-config. Specify a mono prefix manually'
                )

            env.ParseConfig('pkg-config monosgen-2 --cflags --libs')

            mono_lib_path = ''
            mono_so_name = ''
            mono_prefix = subprocess.check_output(
                ["pkg-config", "mono-2",
                 "--variable=prefix"]).decode("utf8").strip()

            tmpenv = Environment()
            tmpenv.AppendENVPath('PKG_CONFIG_PATH',
                                 os.getenv('PKG_CONFIG_PATH'))
            tmpenv.ParseConfig('pkg-config monosgen-2 --libs-only-L')

            for hint_dir in tmpenv['LIBPATH']:
                name_found = find_file_in_dir(hint_dir,
                                              mono_lib_names,
                                              prefix='lib',
                                              extension=sharedlib_ext)
                if name_found:
                    mono_lib_path = hint_dir
                    mono_so_name = name_found
                    break

            if not mono_so_name:
                raise RuntimeError('Could not find mono shared library in: ' +
                                   str(tmpenv['LIBPATH']))

            copy_file(mono_lib_path, 'bin',
                      'lib' + mono_so_name + sharedlib_ext)
            copy_file(os.path.join(mono_prefix, 'lib', 'mono', '4.5'),
                      assemblies_output_dir, 'mscorlib.dll')

        env.Append(LINKFLAGS='-rdynamic')
Exemple #10
0
def configure(env, env_mono):
    from SCons.Script import BoolVariable, PathVariable, Variables

    envvars = Variables()
    envvars.Add(
        PathVariable(
            'mono_prefix',
            'Path to the mono installation directory for the target platform and architecture',
            '', PathVariable.PathAccept))
    envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
    envvars.Add(
        BoolVariable(
            'copy_mono_root',
            'Make a copy of the mono installation directory to bundle with the editor',
            False))
    envvars.Update(env)

    bits = env['bits']
    is_android = env['platform'] == 'android'

    tools_enabled = env['tools']
    mono_static = env['mono_static']
    copy_mono_root = env['copy_mono_root']

    mono_prefix = env['mono_prefix']

    mono_lib_names = ['mono-2.0-sgen', 'monosgen-2.0']

    if is_android and not env['android_arch'] in android_arch_dirs:
        raise RuntimeError(
            'This module does not support for the specified \'android_arch\': '
            + env['android_arch'])

    if is_android and tools_enabled:
        # TODO: Implement this. We have to add the data directory to the apk, concretely the Api and Tools folders.
        raise RuntimeError(
            'This module does not currently support building for android with tools enabled'
        )

    if (os.getenv('MONO32_PREFIX')
            or os.getenv('MONO64_PREFIX')) and not mono_prefix:
        print(
            "WARNING: The environment variables 'MONO32_PREFIX' and 'MONO64_PREFIX' are deprecated; use the 'mono_prefix' SCons parameter instead"
        )

    if env['platform'] == 'windows':
        mono_root = mono_prefix

        if not mono_root and os.name == 'nt':
            mono_root = monoreg.find_mono_root_dir(bits)

        if not mono_root:
            raise RuntimeError(
                "Mono installation directory not found; specify one manually with the 'mono_prefix' SCons parameter"
            )

        print('Found Mono root directory: ' + mono_root)

        mono_version = mono_root_try_find_mono_version(mono_root)
        configure_for_mono_version(env_mono, mono_version)

        mono_lib_path = os.path.join(mono_root, 'lib')

        env.Append(LIBPATH=mono_lib_path)
        env_mono.Prepend(
            CPPPATH=os.path.join(mono_root, 'include', 'mono-2.0'))

        if mono_static:
            lib_suffix = Environment()['LIBSUFFIX']

            if env.msvc:
                mono_static_lib_name = 'libmono-static-sgen'
            else:
                mono_static_lib_name = 'libmonosgen-2.0'

            if not os.path.isfile(
                    os.path.join(mono_lib_path,
                                 mono_static_lib_name + lib_suffix)):
                raise RuntimeError('Could not find static mono library in: ' +
                                   mono_lib_path)

            if env.msvc:
                env.Append(LINKFLAGS=mono_static_lib_name + lib_suffix)

                env.Append(LINKFLAGS='Mincore' + lib_suffix)
                env.Append(LINKFLAGS='msvcrt' + lib_suffix)
                env.Append(LINKFLAGS='LIBCMT' + lib_suffix)
                env.Append(LINKFLAGS='Psapi' + lib_suffix)
            else:
                env.Append(LINKFLAGS=os.path.join(
                    mono_lib_path, mono_static_lib_name + lib_suffix))

                env.Append(LIBS='psapi')
                env.Append(LIBS='version')
        else:
            mono_lib_name = find_file_in_dir(mono_lib_path,
                                             mono_lib_names,
                                             extension='.lib')

            if not mono_lib_name:
                raise RuntimeError('Could not find mono library in: ' +
                                   mono_lib_path)

            if env.msvc:
                env.Append(LINKFLAGS=mono_lib_name +
                           Environment()['LIBSUFFIX'])
            else:
                env.Append(LIBS=mono_lib_name)

            mono_bin_path = os.path.join(mono_root, 'bin')

            mono_dll_name = find_file_in_dir(mono_bin_path,
                                             mono_lib_names,
                                             extension='.dll')

            if not mono_dll_name:
                raise RuntimeError('Could not find mono shared library in: ' +
                                   mono_bin_path)

            copy_file(mono_bin_path, '#bin', mono_dll_name + '.dll')
    else:
        is_apple = (sys.platform == 'darwin' or "osxcross" in env)

        sharedlib_ext = '.dylib' if is_apple else '.so'

        mono_root = mono_prefix
        mono_lib_path = ''
        mono_so_name = ''

        if not mono_root and is_android:
            raise RuntimeError(
                "Mono installation directory not found; specify one manually with the 'mono_prefix' SCons parameter"
            )

        if not mono_root and is_apple:
            # Try with some known directories under OSX
            hint_dirs = [
                '/Library/Frameworks/Mono.framework/Versions/Current',
                '/usr/local/var/homebrew/linked/mono'
            ]
            for hint_dir in hint_dirs:
                if os.path.isdir(hint_dir):
                    mono_root = hint_dir
                    break

        # We can't use pkg-config to link mono statically,
        # but we can still use it to find the mono root directory
        if not mono_root and mono_static:
            mono_root = pkgconfig_try_find_mono_root(mono_lib_names,
                                                     sharedlib_ext)
            if not mono_root:
                raise RuntimeError("Building with mono_static=yes, but failed to find the mono prefix with pkg-config; " + \
                    "specify one manually with the 'mono_prefix' SCons parameter")

        if mono_root:
            print('Found Mono root directory: ' + mono_root)

            mono_version = mono_root_try_find_mono_version(mono_root)
            configure_for_mono_version(env_mono, mono_version)

            mono_lib_path = os.path.join(mono_root, 'lib')

            env.Append(LIBPATH=mono_lib_path)
            env_mono.Prepend(
                CPPPATH=os.path.join(mono_root, 'include', 'mono-2.0'))

            mono_lib = find_file_in_dir(mono_lib_path,
                                        mono_lib_names,
                                        prefix='lib',
                                        extension='.a')

            if not mono_lib:
                raise RuntimeError('Could not find mono library in: ' +
                                   mono_lib_path)

            env_mono.Append(CPPFLAGS=['-D_REENTRANT'])

            if mono_static:
                mono_lib_file = os.path.join(mono_lib_path,
                                             'lib' + mono_lib + '.a')

                if is_apple:
                    env.Append(LINKFLAGS=['-Wl,-force_load,' + mono_lib_file])
                else:
                    env.Append(LINKFLAGS=[
                        '-Wl,-whole-archive', mono_lib_file,
                        '-Wl,-no-whole-archive'
                    ])
            else:
                env.Append(LIBS=[mono_lib])

            if is_apple:
                env.Append(LIBS=['iconv', 'pthread'])
            elif is_android:
                env.Append(LIBS=['m', 'dl'])
            else:
                env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])

            if not mono_static:
                mono_so_name = find_file_in_dir(mono_lib_path,
                                                mono_lib_names,
                                                prefix='lib',
                                                extension=sharedlib_ext)

                if not mono_so_name:
                    raise RuntimeError(
                        'Could not find mono shared library in: ' +
                        mono_lib_path)

                copy_file(mono_lib_path, '#bin',
                          'lib' + mono_so_name + sharedlib_ext)
        else:
            assert not mono_static

            # TODO: Add option to force using pkg-config
            print('Mono root directory not found. Using pkg-config instead')

            mono_version = pkgconfig_try_find_mono_version()
            configure_for_mono_version(env_mono, mono_version)

            env.ParseConfig('pkg-config monosgen-2 --libs')
            env_mono.ParseConfig('pkg-config monosgen-2 --cflags')

            tmpenv = Environment()
            tmpenv.AppendENVPath('PKG_CONFIG_PATH',
                                 os.getenv('PKG_CONFIG_PATH'))
            tmpenv.ParseConfig('pkg-config monosgen-2 --libs-only-L')

            for hint_dir in tmpenv['LIBPATH']:
                name_found = find_file_in_dir(hint_dir,
                                              mono_lib_names,
                                              prefix='lib',
                                              extension=sharedlib_ext)
                if name_found:
                    mono_lib_path = hint_dir
                    mono_so_name = name_found
                    break

            if not mono_so_name:
                raise RuntimeError('Could not find mono shared library in: ' +
                                   str(tmpenv['LIBPATH']))

        if not mono_static:
            libs_output_dir = get_android_out_dir(
                env) if is_android else '#bin'
            copy_file(mono_lib_path, libs_output_dir,
                      'lib' + mono_so_name + sharedlib_ext)

        env.Append(LINKFLAGS='-rdynamic')

    if not tools_enabled and not is_android:
        if not mono_root:
            mono_root = subprocess.check_output(
                ['pkg-config', 'mono-2',
                 '--variable=prefix']).decode('utf8').strip()

        make_template_dir(env, mono_root)

    if copy_mono_root:
        if not mono_root:
            mono_root = subprocess.check_output(
                ['pkg-config', 'mono-2',
                 '--variable=prefix']).decode('utf8').strip()

        if tools_enabled:
            copy_mono_root_files(env, mono_root)
        else:
            print(
                "Ignoring option: 'copy_mono_root'. Only available for builds with 'tools' enabled."
            )