Ejemplo n.º 1
0
def configure(env, env_mono):
    bits = env["bits"]
    is_android = env["platform"] == "android"
    is_javascript = env["platform"] == "javascript"
    is_ios = env["platform"] == "iphone"
    is_ios_sim = is_ios and env["arch"] in ["x86", "x86_64"]

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

    mono_prefix = env["mono_prefix"]
    mono_bcl = env["mono_bcl"]

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

    is_travis = os.environ.get("TRAVIS") == "true"

    if is_travis:
        # Travis CI may have a Mono version lower than 5.12
        env_mono.Append(CPPDEFINES=["NO_PENDING_EXCEPTIONS"])

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

    if tools_enabled and not module_supports_tools_on(env["platform"]):
        # TODO:
        # Android: 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 this platform with tools enabled")

    if is_android and mono_static:
        # FIXME: When static linking and doing something that requires libmono-native, we get a dlopen error as 'libmono-native'
        # seems to depend on 'libmonosgen-2.0'. Could be fixed by re-directing to '__Internal' with a dllmap or in the dlopen hook.
        raise RuntimeError("Statically linking Mono is not currently supported for this platform")

    if not mono_static and (is_javascript or is_ios):
        raise RuntimeError("Dynamically linking Mono is not currently supported for this platform")

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

    # Although we don't support building with tools for any platform where we currently use static AOT,
    # if these are supported in the future, we won't be using static AOT for them as that would be
    # too restrictive for the editor. These builds would probably be made to only use the interpreter.
    mono_aot_static = (is_ios and not is_ios_sim) and not env["tools"]

    # Static AOT is only supported on the root domain
    mono_single_appdomain = mono_aot_static

    if mono_single_appdomain:
        env_mono.Append(CPPDEFINES=["GD_MONO_SINGLE_APPDOMAIN"])

    if (env["tools"] or env["target"] != "release") and not mono_single_appdomain:
        env_mono.Append(CPPDEFINES=["GD_MONO_HOT_RELOAD"])

    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_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"))

        lib_suffixes = [".lib"]

        if not env.msvc:
            # MingW supports both '.a' and '.lib'
            lib_suffixes.insert(0, ".a")

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

            mono_static_lib_file = find_file_in_dir(mono_lib_path, [mono_static_lib_name], extensions=lib_suffixes)

            if not mono_static_lib_file:
                raise RuntimeError("Could not find static mono library in: " + mono_lib_path)

            if env.msvc:
                env.Append(LINKFLAGS=mono_static_lib_file)

                env.Append(LINKFLAGS="Mincore.lib")
                env.Append(LINKFLAGS="msvcrt.lib")
                env.Append(LINKFLAGS="LIBCMT.lib")
                env.Append(LINKFLAGS="Psapi.lib")
            else:
                mono_static_lib_file_path = os.path.join(mono_lib_path, mono_static_lib_file)
                env.Append(LINKFLAGS=["-Wl,-whole-archive", mono_static_lib_file_path, "-Wl,-no-whole-archive"])

                env.Append(LIBS=["psapi"])
                env.Append(LIBS=["version"])
        else:
            mono_lib_file = find_file_in_dir(mono_lib_path, mono_lib_names, extensions=lib_suffixes)

            if not mono_lib_file:
                raise RuntimeError("Could not find mono library in: " + mono_lib_path)

            if env.msvc:
                env.Append(LINKFLAGS=mono_lib_file)
            else:
                mono_lib_file_path = os.path.join(mono_lib_path, mono_lib_file)
                env.Append(LINKFLAGS=mono_lib_file_path)

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

            mono_dll_file = find_file_in_dir(mono_bin_path, mono_lib_names, prefixes=["", "lib"], extensions=[".dll"])

            if not mono_dll_file:
                raise RuntimeError("Could not find mono shared library in: " + mono_bin_path)

            copy_file(mono_bin_path, "#bin", mono_dll_file)
    else:
        is_apple = env["platform"] in ["osx", "iphone"]
        is_macos = is_apple and not is_ios

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

        mono_root = mono_prefix
        mono_lib_path = ""
        mono_so_file = ""

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

        if not mono_root and is_macos:
            # 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 is_ios and not is_ios_sim:
            env_mono.Append(CPPDEFINES=["IOS_DEVICE"])

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

            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_name_in_dir_files(mono_lib_path, mono_lib_names, prefixes=["lib"], extensions=[".a"])

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

            env_mono.Append(CPPDEFINES=["_REENTRANT"])

            if mono_static:
                if not is_javascript:
                    env.Append(LINKFLAGS=["-rdynamic"])

                mono_lib_file = os.path.join(mono_lib_path, "lib" + mono_lib + ".a")

                if is_apple:
                    if is_macos:
                        env.Append(LINKFLAGS=["-Wl,-force_load," + mono_lib_file])
                    else:
                        arch = env["arch"]

                        def copy_mono_lib(libname_wo_ext):
                            copy_file(
                                mono_lib_path, "#bin", libname_wo_ext + ".a", "%s.iphone.%s.a" % (libname_wo_ext, arch)
                            )

                        # Copy Mono libraries to the output folder. These are meant to be bundled with
                        # the export templates and added to the Xcode project when exporting a game.
                        copy_mono_lib("lib" + mono_lib)
                        copy_mono_lib("libmono-native")
                        copy_mono_lib("libmono-profiler-log")

                        if not is_ios_sim:
                            copy_mono_lib("libmono-ee-interp")
                            copy_mono_lib("libmono-icall-table")
                            copy_mono_lib("libmono-ilgen")
                else:
                    assert is_desktop(env["platform"]) or is_android or is_javascript
                    env.Append(LINKFLAGS=["-Wl,-whole-archive", mono_lib_file, "-Wl,-no-whole-archive"])

                if is_javascript:
                    env.Append(LIBS=["mono-icall-table", "mono-native", "mono-ilgen", "mono-ee-interp"])

                    wasm_src_dir = os.path.join(mono_root, "src")
                    if not os.path.isdir(wasm_src_dir):
                        raise RuntimeError("Could not find mono wasm src directory")

                    # Ideally this should be defined only for 'driver.c', but I can't fight scons for another 2 hours
                    env_mono.Append(CPPDEFINES=["CORE_BINDINGS"])

                    env_mono.add_source_files(
                        env.modules_sources,
                        [
                            os.path.join(wasm_src_dir, "driver.c"),
                            os.path.join(wasm_src_dir, "zlib-helper.c"),
                            os.path.join(wasm_src_dir, "corebindings.c"),
                        ],
                    )

                    env.Append(
                        LINKFLAGS=[
                            "--js-library",
                            os.path.join(wasm_src_dir, "library_mono.js"),
                            "--js-library",
                            os.path.join(wasm_src_dir, "binding_support.js"),
                            "--js-library",
                            os.path.join(wasm_src_dir, "dotnet_support.js"),
                        ]
                    )
            else:
                env.Append(LIBS=[mono_lib])

            if is_macos:
                env.Append(LIBS=["iconv", "pthread"])
            elif is_android:
                pass  # Nothing
            elif is_ios:
                pass  # Nothing, linking is delegated to the exported Xcode project
            elif is_javascript:
                env.Append(LIBS=["m", "rt", "dl", "pthread"])
            else:
                env.Append(LIBS=["m", "rt", "dl", "pthread"])

            if not mono_static:
                mono_so_file = find_file_in_dir(
                    mono_lib_path, mono_lib_names, prefixes=["lib"], extensions=[sharedlib_ext]
                )

                if not mono_so_file:
                    raise RuntimeError("Could not find mono shared library in: " + mono_lib_path)
        else:
            assert not mono_static

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

            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"]:
                file_found = find_file_in_dir(hint_dir, mono_lib_names, prefixes=["lib"], extensions=[sharedlib_ext])
                if file_found:
                    mono_lib_path = hint_dir
                    mono_so_file = file_found
                    break

            if not mono_so_file:
                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, mono_so_file)

    if not tools_enabled:
        if is_desktop(env["platform"]):
            if not mono_root:
                mono_root = (
                    subprocess.check_output(["pkg-config", "mono-2", "--variable=prefix"]).decode("utf8").strip()
                )

            make_template_dir(env, mono_root)
        elif is_android:
            # Compress Android Mono Config
            from . import make_android_mono_config

            module_dir = os.getcwd()
            config_file_path = os.path.join(module_dir, "build_scripts", "mono_android_config.xml")
            make_android_mono_config.generate_compressed_config(config_file_path, "mono_gd/")

            # Copy the required shared libraries
            copy_mono_shared_libs(env, mono_root, None)
        elif is_javascript:
            pass  # No data directory for this platform
        elif is_ios:
            pass  # No data directory for this platform

    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:
            # Only supported for editor builds.
            copy_mono_root_files(env, mono_root, mono_bcl)
