1DEPENDS = "virtual/${TUNE_PKGARCH}-go go-native"
2DEPENDS:class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk go-native"
3
4DEBUG_PREFIX_MAP = "\
5                     -fdebug-prefix-map=${STAGING_DIR_HOST}= \
6                     -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
7"
8
9export CGO_CFLAGS = "${CFLAGS}"
10export CGO_CPPFLAGS = "${CPPFLAGS}"
11export CGO_CXXFLAGS = "${CXXFLAGS}"
12# Filter out -fdebug-prefix-map options as they clash with the GO's build system
13export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"
14
15export GOCACHE = "${B}/.cache"
16GO_LDFLAGS = ""
17GO_LDFLAGS:class-nativesdk = " -linkmode external"
18export GO_LDFLAGS
19export GOBUILDFLAGS = "-gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -trimpath"
20CC:append:class-nativesdk = " ${SECURITY_NOPIE_CFLAGS}"
21
22do_configure[noexec] = "1"
23
24do_compile() {
25	export CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CC}"
26	export CXX_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CXX}"
27
28	cd src
29	./make.bash --target-only --no-banner
30	cd ${B}
31}
32do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
33
34do_install() {
35	install -d ${D}${libdir}/go/pkg/tool
36	cp --preserve=mode,timestamps -R ${B}/pkg/tool/${TARGET_GOTUPLE} ${D}${libdir}/go/pkg/tool/
37	install -d ${D}${libdir}/go/src
38	cp --preserve=mode,timestamps -R ${S}/src/cmd ${D}${libdir}/go/src/
39	find ${D}${libdir}/go/src -depth -type d -name testdata -exec rm -rf {} \;
40	install -d ${D}${libdir}/go/bin
41	install -d ${D}${bindir}
42	for f in ${B}/${GO_BUILD_BINDIR}/*; do
43		name=`basename $f`
44		install -m 0755 $f ${D}${libdir}/go/bin/
45		ln -sf ../${baselib}/go/bin/$name ${D}${bindir}/
46	done
47	rm -rf ${D}${libdir}/go/src
48}
49
50PACKAGES = "${PN} ${PN}-dev"
51FILES:${PN} = "${libdir}/go/bin ${libdir}/go/pkg/tool/${TARGET_GOTUPLE} ${bindir}"
52RDEPENDS:${PN} = "go-runtime"
53INSANE_SKIP:${PN} = "ldflags"
54
55BBCLASSEXTEND = "nativesdk"
56