# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=man-db
pkgver=2.9.4
pkgrel=1
pkgdesc="A utility for reading man pages"
arch=('i686' 'x86_64')
url="https://www.nongnu.org/man-db/"
license=('GPL' 'LGPL')
groups=('base-devel')
depends=( 'bash' 'gdbm' 'zlib' 'groff' 'libpipeline' 'less')
optdepends=('gzip')
makedepends=('gettext-devel' 'libgdbm-devel' 'libpipeline-devel' 'zlib-devel' 'pkg-config')
backup=('etc/man_db.conf')
conflicts=('man')
provides=('man')
replaces=('man')
install=${pkgname}.install
source=(https://savannah.nongnu.org/download/man-db/${pkgname}-${pkgver}.tar.xz{,.asc}
        convert-mans
        man-db-2.8.3-msysize.patch)
sha256sums=('b66c99edfad16ad928c889f87cf76380263c1609323c280b3a9e6963fdb16756'
            'SKIP'
            '15c9452984c06335543d9692e25d7825063d39e4d7897a224a36bbbd5e0ffaa8'
            'b4ce66cc48e2d8b3033406ecdea0c80704a2deb76c6ae70a72d4d61e36c639e6')
validpgpkeys=('AC0A4FF12611B6FCCF01C111393587D97D86500B') # Colin Watson <cjwatson@debian.org>

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/man-db-2.8.3-msysize.patch
  
  autoreconf -fiv
}

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

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

package() {
  cd ${srcdir}/${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
}