Ejemplo n.º 2
0
def autobuild_shiparchive(src_file):
    """Create a ship file archive containing a yaml_file and its dependencies.

    If yaml_file depends on any build products as external files, it must
    be a jinja2 template that references the file using the find_product
    filter so that we can figure out where those build products are going
    and create the right dependency graph.

    Args:
        src_file (str): The path to the input yaml file template.  This
            file path must end .yaml.tpl and is rendered into a .yaml
            file and then packaged into a .ship file along with any
            products that are referenced in it.
    """

    if not src_file.endswith('.tpl'):
        raise BuildError("You must pass a .tpl file to autobuild_shiparchive",
                         src_file=src_file)

    env = Environment(tools=[])

    family = ArchitectureGroup('module_settings.json')
    target = family.platform_independent_target()
    resolver = ProductResolver.Create()

    #Parse through build_step products to see what needs to imported
    custom_steps = []
    for build_step in family.tile.find_products('build_step'):
        full_file_name = build_step.split(":")[0]
        basename = os.path.splitext(os.path.basename(full_file_name))[0]
        folder = os.path.dirname(full_file_name)

        fileobj, pathname, description = imp.find_module(basename, [folder])
        mod = imp.load_module(basename, fileobj, pathname, description)
        full_file_name, class_name = build_step.split(":")
        custom_steps.append((class_name, getattr(mod, class_name)))
    env['CUSTOM_STEPS'] = custom_steps

    env["RESOLVER"] = resolver

    base_name, tpl_name = _find_basename(src_file)
    yaml_name = tpl_name[:-4]
    ship_name = yaml_name[:-5] + ".ship"

    output_dir = target.build_dirs()['output']
    build_dir = os.path.join(target.build_dirs()['build'], base_name)
    tpl_path = os.path.join(build_dir, tpl_name)
    yaml_path = os.path.join(build_dir, yaml_name)
    ship_path = os.path.join(build_dir, ship_name)
    output_path = os.path.join(output_dir, ship_name)

    # We want to build up all related files in
    # <build_dir>/<ship archive_folder>/
    # - First copy the template yaml over
    # - Then render the template yaml
    # - Then find all products referenced in the template yaml and copy them
    # - over
    # - Then build a .ship archive
    # - Then copy that archive into output_dir

    ship_deps = [yaml_path]

    env.Command([tpl_path], [src_file], Copy("$TARGET", "$SOURCE"))

    prod_deps = _find_product_dependencies(src_file, resolver)

    env.Command([yaml_path], [tpl_path],
                action=Action(template_shipfile_action, "Rendering $TARGET"))

    for prod in prod_deps:
        dest_file = os.path.join(build_dir, prod.short_name)
        ship_deps.append(dest_file)
        env.Command([dest_file], [prod.full_path], Copy("$TARGET", "$SOURCE"))

    env.Command([ship_path], [ship_deps],
                action=Action(create_shipfile,
                              "Archiving Ship Recipe $TARGET"))
    env.Command([output_path], [ship_path], Copy("$TARGET", "$SOURCE"))
