1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/go/go.conf
3 # Copyright (C) 2021 - 2022 The T2 SDE Project
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2.
10 # --- T2-COPYRIGHT-NOTE-END ---
16 hook_add premake 5 "go_premake"
17 hook_add inmake 5 "go_inmake"
18 hook_add postmake 5 "go_postmake"
20 export GOROOT_FINAL=$root$libdir/go
22 # Translate our arch naming to theirs
28 yes) BE=be; EB=eb; LE=''; EL='';;
29 no) BE=''; EB=''; LE=le; EL=el;;
33 x86-64|x86_64) TARGET_ARCH=amd64 ;;
34 x86) TARGET_ARCH=386 ;;
35 arm64) TARGET_ARCH=arm64 ;;
36 powerpc64) TARGET_ARCH=ppc64$LE ;;
37 mips*) TARGET_ARCH=$ARCH$EL ;;
38 *) TARGET_ARCH=$ARCH ;;
45 export GOOS=$SDECFG_KERNEL
46 #export GOHOSTARCH=$(go env | grep GOHOSTARCH | cut -d'"' -f2)
47 #export GOHOSTARCH=$(translate_arch ${arch_build%%-*})
48 export TARGET_ARCH=$(translate_arch $arch $arch_bigendian)
52 # cross-compile using the compiler built at the toolchain stage
53 if atstage cross; then
54 export GOARCH=$TARGET_ARCH
59 # build the toolchain, first the one written in C then the one written in go
60 # only the last one can be used for cross-compiling
61 if atstage toolchain; then
66 # build the C version if go is not installed and use it to build the latest
67 # go version written in go
68 if atstage native; then
69 pkginstalled go || build_go 1.4
75 mkdir -pv $GOROOT_FINAL
76 cp -rfv go/* $GOROOT_FINAL/
78 # place the cross-compiled binary in the right place as go puts it in
80 if atstage cross; then
81 find "$GOROOT_FINAL/bin/${GOOS}_$GOARCH" -type f -perm /u+x | xargs -I {} mv -v {} $GOROOT_FINAL/bin/
82 rm -rfv "$GOROOT_FINAL/bin/${GOOS}_$GOARCH"
85 # symlink the binaries to the bindir
86 for EXE in $GOROOT_FINAL/bin/* ; do
87 ln -svf $EXE $root/$bindir/${EXE##*/}
92 # set TMPDIR, else it wants to use /var/tmp
93 export TMPDIR="$(mktemp -d -p $PWD)"
96 # extract right go version
97 [ "$1" == "1.4" ] && extract_go $1 || extract_go
101 # go uses uname all over the place to determine host arch, sigh
102 sed -i 's,uname,/bin/uname,g' *.bash
103 [ "$1" != "1.4" ] && sed -i '96s,uname,/bin/uname,g' ./cmd/dist/main.go &&
109 # set go1.4 as our toolchain for the next round to build go latest
110 [ "$1" == "1.4" ] && export GOROOT_BOOTSTRAP="$TMPDIR/go"
117 [ "$1" == "1.4" ] && VER="$1" || VER="$ver"
118 tar $taropt "$(match_source_file -p go-$VER go)"