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

pkgname=help2man
pkgver=1.49.3
pkgrel=1
pkgdesc="Conversion tool to create man files"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/help2man/"
license=('GPL')
depends=('perl-Locale-Gettext' 'libintl')
makedepends=('autotools' 'gcc' 'gettext-devel')
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        1.40.4-cygwin-nls.patch)
noextract=("${pkgname}-${pkgver}.tar.xz")
sha256sums=('4d7e4fdef2eca6afe07a2682151cea78781e0a4e8f9622142d9f70c083a2fd4f'
            'SKIP'
            'a20d4049c9540bf7012d35d93bff8b44e13f15d969b0656284c9866e070763ad')
validpgpkeys=("87EA44D150D89615E39A3FEEF0DC8E00B28C5995") # Brendan O'Dea <bod@debian.org>

# Helper macros to help make tasks easier #
apply_patch_with_msg_p2() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp2 -i "${srcdir}"/${_fname}
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ] || [ -d $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd ${srcdir}
  tar -xf ${pkgname}-${pkgver}.tar.xz || true
  cd "${srcdir}/${pkgname}-${pkgver}"
  del_file_exists Changelog
  ln -s debian/changelog ChangeLog
  apply_patch_with_msg_p2 1.40.4-cygwin-nls.patch
  autoreconf -ivf
}

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

  ./configure \
      --build=${CHOST} \
      --prefix=/usr \
      --mandir=/usr/share/man \
      --infodir=/usr/share/info \
      --libdir=/usr/lib

  make
}

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