2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from os.path import join as path_join
|
|
|
|
|
|
|
|
from options import *
|
|
|
|
from os_utils import *
|
|
|
|
import runtime
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
|
2019-11-10 04:58:04 +01:00
|
|
|
# TODO: mono cross-compilers
|
|
|
|
|
|
|
|
targets = {
|
|
|
|
'linux': ['i686', 'x86_64'],
|
|
|
|
'windows': ['i686', 'x86_64'],
|
|
|
|
'osx': ['x86_64']
|
|
|
|
}
|
|
|
|
|
|
|
|
host_triples = {
|
|
|
|
'linux': '%s-linux-gnu',
|
|
|
|
'windows': '%s-w64-mingw32',
|
|
|
|
'osx': '%s-apple-darwin',
|
|
|
|
}
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
llvm_table = {
|
|
|
|
'linux': {
|
|
|
|
'i686': 'llvm32',
|
|
|
|
'x86_64': 'llvm64'
|
|
|
|
},
|
|
|
|
'windows': {
|
|
|
|
'i686': 'llvm32',
|
|
|
|
'x86_64': 'llvm64'
|
|
|
|
},
|
|
|
|
'osx': {
|
|
|
|
'x86_64': 'llvm64'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
def is_cross_compiling(target_platform: str) -> bool:
|
|
|
|
return (sys.platform == 'darwin' and target_platform != 'osx') or \
|
|
|
|
(sys.platform in ['linux', 'linux2', 'cygwin'] and target_platform != 'linux')
|
|
|
|
|
|
|
|
|
2020-03-11 01:23:59 +01:00
|
|
|
def get_osxcross_sdk(osxcross_bin, arch):
|
|
|
|
osxcross_sdk = os.environ.get('OSXCROSS_SDK', 18)
|
2019-11-13 21:09:19 +01:00
|
|
|
|
2020-03-11 01:23:59 +01:00
|
|
|
name_fmt = path_join(osxcross_bin, arch + '-apple-darwin%s-%s')
|
2019-11-13 21:09:19 +01:00
|
|
|
|
|
|
|
if not os.path.isfile(name_fmt % (osxcross_sdk, 'ar')):
|
|
|
|
raise BuildError('Specify a valid osxcross SDK with the environment variable \'OSXCROSS_SDK\'')
|
|
|
|
|
|
|
|
return osxcross_sdk
|
|
|
|
|
|
|
|
|
|
|
|
def setup_desktop_template(env: dict, opts: DesktopOpts, product: str, target_platform: str, target: str):
|
2019-11-10 04:58:04 +01:00
|
|
|
host_triple = host_triples[target_platform] % target
|
|
|
|
|
|
|
|
CONFIGURE_FLAGS = [
|
|
|
|
'--disable-boehm',
|
|
|
|
'--disable-mcs-build',
|
|
|
|
'--enable-maintainer-mode',
|
|
|
|
'--with-tls=pthread',
|
|
|
|
'--without-ikvm-native'
|
|
|
|
]
|
|
|
|
|
2020-03-11 01:23:59 +01:00
|
|
|
if target_platform == 'windows':
|
|
|
|
CONFIGURE_FLAGS += [
|
|
|
|
'--with-libgdiplus=%s' % opts.mxe_prefix
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
CONFIGURE_FLAGS += [
|
|
|
|
'--disable-iconv',
|
|
|
|
'--disable-nls',
|
|
|
|
'--enable-dynamic-btls',
|
|
|
|
'--with-sigaltstack=yes',
|
|
|
|
]
|
|
|
|
|
2019-11-10 04:58:04 +01:00
|
|
|
if target_platform == 'windows':
|
|
|
|
mxe_bin = path_join(opts.mxe_prefix, 'bin')
|
|
|
|
|
|
|
|
env['_%s-%s_PATH' % (product, target)] = mxe_bin
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
name_fmt = path_join(mxe_bin, target + '-w64-mingw32-%s')
|
2019-11-10 04:58:04 +01:00
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
env['_%s-%s_AR' % (product, target)] = name_fmt % 'ar'
|
|
|
|
env['_%s-%s_AS' % (product, target)] = name_fmt % 'as'
|
|
|
|
env['_%s-%s_CC' % (product, target)] = name_fmt % 'gcc'
|
|
|
|
env['_%s-%s_CXX' % (product, target)] = name_fmt % 'g++'
|
|
|
|
env['_%s-%s_DLLTOOL' % (product, target)] = name_fmt % 'dlltool'
|
|
|
|
env['_%s-%s_LD' % (product, target)] = name_fmt % 'ld'
|
|
|
|
env['_%s-%s_OBJDUMP' % (product, target)] = name_fmt % 'objdump'
|
|
|
|
env['_%s-%s_RANLIB' % (product, target)] = name_fmt % 'ranlib'
|
|
|
|
env['_%s-%s_STRIP' % (product, target)] = name_fmt % 'strip'
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
CONFIGURE_FLAGS += [
|
2020-03-11 01:23:59 +01:00
|
|
|
#'--enable-static-gcc-libs'
|
2019-11-10 04:58:04 +01:00
|
|
|
]
|
2020-03-11 01:23:59 +01:00
|
|
|
elif target_platform == 'osx':
|
|
|
|
if is_cross_compiling(target_platform):
|
|
|
|
osxcross_root = os.environ['OSXCROSS_ROOT']
|
2020-04-07 19:27:27 +02:00
|
|
|
osx_toolchain_path = path_join(osxcross_root, 'target')
|
|
|
|
osxcross_bin = path_join(osx_toolchain_path, 'bin')
|
|
|
|
osx_triple_abi = 'darwin%s' % get_osxcross_sdk(osxcross_bin, arch=target) # TODO: Replace with '--osx-triple-abi' as in ios.py
|
2019-11-13 21:09:19 +01:00
|
|
|
|
2020-03-11 01:23:59 +01:00
|
|
|
env['_%s-%s_PATH' % (product, target)] = osxcross_bin
|
2019-11-13 21:09:19 +01:00
|
|
|
|
2020-04-07 19:27:27 +02:00
|
|
|
wrapper_path = create_osxcross_wrapper(opts, product, target, osx_toolchain_path)
|
|
|
|
name_fmt = path_join(osxcross_bin, target + '-apple-' + osx_triple_abi + '-%s')
|
|
|
|
name_fmt = "%s %s" % (wrapper_path, name_fmt)
|
2019-11-13 21:09:19 +01:00
|
|
|
|
2020-03-11 01:23:59 +01:00
|
|
|
env['_%s-%s_AR' % (product, target)] = name_fmt % 'ar'
|
|
|
|
env['_%s-%s_AS' % (product, target)] = name_fmt % 'as'
|
|
|
|
env['_%s-%s_CC' % (product, target)] = name_fmt % 'clang'
|
|
|
|
env['_%s-%s_CXX' % (product, target)] = name_fmt % 'clang++'
|
|
|
|
env['_%s-%s_LD' % (product, target)] = name_fmt % 'ld'
|
|
|
|
env['_%s-%s_RANLIB' % (product, target)] = name_fmt % 'ranlib'
|
|
|
|
env['_%s-%s_CMAKE' % (product, target)] = name_fmt % 'cmake'
|
|
|
|
env['_%s-%s_STRIP' % (product, target)] = name_fmt % 'strip'
|
2020-04-06 16:12:01 +02:00
|
|
|
|
|
|
|
# DTrace is not available when building with OSXCROSS
|
|
|
|
CONFIGURE_FLAGS += ['--enable-dtrace=no']
|
2020-03-11 01:23:59 +01:00
|
|
|
else:
|
|
|
|
env['_%s-%s_CC' % (product, target)] = 'cc'
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
env['_%s-%s_CONFIGURE_FLAGS' % (product, target)] = CONFIGURE_FLAGS
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
llvm = llvm_table[target_platform][target] if opts.with_llvm else ''
|
2019-11-10 04:58:04 +01:00
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
runtime.setup_runtime_template(env, opts, product, target, host_triple, llvm=llvm)
|
2019-11-10 04:58:04 +01:00
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
|
|
|
|
def strip_libs(opts: DesktopOpts, product: str, target_platform: str, target: str):
|
2020-03-11 01:23:59 +01:00
|
|
|
if target_platform == 'osx':
|
|
|
|
# 'strip' doesn't support '--strip-unneeded' on macOS
|
|
|
|
return
|
2019-11-13 21:09:19 +01:00
|
|
|
|
2020-03-11 01:23:59 +01:00
|
|
|
if is_cross_compiling(target_platform) and target_platform == 'windows':
|
|
|
|
mxe_bin = path_join(opts.mxe_prefix, 'bin')
|
|
|
|
name_fmt = path_join(mxe_bin, target + '-w64-mingw32-%s')
|
|
|
|
strip = name_fmt % 'strip'
|
2019-11-10 04:58:04 +01:00
|
|
|
else:
|
|
|
|
strip = 'strip'
|
|
|
|
|
|
|
|
install_dir = path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
|
|
|
|
out_libs_dir = path_join(install_dir, 'lib')
|
|
|
|
|
|
|
|
lib_files = globs(('*.a', '*.so'), dirpath=out_libs_dir)
|
|
|
|
if len(lib_files):
|
|
|
|
run_command(strip, args=['--strip-unneeded'] + lib_files, name='strip')
|
|
|
|
|
|
|
|
if target_platform == 'windows':
|
|
|
|
out_bin_dir = path_join(install_dir, 'bin')
|
|
|
|
|
|
|
|
dll_files = globs(('*.dll',), dirpath=out_bin_dir)
|
|
|
|
if len(dll_files):
|
|
|
|
run_command(strip, args=['--strip-unneeded'] + dll_files, name='strip')
|
|
|
|
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
def configure(opts: DesktopOpts, product: str, target_platform: str, target: str):
|
2019-11-10 04:58:04 +01:00
|
|
|
env = {}
|
|
|
|
|
|
|
|
setup_desktop_template(env, opts, product, target_platform, target)
|
|
|
|
|
|
|
|
if not os.path.isfile(path_join(opts.mono_source_root, 'configure')):
|
|
|
|
runtime.run_autogen(opts)
|
|
|
|
|
|
|
|
runtime.run_configure(env, opts, product, target)
|
|
|
|
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
def make(opts: DesktopOpts, product: str, target_platform: str, target: str):
|
2019-11-10 04:58:04 +01:00
|
|
|
build_dir = path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration))
|
|
|
|
|
2020-04-06 11:01:36 +02:00
|
|
|
make_args = make_default_args(opts)
|
|
|
|
make_args += ['-C', build_dir]
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
run_command('make', args=make_args, name='make')
|
|
|
|
run_command('make', args=['-C', '%s/mono' % build_dir, 'install'], name='make install mono')
|
|
|
|
run_command('make', args=['-C', '%s/support' % build_dir, 'install'], name='make install support')
|
2019-11-13 21:09:19 +01:00
|
|
|
run_command('make', args=['-C', '%s/data' % build_dir, 'install'], name='make install data')
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
if opts.strip_libs:
|
|
|
|
strip_libs(opts, product, target_platform, target)
|
|
|
|
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
def clean(opts: DesktopOpts, product: str, target_platform: str, target: str):
|
2019-11-10 04:58:04 +01:00
|
|
|
rm_rf(
|
|
|
|
path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration)),
|
|
|
|
path_join(opts.configure_dir, '%s-%s-%s.config.cache' % (product, target, opts.configuration)),
|
|
|
|
path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-01-29 13:00:08 +01:00
|
|
|
def run_main(raw_args, target_platform):
|
2019-11-10 04:58:04 +01:00
|
|
|
import cmd_utils
|
|
|
|
from collections import OrderedDict
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
actions = OrderedDict()
|
|
|
|
actions['configure'] = configure
|
|
|
|
actions['make'] = make
|
|
|
|
actions['clean'] = clean
|
|
|
|
|
|
|
|
parser = cmd_utils.build_arg_parser(description='Builds the Mono runtime for the Desktop')
|
|
|
|
|
|
|
|
default_help = 'default: %(default)s'
|
|
|
|
|
2020-01-29 13:00:08 +01:00
|
|
|
parser.add_argument('action', choices=['configure', 'make', 'clean'])
|
|
|
|
parser.add_argument('--target', choices=targets[target_platform], action='append', required=True)
|
|
|
|
parser.add_argument('--with-llvm', action='store_true', default=False, help=default_help)
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
cmd_utils.add_runtime_arguments(parser, default_help)
|
|
|
|
|
|
|
|
args = parser.parse_args(raw_args)
|
|
|
|
|
|
|
|
input_action = args.action
|
|
|
|
input_targets = args.target
|
|
|
|
|
2019-11-13 21:09:19 +01:00
|
|
|
opts = desktop_opts_from_args(args)
|
2019-11-10 04:58:04 +01:00
|
|
|
|
|
|
|
if not os.path.isdir(opts.mono_source_root):
|
|
|
|
print('Mono sources directory not found: ' + opts.mono_source_root)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-01-29 13:00:08 +01:00
|
|
|
if target_platform == 'osx' and sys.platform != 'darwin' and not 'OSXCROSS_ROOT' in os.environ:
|
2019-11-13 21:09:19 +01:00
|
|
|
raise RuntimeError('The \'OSXCROSS_ROOT\' environment variable is required for cross-compiling to macOS')
|
2019-11-10 04:58:04 +01:00
|
|
|
|
2020-01-29 13:00:08 +01:00
|
|
|
if is_cross_compiling(target_platform) and sys.platform == 'darwin':
|
2019-11-10 04:58:04 +01:00
|
|
|
raise RuntimeError('Cross-compiling from macOS is not supported')
|
|
|
|
|
|
|
|
action = actions[input_action]
|
|
|
|
|
|
|
|
try:
|
|
|
|
for target in input_targets:
|
2020-01-29 13:00:08 +01:00
|
|
|
action(opts, 'desktop-%s' % target_platform, target_platform, target)
|
2019-11-10 04:58:04 +01:00
|
|
|
except BuildError as e:
|
|
|
|
sys.exit(e.message)
|