aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-env
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-06-05 17:14:47 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-06-06 10:02:03 +0200
commit6479ab2a752ba9ef714199de69d096cee0e6db2d (patch)
tree0bba334b61e1a2337cbd3e9af6e1b63ab12c480a /tools/syz-env
parent65c0e1a37ca36fb4799f0d896182a3d070f7a034 (diff)
Makefile, sys/targets: move all native compilation logic to sys/targets
We currently have native cross-compilation logic duplicated in Makefile and in sys/targets. Some pieces are missed in one place, some are in another. Only pkg/csource knows how to check for -static support. Move all CC/CFLAGS logic to sys/targets and pull results in Makefile. This should make Makefile work on distros that have broken x86_64-linux-gnu-gcc, now we will use just gcc. And this removes the need to define NOSTATIC, as it's always auto-detected. This also paves the way for making pkg/csource work on OSes other than Linux.
Diffstat (limited to 'tools/syz-env')
-rw-r--r--tools/syz-env/env.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/syz-env/env.go b/tools/syz-env/env.go
new file mode 100644
index 000000000..775f05ca2
--- /dev/null
+++ b/tools/syz-env/env.go
@@ -0,0 +1,52 @@
+// Copyright 2018 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "runtime"
+ "strconv"
+ "strings"
+
+ "github.com/google/syzkaller/sys/targets"
+)
+
+func main() {
+ hostOS := or(os.Getenv("HOSTOS"), runtime.GOOS)
+ hostArch := or(os.Getenv("HOSTARCH"), runtime.GOARCH)
+ targetOS := or(os.Getenv("TARGETOS"), hostOS)
+ targetArch := or(os.Getenv("TARGETARCH"), hostArch)
+ targetVMArch := or(os.Getenv("TARGETVMARCH"), targetArch)
+ target := targets.Get(targetOS, targetArch)
+ if target == nil {
+ fmt.Printf("unknown target %v/%v\n", targetOS, targetArch)
+ os.Exit(1)
+ }
+ type Var struct {
+ Name string
+ Val string
+ }
+ vars := []Var{
+ {"HOSTOS", hostOS},
+ {"HOSTARCH", hostArch},
+ {"TARGETOS", targetOS},
+ {"TARGETARCH", targetArch},
+ {"TARGETVMARCH", targetVMArch},
+ {"CC", target.CCompiler},
+ {"ADDCFLAGS", strings.Join(target.CrossCFlags, " ")},
+ {"NCORES", strconv.Itoa(runtime.NumCPU())},
+ {"EXE", target.ExeExtension},
+ }
+ for _, v := range vars {
+ fmt.Printf("export %v=%v\\n", v.Name, v.Val)
+ }
+}
+
+func or(s1, s2 string) string {
+ if s1 != "" {
+ return s1
+ }
+ return s2
+}