blob: ea68b8875d940e539b81c56d863a1ad3fb2eaaea [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001inherit cross-canadian
2
3DEPENDS = "go-native virtual/${HOST_PREFIX}go-crosssdk virtual/nativesdk-${HOST_PREFIX}go-runtime \
4 virtual/${HOST_PREFIX}gcc-crosssdk virtual/nativesdk-${HOST_PREFIX}libc-for-gcc \
5 virtual/nativesdk-${HOST_PREFIX}compilerlibs"
6PN = "go-cross-canadian-${TRANSLATED_TARGET_ARCH}"
7
8export GOHOSTOS = "${BUILD_GOOS}"
9export GOHOSTARCH = "${BUILD_GOARCH}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010export GOROOT_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/go"
11export GOTOOLDIR_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/${HOST_SYS}/go/pkg/tool/${BUILD_GOTUPLE}"
12export GOROOT_FINAL = "${libdir}/go"
Brad Bishop316dfdd2018-06-25 12:45:53 -040013export CGO_CFLAGS = "${CFLAGS}"
14export CGO_LDFLAGS = "${LDFLAGS}"
15export GO_LDFLAGS = '-linkmode external -extld ${HOST_PREFIX}gcc -extldflags "--sysroot=${STAGING_DIR_HOST} ${SECURITY_NOPIE_CFLAGS} ${HOST_CC_ARCH} ${LDFLAGS}"'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016
17do_configure[noexec] = "1"
18
19do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040020 export CC_FOR_${HOST_GOOS}_${HOST_GOARCH}="${HOST_PREFIX}gcc --sysroot=${STAGING_DIR_HOST}${SDKPATHNATIVE} ${SECURITY_NOPIE_CFLAGS}"
21 export CXX_FOR_${HOST_GOOS}_${HOST_GOARCH}="${HOST_PREFIX}gxx --sysroot=${STAGING_DIR_HOST}${SDKPATHNATIVE} ${SECURITY_NOPIE_CFLAGS}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022 cd src
23 ./make.bash --host-only --no-banner
24 cd ${B}
25}
Brad Bishop316dfdd2018-06-25 12:45:53 -040026do_compile[dirs] =+ "${GOTMPDIR} ${B}/bin ${B}/pkg"
27do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028
29
30make_wrapper() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040031 rm -f ${D}${bindir}/$2
32 cat <<END >${D}${bindir}/$2
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033#!/bin/sh
34here=\`dirname \$0\`
35native_goroot=\`readlink -f \$here/../../lib/${TARGET_SYS}/go\`
36export GOARCH="${TARGET_GOARCH}"
37export GOOS="${TARGET_GOOS}"
38test -n "\$GOARM" || export GOARM="${TARGET_GOARM}"
39test -n "\$GO386" || export GO386="${TARGET_GO386}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040040test -n "\$GOMIPS" || export GOMIPS="${TARGET_GOMIPS}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050041export GOTOOLDIR="\$native_goroot/pkg/tool/${HOST_GOTUPLE}"
42test -n "\$GOROOT" || export GOROOT="\$OECORE_TARGET_SYSROOT/${target_libdir}/go"
43\$here/../../lib/${TARGET_SYS}/go/bin/$1 "\$@"
44END
Brad Bishop316dfdd2018-06-25 12:45:53 -040045 chmod +x ${D}${bindir}/$2
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046}
47
48do_install() {
49 install -d ${D}${libdir}/go/pkg/tool
50 cp --preserve=mode,timestamps -R ${B}/pkg/tool/${HOST_GOTUPLE} ${D}${libdir}/go/pkg/tool/
51 install -d ${D}${bindir} ${D}${libdir}/go/bin
52 for f in ${B}/${GO_BUILD_BINDIR}/*
53 do
54 base=`basename $f`
55 install -m755 $f ${D}${libdir}/go/bin
56 make_wrapper $base ${TARGET_PREFIX}$base
57 done
58}