From 5d38cbfadef5623f1ac3df2dd48dafa19bb97f3b Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 23 Aug 2013 23:05:22 +0300 Subject: [PATCH] A journey to cross-compilation starts with a single step. --- coredata.py | 1 + cross/ubuntu-mingw.txt | 5 +++++ environment.py | 45 ++++++++++++++++++++++++++++++++++++++++++ meson.py | 6 ++++++ 4 files changed, 57 insertions(+) create mode 100644 cross/ubuntu-mingw.txt diff --git a/coredata.py b/coredata.py index 78a8ef0e9..94a1cda8d 100644 --- a/coredata.py +++ b/coredata.py @@ -34,6 +34,7 @@ class CoreData(): self.buildtype = options.buildtype self.strip = options.strip self.coverage = options.coverage + self.cross_file = options.cross_file self.compilers = {} self.deps = {} diff --git a/cross/ubuntu-mingw.txt b/cross/ubuntu-mingw.txt new file mode 100644 index 000000000..af531971f --- /dev/null +++ b/cross/ubuntu-mingw.txt @@ -0,0 +1,5 @@ +name = 'windows' +exe_runner = 'wine' +c = '/usr/bin/i586-mingw32msvc-gcc' +cpp = '/usr/bin/i586-mingw32msvc-g++' +root = '/usr/i586-mingw32msvc' diff --git a/environment.py b/environment.py index cb62a8bcc..a06ed4c34 100644 --- a/environment.py +++ b/environment.py @@ -709,6 +709,9 @@ class Environment(): self.static_lib_suffix = 'a' self.static_lib_prefix = 'lib' self.object_suffix = 'o' + + def is_cross_build(self): + return self.coredata.cross_file is not None def generating_finished(self): cdf = os.path.join(self.get_build_dir(), Environment.coredata_file) @@ -958,3 +961,45 @@ def get_library_dirs(): unixdirs += glob('/lib/' + plat + '*') unixdirs.append('/usr/local/lib') return unixdirs + +class CrossbuildInfo(): + def __init__(self, filename): + self.items = {} + self.parse_datafile(filename) + if not 'name' in self: + raise EnvironmentException('Cross file must specify "name".') + + def parse_datafile(self, filename): + # This is a bit hackish at the moment. + for linenum, line in enumerate(open(filename)): + line = line.strip() + if line == '': + continue + if '=' not in line: + raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum)) + (varname, value) = line.split('=', 1) + varname = varname.strip() + if ' ' in varname or '\t' in varname or "'" in varname or '"' in varname: + raise EnvironmentException('Malformed variable name in cross file %s:%d.' % (filename, linenum)) + try: + res = eval(value) + except Exception: + raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum)) + if isinstance(res, str): + self.items[varname] = res + elif isinstance(res, list): + for i in res: + if not isinstance(i, str): + raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum)) + self.items[varname] = res + else: + raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum)) + + def __getitem__(self, ind): + return self.items[ind] + + def __contains__(self, item): + return item in self.items + + def get(self, *args, **kwargs): + return self.items.get(*args, **kwargs) diff --git a/meson.py b/meson.py index cad449ed5..9312be2b4 100755 --- a/meson.py +++ b/meson.py @@ -56,6 +56,8 @@ parser.add_option('--strip', action='store_true', dest='strip', default=False,\ help='strip targets on install (default: %default)') parser.add_option('--enable-gcov', action='store_true', dest='coverage', default=False,\ help='measure test coverage') +parser.add_option('--cross-file', default=None, dest='cross_file', + help='file describing cross compilation environment') class MesonApp(): @@ -100,6 +102,10 @@ class MesonApp(): mlog.log(' version:', coredata.version) mlog.log('Source dir:', mlog.bold(app.source_dir)) mlog.log('Build dir:', mlog.bold(app.build_dir)) + if env.is_cross_build(): + mlog.log('Build type:', mlog.bold('cross build')) + else: + mlog.log('Build type:', mlog.bold('native build')) b = build.Build(env) intr = interpreter.Interpreter(b) intr.run()