vinix-ports / tools / vinix-configure.v
50 lines · 47 sloc · 1.82 KB · eed1d00123e847c1c4b4fbf766955f06664b31d0
Raw
1// Configure an Autotools release for an installed Vinix SDK with host build tools.
2module main
3
4import os
5
6fn 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.exec([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 // Some configure scripts reuse CROSS_COMPILE as an internal flag.
29 os.setenv('VINIX_REAL_CC', prefix + 'gcc', false)
30 os.setenv('VINIX_REAL_CXX', prefix + 'g++', false)
31 if prefix != '' {
32 for name in ['ar', 'as', 'ld', 'nm', 'objcopy', 'objdump', 'ranlib', 'strip'] {
33 os.setenv(name.to_upper(), prefix + name, false)
34 }
35 }
36 os.setenv('PKG_CONFIG_SYSROOT_DIR', root, true)
37 os.setenv('PKG_CONFIG_LIBDIR', os.join_path(root, 'usr/lib/pkgconfig') + ':' +
38 os.join_path(root, 'usr/share/pkgconfig'), true)
39 mut options := ['--build=' + build_machine.output.trim_space(), '--host=' + arch + '-linux-musl',
40 '--prefix=/usr', '--sysconfdir=/etc']
41 options << args[1..]
42 os.execvp(args[0], options)!
43}
44
45fn main() {
46 configure(os.args[1..]) or {
47 eprintln(err)
48 exit(1)
49 }
50}
51