Changed cross compilation file to new format.

pull/214/head
Jussi Pakkanen 9 years ago
parent 6af21dd20e
commit eb3cdb6f8d
  1. 2
      backends.py
  2. 6
      compilers.py
  3. 11
      cross/ubuntu-armhf.txt
  4. 14
      cross/ubuntu-mingw.txt
  5. 82
      environment.py
  6. 4
      interpreter.py
  7. 2
      ninjabackend.py

@ -248,7 +248,7 @@ class Backend():
fname = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(t.get_exe()))] fname = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(t.get_exe()))]
is_cross = self.environment.is_cross_build() is_cross = self.environment.is_cross_build()
if is_cross: if is_cross:
exe_wrapper = self.environment.cross_info.get('exe_wrapper', None) exe_wrapper = self.environment.cross_info.config['binaries'].get('exe_wrapper', None)
else: else:
exe_wrapper = None exe_wrapper = None
ts = TestSerialisation(t.get_name(), fname, is_cross, exe_wrapper, ts = TestSerialisation(t.get_name(), fname, is_cross, exe_wrapper,

@ -326,7 +326,7 @@ int main(int argc, char **argv) {
varname = 'sizeof ' + element varname = 'sizeof ' + element
varname = varname.replace(' ', '_') varname = varname.replace(' ', '_')
if self.is_cross: if self.is_cross:
val = env.cross_info.get(varname) val = env.cross_info.config['properties'][varname]
if val is not None: if val is not None:
if isinstance(val, int): if isinstance(val, int):
return val return val
@ -363,7 +363,7 @@ int main(int argc, char **argv) {
varname = 'alignment ' + typename varname = 'alignment ' + typename
varname = varname.replace(' ', '_') varname = varname.replace(' ', '_')
if self.is_cross: if self.is_cross:
val = env.cross_info.get(varname) val = env.cross_info.config['properties'][varname]
if val is not None: if val is not None:
if isinstance(val, int): if isinstance(val, int):
return val return val
@ -399,7 +399,7 @@ int main(int argc, char **argv) {
varname = 'has function ' + funcname varname = 'has function ' + funcname
varname = varname.replace(' ', '_') varname = varname.replace(' ', '_')
if self.is_cross: if self.is_cross:
val = env.cross_info.get(varname) val = env.cross_info.config['properties'].get(varname, None)
if val is not None: if val is not None:
if isinstance(val, bool): if isinstance(val, bool):
return val return val

@ -1,11 +1,14 @@
name = 'linux' [binaries]
# we could set exe_wrapper = qemu-arm-static but to test the case
# when cross compiled binaries can't be built we don't do that
c = '/usr/bin/arm-linux-gnueabihf-gcc' c = '/usr/bin/arm-linux-gnueabihf-gcc'
cpp = '/usr/bin/arm-linux-gnueabihf-g++' cpp = '/usr/bin/arm-linux-gnueabihf-g++'
ar = '/usr/arm-linux-gnueabihf/bin/ar' ar = '/usr/arm-linux-gnueabihf/bin/ar'
strip = '/usr/arm-linux-gnueabihf/bin/strip' strip = '/usr/arm-linux-gnueabihf/bin/strip'
pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'
[properties]
root = '/usr/arm-linux-gnueabihf' root = '/usr/arm-linux-gnueabihf'
pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'
sizeof_int = 4 sizeof_int = 4
sizeof_wchar_t = 4 sizeof_wchar_t = 4
@ -17,3 +20,7 @@ alignment_double = 4 # Don't know if this is correct...
has_function_printf = true has_function_printf = true
has_function_hfkerhisadf = false has_function_hfkerhisadf = false
[hostmachine]
name = 'linux'
cpu = 'arm'

@ -1,8 +1,20 @@
name = 'windows' # Something crazy: compiling on Linux a crosscompiler that
# runs on Windows and generates code for iOS.
[binaries]
exe_wrapper = 'wine' # A command used to run generated executables. exe_wrapper = 'wine' # A command used to run generated executables.
c = '/usr/bin/i686-w64-mingw32-gcc' c = '/usr/bin/i686-w64-mingw32-gcc'
cpp = '/usr/bin/i686-w64-mingw32-g++' cpp = '/usr/bin/i686-w64-mingw32-g++'
ar = '/usr/bin/i686-w64-mingw32-ar' ar = '/usr/bin/i686-w64-mingw32-ar'
strip = '/usr/bin/i686-w64-mingw32-strip' strip = '/usr/bin/i686-w64-mingw32-strip'
[properties]
root = '/usr/i686-w64-mingw32' root = '/usr/i686-w64-mingw32'
[hostmachine]
name = 'windows'
cpu = 'x86'
[targetmachine]
name='darwin'
cpu='arm'

@ -16,6 +16,7 @@ import re
import coredata import coredata
from glob import glob from glob import glob
from compilers import * from compilers import *
import configparser
build_filename = 'meson.build' build_filename = 'meson.build'
@ -90,7 +91,7 @@ class Environment():
cross = self.is_cross_build() cross = self.is_cross_build()
if (not cross and mesonlib.is_windows()) \ if (not cross and mesonlib.is_windows()) \
or (cross and self.cross_info['name'] == 'windows'): or (cross and self.cross_info.has_host() and self.cross_info.config['hostmachine']['name'] == 'windows'):
self.exe_suffix = 'exe' self.exe_suffix = 'exe'
self.import_lib_suffix = 'lib' self.import_lib_suffix = 'lib'
self.shared_lib_suffix = 'dll' self.shared_lib_suffix = 'dll'
@ -101,7 +102,7 @@ class Environment():
else: else:
self.exe_suffix = '' self.exe_suffix = ''
if (not cross and mesonlib.is_osx()) or \ if (not cross and mesonlib.is_osx()) or \
(cross and self.cross_info['name'] == 'darwin'): (cross and self.cross_info.has_host() and self.cross_info.config['hostmachine']['name'] == 'darwin'):
self.shared_lib_suffix = 'dylib' self.shared_lib_suffix = 'dylib'
else: else:
self.shared_lib_suffix = 'so' self.shared_lib_suffix = 'so'
@ -151,10 +152,10 @@ class Environment():
def detect_c_compiler(self, want_cross): def detect_c_compiler(self, want_cross):
evar = 'CC' evar = 'CC'
if self.is_cross_build() and want_cross: if self.is_cross_build() and want_cross:
compilers = [self.cross_info['c']] compilers = [self.cross_info.config['binaries']['c']]
ccache = [] ccache = []
is_cross = True is_cross = True
exe_wrap = self.cross_info.get('exe_wrapper', None) exe_wrap = self.cross_info.config['binaries'].get('exe_wrapper', None)
elif evar in os.environ: elif evar in os.environ:
compilers = os.environ[evar].split() compilers = os.environ[evar].split()
ccache = [] ccache = []
@ -269,10 +270,10 @@ class Environment():
def detect_cpp_compiler(self, want_cross): def detect_cpp_compiler(self, want_cross):
evar = 'CXX' evar = 'CXX'
if self.is_cross_build() and want_cross: if self.is_cross_build() and want_cross:
compilers = [self.cross_info['cpp']] compilers = [self.cross_info.config['binaries']['cpp']]
ccache = [] ccache = []
is_cross = True is_cross = True
exe_wrap = self.cross_info.get('exe_wrapper', None) exe_wrap = self.cross_info.config['binaries'].get('exe_wrapper', None)
elif evar in os.environ: elif evar in os.environ:
compilers = os.environ[evar].split() compilers = os.environ[evar].split()
ccache = [] ccache = []
@ -447,7 +448,7 @@ class Environment():
def detect_static_linker(self, compiler): def detect_static_linker(self, compiler):
if compiler.is_cross: if compiler.is_cross:
linker = self.cross_info['ar'] linker = self.cross_info.config['binaries']['ar']
else: else:
evar = 'AR' evar = 'AR'
if evar in os.environ: if evar in os.environ:
@ -587,49 +588,42 @@ def get_args_from_envvars(lang):
class CrossBuildInfo(): class CrossBuildInfo():
def __init__(self, filename): def __init__(self, filename):
self.items = {} self.config = {}
self.parse_datafile(filename) self.parse_datafile(filename)
if not 'name' in self: if not 'properties' in self.config:
raise EnvironmentException('Cross file must specify "name" (e.g. "linux", "darwin" or "windows".') raise EnvironmentError('Cross file is missing "properties".')
if not 'binaries' in self.config:
raise EnvironmentError('Cross file is missing "binaries".')
def ok_type(self, i): def ok_type(self, i):
return isinstance(i, str) or isinstance(i, int) or isinstance(i, bool) return isinstance(i, str) or isinstance(i, int) or isinstance(i, bool)
def parse_datafile(self, filename): def parse_datafile(self, filename):
config = configparser.ConfigParser()
config.read(filename)
# This is a bit hackish at the moment. # This is a bit hackish at the moment.
for i, line in enumerate(open(filename)): for s in config.sections():
linenum = i+1 self.config[s] = {}
line = line.strip() for entry in config[s]:
if line == '': value = config[s][entry]
continue if ' ' in entry or '\t' in entry or "'" in entry or '"' in entry:
if '=' not in line: raise EnvironmentException('Malformed variable name %s in cross file..' % varname)
raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum)) try:
(varname, value) = line.split('=', 1) res = eval(value, {'true' : True, 'false' : False})
varname = varname.strip() except Exception:
if ' ' in varname or '\t' in varname or "'" in varname or '"' in varname: raise EnvironmentException('Malformed value in cross file variable %s.' % varname)
raise EnvironmentException('Malformed variable name in cross file %s:%d.' % (filename, linenum)) if self.ok_type(res):
try: self.config[s][entry] = res
res = eval(value, {'true' : True, 'false' : False}) elif isinstance(res, list):
except Exception: for i in res:
raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum)) if not self.ok_type(i):
if self.ok_type(res): raise EnvironmentException('Malformed value in cross file variable %s.' % varname)
self.items[varname] = res self.items[varname] = res
elif isinstance(res, list): else:
for i in res: raise EnvironmentException('Malformed value in cross file variable %s.' % varname)
if not self.ok_type(i):
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):
try:
return self.items[ind]
except KeyError:
raise EnvironmentException('Cross file does not specify variable "%s".' % ind)
def __contains__(self, item): def has_host(self):
return item in self.items return 'hostmachine' in self.config
def get(self, *args, **kwargs): def has_target(self):
return self.items.get(*args, **kwargs) return 'targetmachine' in self.config

