_pkgname=ydotool
pkgname=$_pkgname-git
pkgver=1.0.4.r38.g708e96f
pkgrel=3
pkgdesc="Generic command-line automation tool (no X!), works on Wayland & tty"
arch=('x86_64')
makedepends=('cmake' 'git' 'make' 'pkg-config' 'scdoc')
url="https://github.com/ReimuNotMoe/ydotool"
license=('AGPL-3.0-only')
source=(${_pkgname}::git+https://github.com/ReimuNotMoe/ydotool.git
        66-uinput.rules uinput.conf)
sha256sums=('SKIP'
            'be97caf82374a487acc618b84a502613d6c219b73991c8d764f6b6b41617f740'
            'a771c9695d7283f7771adc00b680bd27391e6ac00e9fd026f4796067ee9a87eb')
provides=($_pkgname)
conflicts=($_pkgname)

pkgver() {
  cd "$srcdir/$_pkgname"
  # seems to be a wrong tag
  git tag -d v0.0.1 >/dev/null || true
  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//'
}

build() {
  cd "$srcdir/${_pkgname}"

  mkdir -p build && cd build
  
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=/usr/lib \
    -DCMAKE_INSTALL_MANDIR=/usr/share/man \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo
  make
}

package() {
  cd "$srcdir/${_pkgname}"
  make DESTDIR="$pkgdir" install -C build
  install -Dm644 ../66-uinput.rules "$pkgdir"/usr/lib/udev/rules.d/66-uinput-ydotool.rules
  install -Dm644 ../uinput.conf "$pkgdir"/usr/lib/modules-load.d/uinput-ydotool.conf
}
