diff options
Diffstat (limited to 'modules/mono/config.py')
-rw-r--r-- | modules/mono/config.py | 88 |
1 files changed, 64 insertions, 24 deletions
diff --git a/modules/mono/config.py b/modules/mono/config.py index 9de199bb5a..44eef45f76 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -2,7 +2,6 @@ import imp import os import sys -from shutil import copyfile from SCons.Script import BoolVariable, Environment, Variables @@ -16,8 +15,7 @@ def find_file_in_dir(directory, files, prefix='', extension=''): for curfile in files: if os.path.isfile(os.path.join(directory, prefix + curfile + extension)): return curfile - - return None + return '' def can_build(platform): @@ -31,6 +29,22 @@ def is_enabled(): return False +def copy_file_no_replace(src_dir, dst_dir, name): + from shutil import copyfile + + src_path = os.path.join(src_dir, name) + dst_path = os.path.join(dst_dir, name) + need_copy = True + + if not os.path.isdir(dst_dir): + os.mkdir(dst_dir) + elif os.path.exists(dst_path): + need_copy = False + + if need_copy: + copyfile(src_path, dst_path) + + def configure(env): env.use_ptrcall = True @@ -38,6 +52,8 @@ def configure(env): envvars.Add(BoolVariable('mono_static', 'Statically link mono', False)) envvars.Update(env) + bits = env['bits'] + mono_static = env['mono_static'] mono_lib_names = ['mono-2.0-sgen', 'monosgen-2.0'] @@ -46,18 +62,18 @@ def configure(env): if mono_static: raise RuntimeError('mono-static: Not supported on Windows') - if env['bits'] == '32': + 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() + 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() + mono_root = monoreg.find_mono_root_dir(bits) - if mono_root is None: + if not mono_root: raise RuntimeError('Mono installation directory not found') mono_lib_path = os.path.join(mono_root, 'lib') @@ -67,7 +83,7 @@ def configure(env): mono_lib_name = find_file_in_dir(mono_lib_path, mono_lib_names, extension='.lib') - if mono_lib_name is None: + if not mono_lib_name: raise RuntimeError('Could not find mono library in: ' + mono_lib_path) if os.getenv('VCINSTALLDIR'): @@ -79,28 +95,23 @@ def configure(env): 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 mono_dll_name: + raise RuntimeError('Could not find mono shared library in: ' + mono_bin_path) - 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) + copy_file_no_replace(mono_bin_path, 'bin', mono_dll_name + '.dll') else: - mono_root = None + sharedlib_ext = '.dylib' if sys.platform == 'darwin' else '.so' + + mono_root = '' - if env['bits'] == '32': + 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 is not None: + if mono_root: mono_lib_path = os.path.join(mono_root, 'lib') env.Append(LIBPATH=mono_lib_path) @@ -108,7 +119,7 @@ def configure(env): mono_lib = find_file_in_dir(mono_lib_path, mono_lib_names, prefix='lib', extension='.a') - if mono_lib is None: + if not mono_lib: raise RuntimeError('Could not find mono library in: ' + mono_lib_path) env.Append(CPPFLAGS=['-D_REENTRANT']) @@ -125,12 +136,41 @@ def configure(env): else: env.Append(LIBS=[mono_lib]) - env.Append(LIBS=['m', 'rt', 'dl', 'pthread']) + 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_no_replace(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 mono-2 --cflags --libs') + env.ParseConfig('pkg-config monosgen-2 --cflags --libs') + + mono_lib_path = '' + mono_so_name = '' + + tmpenv = Environment() + 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_no_replace(mono_lib_path, 'bin', 'lib' + mono_so_name + sharedlib_ext) env.Append(LINKFLAGS='-rdynamic') |