# Maintainer: Jef Roosens
# This PKGBUILD is mostly copied over from the AUR
# https://aur.archlinux.org/packages/vlang-git

pkgname=vieter-v
pkgver=0.2.2.r796.gfbc02cbc5
pkgrel=1
pkgdesc='Simple, fast, safe, compiled language for developing maintainable software'
arch=('x86_64' 'aarch64')
url='https://vlang.io'
license=('MIT')
depends=('glibc')
makedepends=('git')
optdepends=('glfw: Needed for graphics support'
            'freetype2: Needed for graphics support'
            'openssl: Needed for http support')
provides=('vlang')
conflicts=('v' 'vlang' 'vlang-bin')
source=('vlang::git+https://git.rustybever.be/Chewing_Bever/v')
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/vlang"
  # Weekly tags are considered older than semantic tags that are older than
  # them, so to prevent version resolution problems we exclude weekly tags.
  git describe --long --tags --exclude "weekly*" | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd "${srcdir}/vlang"
  # We don't require optimizations when compiling the bootstrap executable and
  # -O2 actually breaks `./v self` (resulting in "cgen error:"), so we empty
  # CFLAGS and LDFLAGS to ensure successful compilation.
  CFLAGS="" LDFLAGS="" prod=1 make

  # vpm and vdoc fail to compile with "unsupported linker option" when LDFLAGS
  # is set
  LDFLAGS="" ./v build-tools
}

package() {
  cd "${srcdir}/vlang"
  install -d "$pkgdir/usr/lib/vlang" "$pkgdir/usr/share/vlang" "$pkgdir/usr/bin"
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm755 v "$pkgdir/usr/lib/vlang"
  cp -a cmd "$pkgdir/usr/lib/vlang/"
  cp -a examples "$pkgdir/usr/share/vlang/"
  cp -a thirdparty "$pkgdir/usr/lib/vlang/"
  cp -a vlib "$pkgdir/usr/lib/vlang/"
  cp v.mod "$pkgdir/usr/lib/vlang/"
  ln -s /usr/lib/vlang/v "$pkgdir/usr/bin/v"

  touch "$pkgdir/usr/lib/vlang/cmd/tools/.disable_autorecompilation"
}