// Configure an Autotools release for an installed Vinix SDK with host build tools. module main import os fn configure(args []string) ! { if args.len == 0 { return error('usage: vinix-configure SOURCE/configure [CONFIGURE_OPTION ...]') } root := os.getenv('VPAC_MAKEPKG_ROOT') arch := os.getenv_opt('VPAC_TARGET_ARCH') or { os.uname().machine } 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-configure requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT') } for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH'] { os.unsetenv(name) } build_cc := os.getenv_opt('CC_FOR_BUILD') or { 'cc' } build_machine := os.exec([build_cc, '-dumpmachine']) if build_machine.exit_code != 0 { return error('${build_cc} -dumpmachine failed: ${build_machine.output}') } os.setenv('CC_FOR_BUILD', build_cc, true) os.setenv('CC', 'vinix-cc', true) os.setenv('CXX', 'vinix-c++', true) prefix := os.getenv('CROSS_COMPILE') // Some configure scripts reuse CROSS_COMPILE as an internal flag. os.setenv('VINIX_REAL_CC', prefix + 'gcc', false) os.setenv('VINIX_REAL_CXX', prefix + 'g++', false) if prefix != '' { for name in ['ar', 'as', 'ld', 'nm', 'objcopy', 'objdump', 'ranlib', 'strip'] { os.setenv(name.to_upper(), prefix + name, false) } } os.setenv('PKG_CONFIG_SYSROOT_DIR', root, true) os.setenv('PKG_CONFIG_LIBDIR', os.join_path(root, 'usr/lib/pkgconfig') + ':' + os.join_path(root, 'usr/share/pkgconfig'), true) mut options := ['--build=' + build_machine.output.trim_space(), '--host=' + arch + '-linux-musl', '--prefix=/usr', '--sysconfdir=/etc'] options << args[1..] os.execvp(args[0], options)! } fn main() { configure(os.args[1..]) or { eprintln(err) exit(1) } }