# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Daniel Martí <mvdan@mvdan.cc>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Pierre Neidhardt <ambrevar@gmail.com>
# Contributor: Vesa Kaihlavirta <vegai@iki.fi>
# Contributor: Rémy Oudompheng <remy@archlinux.org>
# Contributor: Andres Perera <andres87p gmail>
# Contributor: Matthew Bauer <mjbauer95@gmail.com>
# Contributor: Christian Himpel <chressie@gmail.com>
# Contributor: Mike Rosset <mike.rosset@gmail.com>
# Contributor: Daniel YC Lin <dlin.tw@gmail.com>
# Contributor: John Luebs <jkluebs@gmail.com>

#Included in Slint by Didier Spaier didieratslintdotfr
pkgname=google-go-lang
pkgver=1.25.1
pkgrel=1slint
slackdesc="$pkgname (Core compiler tools for the Go programming language)"
url='https://golang.org/'
license=(BSD-3-Clause)
makedepends=(git go)
replaces=(go-pie)
provides=(go-pie)
source=("go${pkgver}.src.tar.gz")
docs=("README.*" LICENSE PATENTS)
options=("nosrcpack")
build() {
  export GOARCH=amd64
  export GOAMD64=v1 # make sure we're building for the right x86-64 version
  export GOROOT_FINAL=/usr/lib64/go
  export GOROOT_BOOTSTRAP=/usr/lib64/go
  cd "$SRC/go"
[ -f README.md ] && pandoc -f gfm -t html5 -o README.html README.md
  cd "$SRC/go/src"
  ./make.bash -v
  cd "$SRC/go"
  install -d "$PKG/usr/bin" "$PKG/usr/lib64/go" "$PKG/usr/share/doc/go" \
    "$PKG/usr/lib64/go/pkg/linux_amd64_"{dynlink,race}

  cp -a bin pkg src lib misc api test "$PKG/usr/lib64/go"
  # We can't strip all binaries and libraries,
  # as that also strips some testdata directories and breaks the tests.
  # Just strip the packaged binaries as a compromise.
  strip $STRIP_BINARIES "$PKG/usr/lib64/go"{/bin/*,/pkg/tool/*/*}

  cp -r doc/* "$PKG/usr/doc/go"

  ln -sf /usr/lib64/go/bin/go "$PKG/usr/bin/go"
  ln -sf /usr/lib64/go/bin/gofmt "$PKG/usr/bin/gofmt"
  ln -sf /usr/share/doc/go "$PKG/usr/lib64/go/doc"

  install -Dm644 VERSION "$PKG/usr/lib64/go/VERSION"

  rm -rf "$PKG/usr/lib64/go/pkg/bootstrap" "$PKG/usr/lib64/go/pkg/tool/*/api"

  # TODO: Figure out if really needed
  rm -rf "$PKG"/usr/lib64/go/pkg/obj/go-build


  # https://github.com/golang/go/issues/57179
  install -Dm644 go.env "$PKG/usr/lib64/go/go.env"
  # Put the profile scripts for setting PATH and env variables
mkdir -p $PKG/etc/profile.d
cat > $PKG/etc/profile.d/go.csh << EOF
#!/bin/csh
setenv GOROOT ${GOROOT_FINAL}
setenv PATH \${GOROOT}/bin:\${PATH}
EOF
cat > $PKG/etc/profile.d/go.sh << EOF
#!/bin/sh
export GOROOT="${GOROOT_FINAL}"
export PATH="\${GOROOT}/bin:\${PATH}"
EOF

chmod 0755 $PKG/etc/profile.d/go.csh
chmod 0755 $PKG/etc/profile.d/go.sh
}
