]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix LDFLAGS handling, enable misc/cgo/testso on Darwin
authorShenghou Ma <minux.ma@gmail.com>
Tue, 21 May 2013 16:32:03 +0000 (00:32 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 21 May 2013 16:32:03 +0000 (00:32 +0800)
Fixes #5479.

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/9416047

misc/cgo/testso/cgoso.go
misc/cgo/testso/test.bash
src/cmd/go/build.go
src/run.bash

index 216cb1f05f55b930f5b97980a228fc2787b8598c..0f800afb17e9fc85256adf617dbf9613823fc2de 100644 (file)
@@ -5,7 +5,15 @@
 package cgosotest
 
 /*
-#cgo LDFLAGS: -L. -lcgosotest
+// intentionally write the same LDFLAGS differently
+// to test correct handling of LDFLAGS.
+#cgo linux LDFLAGS: -L. -lcgosotest
+#cgo freebsd LDFLAGS: -L. -l cgosotest
+#cgo openbsd LDFLAGS: -L. -l cgosotest
+#cgo netbsd LDFLAGS: -L. libcgosotest.so
+#cgo darwin LDFLAGS: -L. libcgosotest.dylib
+#cgo windows LDFLAGS: -L. libcgosotest.dll
+
 void init(void);
 void sofunc(void);
 */
index 5f113d21629c26e5cd9bbd512bbac9a0c77c5133..f9fad126eb310cfb5d11605c818d835379a2980e 100755 (executable)
@@ -4,7 +4,19 @@
 # license that can be found in the LICENSE file.
 
 set -e
-$(go env CC) $(go env GOGCCFLAGS) -shared -o libcgosotest.so cgoso_c.c
+
+args=
+dyld_envvar=LD_LIBRARY_PATH
+ext=so
+if [ "$(uname)" == "Darwin" ]; then
+       args="-undefined suppress -flat_namespace"
+       dyld_envvar=DYLD_LIBRARY_PATH
+       ext=dylib
+fi
+
+dylib=libcgosotest.$ext
+$(go env CC) $(go env GOGCCFLAGS) -shared $args -o $dylib cgoso_c.c
 go build main.go
-LD_LIBRARY_PATH=. ./main
-rm -f libcgosotest.so main
+
+eval "$dyld_envvar"=. ./main
+rm -rf $dylib main *.dSYM
index 025b258bf576b12b6d16ce9ec4cac8c5f7b74db8..e1caf09f8300b273aabad950484347d21983c4f9 100644 (file)
@@ -1855,14 +1855,24 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo,
        var linkobj []string
 
        var bareLDFLAGS []string
-       // filter out -lsomelib, and -framework X if on Darwin
+       // filter out -lsomelib, -l somelib, *.{so,dll,dylib}, and (on Darwin) -framework X
        for i := 0; i < len(cgoLDFLAGS); i++ {
                f := cgoLDFLAGS[i]
-               if !strings.HasPrefix(f, "-l") {
-                       if goos == "darwin" && f == "-framework" { // skip the -framework X
-                               i += 1
-                               continue
+               switch {
+               // skip "-lc" or "-l somelib"
+               case strings.HasPrefix(f, "-l"):
+                       if f == "-l" {
+                               i++
                        }
+               // skip "-framework X" on Darwin
+               case goos == "darwin" && f == "-framework":
+                       i++
+               // skip "*.{dylib,so,dll}"
+               case strings.HasSuffix(f, ".dylib"),
+                       strings.HasSuffix(f, ".so"),
+                       strings.HasSuffix(f, ".dll"):
+                       continue
+               default:
                        bareLDFLAGS = append(bareLDFLAGS, f)
                }
        }
index 305ff7f417d52e3abb5d74f36c6e9608386f56ab..03570ab3285c6e32e15e3095986905b7e9634e2e 100755 (executable)
@@ -104,7 +104,6 @@ esac
 
 [ "$CGO_ENABLED" != 1 ] ||
 [ "$GOHOSTOS" == windows ] ||
-[ "$GOHOSTOS" == darwin ] ||
 (xcd ../misc/cgo/testso
 ./test.bash
 ) || exit $?