2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
import imp
|
|
|
|
import os
|
|
|
|
import sys
|
2018-02-27 16:54:16 +00:00
|
|
|
import subprocess
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-01-12 21:44:22 +00:00
|
|
|
from SCons.Script import BoolVariable, Dir, Environment, PathVariable, Variables
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
monoreg = imp.load_source('mono_reg_utils', 'modules/mono/mono_reg_utils.py')
|
|
|
|
|
|
|
|
|
|
|
|
def find_file_in_dir(directory, files, prefix='', extension=''):
|
|
|
|
if not extension.startswith('.'):
|
|
|
|
extension = '.' + extension
|
|
|
|
for curfile in files:
|
|
|
|
if os.path.isfile(os.path.join(directory, prefix + curfile + extension)):
|
|
|
|
return curfile
|
2017-10-24 20:47:27 +00:00
|
|
|
return ''
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def can_build(platform):
|
|
|
|
if platform in ["javascript"]:
|
|
|
|
return False # Not yet supported
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def is_enabled():
|
|
|
|
# The module is disabled by default. Use module_mono_enabled=yes to enable it.
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2018-01-12 21:44:22 +00:00
|
|
|
def copy_file(src_dir, dst_dir, name):
|
2017-10-24 20:47:27 +00:00
|
|
|
from shutil import copyfile
|
|
|
|
|
|
|
|
src_path = os.path.join(src_dir, name)
|
|
|
|
dst_path = os.path.join(dst_dir, name)
|
|
|
|
|
|
|
|
if not os.path.isdir(dst_dir):
|
|
|
|
os.mkdir(dst_dir)
|
|
|
|
|
2018-01-12 21:44:22 +00:00
|
|
|
copyfile(src_path, dst_path)
|
2017-10-24 20:47:27 +00:00
|
|
|
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
def configure(env):
|
|
|
|
env.use_ptrcall = True
|
2017-11-02 02:12:28 +00:00
|
|
|
env.add_module_version_string("mono")
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
envvars = Variables()
|
|
|
|
envvars.Add(BoolVariable('mono_static', 'Statically link mono', False))
|
2018-01-12 21:44:22 +00:00
|
|
|
envvars.Add(PathVariable('mono_assemblies_output_dir', 'Path to the assemblies output directory', '#bin', PathVariable.PathIsDirCreate))
|
2017-10-02 21:24:00 +00:00
|
|
|
envvars.Update(env)
|
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
bits = env['bits']
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
mono_static = env['mono_static']
|
2018-01-12 21:44:22 +00:00
|
|
|
assemblies_output_dir = Dir(env['mono_assemblies_output_dir']).abspath
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
mono_lib_names = ['mono-2.0-sgen', 'monosgen-2.0']
|
|
|
|
|
|
|
|
if env['platform'] == 'windows':
|
2017-10-24 20:47:27 +00:00
|
|
|
if bits == '32':
|
2017-10-02 21:24:00 +00:00
|
|
|
if os.getenv('MONO32_PREFIX'):
|
|
|
|
mono_root = os.getenv('MONO32_PREFIX')
|
|
|
|
elif os.name == 'nt':
|
2017-10-24 20:47:27 +00:00
|
|
|
mono_root = monoreg.find_mono_root_dir(bits)
|
2017-10-02 21:24:00 +00:00
|
|
|
else:
|
|
|
|
if os.getenv('MONO64_PREFIX'):
|
|
|
|
mono_root = os.getenv('MONO64_PREFIX')
|
|
|
|
elif os.name == 'nt':
|
2017-10-24 20:47:27 +00:00
|
|
|
mono_root = monoreg.find_mono_root_dir(bits)
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
if not mono_root:
|
2017-10-02 21:24:00 +00:00
|
|
|
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'))
|
|
|
|
|
2018-04-25 19:15:35 +00:00
|
|
|
if mono_static:
|
|
|
|
lib_suffix = Environment()['LIBSUFFIX']
|
2018-06-01 19:45:21 +00:00
|
|
|
|
|
|
|
if env.msvc:
|
|
|
|
mono_static_lib_name = 'libmono-static-sgen'
|
|
|
|
else:
|
|
|
|
mono_static_lib_name = 'libmonosgen-2.0'
|
2018-04-25 19:15:35 +00:00
|
|
|
|
|
|
|
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)
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-05-02 13:19:02 +00:00
|
|
|
if env.msvc:
|
2018-04-25 19:15:35 +00:00
|
|
|
env.Append(LINKFLAGS=mono_static_lib_name + lib_suffix)
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-04-25 19:15:35 +00:00
|
|
|
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:
|
2018-06-01 19:45:21 +00:00
|
|
|
env.Append(LINKFLAGS=os.path.join(mono_lib_path, mono_static_lib_name + lib_suffix))
|
|
|
|
|
|
|
|
env.Append(LIBS='psapi')
|
|
|
|
env.Append(LIBS='version')
|
2017-10-02 21:24:00 +00:00
|
|
|
else:
|
2018-04-25 19:15:35 +00:00
|
|
|
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)
|
|
|
|
|
2018-05-02 13:19:02 +00:00
|
|
|
if env.msvc:
|
2018-04-25 19:15:35 +00:00
|
|
|
env.Append(LINKFLAGS=mono_lib_name + Environment()['LIBSUFFIX'])
|
|
|
|
else:
|
|
|
|
env.Append(LIBS=mono_lib_name)
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-04-25 19:15:35 +00:00
|
|
|
mono_bin_path = os.path.join(mono_root, 'bin')
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-04-25 19:15:35 +00:00
|
|
|
mono_dll_name = find_file_in_dir(mono_bin_path, mono_lib_names, extension='.dll')
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-04-25 19:15:35 +00:00
|
|
|
if not mono_dll_name:
|
|
|
|
raise RuntimeError('Could not find mono shared library in: ' + mono_bin_path)
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-04-25 19:15:35 +00:00
|
|
|
copy_file(mono_bin_path, 'bin', mono_dll_name + '.dll')
|
2018-01-12 21:44:22 +00:00
|
|
|
|
|
|
|
copy_file(os.path.join(mono_lib_path, 'mono', '4.5'), assemblies_output_dir, 'mscorlib.dll')
|
2017-10-02 21:24:00 +00:00
|
|
|
else:
|
2017-10-24 20:47:27 +00:00
|
|
|
sharedlib_ext = '.dylib' if sys.platform == 'darwin' else '.so'
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
mono_root = ''
|
2018-01-12 21:44:22 +00:00
|
|
|
mono_lib_path = ''
|
2017-10-24 20:47:27 +00:00
|
|
|
|
|
|
|
if bits == '32':
|
2017-10-02 21:24:00 +00:00
|
|
|
if os.getenv('MONO32_PREFIX'):
|
|
|
|
mono_root = os.getenv('MONO32_PREFIX')
|
|
|
|
else:
|
|
|
|
if os.getenv('MONO64_PREFIX'):
|
|
|
|
mono_root = os.getenv('MONO64_PREFIX')
|
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
if mono_root:
|
2017-10-02 21:24:00 +00:00
|
|
|
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')
|
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
if not mono_lib:
|
2017-10-02 21:24:00 +00:00
|
|
|
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])
|
|
|
|
|
2017-10-20 16:40:41 +00:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
env.Append(LIBS=['iconv', 'pthread'])
|
|
|
|
elif sys.platform == "linux" or sys.platform == "linux2":
|
|
|
|
env.Append(LIBS=['m', 'rt', 'dl', 'pthread'])
|
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
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)
|
|
|
|
|
2018-01-12 21:44:22 +00:00
|
|
|
copy_file(mono_lib_path, 'bin', 'lib' + mono_so_name + sharedlib_ext)
|
2018-02-27 16:54:16 +00:00
|
|
|
|
|
|
|
copy_file(os.path.join(mono_lib_path, 'mono', '4.5'), assemblies_output_dir, 'mscorlib.dll')
|
2017-10-02 21:24:00 +00:00
|
|
|
else:
|
|
|
|
if mono_static:
|
|
|
|
raise RuntimeError('mono-static: Not supported with pkg-config. Specify a mono prefix manually')
|
|
|
|
|
2017-10-14 21:54:23 +00:00
|
|
|
env.ParseConfig('pkg-config monosgen-2 --cflags --libs')
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2017-10-24 20:47:27 +00:00
|
|
|
mono_lib_path = ''
|
|
|
|
mono_so_name = ''
|
2018-02-27 16:54:16 +00:00
|
|
|
mono_prefix = subprocess.check_output(["pkg-config", "mono-2", "--variable=prefix"]).strip()
|
2017-10-24 20:47:27 +00:00
|
|
|
|
|
|
|
tmpenv = Environment()
|
2018-02-02 18:17:53 +00:00
|
|
|
tmpenv.AppendENVPath('PKG_CONFIG_PATH', os.getenv('PKG_CONFIG_PATH'))
|
2017-10-24 20:47:27 +00:00
|
|
|
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']))
|
|
|
|
|
2018-01-12 21:44:22 +00:00
|
|
|
copy_file(mono_lib_path, 'bin', 'lib' + mono_so_name + sharedlib_ext)
|
2018-02-27 16:54:16 +00:00
|
|
|
copy_file(os.path.join(mono_prefix, 'lib', 'mono', '4.5'), assemblies_output_dir, 'mscorlib.dll')
|
2017-10-24 20:47:27 +00:00
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
env.Append(LINKFLAGS='-rdynamic')
|
|
|
|
|
|
|
|
|
|
|
|
def get_doc_classes():
|
2017-11-15 18:23:20 +00:00
|
|
|
return [
|
|
|
|
"@C#",
|
|
|
|
"CSharpScript",
|
|
|
|
"GodotSharp",
|
|
|
|
]
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_doc_path():
|
|
|
|
return "doc_classes"
|