# Maintainer: Ricardo Band <email@ricardo.band>

pkgname=sanic
pkgver=0.0.1
pkgrel=1
pkgdesc="chaos music control inspired by relaxx player"
arch=('any')
url=https://git.berlin.ccc.de/cccb/sanic
license=('custom:MIT')
makedepends=('go')
source=("$pkgname.service"
        "$pkgname.sysusers"
        "$pkgname.tmpfiles"
        "$url/archive/v$pkgver.tar.gz")
sha256sums=("1337deadbeef"
            "1337deadbeef"
            "1337deadbeef"
            "1337deadbeef")

prepare() {
  cd "$pkgname-$pkgver"

  mkdir -p build/
}

build() {
  cd "$pkgname-$pkgver"

  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export CGO_LDFLAGS="$LDFLAGS"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"

  go build -o build/ .
}

check() {
  cd "$pkgname-$pkgver"

  go test ./...
}

package() {
  cd "$pkgname-$pkgver"

  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm755 build/$pkgname "$pkgdir"/usr/bin/$pkgname
  install -Dm644 "../$pkgname.service" "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -Dm644 "../$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
  install -Dm644 "../$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
}