2023-03-06 14:17:19 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
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}'
|
2021-12-26 16:36:30 +01:00
|
|
|
""")
|
|
|
|
|
|
|
|
if 'android' in toolchain.arch:
|
|
|
|
f.write("""
|
|
|
|
# Keep Meson from executing Android-x86 test binariees
|
|
|
|
needs_exe_wrapper = true
|
|
|
|
""")
|
2018-05-12 15:00:17 +02:00
|
|
|
|
2021-12-26 16:36:30 +01:00
|
|
|
f.write(f"""
|
2021-09-21 14:56:50 +02:00
|
|
|
[built-in options]
|
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-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 = [
|
2022-11-12 12:10:05 +01:00
|
|
|
'meson', 'setup',
|
|
|
|
build, src,
|
2018-10-14 21:39:36 +02:00
|
|
|
|
|
|
|
'--prefix', toolchain.install_prefix,
|
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()
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-08-28 22:41:31 +02:00
|
|
|
def _build(self, toolchain):
|
2018-05-12 15:00:17 +02:00
|
|
|
build = self.configure(toolchain)
|
2022-08-08 10:05:30 +02:00
|
|
|
subprocess.check_call(['ninja', '-v', 'install'],
|
2018-05-12 15:00:17 +02:00
|
|
|
cwd=build, env=toolchain.env)
|