#TODO compiling, not tested further
[source]
git = "https://github.com/willnode/go"
branch = "go-1.25-redox"
shallow_clone = true

[build]
template = "custom"
script = """
export PATH=$HOME/go/bin:$PATH

export GOPATH=${COOKBOOK_BUILD}/gopath
if ! command -v go &> /dev/null; then
   GO_TARBALL=go1.24.6.linux-$( [ "$(uname -m)" = "aarch64" ] && echo "arm64" || echo "amd64" ).tar.gz
   GO_DOWNLOAD_URL="https://dl.google.com/go/${GO_TARBALL}"
   echo "Installing Go..."
   wget -q --show-progress "${GO_DOWNLOAD_URL}"
   tar -C "$HOME" -xzf "${GO_TARBALL}"
fi

# Go does not support out-of-tree builds :(
rsync -a --delete "${COOKBOOK_SOURCE}/" ./

case "${TARGET}" in
    x86_64-unknown-linux-gnu)  export GOARCH=amd64 GOOS=linux;;
    aarch64-unknown-linux-gnu) export GOARCH=arm64 GOOS=linux;;
    i586-unknown-redox)     export GOARCH=386 GOOS=redox;;
    x86_64-unknown-redox)  export GOARCH=amd64 GOOS=redox;;
    aarch64-unknown-redox) export GOARCH=arm64 GOOS=redox;;
    riscv64gc-unknown-redox) export GOARCH=riscv64 GOOS=redox;;
esac

export CGO_ENABLED=1
echo "go1.25.0" > VERSION # to set -trimpath
(cd ./src && bash ./make.bash)

mkdir -p "${COOKBOOK_STAGE}"/usr/bin \
    "${COOKBOOK_STAGE}"/usr/lib/golang/{bin,lib,misc,pkg/include,pkg/tool,src}

if [ "$TARGET" = "$COOKBOOK_HOST_TARGET" ]; then
    rsync -a bin/* "${COOKBOOK_STAGE}"/usr/lib/golang/bin/
else
    rsync -a bin/${GOOS}_${GOARCH}/* "${COOKBOOK_STAGE}"/usr/lib/golang/bin/
fi
rsync -a lib/* "${COOKBOOK_STAGE}"/usr/lib/golang/lib/
rsync -a misc/* "${COOKBOOK_STAGE}"/usr/lib/golang/misc/
rsync -a pkg/include/* "${COOKBOOK_STAGE}"/usr/lib/golang/pkg/include/
rsync -a pkg/tool/${GOOS}_${GOARCH} "${COOKBOOK_STAGE}"/usr/lib/golang/pkg/tool/
rsync -a src/* "${COOKBOOK_STAGE}"/usr/lib/golang/src/
cat go.env > "${COOKBOOK_STAGE}"/usr/lib/golang/go.env
ln -s "../lib/golang/bin/go" "${COOKBOOK_STAGE}"/usr/bin/go
ln -s "../lib/golang/bin/gofmt" "${COOKBOOK_STAGE}"/usr/bin/gofmt
"""