Ejemplo n.º 3
0
def configure(env, env_mono):
    envvars = Variables()
    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']

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

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

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

        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')

        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.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')
    else:
        is_apple = (sys.platform == 'darwin' or "osxcross" in env)

        sharedlib_ext = '.dylib' if is_apple 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 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'
                )

        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.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_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'])
            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')

            mono_lib_path = ''
            mono_so_name = ''

            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)

        env.Append(LINKFLAGS='-rdynamic')

    if not tools_enabled:
        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."
            )
Ejemplo n.º 4
0
def configure(env, env_mono):
    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']

    is_travis = os.environ.get('TRAVIS') == 'true'

    if is_travis:
        # Travis CI may have a Mono version lower than 5.12
        env_mono.Append(CPPDEFINES=['NO_PENDING_EXCEPTIONS'])

    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 is_android and mono_static:
        # When static linking and doing something that requires libmono-native, we get a dlopen error as libmono-native seems to depend on libmonosgen-2.0
        raise RuntimeError(
            'Linking Mono statically is not currently supported on Android')

    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_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_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(CPPDEFINES=['_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:
                pass  # Nothing
            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')

            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)
    elif not tools_enabled and is_android:
        # Compress Android Mono Config
        from . import make_android_mono_config
        config_file_path = os.path.join(mono_root, 'etc', 'mono', 'config')
        make_android_mono_config.generate_compressed_config(
            config_file_path, 'mono_gd/')

        # Copy the required shared libraries
        copy_mono_shared_libs(env, mono_root, None)

    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."
            )
Ejemplo n.º 5
0
        env.AppendUnique(CPPPATH=[env['SPATIALITEDIR'] + '/include'])
        env.AppendUnique(LIBPATH=[env['SPATIALITEDIR'] + '/lib'])

    # other tools we need
    env.Require(['qtcore', 'qtgui', 'sqlitedb'])
    env.AppendLibrary('spatialite')
    env.AppendLibrary('geos')
    env.AppendLibrary('geos_c')
    env.AppendLibrary('proj')
    if (env['PLATFORM'] != 'posix'):
        env.AppendLibrary('iconv')
    if (env['PLATFORM'] == 'win32'):
        env.AppendLibrary('freexl')


