// Set up a Meson cross build against an installed Vinix SDK. module main import os fn quoted(value string) string { return "'" + value.replace('\\', '\\\\').replace("'", "\\'") + "'" } fn setup(args []string) ! { if args.len < 2 { return error('usage: vinix-meson SOURCE_DIR BUILD_DIR [MESON_OPTION ...]') } host := os.uname().machine arch := os.getenv_opt('VPAC_TARGET_ARCH') or { host } root := os.getenv('VPAC_MAKEPKG_ROOT') if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root) || !os.is_file(os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')) { return error('vinix-meson requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT') } prefix := os.getenv('CROSS_COMPILE') mut machine := ['[binaries]', "c = 'vinix-cc'", "cpp = 'vinix-c++'", "pkg-config = 'pkg-config'", "exe_wrapper = 'vinix-run'"] for name in ['ar', 'ranlib', 'strip', 'nm', 'objcopy', 'objdump'] { machine << '${name} = ' + quoted(prefix + name) } machine << ['', '[properties]', 'needs_exe_wrapper = true', 'sys_root = ' + quoted(root), 'pkg_config_libdir = [' + quoted(os.join_path(root, 'usr/lib/pkgconfig')) + ', ' + quoted(os.join_path(root, 'usr/share/pkgconfig')) + ']', '', '[host_machine]', "system = 'linux'", 'cpu_family = ' + quoted(arch), 'cpu = ' + quoted(arch), "endian = 'little'"] file := os.abs_path(args[1]) + '.vinix-cross.ini' os.write_file(file, machine.join('\n') + '\n')! for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH', 'PKG_CONFIG_LIBDIR', 'PKG_CONFIG_SYSROOT_DIR'] { os.unsetenv(name) } mut options := ['setup', '--cross-file', file, '--prefix=/usr', '--sysconfdir=/etc', '--libdir=lib', '--buildtype=release'] options << args[2..] options << [args[1], args[0]] os.execvp('meson', options)! } fn main() { setup(os.args[1..]) or { eprintln(err) exit(1) } }