1// Copyright 2018 syzkaller project authors. All rights reserved.
2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4package main
5
6import (
7	"fmt"
8	"os"
9	"runtime"
10	"strconv"
11	"strings"
12
13	"github.com/google/syzkaller/sys/targets"
14)
15
16func main() {
17	hostOS := or(os.Getenv("HOSTOS"), runtime.GOOS)
18	hostArch := or(os.Getenv("HOSTARCH"), runtime.GOARCH)
19	targetOS := or(os.Getenv("TARGETOS"), hostOS)
20	targetArch := or(os.Getenv("TARGETARCH"), hostArch)
21	targetVMArch := or(os.Getenv("TARGETVMARCH"), targetArch)
22	target := targets.Get(targetOS, targetArch)
23	if target == nil {
24		fmt.Printf("unknown target %v/%v\n", targetOS, targetArch)
25		os.Exit(1)
26	}
27	type Var struct {
28		Name string
29		Val  string
30	}
31	vars := []Var{
32		{"HOSTOS", hostOS},
33		{"HOSTARCH", hostArch},
34		{"TARGETOS", targetOS},
35		{"TARGETARCH", targetArch},
36		{"TARGETVMARCH", targetVMArch},
37		{"CC", target.CCompiler},
38		{"ADDCFLAGS", strings.Join(target.CrossCFlags, " ")},
39		{"NCORES", strconv.Itoa(runtime.NumCPU())},
40		{"EXE", target.ExeExtension},
41	}
42	for _, v := range vars {
43		fmt.Printf("export %v=%v\\n", v.Name, v.Val)
44	}
45}
46
47func or(s1, s2 string) string {
48	if s1 != "" {
49		return s1
50	}
51	return s2
52}
53