blob: dd485b6799b5815f1eb03e851499091e0824792e [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001inherit cross-canadian
2
Andrew Geissler028142b2023-05-05 11:29:21 -05003DEPENDS = "go-native virtual/${HOST_PREFIX}go virtual/nativesdk-${HOST_PREFIX}go-runtime \
4 virtual/${HOST_PREFIX}gcc virtual/nativesdk-libc \
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005 virtual/nativesdk-${HOST_PREFIX}compilerlibs"
6PN = "go-cross-canadian-${TRANSLATED_TARGET_ARCH}"
7
Brad Bishop19323692019-04-05 15:28:33 -04008# it uses gcc on build machine during go-cross-canadian bootstrap, but
9# the gcc version may be old and not support option '-fmacro-prefix-map'
10# which is one of default values of DEBUG_PREFIX_MAP
Patrick Williamsac13d5f2023-11-24 18:59:46 -060011DEBUG_PREFIX_MAP = "-fdebug-prefix-map=${WORKDIR}=${TARGET_DBGSRC_DIR} \
Brad Bishop19323692019-04-05 15:28:33 -040012 -fdebug-prefix-map=${STAGING_DIR_HOST}= \
13 -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
14 "
15
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016export GOTOOLDIR_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/${HOST_SYS}/go/pkg/tool/${BUILD_GOTUPLE}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040017export CGO_CFLAGS = "${CFLAGS}"
18export CGO_LDFLAGS = "${LDFLAGS}"
Patrick Williamsb58112e2024-03-07 11:16:36 -060019export GO_LDFLAGS = '-extld ${HOST_PREFIX}gcc -extldflags "--sysroot=${STAGING_DIR_HOST} ${SECURITY_NOPIE_CFLAGS} ${HOST_CC_ARCH} ${LDFLAGS}"'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020
21do_configure[noexec] = "1"
22
23do_compile() {
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060024 export CC_FOR_${HOST_GOTUPLE}="${HOST_PREFIX}gcc --sysroot=${STAGING_DIR_HOST} ${SECURITY_NOPIE_CFLAGS}"
25 export CXX_FOR_${HOST_GOTUPLE}="${HOST_PREFIX}gxx --sysroot=${STAGING_DIR_HOST} ${SECURITY_NOPIE_CFLAGS}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026 cd src
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060027 ./make.bash --target-only --no-banner
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028 cd ${B}
29}
Brad Bishop316dfdd2018-06-25 12:45:53 -040030do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031
32
33make_wrapper() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040034 rm -f ${D}${bindir}/$2
35 cat <<END >${D}${bindir}/$2
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036#!/bin/sh
37here=\`dirname \$0\`
38native_goroot=\`readlink -f \$here/../../lib/${TARGET_SYS}/go\`
39export GOARCH="${TARGET_GOARCH}"
40export GOOS="${TARGET_GOOS}"
41test -n "\$GOARM" || export GOARM="${TARGET_GOARM}"
42test -n "\$GO386" || export GO386="${TARGET_GO386}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040043test -n "\$GOMIPS" || export GOMIPS="${TARGET_GOMIPS}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044export GOTOOLDIR="\$native_goroot/pkg/tool/${HOST_GOTUPLE}"
45test -n "\$GOROOT" || export GOROOT="\$OECORE_TARGET_SYSROOT/${target_libdir}/go"
46\$here/../../lib/${TARGET_SYS}/go/bin/$1 "\$@"
47END
Brad Bishop316dfdd2018-06-25 12:45:53 -040048 chmod +x ${D}${bindir}/$2
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049}
50
51do_install() {
52 install -d ${D}${libdir}/go/pkg/tool
53 cp --preserve=mode,timestamps -R ${B}/pkg/tool/${HOST_GOTUPLE} ${D}${libdir}/go/pkg/tool/
54 install -d ${D}${bindir} ${D}${libdir}/go/bin
55 for f in ${B}/${GO_BUILD_BINDIR}/*
56 do
57 base=`basename $f`
58 install -m755 $f ${D}${libdir}/go/bin
59 make_wrapper $base ${TARGET_PREFIX}$base
60 done
61}