summaryrefslogtreecommitdiffstats
path: root/plugins/go/go-1-fixes.patch
blob: 27281c76673038acea5f4770267cbd6f2f980f76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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