// A single compiler name for build systems such as libtool that independently // expand CC and its arguments. Repeating musl's specs option makes GCC fail. module main import os // Libtool can add -L/usr/lib while it relinks libraries under DESTDIR. GCC's // --sysroot does not rebase an ordinary -L argument. Keep these explicit // system directories inside the SDK, including their two-argument spellings. fn target_search_args(root string, input []string) []string { mut args := []string{cap: input.len} mut previous := '' for arg in input { if (previous == '-L' && arg in ['/usr/lib', '/lib']) || (previous in ['-I', '-isystem'] && arg == '/usr/include') { args << root + arg } else if arg in ['-L/usr/lib', '-L/lib', '-I/usr/include'] { args << arg[..2] + root + arg[2..] } else { args << arg } previous = arg } return args } fn main() { driver := os.base(os.args[0]) root := os.getenv('VPAC_MAKEPKG_ROOT') if !os.is_abs_path(root) { eprintln('${driver} requires an absolute VPAC_MAKEPKG_ROOT') exit(1) } specs := os.join_path(root, 'usr/lib/musl-gcc-sysroot.specs') if !os.is_file(specs) { eprintln('${driver}: missing installed musl specs at ${specs}') exit(1) } prefix := os.getenv('CROSS_COMPILE') compiler := if driver == 'vinix-c++' { os.getenv_opt('VINIX_REAL_CXX') or { prefix + 'g++' } } else { os.getenv_opt('VINIX_REAL_CC') or { prefix + 'gcc' } } mut args := ['--sysroot=${root}', '-specs=${specs}'] args << target_search_args(root, os.args[1..]) // The released AArch64 kernel maps 16 KiB pages. Some cross GCC // distributions select a 4 KiB linker maximum even with a musl sysroot. if os.is_file(os.join_path(root, 'lib/ld-musl-aarch64.so.1')) && !os.args[1..].any(it in ['-c', '-E', '-S', '-M', '-MM', '-fsyntax-only', '-r']) { args << '-Wl,-z,max-page-size=16384' } os.execvp(compiler, args) or { eprintln('${driver}: ${compiler}: ${err}') exit(1) } }