aboutsummaryrefslogtreecommitdiffstats
path: root/community/go/APKBUILD
blob: 2f33f72fb6f327422dc2bdaee869c93b12221a58 (plain) (blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Contributor: S├Âren Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=go
pkgver=1.11
# This should be the latest commit on the corresponding release branch
# https://github.com/golang/tools/commits/release-branch.go1.10
_toolsver="e9928cbe4ab476eebf6ff177f77b344773acfa9b"
pkgrel=0
pkgdesc="Go programming language compiler"
url="http://www.golang.org/"
arch="all"
license="BSD"
depends="binutils gcc"
depends_dev=""
makedepends="bash go-bootstrap"
options="!strip"
provides="go-bootstrap=$pkgver-r$pkgrel"
install=""
subpackages="$pkgname-doc"
source="http://golang.org/dl/go${pkgver/_/}.src.tar.gz
	go-tools-${pkgver/_/}-$_toolsver.tar.gz::https://github.com/golang/tools/archive/${_toolsver}.tar.gz
	default-buildmode-pie.patch
	set-external-linker.patch
	"

# secfixes:
#   1.9.4-r0:
#     - CVE-2018-6574

# NOTE: building go for x86 with grsec kernel requires:
#           sysctl -w kernel.modify_ldt=1

if [ "$CBUILD" = "$CTARGET" ]; then
	makedepends="go-bootstrap $makedepends"
	provides="go-bootstrap=$pkgver-r$pkgrel"
	subpackages="$subpackages $pkgname-tools"
	_gotools="cover godoc stringer"
else
	pkgname="go-bootstrap"
	makedepends="go $makedepends"
	# Go expect host linker instead of the cross-compiler
	export CC_FOR_TARGET="$CC"
	export CC="${HOSTLD:-gcc}"
	export CXX="${HOSTLD:-g++}"
	export LD="${HOSTLD:-ld}"
fi

_tooldir="$srcdir"/tools-${_toolsver}

case "$CTARGET_ARCH" in
aarch64)export GOARCH="arm64" ;;
armhf)  export GOARCH="arm" GOARM=6 ;;
armv7)  export GOARCH="arm" GOARM=7 ;;
s390x)  export GOARCH="s390x" ;;
x86)    export GOARCH="386" GO386=387 ;;
x86_64) export GOARCH="amd64" ;;
ppc64le) export GOARCH="ppc64le" ;;
mips)   export GOARCH="mips" ;;
mips64) export GOARCH="mips64" ;;
mips64el) export GOARCH="mips64le" ;;
mipsel) export GOARCH="mipsle" ;;
*)      die "Unsupported arch" ;;
esac

builddir="$srcdir"/go
build() {
	cd "$builddir/src"

	export GOOS="linux"
	export GOPATH="$srcdir"
	export GOROOT="$builddir"
	export GOBIN="$GOROOT"/bin
	export GOROOT_FINAL=/usr/lib/go
	local p; for p in /usr/lib/go-bootstrap /usr/lib/go-linux-$GOARCH-bootstrap /usr/lib/go; do
		if [ -d "$p" ]; then
			export GOROOT_BOOTSTRAP="$p"
			break
		fi
	done

	./make.bash

	# copied from bootstrap.bash to fixup cross-built bootstrap go
	if [ "$CBUILD" != "$CTARGET" ]; then
		local gohostos="$(../bin/go env GOHOSTOS)"
		local gohostarch="$(../bin/go env GOHOSTARCH)"
		mv ../bin/*_*/* ../bin
		rmdir ../bin/*_*
		rm -rf "../pkg/${gohostos}_${gohostarch}"* "../pkg/tool/${gohostos}_${gohostarch}"*
		rm -rf ../pkg/bootstrap ../pkg/obj
	fi

	# FIXME some tests fail:
	# PATH="$GOROOT/bin:$PATH" ./run.bash -no-rebuild

	mkdir -p "$GOPATH"/src/golang.org/x/tools
	cp -r "$_tooldir"/* "$GOPATH"/src/golang.org/x/tools

	for tool in $_gotools; do
		"$GOROOT"/bin/go install golang.org/x/tools/cmd/$tool
	done
}

check() {
	cd "$builddir"
	./bin/go run doc/play/hello.go
}

package() {
	cd "$builddir"
	mkdir -p "$pkgdir"/usr/bin "$pkgdir"/usr/lib/go/bin "$pkgdir"/usr/share/doc/go

	for binary in go gofmt; do
		install -Dm755 bin/"$binary" "$pkgdir"/usr/lib/go/bin/"$binary"
		ln -s /usr/lib/go/bin/"$binary" "$pkgdir"/usr/bin/
	done

	cp -a pkg lib "$pkgdir"/usr/lib/go
	cp -r doc misc "$pkgdir"/usr/share/doc/go
	rm -rf "$pkgdir"/usr/lib/go/pkg/obj
	rm -rf "$pkgdir"/usr/lib/go/pkg/bootstrap
	rm -f  "$pkgdir"/usr/lib/go/pkg/tool/*/api

	# The source needs to be installed due to an upstream
	# bug (https://github.com/golang/go/issues/2775).
	# When this is resolved we can split out the source to a
	# go-src sub package.
	mkdir -p "$pkgdir"/usr/lib/go/
	cp -a "$builddir"/src "$pkgdir"/usr/lib/go

	# Remove tests from /usr/lib/go/src.
	# Those shouldn't be affacted by the upstream bug (see above).
	find "$pkgdir"/usr/lib/go/src \( -type f -a -name "*_test.go" \) \
		-exec rm -rf \{\} \+
	find "$pkgdir"/usr/lib/go/src \( -type d -a -name "testdata" \) \
		-exec rm -rf \{\} \+
	find "$pkgdir"/usr/lib/go/src -type f -a \( -name "*.bash" -o -name "*.rc" -o -name "*.bat" \) \
		-exec rm -rf \{\} \+
}

tools() {
	pkgdesc="Go programming language tools"
	depends="$pkgname"

	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/usr/lib/go/bin \
		"$subpkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH

	for tool in $_gotools; do
		if [ -f "$pkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/$tool ]; then
			mv "$pkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/$tool \
				"$subpkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/$tool
		fi
		if [ -f "$builddir/bin/$tool" ]; then
			install -Dm755 "$builddir/bin/$tool" "$subpkgdir"/usr/lib/go/bin/"$tool"
			ln -s /usr/lib/go/bin/"$tool" "$subpkgdir"/usr/bin/
		fi
	done
}

sha512sums="2758b7924b4b8cffc30b56fbf039b8e23d1a3c42506ed4997bd64531ba742e2c60e95d1fa70cae2ccda45d1959fadccfd2404af87d962530e4b1d3556c4aaf43  go1.11.src.tar.gz
3b0bf5d4dc60bae92b04b9be9d193a36a35d4abbfce39480a02066ad5557f7529a088b233395c82727e2ebc312aff2fd5e3c9f00cca491e2a8db48e5c31657a4  go-tools-1.11-e9928cbe4ab476eebf6ff177f77b344773acfa9b.tar.gz
a8f3afd97992f03ccf2680cde214eefccac47daeb9eeb689b5e0b206ea3c19cfb23d448a4eb532894d830d4b91cd97b249e88f04c17feba02d9e243b40243bd0  default-buildmode-pie.patch
6abfdd8521b61ce1e823465f9b950a75dc235d7d58cc4c641c4e7830f7da28b8c57be53aef85641ff79bc95d7bd47bb0796659309d9d8e7907e29df520b150b0  set-external-linker.patch"