* updated kmailtransport (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / develop / go / go.conf
blob4df6c36b902e7d6497b75a55fc8266ba30f85085
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/go/go.conf
3 # Copyright (C) 2021 - 2022 The T2 SDE Project
4
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
7
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 ---
12 autoextract=0
13 makeopt=
14 makeinstopt=
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
23 translate_arch() {
24         local ARCH=$1
25         local ENDIAN=$2
27         case $ENDIAN in
28                 yes) BE=be; EB=eb; LE=''; EL='';;
29                 no) BE=''; EB=''; LE=le; EL=el;;
30         esac
32         case $ARCH in
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 ;;
39         esac
41         echo $TARGET_ARCH
44 go_premake() {
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)
51 go_inmake() {
52         # cross-compile using the compiler built at the toolchain stage
53         if atstage cross; then
54                 export GOARCH=$TARGET_ARCH
55                 export CGO_ENABLED=0
56                 build_go
57         fi
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
62                 build_go 1.4
63                 build_go
64         fi
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
70                 build_go
71         fi
74 go_postmake() {
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
79         # a subdirectory
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"
83         fi
85         # symlink the binaries to the bindir
86         for EXE in $GOROOT_FINAL/bin/* ; do
87                 ln -svf $EXE $root/$bindir/${EXE##*/}
88         done
91 build_go() {
92         # set TMPDIR, else it wants to use /var/tmp
93         export TMPDIR="$(mktemp -d -p $PWD)"
94         cd $TMPDIR
96         # extract right go version
97         [ "$1" == "1.4" ] && extract_go $1 || extract_go
99         cd go/src
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 &&
104         export CGO_ENABLED=0
106         # build
107         ./make.bash
109         # set go1.4 as our toolchain for the next round to build go latest
110         [ "$1" == "1.4" ] && export GOROOT_BOOTSTRAP="$TMPDIR/go"
111         unset TMPDIR
113         cd ../..
116 extract_go() {
117         [ "$1" == "1.4" ] && VER="$1" || VER="$ver"
118         tar $taropt "$(match_source_file -p go-$VER go)"