2018-05-12 15:00:17 +02:00
|
|
|
import os.path, subprocess, sys
|
|
|
|
|
|
|
|
from build.project import Project
|
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
def make_cross_file(toolchain):
|
|
|
|
if toolchain.is_windows:
|
|
|
|
system = 'windows'
|
2018-10-14 23:41:20 +02:00
|
|
|
windres = "windres = '%s'" % toolchain.windres
|
2018-10-14 21:39:36 +02:00
|
|
|
else:
|
|
|
|
system = 'linux'
|
2018-10-14 23:41:20 +02:00
|
|
|
windres = ''
|
2018-10-14 21:39:36 +02:00
|
|
|
|
|
|
|
if toolchain.is_arm:
|
|
|
|
cpu_family = 'arm'
|
|
|
|
if toolchain.is_armv7:
|
|
|
|
cpu = 'armv7'
|
2018-05-12 15:00:17 +02:00
|
|
|
else:
|
2018-10-14 21:39:36 +02:00
|
|
|
cpu = 'armv6'
|
|
|
|
elif toolchain.is_aarch64:
|
|
|
|
cpu_family = 'aarch64'
|
|
|
|
cpu = 'arm64-v8a'
|
|
|
|
else:
|
|
|
|
cpu_family = 'x86'
|
|
|
|
if 'x86_64' in toolchain.arch:
|
|
|
|
cpu = 'x86_64'
|
2018-05-12 15:00:17 +02:00
|
|
|
else:
|
2018-10-14 21:39:36 +02:00
|
|
|
cpu = 'i686'
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
# TODO: support more CPUs
|
|
|
|
endian = 'little'
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
# TODO: write pkg-config wrapper
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
path = os.path.join(toolchain.build_path, 'meson.cross')
|
|
|
|
os.makedirs(toolchain.build_path, exist_ok=True)
|
|
|
|
with open(path, 'w') as f:
|
|
|
|
f.write("""
|
2018-05-12 15:00:17 +02:00
|
|
|
[binaries]
|
|
|
|
c = '%s'
|
|
|
|
cpp = '%s'
|
|
|
|
ar = '%s'
|
|
|
|
strip = '%s'
|
2017-12-29 17:12:55 +01:00
|
|
|
pkgconfig = '%s'
|
2018-10-14 23:41:20 +02:00
|
|
|
%s
|
2018-05-12 15:00:17 +02:00
|
|
|
|
|
|
|
[properties]
|
|
|
|
root = '%s'
|
|
|
|
|
|
|
|
c_args = %s
|
|
|
|
c_link_args = %s
|
|
|
|
|
|
|
|
cpp_args = %s
|
|
|
|
cpp_link_args = %s
|
|
|
|
|
2018-08-17 18:10:00 +02:00
|
|
|
# Keep Meson from executing Android-x86 test binariees
|
|
|
|
needs_exe_wrapper = true
|
|
|
|
|
2018-05-12 15:00:17 +02:00
|
|
|
[host_machine]
|
|
|
|
system = '%s'
|
|
|
|
cpu_family = '%s'
|
|
|
|
cpu = '%s'
|
|
|
|
endian = '%s'
|
|
|
|
""" % (toolchain.cc, toolchain.cxx, toolchain.ar, toolchain.strip,
|
2017-12-29 17:12:55 +01:00
|
|
|
toolchain.pkg_config,
|
2018-10-14 23:41:20 +02:00
|
|
|
windres,
|
2018-05-12 15:00:17 +02:00
|
|
|
toolchain.install_prefix,
|
|
|
|
repr((toolchain.cppflags + ' ' + toolchain.cflags).split()),
|
2018-10-30 13:29:02 +01:00
|
|
|
repr(toolchain.ldflags.split() + toolchain.libs.split()),
|
2018-05-12 15:00:17 +02:00
|
|
|
repr((toolchain.cppflags + ' ' + toolchain.cxxflags).split()),
|
2018-10-30 13:29:02 +01:00
|
|
|
repr(toolchain.ldflags.split() + toolchain.libs.split()),
|
2018-05-12 15:00:17 +02:00
|
|
|
system, cpu_family, cpu, endian))
|
2018-10-14 21:39:36 +02:00
|
|
|
return path
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
def configure(toolchain, src, build, args=()):
|
|
|
|
cross_file = make_cross_file(toolchain)
|
|
|
|
configure = [
|
|
|
|
'meson',
|
|
|
|
src, build,
|
|
|
|
|
|
|
|
'--prefix', toolchain.install_prefix,
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
# this is necessary because Meson uses Debian's build machine
|
|
|
|
# MultiArch path (e.g. "lib/x86_64-linux-gnu") for cross
|
|
|
|
# builds, which is obviously wrong
|
|
|
|
'--libdir', 'lib',
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
'--buildtype', 'plain',
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
'--default-library=static',
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
'--cross-file', cross_file,
|
|
|
|
] + args
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
subprocess.check_call(configure, env=toolchain.env)
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2018-10-14 21:39:36 +02:00
|
|
|
class MesonProject(Project):
|
|
|
|
def __init__(self, url, md5, installed, configure_args=[],
|
|
|
|
**kwargs):
|
|
|
|
Project.__init__(self, url, md5, installed, **kwargs)
|
|
|
|
self.configure_args = configure_args
|
|
|
|
|
|
|
|
def configure(self, toolchain):
|
|
|
|
src = self.unpack(toolchain)
|
|
|
|
build = self.make_build_path(toolchain)
|
|
|
|
configure(toolchain, src, build, self.configure_args)
|
2018-05-12 15:00:17 +02:00
|
|
|
return build
|
|
|
|
|
|
|
|
def build(self, toolchain):
|
|
|
|
build = self.configure(toolchain)
|
|
|
|
subprocess.check_call(['ninja', 'install'],
|
|
|
|
cwd=build, env=toolchain.env)
|