# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/go/go.conf # Copyright (C) 2021 - 2023 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2. # --- T2-COPYRIGHT-NOTE-END --- autoextract=0 makeopt= makeinstopt= hook_add premake 5 "go_premake" hook_add inmake 5 "go_inmake" hook_add postmake 5 "go_postmake" export GOROOT_FINAL=$root$libdir/go # Translate our arch naming to theirs translate_arch() { local ARCH=$1 local ENDIAN=$2 local TARGET_ARCH=$ARCH case $ENDIAN in yes) BE=be EB=eb LE='' ;; no) BE='' EB='' LE=le ;; esac case $ARCH in loongarch*) TARGET_ARCH=${ARCH/arch} ;; mips*) TARGET_ARCH=$ARCH$LE ;; powerpc64) TARGET_ARCH=ppc64$LE ;; x86) TARGET_ARCH=386 ;; x86-64|x86_64) TARGET_ARCH=amd64 ;; esac echo $TARGET_ARCH } go_premake() { export GOOS=$SDECFG_KERNEL #export GOHOSTARCH=$(go env | grep GOHOSTARCH | cut -d'"' -f2) #export GOHOSTARCH=$(translate_arch ${arch_build%%-*}) export TARGET_ARCH=$(translate_arch $arch $arch_bigendian) } go_inmake() { # cross-compile using the compiler built at the toolchain stage if atstage cross; then export GOARCH=$TARGET_ARCH export CGO_ENABLED=0 build_go fi # build the toolchain, first the one written in C then the one written in go # only the last one can be used for cross-compiling if atstage toolchain; then build_go 1.4 build_go fi # build the C version if go is not installed and use it to build the latest # go version written in go if atstage native; then pkginstalled go || build_go 1.4 build_go fi } go_postmake() { # delete previous go installs as it creates conflicts like redeclaration etc rm -rf $GOROOT_FINAL/ mkdir -pv $GOROOT_FINAL cp -rfv go/* $GOROOT_FINAL/ # place the cross-compiled binary in the right place as go puts it in # a subdirectory if atstage cross; then find "$GOROOT_FINAL/bin/${GOOS}_$GOARCH" -type f -perm /u+x | xargs -I {} mv -v {} $GOROOT_FINAL/bin/ rm -rfv "$GOROOT_FINAL/bin/${GOOS}_$GOARCH" fi # symlink the binaries to the bindir for bin in $GOROOT_FINAL/bin/* ; do ln -srfv $bin $root/$bindir/${bin##*/} done } build_go() { # set TMPDIR, else it wants to use /var/tmp export TMPDIR="$(mktemp -d -p $PWD)" cd $TMPDIR # extract right go version [ "$1" == "1.4" ] && extract_go $1 || extract_go cd go/src # go uses uname all over the place to determine host arch, sigh sed -i 's,uname,/bin/uname,g' *.bash [ "$1" != "1.4" ] && sed -i '96s,uname,/bin/uname,g' ./cmd/dist/main.go && export CGO_ENABLED=0 # build ./make.bash # set go1.4 as our toolchain for the next round to build go latest [ "$1" == "1.4" ] && export GOROOT_BOOTSTRAP="$TMPDIR/go" unset TMPDIR cd ../.. } extract_go() { [ "$1" == "1.4" ] && VER="$1" || VER="$ver" tar $taropt "$(match_source_file -p go-$VER go)" }