summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go-native.inc
blob: 35561768dfa5ed9bbfb84d544bcf7806b3573abe (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
# Use immediate assingment here to get the original (/usr/lib)
# instead of the one rewritten by native.bbclass.
nonstaging_libdir := "${libdir}"

inherit native

SRC_URI_append = " https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz;name=bootstrap;subdir=go1.4"
SRC_URI[bootstrap.md5sum] = "dbf727a4b0e365bf88d97cbfde590016"
SRC_URI[bootstrap.sha256sum] = "f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52"

export GOOS = "${BUILD_GOOS}"
export GOARCH = "${BUILD_GOARCH}"
export GOTMPDIR ?= "${WORKDIR}/go-tmp"
GOTMPDIR[vardepvalue] = ""
CC = "${@d.getVar('BUILD_CC').strip()}"

export CGO_ENABLED = "1"
GOMAKEARGS ?= "--no-banner"

do_configure() {
	cd ${WORKDIR}/go1.4/go/src
	CGO_ENABLED=0 GOROOT=${WORKDIR}/go1.4/go ./make.bash
}

do_compile() {
	export GOROOT_FINAL="${nonstaging_libdir}/go"
	export GOROOT_BOOTSTRAP="${WORKDIR}/go1.4/go"

	cd src
	./make.bash ${GOMAKEARGS}
	cd ${B}
}
do_compile[dirs] =+ "${GOTMPDIR} ${B}/bin"
do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin"

make_wrapper() {
	rm -f ${D}${bindir}/$2$3
	cat <<END >${D}${bindir}/$2$3
#!/bin/bash
here=\`dirname \$0\`
export GOROOT="${GOROOT:-\`readlink -f \$here/../lib/go\`}"
\$here/../lib/go/bin/$1 "\$@"
END
	chmod +x ${D}${bindir}/$2
}

do_install() {
	install -d ${D}${libdir}/go
	cp --preserve=mode,timestamps -R ${B}/pkg ${D}${libdir}/go/
	install -d ${D}${libdir}/go/src
	(cd ${S}/src; for d in *; do \
		[ -d $d ] && cp -a ${S}/src/$d ${D}${libdir}/go/src/; \
	done)
	find ${D}${libdir}/go/src -depth -type d -name testdata -exec rm -rf {} \;
	install -d ${D}${bindir} ${D}${libdir}/go/bin
	for f in ${B}/bin/*
	do
		base=`basename $f`
		install -m755 $f ${D}${libdir}/go/bin
		make_wrapper $base $base
	done
}