]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: cgo to use GOARCH from the environment, not runtime.GOARCH (otherwise it results...
authorJaroslavas Počepko <jp@webmaster.ms>
Mon, 19 Sep 2011 15:50:59 +0000 (11:50 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 19 Sep 2011 15:50:59 +0000 (11:50 -0400)
R=rsc, adg
CC=golang-dev
https://golang.org/cl/4978061

src/cmd/cgo/gcc.go
src/cmd/cgo/main.go

index 7ec4d8ccf965f7bcc84406b6409eb905dea50c00..04d95f0b9b0bbd7ad596b34aaac58e883b6e65ad 100644 (file)
@@ -20,7 +20,6 @@ import (
        "go/parser"
        "go/token"
        "os"
-       "runtime"
        "strconv"
        "strings"
        "unicode"
@@ -91,9 +90,9 @@ NextLine:
                case 2:
                        k = kf[1]
                        switch kf[0] {
-                       case runtime.GOOS:
-                       case runtime.GOARCH:
-                       case runtime.GOOS + "/" + runtime.GOARCH:
+                       case goos:
+                       case goarch:
+                       case goos + "/" + goarch:
                        default:
                                continue NextLine
                        }
@@ -688,7 +687,7 @@ func (p *Package) gccName() (ret string) {
 
 // gccMachine returns the gcc -m flag to use, either "-m32" or "-m64".
 func (p *Package) gccMachine() []string {
-       switch runtime.GOARCH {
+       switch goarch {
        case "amd64":
                return []string{"-m64"}
        case "386":
index be9c2bc4fbdbd45eddb3488c3dd72e19b6c2c583..106698114508ff79e6424cb91b9c99b6c3af3ccc 100644 (file)
@@ -20,6 +20,7 @@ import (
        "os"
        "path/filepath"
        "reflect"
+       "runtime"
        "strings"
 )
 
@@ -122,6 +123,8 @@ var fset = token.NewFileSet()
 
 var dynobj = flag.String("dynimport", "", "if non-empty, print dynamic import data for that file")
 
+var goarch, goos string
+
 func main() {
        flag.Usage = usage
        flag.Parse()
@@ -162,13 +165,17 @@ func main() {
 
        goFiles := args[i:]
 
-       arch := os.Getenv("GOARCH")
-       if arch == "" {
-               fatalf("$GOARCH is not set")
+       goarch = runtime.GOARCH
+       if s := os.Getenv("GOARCH"); s != "" {
+               goarch = s
+       }
+       goos = runtime.GOOS
+       if s := os.Getenv("GOOS"); s != "" {
+               goos = s
        }
-       ptrSize := ptrSizeMap[arch]
+       ptrSize := ptrSizeMap[goarch]
        if ptrSize == 0 {
-               fatalf("unknown $GOARCH %q", arch)
+               fatalf("unknown $GOARCH %q", goarch)
        }
 
        // Clear locale variables so gcc emits English errors [sic].