env = Environment(tools=['default', 'doxygen'])

options = env.GlobalVariables()
options.AddVariables(
    PathVariable('SPATIALITEDIR', 'SpatiaLite installation root.', None))

env.Require(build_spatialdb)

sources = env.Split("""
   SpatiaLiteDB.cpp
""")

headers = env.Split("""
   SpatiaLiteDB.h
""")
    def __init__(self, tools_path, **params):
        self.project_path = os.getcwd().replace('\\', '/')
        self.Decider('MD5-timestamp')
        self.deps_analyzer = dependency_analyzer.DependencyAnalyzer()
        project_db = projectdb.ProjectDB("--obj/project.pickle")

        project_db['paths'] = {
            'graphviz': '',
            'python': '',
            'inkscape': '',
            'tex': '',
            'gs': ''
        }
        if platform.system() != 'Linux':
            project_db['paths']['graphviz'] = os.path.join(
                tools_path, "graphviz", "bin")
            project_db['paths']['python'] = os.path.join(
                tools_path, "python27")
            project_db['paths']['inkscape'] = os.path.join(
                tools_path, "inkscape")
            project_db['paths']['tex'] = os.path.join(tools_path,
                                                      r"xetex\bin\win32")
            project_db['paths']['gs'] = os.path.join(tools_path,
                                                     r"xetex\tlpkg\tlgs\bin")
            os.environ['PATH'] = ';'.join([
                project_db['paths']['python'], project_db['paths']['tex'],
                project_db['paths']['gs'], os.environ['PATH']
            ])

        self.project_db = project_db
        Environment.__init__(self, **params)
        self['ENV']['PATH'] = os.environ['PATH']

        self.project_db["include_commands"] = [{
            'regexp':
            r'\n[^%]*?\\(include|input|localInclude){(?P<relfile>[^#}]+)}',
            'file': '%(relfile)s',
            'ext': '.tex'
        }, {
            'regexp': r'\n[^%]*?\\(verbatiminput){(?P<relfile>[^#}]+)}',
            'file': '%(relfile)s',
            'ext': ''
        }, {
            'regexp': r'\n[^%]*?\\(includeOnce){(?P<relfile>[^#}]+)}',
            'file': r'\projectpath/%(relfile)s',
            'ext': '.tex'
        }, {
            'regexp':
            r'(?s)\n[^%]*?\\(localPDF)(\[[^\[]*\])?{(?P<relfile>[^#}]+)}',
            'file': r'',
            'ext': '.pdf'
        }, {
            'regexp':
            r'\n[^%]*?\\(localSVG)(\[.*\])?{(?P<dir>[^#}]+)}{(?P<relfile>[^#}]+)}',
            'file': r'%(dir)s/--obj/%(relfile)s.svg.obj/obj.pdf',
            'ext': ''
        }, {
            'regexp':
            r'\n[^%]*?\\(projectSVG)(\[.*\])?{(?P<dir>[^#}]+)}{(?P<relfile>[^#}]+)}',
            'file': r'\projectpath/%(dir)s/--obj/%(relfile)s.svg.obj/obj.pdf',
            'ext': ''
        }]

        for item in self.project_db["include_commands"]:
            if "re" not in item:
                item["re"] = re.compile(item['regexp'])

        self.executors = {}

        self.meta_analyzer = mydepends.MetaAnalyzer(self)
        metascan = Scanner(function=self.meta_analyzer.meta_scan,
                           skeys=['.meta'],
                           recursive=0)

        self.Append(SCANNERS=metascan)

        depsscan = Scanner(function=self.meta_analyzer.deps_scan,
                           skeys=['.deps'],
                           recursive=0)

        self.Append(SCANNERS=depsscan)

        #texscan = Scanner(function = ds.tex_scan, skeys = ['.tex'], recursive = 0)
        #self.Append(SCANNERS = texscan )

        #svgscan = Scanner(function = ds.svg_scan, skeys = ['.svg'], recursive = 1)
        #self.Append(SCANNERS = svgscan )

        self.warnings = []
Ejemplo n.º 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',
                     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)
        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 = ''

            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_lib_path, 'mono', '4.5'),
                  assemblies_output_dir, 'mscorlib.dll')

        env.Append(LINKFLAGS='-rdynamic')
