# $Id: PKGBUILD 223801 2014-10-03 07:16:02Z andyrtr $
# Maintainer: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Sergej Pupykin <sergej@aur.archlinux.org>

pkgname=man-db
pkgver=2.7.0.2
pkgrel=2
pkgdesc="A utility for reading man pages"
arch=('i686' 'x86_64')
url="http://www.nongnu.org/man-db/"
license=('GPL' 'LGPL')
groups=('base')
depends=( 'bash' 'gdbm' 'zlib' 'groff' 'libpipeline' 'less')
optdepends=('gzip')
backup=('etc/man_db.conf')
conflicts=('man')
provides=('man')
replaces=('man')
install=${pkgname}.install
source=(http://download-mirror.savannah.gnu.org/releases/man-db/$pkgname-$pkgver.tar.xz{,.sig}
        convert-mans
        man-db.{timer,service})
md5sums=('8ea7be9daf7af7da0fcd619e3da3991c'
         'SKIP'
         '2b7662a7d5b33fe91f9f3e034361a2f6'
         'df6d4f432e3e16c255c785fca1447346'
         '36fb3f616e42a0e23cf7a4d284e640cd')

build() {
  cd ${pkgname}-${pkgver}
  
  # fix group in systemd tempfile
  sed -i 's/man\ root/root\ root/' init/systemd/man-db.conf
    
  ./configure --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib \
	--with-db=gdbm \
	--disable-setuid \
	--enable-mandirs=GNU \
	--with-sections="1 n l 8 3 0 2 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 man-db update timer
  install -D -m644 ${srcdir}/man-db.timer ${pkgdir}/usr/lib/systemd/system/man-db.timer
  install -D -m644 ${srcdir}/man-db.service ${pkgdir}/usr/lib/systemd/system/man-db.service
  install -d -m755 ${pkgdir}/usr/lib/systemd/system/multi-user.target.wants
  ln -s ../man-db.timer ${pkgdir}//usr/lib/systemd/system/multi-user.target.wants/man-db.timer
}
