2018-05-12 15:00:17 +02:00
|
|
|
import os.path, subprocess, sys
|
2021-08-10 14:51:02 +02:00
|
|
|
import platform
|
2018-05-12 15:00:17 +02:00
|
|
|
|
|
|
|
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:
|
2021-08-10 14:34:17 +02:00
|
|
|
f.write(f"""
|
2018-05-12 15:00:17 +02:00
|
|
|
[binaries]
|
2021-08-10 14:34:17 +02:00
|
|
|
c = '{toolchain.cc}'
|
|
|
|
cpp = '{toolchain.cxx}'
|
|
|
|
ar = '{toolchain.ar}'
|
|
|
|
strip = '{toolchain.strip}'
|
|
|
|
pkgconfig = '{toolchain.pkg_config}'
|
|
|
|
""")
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2021-08-10 14:51:02 +02:00
|
|
|
if toolchain.is_windows and platform.system() != 'Windows':
|
2021-08-10 14:34:17 +02:00
|
|
|
f.write(f"windres = '{toolchain.windres}'\n")
|
|
|
|
|
2021-08-10 14:51:02 +02:00
|
|
|
# Run unit tests with WINE when cross-building for Windows
|
|
|
|
print("exe_wrapper = 'wine'", file=f)
|
|
|
|
|
2021-08-10 14:34:17 +02:00
|
|
|
f.write(f"""
|
2018-05-12 15:00:17 +02:00
|
|
|
[properties]
|
2021-08-10 14:34:17 +02:00
|
|
|
root = '{toolchain.install_prefix}'
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2021-08-10 14:34:17 +02:00
|
|
|
c_args = {repr((toolchain.cppflags + ' ' + toolchain.cflags).split())}
|
|
|
|
c_link_args = {repr(toolchain.ldflags.split() + toolchain.libs.split())}
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2021-08-10 14:34:17 +02:00
|
|
|
cpp_args = {repr((toolchain.cppflags + ' ' + toolchain.cxxflags).split())}
|
|
|
|
cpp_link_args = {repr(toolchain.ldflags.split() + toolchain.libs.split())}
|
2021-08-10 14:51:20 +02:00
|
|
|
""")
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2021-08-10 14:51:20 +02:00
|
|
|
if 'android' in toolchain.arch:
|
|
|
|
f.write("""
|
2018-08-17 18:10:00 +02:00
|
|
|
# Keep Meson from executing Android-x86 test binariees
|
|
|
|
needs_exe_wrapper = true
|
2021-08-10 14:51:20 +02:00
|
|
|
""")
|
2018-08-17 18:10:00 +02:00
|
|
|
|
2021-08-10 14:51:20 +02:00
|
|
|
f.write(f"""
|
2018-05-12 15:00:17 +02:00
|
|
|
[host_machine]
|
2021-08-10 14:34:17 +02:00
|
|
|
system = '{system}'
|
|
|
|
cpu_family = '{cpu_family}'
|
|
|
|
cpu = '{cpu}'
|
|
|
|
endian = '{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
|
|
|
|
2020-07-01 16:37:50 +02:00
|
|
|
env = toolchain.env.copy()
|
|
|
|
|
|
|
|
# Meson 0.54 requires the BOOST_ROOT environment variable
|
|
|
|
env['BOOST_ROOT'] = toolchain.install_prefix
|
|
|
|
|
|
|
|
subprocess.check_call(configure, env=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)
|