summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2017-03-07 22:40:22 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-10 15:51:55 +0000
commit760e81678cec80dcdaab12c2a0a0148e3e0ba275 (patch)
tree6b587a2e9bd13c68788c1ff20df54db7e2f38c53 /meta/classes
parent0efe58df2e5389f86dfbd53f90afc8f2970def7d (diff)
downloadpoky-760e81678cec80dcdaab12c2a0a0148e3e0ba275.tar.gz
go: Add recipes for golang compilers and tools
* This is converging the recipes for go from meta-virtualization and oe-meta-go * Add recipes for go 1.7 * go.bbclass is added to ease out writing recipes for go packages * go-examples: Add an example, helloworld written in go This should serve as temlate for writing go recipes * Disable for musl, at least for now * Disable for x32/ppc32 which is not supported (From OE-Core rev: 78615e9260fb5d6569de4883521b049717fa4340) Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/go.bbclass79
-rw-r--r--meta/classes/goarch.bbclass50
2 files changed, 129 insertions, 0 deletions
diff --git a/meta/classes/go.bbclass b/meta/classes/go.bbclass
new file mode 100644
index 0000000000..f1984604b0
--- /dev/null
+++ b/meta/classes/go.bbclass
@@ -0,0 +1,79 @@
1inherit goarch
2
3# Incompatible with musl, at least for now
4COMPATIBLE_HOST_libc-musl_class-target = "null"
5# x32 ABI is not supported on go compiler so far
6COMPATIBLE_HOST_linux-gnux32 = "null"
7# ppc32 is not supported in go compilers
8COMPATIBLE_HOST_powerpc = "null"
9
10GOROOT_class-native = "${STAGING_LIBDIR_NATIVE}/go"
11GOROOT = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go"
12GOBIN_FINAL_class-native = "${GOROOT_FINAL}/bin"
13GOBIN_FINAL = "${GOROOT_FINAL}/bin/${GOOS}_${GOARCH}"
14
15export GOOS = "${TARGET_GOOS}"
16export GOARCH = "${TARGET_GOARCH}"
17export GOARM = "${TARGET_GOARM}"
18export CGO_ENABLED = "1"
19export GOROOT
20export GOROOT_FINAL = "${libdir}/${TARGET_SYS}/go"
21export GOBIN_FINAL
22export GOPKG_FINAL = "${GOROOT_FINAL}/pkg/${GOOS}_${GOARCH}"
23export GOSRC_FINAL = "${GOROOT_FINAL}/src"
24export GO_GCFLAGS = "${TARGET_CFLAGS}"
25export GO_LDFLAGS = "${TARGET_LDFLAGS}"
26export CGO_CFLAGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS} ${TARGET_CFLAGS}"
27export CGO_CPPFLAGS = "${TARGET_CPPFLAGS}"
28export CGO_CXXFLAGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS} ${TARGET_CXXFLAGS}"
29export CGO_LDFLAGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS} ${TARGET_LDFLAGS}"
30
31DEPENDS += "go-cross-${TARGET_ARCH}"
32DEPENDS_class-native += "go-native"
33
34FILES_${PN}-staticdev += "${GOSRC_FINAL}/${GO_IMPORT}"
35FILES_${PN}-staticdev += "${GOPKG_FINAL}/${GO_IMPORT}*"
36
37GO_INSTALL ?= "${GO_IMPORT}/..."
38
39do_go_compile() {
40 GOPATH=${S}:${STAGING_LIBDIR}/${TARGET_SYS}/go go env
41 if test -n "${GO_INSTALL}" ; then
42 GOPATH=${S}:${STAGING_LIBDIR}/${TARGET_SYS}/go go install -v ${GO_INSTALL}
43 fi
44}
45
46do_go_install() {
47 rm -rf ${WORKDIR}/staging
48 install -d ${WORKDIR}/staging${GOROOT_FINAL} ${D}${GOROOT_FINAL}
49 tar -C ${S} -cf - . | tar -C ${WORKDIR}/staging${GOROOT_FINAL} -xpvf -
50
51 find ${WORKDIR}/staging${GOROOT_FINAL} \( \
52 -name \*.indirectionsymlink -o \
53 -name .git\* -o \
54 -name .hg -o \
55 -name .svn -o \
56 -name .pc\* -o \
57 -name patches\* \
58 \) -print0 | \
59 xargs -r0 rm -rf
60
61 tar -C ${WORKDIR}/staging${GOROOT_FINAL} -cf - . | \
62 tar -C ${D}${GOROOT_FINAL} -xpvf -
63
64 chown -R root:root "${D}${GOROOT_FINAL}"
65
66 if test -e "${D}${GOBIN_FINAL}" ; then
67 install -d -m 0755 "${D}${bindir}"
68 find "${D}${GOBIN_FINAL}" ! -type d -print0 | xargs -r0 mv --target-directory="${D}${bindir}"
69 rmdir -p "${D}${GOBIN_FINAL}" || true
70 fi
71}
72
73do_compile() {
74 do_go_compile
75}
76
77do_install() {
78 do_go_install
79}
diff --git a/meta/classes/goarch.bbclass b/meta/classes/goarch.bbclass
new file mode 100644
index 0000000000..4a5b2ec787
--- /dev/null
+++ b/meta/classes/goarch.bbclass
@@ -0,0 +1,50 @@
1BUILD_GOOS = "${@go_map_os(d.getVar('BUILD_OS', True), d)}"
2BUILD_GOARCH = "${@go_map_arch(d.getVar('BUILD_ARCH', True), d)}"
3BUILD_GOTUPLE = "${BUILD_GOOS}_${BUILD_GOARCH}"
4HOST_GOOS = "${@go_map_os(d.getVar('HOST_OS', True), d)}"
5HOST_GOARCH = "${@go_map_arch(d.getVar('HOST_ARCH', True), d)}"
6HOST_GOARM = "${@go_map_arm(d.getVar('HOST_ARCH', True), d.getVar('TUNE_FEATURES', True), d)}"
7HOST_GOTUPLE = "${HOST_GOOS}_${HOST_GOARCH}"
8TARGET_GOOS = "${@go_map_os(d.getVar('TARGET_OS', True), d)}"
9TARGET_GOARCH = "${@go_map_arch(d.getVar('TARGET_ARCH', True), d)}"
10TARGET_GOARM = "${@go_map_arm(d.getVar('TARGET_ARCH', True), d.getVar('TUNE_FEATURES', True), d)}"
11TARGET_GOTUPLE = "${TARGET_GOOS}_${TARGET_GOARCH}"
12GO_BUILD_BINDIR = "${@['bin/${HOST_GOTUPLE}','bin'][d.getVar('BUILD_GOTUPLE',True) == d.getVar('HOST_GOTUPLE',True)]}"
13
14def go_map_arch(a, d):
15 import re
16 if re.match('i.86', a):
17 return '386'
18 elif a == 'x86_64':
19 return 'amd64'
20 elif re.match('arm.*', a):
21 return 'arm'
22 elif re.match('aarch64.*', a):
23 return 'arm64'
24 elif re.match('mips64el*', a):
25 return 'mips64le'
26 elif re.match('mips64*', a):
27 return 'mips64'
28 elif re.match('mipsel*', a):
29 return 'mipsle'
30 elif re.match('mips*', a):
31 return 'mips'
32 elif re.match('p(pc|owerpc)(64)', a):
33 return 'ppc64'
34 elif re.match('p(pc|owerpc)(64el)', a):
35 return 'ppc64le'
36 else:
37 raise bb.parse.SkipPackage("Unsupported CPU architecture: %s" % a)
38
39def go_map_arm(a, f, d):
40 import re
41 if re.match('arm.*', a) and re.match('arm.*7.*', f):
42 return '7'
43 return ''
44
45def go_map_os(o, d):
46 if o.startswith('linux'):
47 return 'linux'
48 return o
49
50