Ejemplo n.º 8
0
def configure(env):
    env.use_ptrcall = True

    envvars = Variables()
    envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
    envvars.Update(env)

    mono_static = env['mono_static']

    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 env['bits'] == '32':
            if os.getenv('MONO32_PREFIX'):
                mono_root = os.getenv('MONO32_PREFIX')
            elif os.name == 'nt':
                mono_root = monoreg.find_mono_root_dir()
        else:
            if os.getenv('MONO64_PREFIX'):
                mono_root = os.getenv('MONO64_PREFIX')
            elif os.name == 'nt':
                mono_root = monoreg.find_mono_root_dir()

        if mono_root is None:
            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 mono_lib_name is None:
            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')

        mono_dll_src = os.path.join(mono_bin_path, mono_dll_name + '.dll')
        mono_dll_dst = os.path.join('bin', mono_dll_name + '.dll')
        copy_mono_dll = True

        if not os.path.isdir('bin'):
            os.mkdir('bin')
        elif os.path.exists(mono_dll_dst):
            copy_mono_dll = False

        if copy_mono_dll:
            copyfile(mono_dll_src, mono_dll_dst)
    else:
        mono_root = None

        if env['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 is not None:
            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 mono_lib is None:
                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])

            env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])
        else:
            if mono_static:
                raise RuntimeError(
                    'mono-static: Not supported with pkg-config. Specify a mono prefix manually'
                )

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

        env.Append(LINKFLAGS='-rdynamic')
Ejemplo n.º 9
0
    def __init__(self):

        #----------------------------------------------------------------------
        # Setup default environment, checking command line options

        env = Environment(ENV=os.environ, LIBPATH=[], LIBS=[])

        env['NS_ON_CYGWIN'] = False
        env['NS_ON_LINUX'] = False
        env['NS_ON_MAC'] = False
        env['NS_ON_WINDOWS'] = False

        # Check options
        env['NS_BUILD_STATIC'] = GetOption("build_static")
        env['NS_COMPILER'] = GetOption("compiler")
        env['NS_CONFIG_DEBUG'] = GetOption("config_debug")
        env['NS_DEBUG_BUILD'] = GetOption("debug_build")
        env['NS_DISABLE_64'] = GetOption("disable_64")
        env['NS_DISABLE_CUDA'] = not GetOption("enable_cuda")
        env['NS_DISABLE_LIBAO'] = GetOption("disable_libao")
        env['NS_DISABLE_LIBPORTAUDIO'] = GetOption("disable_libportaudio")
        env['NS_DISABLE_OPENMP'] = GetOption("disable_openmp")
        env['NS_DISABLE_PYTHON'] = GetOption("disable_python")
        env['NS_EXTRA_WARNINGS'] = GetOption("extra_warnings")

        # There was a bug in either openMP or matplotlib that caused
        # segmentation faults when used together, last tried in 2010.
        if "setup_builder.py" in COMMAND_LINE_TARGETS:
            env['NS_DISABLE_OPENMP'] = True

        env['NS_HAVE_BOOST'] = False
        env['NS_HAVE_CPP11'] = False
        env['NS_HAVE_CUDA'] = False
        env['NS_HAVE_LIBAO'] = False
        env['NS_HAVE_LIBPORTAUDIO'] = False
        env['NS_HAVE_OPENMP'] = False
        env['NS_HAVE_PYLAB_C_API'] = False
        env['NS_HAVE_PYTHON_H'] = False

        env['NSOUND_PLATFORM_OS'] = 'Unknown'

        # Boost header
        boost_prefix = GetOption("boost_prefix")

        if boost_prefix:
            if os.path.isdir(boost_prefix):
                env.AppendUnique(CPPPATH=[boost_prefix])

        #----------------------------------------------------------------------
        # Setup installer prefixes

        prefix = GetOption("prefix")

        if prefix is None:
            prefix = os.path.dirname(os.path.realpath(__file__))

        env['NS_BINDIR'] = os.path.join(prefix, "bin")
        env['NS_LIBDIR'] = os.path.join(prefix, "lib")

        #----------------------------------------------------------------------
        # Add local tools

        env.Tool('ImportPythonConfig')
        env.Tool('AcGenerateFile')

        if env['NS_COMPILER']:
            env['NS_COMPILER'] = env['NS_COMPILER'].lower()

            compiler = env['NS_COMPILER']

            if compiler in ['gcc', 'g++']:
                env.Tool(compiler)

            elif compiler in ['mingw']:
                env.Tool(compiler)

            elif compiler in ['clang', 'clang++']:
                env.Tool('g++')
                env['CXX'] = 'clang++'

        #----------------------------------------------------------------------
        # Supress command output?

        if not GetOption('verbose'):
            env['ARCOMSTR'] = "Archiving $TARGET"
            env['CCCOMSTR'] = "Compiling $SOURCE"
            env['CXXCOMSTR'] = env['CCCOMSTR']
            env['LINKCOMSTR'] = "Linking   $TARGET"
            env['PYTHONSETUPCOMSTR'] = "Building Python Extension with $SOURCE"
            env['RANLIBCOMSTR'] = "Indexing  $TARGET"
            env['SHCCCOMSTR'] = env['CCCOMSTR']
            env['SHCXXCOMSTR'] = env['CCCOMSTR']
            env['SHLINKCOMSTR'] = env['LINKCOMSTR']
            env['LDMODULECOMSTR'] = env['LINKCOMSTR']
            env['SWIGGENCOMSTR'] = "Generating SWIG interface $TARGET"

        else:
            print("")
            print("CXXFLAGS = %s" % env['CXXFLAGS'])
            print("LINKFLAGS = %s" % env['LINKFLAGS'])
            print("LIBPATH = %s" % env['LIBPATH'])
            print("LIBS = %s" % env['LIBS'])
            print("LINKFLAGS = %s" % env['LINKFLAGS'])
            print("")

        self.env = env
        self._orig_env = env

        #----------------------------------------------------------------------
        # Platform specific customization

        self._customize_environment()

        #----------------------------------------------------------------------
        # Insert python config into environment
        if self.env['HAVE_PYTHON_CONFIG']:

            cpppath = self.env['PYTHON_CONFIG']['CPPPATH']
            libpath = self.env['PYTHON_CONFIG']['LIBPATH']
            libs = self.env['PYTHON_CONFIG']['LIBS']

            self.env.AppendUnique(CPPPATH=cpppath, LIBPATH=libpath, LIBS=libs)

            self.add_to_rpath(libpath)

        SConfBase.__init__(self, env)
