aboutsummaryrefslogtreecommitdiffstats
path: root/community/go/APKBUILD
blob: e4c2636b7b221c3ccdab18aa648c983ee201e803 (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
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
164
165
166
167
168
169
170
171
172
173
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Eivind Uggedal <eivind@uggedal.com>
pkgname=go
pkgver=1.8.1
# This should be the latest commit on the corresponding release branch
_toolsver="5682db0e919ed9cfc6f52ac32e170511a106eb3b"
pkgrel=1
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/_/}.tar.gz::https://github.com/golang/tools/archive/${_toolsver}.tar.gz
	default-buildmode-pie.patch
	set-external-linker.patch
	"

# 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"
	_gocross="darwin freebsd openbsd windows"
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}
for os in $_gocross; do
	subpackages="$subpackages $pkgname-cross-${os}:_crosspkg"
done

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

	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" ;;
	*)      die "Unsupported arch" ;;
	esac

	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
	for os in $_gocross; do
                local hostarch="$GOARCH"
		for arch in "386" "amd64"; do
			GOHOSTARCH=$hostarch GOARCH=$arch GOOS=$os ./make.bash
		done
	done

	# 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 || return 1

	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 || return 1
	done
}

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

	for binary in go gofmt; do
		mv bin/"$binary" "$pkgdir"/usr/lib/go/bin/ || return 1
		ln -s /usr/lib/go/bin/"$binary" "$pkgdir"/usr/bin/ || return 1
	done

	# 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.
	cp -a pkg src lib "$pkgdir"/usr/lib/go || return 1
	cp -r doc misc "$pkgdir"/usr/share/doc/go || return 1

	# 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 \{\} \+ || return 1
	find "$pkgdir"/usr/lib/go/src \( -type d -a -name "testdata" \) \
		-exec rm -rf \{\} \+ || return 1
	find "$pkgdir"/usr/lib/go/src -type f -a \( -name "*.bash" -o -name "*.rc" -o -name "*.bat" \) \
		-exec rm -rf \{\} \+ || return 1

	rm -rf "$pkgdir"/usr/lib/go/pkg/bootstrap
	rm -f  "$pkgdir"/usr/lib/go/pkg/tool/*/api
}

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

	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/usr/lib/go/bin
	for binary in "$builddir"/bin/*; do
		mv $binary "$subpkgdir"/usr/lib/go/bin || return 1
		ln -s /usr/lib/go/bin/"${binary##*/}" "$subpkgdir"/usr/bin/ || return 1
	done

	mkdir -p "$subpkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH
	cp "$subpkgdir"/usr/lib/go/bin/godoc \
		"$pkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/godoc || return 1

	for tool in $_gotools; do
		[ -f "$pkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/$tool ] \
			|| continue

		mv "$pkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/$tool \
			"$subpkgdir"/usr/lib/go/pkg/tool/linux_$GOARCH/$tool || return 1
	done
}

_crosspkg() {
	local name="$(echo "${subpkgname}" | cut -d '-' -f3)"
	pkgdesc="Go cross compiler for $name"
	depends="$pkgname"

	mkdir -p "$subpkgdir"/usr/lib/go/pkg/tool/
	mv "$pkgdir"/usr/lib/go/pkg/tool/${name}_* \
		"$subpkgdir"/usr/lib/go/pkg/tool/ || return 1
	mv "$pkgdir"/usr/lib/go/pkg/${name}_* \
		"$subpkgdir"/usr/lib/go/pkg/ || return 1
}

sha512sums="f01fe7b35ac23101610f6fc169b88dafe2edc49b3b044d5d0aff771b05dcb2c8d2e7a5090ed6dbe67f861e78e792ace32e209ed464399ca02dcd186b13ec8037  go1.8.1.src.tar.gz
343fca47f250278b22df1c1cd92cce91e01009043d05d8ccce095e4386fa0f5ca8ccaa58232635332c7288ceca9d2a240f774f8bb3b08129a681a582cba60248  go-tools-1.8.1.tar.gz
13cd386c38875b951da4057586007f3c67503dc79ddf57befbf763af85ec2cd2a2e6b00614450c179c93f1f8747ee7456ee412adccd08a5f115b33812598a148  default-buildmode-pie.patch
6b36f3780ab10e5c4902473a8ab5c0417220ece584b537517e9e60979bdc5a548ed14dd2546605392c89ec5ea6691769d337d34e2e19b92eba5bbca1898f4ada  set-external-linker.patch"