vinix-ports / tools / vinix-cc.v
31 lines · 29 sloc · 905 bytes
Raw
1// A single compiler name for build systems such as libtool that independently
2// expand CC and its arguments. Repeating musl's specs option makes GCC fail.
3module main
4
5import os
6
7fn main() {
8 driver := os.base(os.args[0])
9 root := os.getenv('VPAC_MAKEPKG_ROOT')
10 if !os.is_abs_path(root) {
11 eprintln('${driver} requires an absolute VPAC_MAKEPKG_ROOT')
12 exit(1)
13 }
14 specs := os.join_path(root, 'usr/lib/musl-gcc-sysroot.specs')
15 if !os.is_file(specs) {
16 eprintln('${driver}: missing installed musl specs at ${specs}')
17 exit(1)
18 }
19 prefix := os.getenv('CROSS_COMPILE')
20 compiler := if driver == 'vinix-c++' {
21 os.getenv_opt('VINIX_REAL_CXX') or { prefix + 'g++' }
22 } else {
23 os.getenv_opt('VINIX_REAL_CC') or { prefix + 'gcc' }
24 }
25 mut args := ['--sysroot=${root}', '-specs=${specs}']
26 args << os.args[1..]
27 os.execvp(compiler, args) or {
28 eprintln('${driver}: ${compiler}: ${err}')
29 exit(1)
30 }
31}
32