| 1 | // Configure an Autotools release for an installed Vinix SDK with host build tools. |
| 2 | module main |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | fn configure(args []string) ! { |
| 7 | if args.len == 0 { |
| 8 | return error('usage: vinix-configure SOURCE/configure [CONFIGURE_OPTION ...]') |
| 9 | } |
| 10 | root := os.getenv('VPAC_MAKEPKG_ROOT') |
| 11 | arch := os.getenv_opt('VPAC_TARGET_ARCH') or { os.uname().machine } |
| 12 | if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root) |
| 13 | || !os.is_file(os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')) { |
| 14 | return error('vinix-configure requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT') |
| 15 | } |
| 16 | for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH'] { |
| 17 | os.unsetenv(name) |
| 18 | } |
| 19 | build_cc := os.getenv_opt('CC_FOR_BUILD') or { 'cc' } |
| 20 | build_machine := os.execute(os.quoted_path(build_cc) + ' -dumpmachine') |
| 21 | if build_machine.exit_code != 0 { |
| 22 | return error('${build_cc} -dumpmachine failed: ${build_machine.output}') |
| 23 | } |
| 24 | os.setenv('CC_FOR_BUILD', build_cc, true) |
| 25 | os.setenv('CC', 'vinix-cc', true) |
| 26 | os.setenv('CXX', 'vinix-c++', true) |
| 27 | prefix := os.getenv('CROSS_COMPILE') |
| 28 | if prefix != '' { |
| 29 | for name in ['ar', 'as', 'ld', 'nm', 'objcopy', 'objdump', 'ranlib', 'strip'] { |
| 30 | os.setenv(name.to_upper(), prefix + name, false) |
| 31 | } |
| 32 | } |
| 33 | os.setenv('PKG_CONFIG_SYSROOT_DIR', root, true) |
| 34 | os.setenv('PKG_CONFIG_LIBDIR', os.join_path(root, 'usr/lib/pkgconfig') + ':' + |
| 35 | os.join_path(root, 'usr/share/pkgconfig'), true) |
| 36 | mut options := ['--build=' + build_machine.output.trim_space(), '--host=' + arch + '-linux-musl', |
| 37 | '--prefix=/usr', '--sysconfdir=/etc'] |
| 38 | options << args[1..] |
| 39 | os.execvp(args[0], options)! |
| 40 | } |
| 41 | |
| 42 | fn main() { |
| 43 | configure(os.args[1..]) or { |
| 44 | eprintln(err) |
| 45 | exit(1) |
| 46 | } |
| 47 | } |
| 48 | |