Ejemplo n.º 10
0
# -*- coding: utf-8 -*-
from SCons.Script import Repository, Environment
# Mount code directories
Repository(['#./vendor/ceedling/vendor/unity/src'])

CCCOM = '$CC -c $_CCCOMCOM $SOURCE -o $TARGET '
CPPPATH = ['#./vendor/ceedling/vendor/unity/src', '#./include']
CPPFLAGS = ['-g', '-std=c99', '-pedantic', '-Wall', '-DTEST']
UNITYHELPDIR = '#./vendor/ceedling/vendor/unity/auto'

env_test = Environment()
env_test.Append(UNITYHELPDIR=UNITYHELPDIR, )

env_test.Replace(
    CCCOM=CCCOM,
    CPPPATH=CPPPATH,
    CPPFLAGS=CPPFLAGS,
)
Ejemplo n.º 11
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':
        mono_root = ''

        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')

        print('Found Mono root directory: ' + 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'))

        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')

        if not mono_root and sys.platform == 'darwin':
            # 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')

        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_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

            # 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_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')
Ejemplo n.º 12
0
def configure(env, env_mono):
    bits = env["bits"]
    is_android = env["platform"] == "android"
    is_javascript = env["platform"] == "javascript"

    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"]

    is_travis = os.environ.get("TRAVIS") == "true"

    if is_travis:
        # Travis CI may have a Mono version lower than 5.12
        env_mono.Append(CPPDEFINES=["NO_PENDING_EXCEPTIONS"])

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

    if tools_enabled and not module_supports_tools_on(env["platform"]):
        # TODO:
        # Android: 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 this platform with tools enabled"
        )

    if is_android and mono_static:
        # Android: When static linking and doing something that requires libmono-native, we get a dlopen error as libmono-native seems to depend on libmonosgen-2.0
        raise RuntimeError(
            "Statically linking Mono is not currently supported on this platform"
        )

    if is_javascript:
        mono_static = True

    if not mono_prefix and (os.getenv("MONO32_PREFIX")
                            or os.getenv("MONO64_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_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"))

        lib_suffix = Environment()["LIBSUFFIX"]

        if mono_static:
            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_suffix)

            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 + lib_suffix)
            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 = env["platform"] in ["osx", "iphone"]

        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 or is_javascript):
            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_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(CPPDEFINES=["_REENTRANT"])

            if mono_static:
                env.Append(LINKFLAGS=["-rdynamic"])

                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:
                    assert is_desktop(
                        env["platform"]) or is_android or is_javascript
                    env.Append(LINKFLAGS=[
                        "-Wl,-whole-archive", mono_lib_file,
                        "-Wl,-no-whole-archive"
                    ])

                if is_javascript:
                    env.Append(LIBS=[
                        "mono-icall-table", "mono-native", "mono-ilgen",
                        "mono-ee-interp"
                    ])

                    wasm_src_dir = os.path.join(mono_root, "src")
                    if not os.path.isdir(wasm_src_dir):
                        raise RuntimeError(
                            "Could not find mono wasm src directory")

                    # Ideally this should be defined only for 'driver.c', but I can't fight scons for another 2 hours
                    env_mono.Append(CPPDEFINES=["CORE_BINDINGS"])

                    env_mono.add_source_files(
                        env.modules_sources,
                        [
                            os.path.join(wasm_src_dir, "driver.c"),
                            os.path.join(wasm_src_dir, "zlib-helper.c"),
                            os.path.join(wasm_src_dir, "corebindings.c"),
                        ],
                    )

                    env.Append(LINKFLAGS=[
                        "--js-library",
                        os.path.join(wasm_src_dir, "library_mono.js"),
                        "--js-library",
                        os.path.join(wasm_src_dir, "binding_support.js"),
                        "--js-library",
                        os.path.join(wasm_src_dir, "dotnet_support.js"),
                    ])
            else:
                env.Append(LIBS=[mono_lib])

            if is_apple:
                env.Append(LIBS=["iconv", "pthread"])
            elif is_android:
                pass  # Nothing
            elif is_javascript:
                env.Append(LIBS=["m", "rt", "dl", "pthread"])
            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")

            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)

    if not tools_enabled:
        if is_desktop(env["platform"]):
            if not mono_root:
                mono_root = (subprocess.check_output(
                    ["pkg-config", "mono-2",
                     "--variable=prefix"]).decode("utf8").strip())

            make_template_dir(env, mono_root)
        elif is_android:
            # Compress Android Mono Config
            from . import make_android_mono_config

            module_dir = os.getcwd()
            config_file_path = os.path.join(module_dir, "build_scripts",
                                            "mono_android_config.xml")
            make_android_mono_config.generate_compressed_config(
                config_file_path, "mono_gd/")

            # Copy the required shared libraries
            copy_mono_shared_libs(env, mono_root, None)
        elif is_javascript:
            pass  # No data directory for this platform

    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."
            )
