]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: add -extar option to set ar program for c-archive
authorIan Lance Taylor <iant@golang.org>
Mon, 25 Jan 2016 19:44:02 +0000 (11:44 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 26 Jan 2016 18:52:36 +0000 (18:52 +0000)
People who want to use -buildmode=c-archive in unusual cross-compilation
setups will need something like this.  It could also be done via (yet
another) environment variable but I use -extar by analogy with the
existing -extld.

Change-Id: I354cfabc4c470603affd13cd946997b3a24c0e6c
Reviewed-on: https://go-review.googlesource.com/18913
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/testcarchive/test.bash
src/cmd/link/doc.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/pobj.go

index f4b4a3079fe1f06f6f5a401538ea35b4f9ff8363..f4e7c458ec670f50f2fefce688fc98702c6f8230 100755 (executable)
@@ -85,4 +85,22 @@ if ! $bin; then
 fi
 rm -rf libgo4.a libgo4.h testp pkg
 
+rm -f testar
+cat >testar <<EOF
+#!/usr/bin/env bash
+while expr \$1 : '[-]' >/dev/null; do
+  shift
+done
+echo "testar" > \$1
+echo "testar" > $(pwd)/testar.ran
+EOF
+chmod +x testar
+rm -f testar.ran
+GOPATH=$(pwd) go build -buildmode=c-archive -ldflags=-extar=$(pwd)/testar -o libgo4.a libgo4
+if ! test -f testar.ran; then
+    echo "FAIL test5"
+    status=1
+fi
+rm -rf libgo4.a libgo4.h testar testar.ran pkg
+
 exit $status
index 69f9b5785907bd3458dee8e685122bc12f119cfe..ffaead7ba0d31a6f77cce12c2f15b04e5edb3af6 100644 (file)
@@ -52,6 +52,9 @@ Flags:
                The dynamic header is on by default, even without any
                references to dynamic libraries, because many common
                system tools now assume the presence of the header.
+       -extar ar
+               Set the external archive program (default "ar").
+               Used only for -buildmode=c-archive.
        -extld linker
                Set the external linker (default "clang" or "gcc").
        -extldflags flags
index a23a437e3d0023001ec5dc1c866839c770e0752b..bdfa0563c3d269c659ccb628944883c5486361e7 100644 (file)
@@ -207,6 +207,7 @@ var (
        tmpdir             string
        extld              string
        extldflags         string
+       extar              string
        libgccfile         string
        debug_s            int // backup old value of debug['s']
        Ctxt               *Link
@@ -1015,8 +1016,12 @@ func archive() {
                return
        }
 
+       if extar == "" {
+               extar = "ar"
+       }
+
        mayberemoveoutfile()
-       argv := []string{"ar", "-q", "-c", "-s", outfile}
+       argv := []string{extar, "-q", "-c", "-s", outfile}
        argv = append(argv, fmt.Sprintf("%s/go.o", tmpdir))
        argv = append(argv, hostobjCopy()...)
 
index 319e85046706858b3b3b73aa8e7b138a4ac2c2b1..808d377f8a0473ea1744658e9a49027219d30725 100644 (file)
@@ -89,6 +89,7 @@ func Ldmain() {
        flag.Var(&Buildmode, "buildmode", "set build `mode`")
        obj.Flagcount("c", "dump call graph", &Debug['c'])
        obj.Flagcount("d", "disable dynamic executable", &Debug['d'])
+       obj.Flagstr("extar", "archive program for buildmode=c-archive", &extar)
        obj.Flagstr("extld", "use `linker` when linking in external mode", &extld)
        obj.Flagstr("extldflags", "pass `flags` to external linker", &extldflags)
        obj.Flagcount("f", "ignore version mismatch", &Debug['f'])