# Description: The Go Programming Language
# URL: https://go.dev/
# Maintainer: Matt Housh, jaeger at crux dot ninja

name=go
version=1.21.0
release=1
source=(https://golang.org/dl/go${version}.src.tar.gz \
    https://golang.org/dl/go${version}.linux-amd64.tar.gz)

unpack_source() {
    install -d $SRC/go${version}
    bsdtar -xf $PKGMK_SOURCE_DIR/go${version}.linux-amd64.tar.gz \
        -C $SRC/go${version} --strip-components=1
    bsdtar -xf $PKGMK_SOURCE_DIR/go${version}.src.tar.gz \
        -C $SRC
}

build() {
    export GOCACHE=$SRC/go-build
    export GOROOT_BOOTSTRAP=$SRC/go${version}
    export GOROOT_FINAL=/usr/lib/go

    cd go/src
    ./make.bash

    install -d $PKG/usr/lib
    mv $SRC/go $PKG/usr/lib/

    install -d $PKG/usr/bin
    ln -s /usr/lib/go/bin/go $PKG/usr/bin/
    ln -s /usr/lib/go/bin/gofmt $PKG/usr/bin/

    find $PKG \( -name "README*" -o -name "AUTHORS" -o -name "TODO" \) -delete
    rm $PKG/usr/lib/go/src/*.bat
}
