// 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 ordinary -L or -I arguments. Keep explicit // system directories and their descendants inside the SDK. fn target_search_path(root string, flag string, path string) string { if flag == '-L' && (path == '/usr/lib' || path.starts_with('/usr/lib/') || path == '/lib' || path.starts_with('/lib/')) { return root + path } if flag in ['-I', '-isystem'] && (path == '/usr/include' || path.starts_with('/usr/include/')) { return root + path } return path } fn target_search_args(root string, input []string) []string { mut args := []string{cap: input.len} mut previous := '' for arg in input { if previous != '' { args << target_search_path(root, previous, arg) previous = '' continue } if arg in ['-L', '-I', '-isystem'] { previous = arg } flag := arg.all_before('/') if flag in ['-L', '-I', '-isystem'] && arg.len > flag.len { args << flag + target_search_path(root, flag, arg[flag.len..]) } else { args << 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..]) if !os.args[1..].any(it in ['-c', '-E', '-S', '-M', '-MM', '-fsyntax-only', '-r']) { // The build machine's linker also needs to find DT_NEEDED libraries // named by input shared objects. Keep this path out of the target ELF. args << ['-Xlinker', '-rpath-link', '-Xlinker', '${root}/usr/lib:${root}/lib'] // The released AArch64 kernel maps 16 KiB pages. if os.is_file(os.join_path(root, 'lib/ld-musl-aarch64.so.1')) { args << '-Wl,-z,max-page-size=16384' } } os.execvp(compiler, args) or { eprintln('${driver}: ${compiler}: ${err}') exit(1) } }