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

pkgname=man-db
pkgver=2.13.1
pkgrel=1
pkgdesc="A utility for reading man pages"
arch=('i686' 'x86_64')
url="https://man-db.gitlab.io/man-db/"
msys2_repository_url='https://gitlab.com/man-db/man-db'
msys2_references=(
  "cpe: cpe:/a:man-db_project:man-db"
)
license=('GPL' 'LGPL')
depends=( 'bash' 'gdbm' 'zlib' 'groff' 'libpipeline' 'less')
optdepends=('gzip')
makedepends=('gettext-devel' 'libgdbm-devel' 'libpipeline-devel' 'zlib-devel' 'autotools' 'gcc')
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)
sha256sums=('8afebb6f7eb6bb8542929458841f5c7e6f240e30c86358c1fbcefbea076c87d9'
            'SKIP'
            '15c9452984c06335543d9692e25d7825063d39e4d7897a224a36bbbd5e0ffaa8')
validpgpkeys=('AC0A4FF12611B6FCCF01C111393587D97D86500B') # Colin Watson <cjwatson@debian.org>

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  local -a extra_config
  # 32-bit cygwin only has 32-bit time_t
  # https://github.com/msys2/MSYS2-packages/issues/4078
  if [[ "$CARCH" == "i686" ]]; then
    extra_config+=("--disable-year2038")
  fi
  ./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 \
    "${extra_config[@]}"
  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
}
