# Maintainer: Mark Wagie <mark dot wagie at proton dot me>
pkgname=needrestart-git
pkgver=3.11.r5.g702db55
pkgrel=1
pkgdesc="Restart daemons after library updates."
arch=('any')
url="https://github.com/liske/needrestart"
license=('GPL-2.0-or-later')
depends=(
  'perl-module-find'
  'perl-term-readkey'
  'perl-proc-processtable'
  'perl-sort-naturally'
  'perl-module-scandeps'
  'perl-libintl-perl'
)
makedepends=('git')
optdepends=('iucode-tool: for outdated Intel microcode detection')
provides=("${pkgname%-git}")
conflicts=("${pkgname%-git}")
backup=("etc/${pkgname%-git}/${pkgname%-git}.conf"
        "etc/${pkgname%-git}/notify.conf")
source=('git+https://github.com/liske/needrestart.git'
        "${pkgname%-git}.hook")
sha256sums=('SKIP'
            'b2ba87c931950d5d0a089de0626e964ed3a95cc281a21e0dfdbc16e01ea1dec7')

pkgver() {
  cd "${pkgname%-git}"
  git describe --long --tags --abbrev=7 | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "${pkgname%-git}"
  find . -type f -exec sed -i 's|usr/sbin|usr/bin|' {} \;
  sed -i 's|sbin/init|bin/init|g' "${pkgname%-git}"
}

build() {
  cd "${pkgname%-git}"
  unset PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT
  export PERL_MM_USE_DEFAULT=1 PERL_AUTOINSTALL=--skipdeps
  make
}

package() {
  cd "${pkgname%-git}"
  unset PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT
  make DESTDIR="$pkgdir/" install

  install -Dm644 "man/${pkgname%-git}.1" -t "$pkgdir/usr/share/man/man1/"
  install -Dm644 "$srcdir/${pkgname%-git}.hook" -t "$pkgdir/usr/share/lipalpm/hooks/"
}
