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

pkgname=automake1.16
pkgver=1.16.3
pkgrel=1
pkgdesc="A GNU tool for automatically creating Makefiles"
arch=('any')
license=('GPL')
url="https://www.gnu.org/software/automake"
groups=('base-devel')
depends=('perl' 'bash')
makedepends=('autoconf')
checkdepends=('dejagnu')
install=automake.install
source=(https://ftp.gnu.org/gnu/automake/automake-${pkgver}.tar.xz{,.sig}
        automake-1.16.1-documentation.patch
        automake-1.16.1-msys2.patch)
sha256sums=('ff2bf7656c4d1c6fdda3b8bebb21f09153a736bcba169aaf65eab25fa113bf3a'
            'SKIP'
            '18129ade01c1b1be3cb60e20349db0c08e7ea7fae7e72b937b1317c5f36dda41'
            'fe7bf1235399d2b1ff0e6a74eef96693449bf06e71a1a18c2a995fd41abbe6ce')
validpgpkeys=('E1622F96D2BB4E58018EEF9860F906016E407573'   # Stefano Lattarini
              'F2A38D7EEB2B66405761070D0ADEE10094604D37'   # Mathieu Lirzin
              '155D3FC500C834486D1EEA677FD9FCCB000BEEEE')  # Jim Meyering
replace=('automake')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -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}/automake-${pkgver}

  apply_patch_with_msg  automake-1.16.1-documentation.patch \
    automake-1.16.1-msys2.patch
}

build() {
  cd ${srcdir}/automake-${pkgver}
  ./configure --prefix=/usr
  make

  (cd doc && makeinfo -I ${srcdir}/automake-${pkgver}/doc -o automake1.16.info automake.texi)
  (cd doc && makeinfo -I ${srcdir}/automake-${pkgver}/doc -o automake-history1.16.info automake-history.texi)
}

check() {
  cd ${srcdir}/automake-${pkgver}

  # expect 2 failures due to perl-5.18 incompatibility
  make -k check || true
}

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

  mv ${pkgdir}/usr/share/aclocal/README ${pkgdir}/usr/share/aclocal/README.am16

  # install the 1.16 versioned info files
  for f in `find ${pkgdir}/usr/share/info -name "*.info*"` ; do
    rm -f ${f}
  done
  for f in `find ${srcdir}/automake-${pkgver} -name "*.info*"` ; do
    bf=`basename $f`
    cp $f ${pkgdir}/usr/share/info/
  done

  # remove the unversioned executables
  rm -f ${pkgdir}/usr/bin/automake ${pkgdir}/usr/bin/aclocal

  # remove the unversioned man pages
  rm -f ${pkgdir}/usr/share/man/man1/automake.1
  rm -f ${pkgdir}/usr/share/man/man1/aclocal.1

  # remove the unversioned info files
  rm -f ${pkgdir}/usr/share/info/automake.info*
  rm -f ${pkgdir}/usr/share/info/automake-history.info*

  rm -rf ${pkgdir}/usr/share/doc
}
