1DEPENDS = "virtual/${TARGET_PREFIX}go go-native"
2DEPENDS_class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk"
3PROVIDES = "virtual/${TARGET_PREFIX}go-runtime"
4
5export GOHOSTOS = "${BUILD_GOOS}"
6export GOHOSTARCH = "${BUILD_GOARCH}"
7export GOOS = "${TARGET_GOOS}"
8export GOARCH = "${TARGET_GOARCH}"
9export GOARM = "${TARGET_GOARM}"
10export GO386 = "${TARGET_GO386}"
11export GOMIPS = "${TARGET_GOMIPS}"
12export GOROOT_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/go"
13export GOROOT_FINAL = "${libdir}/go"
14export CGO_CFLAGS = "${CFLAGS}"
15export CGO_CPPFLAGS = "${CPPFLAGS}"
16export CGO_CXXFLAGS = "${CXXFLAGS}"
17export CGO_LDFLAGS = "${LDFLAGS}"
18
19GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${LDFLAGS}"
20GO_SHLIB_LDFLAGS ?= '-ldflags="--linkmode=external -extldflags '${GO_EXTLDFLAGS}'"'
21
22do_configure() {
23	:
24}
25
26do_configure_libc-musl() {
27	rm -f ${S}/src/runtime/race/*.syso
28}
29
30do_compile() {
31	export CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CC}"
32	export CXX_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CXX}"
33
34	cd src
35	./make.bash --target-only --no-banner std
36	if [ -n "${GO_DYNLINK}" ]; then
37		export GOTOOLDIR="${B}/pkg/tool/native_native"
38		CC="$CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}" GOARCH="${TARGET_GOARCH}" GOOS="${TARGET_GOOS}" GOROOT=${B} \
39			$GOTOOLDIR/go_bootstrap install -linkshared -buildmode=shared ${GO_SHLIB_LDFLAGS} std
40	fi
41	cd ${B}
42}
43do_compile[dirs] =+ "${GOTMPDIR} ${B}/bin ${B}/pkg"
44do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
45
46do_install() {
47	install -d ${D}${libdir}/go/src
48	cp --preserve=mode,timestamps -R ${B}/pkg ${D}${libdir}/go/
49	if [ "${BUILD_GOTUPLE}" != "${TARGET_GOTUPLE}" ]; then
50		rm -rf ${D}${libdir}/go/pkg/${BUILD_GOTUPLE}
51		rm -rf ${D}${libdir}/go/pkg/obj/${BUILD_GOTUPLE}
52	fi
53	rm -rf ${D}${libdir}/go/pkg/tool
54	rm -rf ${D}${libdir}/go/pkg/obj
55	rm -rf ${D}${libdir}/go/pkg/bootstrap
56	find src -mindepth 1 -maxdepth 1 -type d | while read srcdir; do
57		cp --preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
58	done
59	find ${D}${libdir}/go/src -depth -type d -name testdata -exec rm -rf {} \;
60	rm -f ${D}${libdir}/go/src/cmd/dist/dist
61}
62
63ALLOW_EMPTY_${PN} = "1"
64FILES_${PN} = "${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*${SOLIBSDEV}"
65FILES_${PN}-dev = "${libdir}/go/src ${libdir}/go/pkg/include \
66                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*.shlibname \
67                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*.shlibname \
68                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*.shlibname \
69                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*.shlibname \
70                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*.shlibname \
71                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*.shlibname \
72                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*/*.shlibname \
73                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*.a \
74                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*.a \
75                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*.a \
76                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*.a \
77                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*.a \
78                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*.a \
79                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*/*.a \
80"
81FILES_${PN}-staticdev = "${libdir}/go/pkg/${TARGET_GOTUPLE}"
82
83# Go sources include some scripts and pre-built binaries for
84# multiple architectures.  The static .a files for dynamically-linked
85# runtime are also required in -dev.
86INSANE_SKIP_${PN}-dev = "staticdev file-rdeps arch"
87
88INHIBIT_PACKAGE_STRIP = "1"
89INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
90INHIBIT_SYSROOT_STRIP = "1"
91
92BBCLASSEXTEND = "nativesdk"
93