Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | inherit cross-canadian |
| 2 | |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 3 | DEPENDS = "go-native virtual/${HOST_PREFIX}go virtual/nativesdk-${HOST_PREFIX}go-runtime \ |
| 4 | virtual/${HOST_PREFIX}gcc virtual/nativesdk-libc \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | virtual/nativesdk-${HOST_PREFIX}compilerlibs" |
| 6 | PN = "go-cross-canadian-${TRANSLATED_TARGET_ARCH}" |
| 7 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 8 | # 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 Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 11 | DEBUG_PREFIX_MAP = "-fdebug-prefix-map=${WORKDIR}=${TARGET_DBGSRC_DIR} \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 12 | -fdebug-prefix-map=${STAGING_DIR_HOST}= \ |
| 13 | -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \ |
| 14 | " |
| 15 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | export GOTOOLDIR_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/${HOST_SYS}/go/pkg/tool/${BUILD_GOTUPLE}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 17 | export CGO_CFLAGS = "${CFLAGS}" |
| 18 | export CGO_LDFLAGS = "${LDFLAGS}" |
| 19 | export GO_LDFLAGS = '-linkmode external -extld ${HOST_PREFIX}gcc -extldflags "--sysroot=${STAGING_DIR_HOST} ${SECURITY_NOPIE_CFLAGS} ${HOST_CC_ARCH} ${LDFLAGS}"' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 20 | |
| 21 | do_configure[noexec] = "1" |
| 22 | |
| 23 | do_compile() { |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 24 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | cd src |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 27 | ./make.bash --target-only --no-banner |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | cd ${B} |
| 29 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 30 | do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | |
| 32 | |
| 33 | make_wrapper() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 34 | rm -f ${D}${bindir}/$2 |
| 35 | cat <<END >${D}${bindir}/$2 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | #!/bin/sh |
| 37 | here=\`dirname \$0\` |
| 38 | native_goroot=\`readlink -f \$here/../../lib/${TARGET_SYS}/go\` |
| 39 | export GOARCH="${TARGET_GOARCH}" |
| 40 | export GOOS="${TARGET_GOOS}" |
| 41 | test -n "\$GOARM" || export GOARM="${TARGET_GOARM}" |
| 42 | test -n "\$GO386" || export GO386="${TARGET_GO386}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 43 | test -n "\$GOMIPS" || export GOMIPS="${TARGET_GOMIPS}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | export GOTOOLDIR="\$native_goroot/pkg/tool/${HOST_GOTUPLE}" |
| 45 | test -n "\$GOROOT" || export GOROOT="\$OECORE_TARGET_SYSROOT/${target_libdir}/go" |
| 46 | \$here/../../lib/${TARGET_SYS}/go/bin/$1 "\$@" |
| 47 | END |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 48 | chmod +x ${D}${bindir}/$2 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | do_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 | } |