# Maintainer: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Sergej Pupykin <sergej@aur.archlinux.org>

pkgname=man-db
pkgver=2.11.2
pkgrel=1
pkgdesc="A utility for reading man pages"
arch=('x86_64')
url="https://gitlab.com/cjwatson/man-db"
license=('GPL' 'LGPL')
depends=( 'bash' 'gdbm' 'zlib' 'groff' 'libpipeline' 'less' 'libseccomp')
makedepends=('po4a')
optdepends=('gzip') # covered by virtual "base" package
backup=('etc/man_db.conf')
conflicts=('man')
provides=('man')
replaces=('man')
options=('debug')
install=${pkgname}.install
source=(https://savannah.nongnu.org/download/man-db/$pkgname-$pkgver.tar.xz{,.asc}
        # fallback should be used within first 24h after a release
        #https://download-mirror.savannah.gnu.org/releases/man-db/$pkgname-$pkgver.tar.xz{,.asc} 
        convert-mans
)
validpgpkeys=('AC0A4FF12611B6FCCF01C111393587D97D86500B') # Colin Watson <cjwatson@debian.org>
sha512sums=('edb71cce7249c7b7f2f524e92f682047a77ed9ae8856763dfc8e18e239444651ff4c505e697f5a8b1be3b85678e714fbb1a520defe72a4eb685bc2cecc0e4391'
            'SKIP'
            '0b159285da20008f0fc0afb21f1eaebd39e8df5b0594880aa0e8a913b656608b8d16bb8d279d9e62d7aae52f62cb9b2fc49e237c6711f4a5170972b38d345535')

build() {
  cd ${pkgname}-${pkgver}
  ./configure --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib \
    --with-systemdsystemunitdir=/usr/lib/systemd/system \
    --with-snapdir=/var/lib/snapd/snap \
    --with-db=gdbm \
    --disable-setuid \
    --enable-cache-owner=root \
    --enable-mandirs=GNU \
    --with-sections="1 1p n l 8 3 3p 0 0p 2 3type 5 4 9 6 7"
  make
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install

  # part of groff pkg
  rm -f ${pkgdir}/usr/bin/zsoelim

  # script from LFS to convert manpages, see
  # http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/man-db.html
  install -D -m755 ${srcdir}/convert-mans  ${pkgdir}/usr/bin/convert-mans

  install -d -m755 ${pkgdir}/usr/lib/systemd/system/timers.target.wants
  ln -s ../man-db.timer ${pkgdir}/usr/lib/systemd/system/timers.target.wants/man-db.timer
}
