1DEPENDS = "virtual/${TUNE_PKGARCH}-go go-native"
2DEPENDS:class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk"
3PROVIDES = "virtual/${TARGET_PREFIX}go-runtime"
4
5DEBUG_PREFIX_MAP = "\
6                     -fdebug-prefix-map=${STAGING_DIR_HOST}= \
7                     -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
8"
9
10export CGO_CFLAGS = "${CFLAGS}"
11export CGO_CPPFLAGS = "${CPPFLAGS}"
12export CGO_CXXFLAGS = "${CXXFLAGS}"
13# Filter out -fdebug-prefix-map options as they clash with the GO's build system
14export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"
15export GOCACHE = "${B}/.cache"
16
17GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${LDFLAGS}"
18GO_SHLIB_LDFLAGS ?= '-ldflags="--linkmode=external -extldflags '${GO_EXTLDFLAGS}'"'
19
20do_configure() {
21	:
22}
23
24do_configure:libc-musl() {
25	rm -f ${S}/src/runtime/race/*.syso
26}
27
28do_compile() {
29	export CC_FOR_${TARGET_GOTUPLE}="${CC}"
30	export CXX_FOR_${TARGET_GOTUPLE}="${CXX}"
31
32	cd src
33	./make.bash --target-only --no-banner std
34	if [ -n "${GO_DYNLINK}" ]; then
35		export GOTOOLDIR="${B}/pkg/tool/native_native"
36		CC="$CC_FOR_${TARGET_GOTUPLE}" GOARCH="${TARGET_GOARCH}" GOOS="${TARGET_GOOS}" GOROOT=${B} \
37			$GOTOOLDIR/go_bootstrap install -linkshared -buildmode=shared ${GO_SHLIB_LDFLAGS} std
38	fi
39	cd ${B}
40}
41do_compile[dirs] =+ "${GOTMPDIR} ${B}/bin ${B}/pkg"
42do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
43
44do_install() {
45	install -d ${D}${libdir}/go/src
46	cp --preserve=mode,timestamps -R ${B}/pkg ${D}${libdir}/go/
47	if [ "${BUILD_GOTUPLE}" != "${TARGET_GOTUPLE}" ]; then
48		rm -rf ${D}${libdir}/go/pkg/${BUILD_GOTUPLE}
49		rm -rf ${D}${libdir}/go/pkg/obj/${BUILD_GOTUPLE}
50	fi
51	rm -rf ${D}${libdir}/go/pkg/tool
52	rm -rf ${D}${libdir}/go/pkg/obj
53	rm -rf ${D}${libdir}/go/pkg/bootstrap
54	find src -mindepth 1 -maxdepth 1 -type d | while read srcdir; do
55		cp --preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
56	done
57	find ${D}${libdir}/go/src -depth -type d -name testdata -exec rm -rf {} \;
58	rm -f ${D}${libdir}/go/src/cmd/dist/dist
59        rm -f ${D}${libdir}/go/src/cmd/cgo/zdefaultcc.go
60        rm -f ${D}${libdir}/go/src/cmd/go/internal/cfg/zdefaultcc.go
61
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