1DEPENDS = "virtual/${TUNE_PKGARCH}-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}"
18export GOCACHE = "${B}/.cache"
19
20GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${LDFLAGS}"
21GO_SHLIB_LDFLAGS ?= '-ldflags="--linkmode=external -extldflags '${GO_EXTLDFLAGS}'"'
22
23do_configure() {
24	:
25}
26
27do_configure_libc-musl() {
28	rm -f ${S}/src/runtime/race/*.syso
29}
30
31do_compile() {
32	export CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CC}"
33	export CXX_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CXX}"
34
35	cd src
36	./make.bash --target-only --no-banner std
37	if [ -n "${GO_DYNLINK}" ]; then
38		export GOTOOLDIR="${B}/pkg/tool/native_native"
39		CC="$CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}" GOARCH="${TARGET_GOARCH}" GOOS="${TARGET_GOOS}" GOROOT=${B} \
40			$GOTOOLDIR/go_bootstrap install -linkshared -buildmode=shared ${GO_SHLIB_LDFLAGS} std
41	fi
42	cd ${B}
43}
44do_compile[dirs] =+ "${GOTMPDIR} ${B}/bin ${B}/pkg"
45do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
46
47do_install() {
48	install -d ${D}${libdir}/go/src
49	cp --preserve=mode,timestamps -R ${B}/pkg ${D}${libdir}/go/
50	if [ "${BUILD_GOTUPLE}" != "${TARGET_GOTUPLE}" ]; then
51		rm -rf ${D}${libdir}/go/pkg/${BUILD_GOTUPLE}
52		rm -rf ${D}${libdir}/go/pkg/obj/${BUILD_GOTUPLE}
53	fi
54	rm -rf ${D}${libdir}/go/pkg/tool
55	rm -rf ${D}${libdir}/go/pkg/obj
56	rm -rf ${D}${libdir}/go/pkg/bootstrap
57	find src -mindepth 1 -maxdepth 1 -type d | while read srcdir; do
58		cp --preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
59	done
60	find ${D}${libdir}/go/src -depth -type d -name testdata -exec rm -rf {} \;
61	rm -f ${D}${libdir}/go/src/cmd/dist/dist
62}
63
64ALLOW_EMPTY_${PN} = "1"
65FILES_${PN} = "${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*${SOLIBSDEV}"
66FILES_${PN}-dev = "${libdir}/go/src ${libdir}/go/pkg/include \
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/*/*/*/*/*/*/*.shlibname \
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                   ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*/*.a \
81"
82FILES_${PN}-staticdev = "${libdir}/go/pkg/${TARGET_GOTUPLE}"
83
84# Go sources include some scripts and pre-built binaries for
85# multiple architectures.  The static .a files for dynamically-linked
86# runtime are also required in -dev.
87INSANE_SKIP_${PN}-dev = "staticdev file-rdeps arch"
88
89INHIBIT_PACKAGE_STRIP = "1"
90INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
91INHIBIT_SYSROOT_STRIP = "1"
92
93BBCLASSEXTEND = "nativesdk"
94