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

pkgname=help2man
pkgver=1.47.6
pkgrel=1
pkgdesc="Conversion tool to create man files"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/help2man/"
license=('GPL')
groups=('base-devel')
depends=('perl-Locale-Gettext' 'libintl')
install=help2man.install
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        1.40.4-cygwin-nls.patch)
noextract=("${pkgname}-${pkgver}.tar.xz")
sha256sums=('d91b0295b72a638e4a564f643e4e6d1928779131f628c00f356c13bf336de46f'
            'SKIP'
            '6cf5541d6233b6c0ce0248ecb6376682646ee56f795b19906f0acc63d83de482')
validpgpkeys=("F0DC8E00B28C5995" "87EA44D150D89615E39A3FEEF0DC8E00B28C5995")

# 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
}