@ -323,7 +323,7 @@ class Host(InterpreterObject):
def get_name_method(self, args, kwargs): def get_name_method(self, args, kwargs):
if self.environment.is_cross_build(): if self.environment.is_cross_build():
return self.environment.cross_info.get('name') return self.environment.cross_info.config['hostmachine']['name']
return platform.system().lower() return platform.system().lower()
def is_big_endian_method(self, args, kwargs): def is_big_endian_method(self, args, kwargs):
@ -735,7 +735,7 @@ class MesonMain(InterpreterObject):
def has_exe_wrapper_method(self, args, kwargs): def has_exe_wrapper_method(self, args, kwargs):
if self.is_cross_build_method(None, None): if self.is_cross_build_method(None, None):
return 'exe_wrap' in self.build.environment.cross_info return 'exe_wrap' in self.build.environment.cross_info.config['binaries']
return True # This is semantically confusing. return True # This is semantically confusing.
def is_cross_build_method(self, args, kwargs): def is_cross_build_method(self, args, kwargs):

@ -1268,7 +1268,7 @@ rule FORTRAN_DEP_HACK
symname = os.path.join(targetdir, target_name + '.symbols') symname = os.path.join(targetdir, target_name + '.symbols')
elem = NinjaBuildElement(symname, 'SHSYM', target_name) elem = NinjaBuildElement(symname, 'SHSYM', target_name)
if self.environment.is_cross_build(): if self.environment.is_cross_build():
elem.add_item('CROSS', '--cross-host=' + self.environment.cross_info['name']) elem.add_item('CROSS', '--cross-host=' + self.environment.cross_info.config['hostmachine']['name'])
elem.write(outfile) elem.write(outfile)
def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[]): def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[]):

Loading…
Cancel
Save