Ejemplo n.º 13
0
def configure(env, env_mono):
    bits = env['bits']
    is_android = env['platform'] == 'android'
    is_javascript = env['platform'] == 'javascript'
    is_ios = env['platform'] == 'iphone'
    is_ios_sim = is_ios and env['arch'] in ['x86', 'x86_64']

    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']

    is_travis = os.environ.get('TRAVIS') == 'true'

    if is_travis:
        # Travis CI may have a Mono version lower than 5.12
        env_mono.Append(CPPDEFINES=['NO_PENDING_EXCEPTIONS'])

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

    if tools_enabled and not module_supports_tools_on(env['platform']):
        # TODO:
        # Android: 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 this platform with tools enabled')

    if is_android and mono_static:
        # FIXME: When static linking and doing something that requires libmono-native, we get a dlopen error as 'libmono-native'
        # seems to depend on 'libmonosgen-2.0'. Could be fixed by re-directing to '__Internal' with a dllmap or in the dlopen hook.
        raise RuntimeError('Statically linking Mono is not currently supported for this platform')

    if not mono_static and (is_javascript or is_ios):
        raise RuntimeError('Dynamically linking Mono is not currently supported for this platform')

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

    # Although we don't support building with tools for any platform where we currently use static AOT,
    # if these are supported in the future, we won't be using static AOT for them as that would be
    # too restrictive for the editor. These builds would probably be made to only use the interpreter.
    mono_aot_static = (is_ios and not is_ios_sim) and not env['tools']

    # Static AOT is only supported on the root domain
    mono_single_appdomain = mono_aot_static

    if mono_single_appdomain:
        env_mono.Append(CPPDEFINES=['GD_MONO_SINGLE_APPDOMAIN'])

    if (env['tools'] or env['target'] != 'release') and not mono_single_appdomain:
        env_mono.Append(CPPDEFINES=['GD_MONO_HOT_RELOAD'])

    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_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'))

        lib_suffixes = ['.lib']

        if not env.msvc:
            # MingW supports both '.a' and '.lib'
            lib_suffixes.insert(0, '.a')

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

            mono_static_lib_file = find_file_in_dir(mono_lib_path, [mono_static_lib_name], extensions=lib_suffixes)

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

            if env.msvc:
                env.Append(LINKFLAGS=mono_static_lib_file)

                env.Append(LINKFLAGS='Mincore.lib')
                env.Append(LINKFLAGS='msvcrt.lib')
                env.Append(LINKFLAGS='LIBCMT.lib')
                env.Append(LINKFLAGS='Psapi.lib')
            else:
                mono_static_lib_file_path = os.path.join(mono_lib_path, mono_static_lib_file)
                env.Append(LINKFLAGS=['-Wl,-whole-archive', mono_static_lib_file_path, '-Wl,-no-whole-archive'])

                env.Append(LIBS=['psapi'])
                env.Append(LIBS=['version'])
        else:
            mono_lib_name = find_name_in_dir_files(mono_lib_path, mono_lib_names, prefixes=['', 'lib'], extensions=lib_suffixes)

            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 + '.lib')
            else:
                env.Append(LIBS=[mono_lib_name])

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

            mono_dll_file = find_file_in_dir(mono_bin_path, mono_lib_names, prefixes=['', 'lib'], extensions=['.dll'])

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

            copy_file(mono_bin_path, '#bin', mono_dll_file)
    else:
        is_apple = env['platform'] in ['osx', 'iphone']
        is_macos = is_apple and not is_ios

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

        mono_root = mono_prefix
        mono_lib_path = ''
        mono_so_file = ''

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

        if not mono_root and is_macos:
            # 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 is_ios and not is_ios_sim:
            env_mono.Append(CPPDEFINES=['IOS_DEVICE'])

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

            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_name_in_dir_files(mono_lib_path, mono_lib_names, prefixes=['lib'], extensions=['.a'])

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

            env_mono.Append(CPPDEFINES=['_REENTRANT'])

            if mono_static:
                env.Append(LINKFLAGS=['-rdynamic'])

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

                if is_apple:
                    if is_macos:
                        env.Append(LINKFLAGS=['-Wl,-force_load,' + mono_lib_file])
                    else:
                        arch = env['arch']
                        def copy_mono_lib(libname_wo_ext):
                            copy_file(mono_lib_path, '#bin', libname_wo_ext + '.a', '%s.iphone.%s.a' % (libname_wo_ext, arch))

                        # Copy Mono libraries to the output folder. These are meant to be bundled with
                        # the export templates and added to the Xcode project when exporting a game.
                        copy_mono_lib('lib' + mono_lib)
                        copy_mono_lib('libmono-native')
                        copy_mono_lib('libmono-profiler-log')

                        if not is_ios_sim:
                            copy_mono_lib('libmono-ee-interp')
                            copy_mono_lib('libmono-icall-table')
                            copy_mono_lib('libmono-ilgen')
                else:
                    assert is_desktop(env['platform']) or is_android or is_javascript
                    env.Append(LINKFLAGS=['-Wl,-whole-archive', mono_lib_file, '-Wl,-no-whole-archive'])

                if is_javascript:
                    env.Append(LIBS=['mono-icall-table', 'mono-native', 'mono-ilgen', 'mono-ee-interp'])

                    wasm_src_dir = os.path.join(mono_root, 'src')
                    if not os.path.isdir(wasm_src_dir):
                        raise RuntimeError('Could not find mono wasm src directory')

                    # Ideally this should be defined only for 'driver.c', but I can't fight scons for another 2 hours
                    env_mono.Append(CPPDEFINES=['CORE_BINDINGS'])

                    env_mono.add_source_files(env.modules_sources, [
                        os.path.join(wasm_src_dir, 'driver.c'),
                        os.path.join(wasm_src_dir, 'zlib-helper.c'),
                        os.path.join(wasm_src_dir, 'corebindings.c')
                    ])

                    env.Append(LINKFLAGS=[
                        '--js-library', os.path.join(wasm_src_dir, 'library_mono.js'),
                        '--js-library', os.path.join(wasm_src_dir, 'binding_support.js'),
                        '--js-library', os.path.join(wasm_src_dir, 'dotnet_support.js')
                    ])
            else:
                env.Append(LIBS=[mono_lib])

            if is_macos:
                env.Append(LIBS=['iconv', 'pthread'])
            elif is_android:
                pass # Nothing
            elif is_ios:
                pass # Nothing, linking is delegated to the exported Xcode project
            elif is_javascript:
                env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])
            else:
                env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])

            if not mono_static:
                mono_so_file = find_file_in_dir(mono_lib_path, mono_lib_names, prefixes=['lib'], extensions=[sharedlib_ext])

                if not mono_so_file:
                    raise RuntimeError('Could not find mono shared library in: ' + mono_lib_path)
        else:
            assert not mono_static

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

            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']:
                file_found = find_file_in_dir(hint_dir, mono_lib_names, prefixes=['lib'], extensions=[sharedlib_ext])
                if file_found:
                    mono_lib_path = hint_dir
                    mono_so_file = file_found
                    break

            if not mono_so_file:
                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, mono_so_file)

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

            make_template_dir(env, mono_root)
        elif is_android:
            # Compress Android Mono Config
            from . import make_android_mono_config
            module_dir = os.getcwd()
            config_file_path = os.path.join(module_dir, 'build_scripts', 'mono_android_config.xml')
            make_android_mono_config.generate_compressed_config(config_file_path, 'mono_gd/')

            # Copy the required shared libraries
            copy_mono_shared_libs(env, mono_root, None)
        elif is_javascript:
            pass # No data directory for this platform
        elif is_ios:
            pass # No data directory for this platform

    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.")