summaryrefslogtreecommitdiffstats
path: root/plugins/go/go-1-fixes.patch
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/go/go-1-fixes.patch')
-rw-r--r--plugins/go/go-1-fixes.patch108
1 files changed, 108 insertions, 0 deletions
diff --git a/plugins/go/go-1-fixes.patch b/plugins/go/go-1-fixes.patch
new file mode 100644
index 0000000..27281c7
--- /dev/null
+++ b/plugins/go/go-1-fixes.patch
@@ -0,0 +1,108 @@
+This file is part of MXE.
+See index.html for further information.
+
+Contains ad hoc patches for cross building.
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sat, 25 Jun 2016 13:51:06 +0200
+Subject: [PATCH] cgo: add environmental variable override for pkg-config
+
+Allow overriding default name of `pkg-config` utility via
+environmental variable PKG_CONFIG (same as used by autoconf
+pkg.m4 macros). This facilitates easy cross-compilation of cgo
+code.
+
+Original patch against Go <= 1.4 was written by
+xnox_canonical <dimitri.ledkov@canonical.com> in 2014.
+Source: https://codereview.appspot.com/104960043/
+
+Rebased against Go 1.6.2 by Boris Nagaev <bnagaev@gmail.com>.
+
+diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
+index 1111111..2222222 100644
+--- a/src/cmd/dist/build.go
++++ b/src/cmd/dist/build.go
+@@ -41,6 +41,7 @@ var (
+ defaultldflags string
+ defaultcxxtarget string
+ defaultcctarget string
++ defaultpkgconfigtarget string
+ rebuildall bool
+ defaultclang bool
+
+@@ -203,6 +204,12 @@ func xinit() {
+ }
+ defaultcxxtarget = b
+
++ b = os.Getenv("PKG_CONFIG")
++ if b == "" {
++ b = "pkg-config"
++ }
++ defaultpkgconfigtarget = b
++
+ // For tools being invoked but also for os.ExpandEnv.
+ os.Setenv("GO386", go386)
+ os.Setenv("GOARCH", goarch)
+diff --git a/src/cmd/dist/buildgo.go b/src/cmd/dist/buildgo.go
+index 1111111..2222222 100644
+--- a/src/cmd/dist/buildgo.go
++++ b/src/cmd/dist/buildgo.go
+@@ -15,6 +15,7 @@ import "fmt"
+ // package main
+ // const defaultCC = <defaultcc>
+ // const defaultCXX = <defaultcxx>
++// const defaultPkgConfig = <defaultpkgconfig>
+ //
+ // It is invoked to write cmd/go/zdefaultcc.go
+ // but we also write cmd/cgo/zdefaultcc.go
+@@ -27,8 +28,9 @@ func mkzdefaultcc(dir, file string) {
+ "package main\n"+
+ "\n"+
+ "const defaultCC = `%s`\n"+
+- "const defaultCXX = `%s`\n",
+- defaultcctarget, defaultcxxtarget)
++ "const defaultCXX = `%s`\n"+
++ "const defaultPkgConfig = `%s`\n",
++ defaultcctarget, defaultcxxtarget, defaultpkgconfigtarget)
+
+ writefile(out, file, writeSkipSame)
+
+diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
+index 1111111..2222222 100644
+--- a/src/cmd/go/build.go
++++ b/src/cmd/go/build.go
+@@ -1575,13 +1575,19 @@ func (b *builder) build(a *action) (err error) {
+ return nil
+ }
+
++// pkgconfigCmd returns a pkg-config binary name
++// defaultPkgConfig is defined in zdefaultcc.go, written by cmd/dist.
++func (b *builder) pkgconfigCmd() string {
++ return envList("PKG_CONFIG", defaultPkgConfig)[0]
++}
++
+ // Calls pkg-config if needed and returns the cflags/ldflags needed to build the package.
+ func (b *builder) getPkgConfigFlags(p *Package) (cflags, ldflags []string, err error) {
+ if pkgs := p.CgoPkgConfig; len(pkgs) > 0 {
+ var out []byte
+- out, err = b.runOut(p.Dir, p.ImportPath, nil, "pkg-config", "--cflags", pkgs)
++ out, err = b.runOut(p.Dir, p.ImportPath, nil, b.pkgconfigCmd(), "--cflags", pkgs)
+ if err != nil {
+- b.showOutput(p.Dir, "pkg-config --cflags "+strings.Join(pkgs, " "), string(out))
++ b.showOutput(p.Dir, b.pkgconfigCmd()+" --cflags "+strings.Join(pkgs, " "), string(out))
+ b.print(err.Error() + "\n")
+ err = errPrintedOutput
+ return
+@@ -1589,9 +1595,9 @@ func (b *builder) getPkgConfigFlags(p *Package) (cflags, ldflags []string, err e
+ if len(out) > 0 {
+ cflags = strings.Fields(string(out))
+ }
+- out, err = b.runOut(p.Dir, p.ImportPath, nil, "pkg-config", "--libs", pkgs)
++ out, err = b.runOut(p.Dir, p.ImportPath, nil, b.pkgconfigCmd(), "--libs", pkgs)
+ if err != nil {
+- b.showOutput(p.Dir, "pkg-config --libs "+strings.Join(pkgs, " "), string(out))
++ b.showOutput(p.Dir, b.pkgconfigCmd()+" --libs "+strings.Join(pkgs, " "), string(out))
+ b.print(err.Error() + "\n")
+ err = errPrintedOutput
+ return