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

pkgname=automake1.9
pkgver=1.9.6
pkgrel=3
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.bz2
        automake-1.9.6-gentoo-aclocal7-test-sleep.patch
        automake-1.9.6-gentoo-ignore-comments.patch
        automake-1.9.6-gentoo-include-dir-prefix.patch
        automake1.9-backport-pr401-test-and-fix.patch
        automake1.9-vs-modern-libtool.patch
        automake1.9-cygwin-test-fixes.patch
        automake1.9-documentation.patch
        automake1.9-avoid-autoreconf.patch
        automake-1.9-msys2.patch
        automake-1.9-makeinfo-fix.patch)
sha256sums=('8eccaa98e1863d10e4a5f861d8e2ec349a23e88cb12ad10f6b6f79022ad2bb8d'
            '9bc281d49a753a6135c65b80642b03a6056538a6e944aeb344f1ed460be2904e'
            '28b80f088b53a72935f15c7d845919f474224ece83847d7b3bae5f2236fe30fe'
            '01d85d830875aa05eec4ad209033473f3f8603f66781fdd9fd9b3cbb07ecbbd2'
            '2b88a9fc60e8837d864dc93dc6f49cc1d501fd5e51846247fa843843f6863085'
            '8b66a01f412d95a81c3994ec8921cf34a40f9b4f80c4bb274840ee66637c4d38'
            'b5ea7a62a3b274e9ded0126d1050b8d8b3fd70ee5c7c73e8123ebe7263861962'
            '568d5b7fc64d6c44b752587de02f0c12129af9267a1e634407feccfc11c7929d'
            '23c3e0c29298e490c5b2e9871dc7fc26cba933c2bb23dc4665226f3921301d39'
            '6268b44ed3b82551b7e7dcd7bc61604d22703fdd8c8e8bc26a90608b49bf003a'
            'a7a4a09741ada50dfb3e35bd5e14e20bb5654a112ddef4af59ef9af21938bdd9')

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

  patch -p1 -i ${srcdir}/automake-1.9.6-gentoo-aclocal7-test-sleep.patch
  patch -p0 -i ${srcdir}/automake-1.9.6-gentoo-ignore-comments.patch
  patch -p0 -i ${srcdir}/automake-1.9.6-gentoo-include-dir-prefix.patch
  patch -p2 -i ${srcdir}/automake1.9-backport-pr401-test-and-fix.patch
  patch -p2 -i ${srcdir}/automake1.9-vs-modern-libtool.patch
  patch -p2 -i ${srcdir}/automake1.9-cygwin-test-fixes.patch
  patch -p2 -i ${srcdir}/automake1.9-documentation.patch
  patch -p1 -i ${srcdir}/automake1.9-avoid-autoreconf.patch

  patch -p1 -i ${srcdir}/automake-1.9-makeinfo-fix.patch
  patch -p1 -i ${srcdir}/automake-1.9-msys2.patch
}

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

  (cd doc && makeinfo -I ${srcdir}/automake-${pkgver}/doc -o automake1.9.info automake.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

  # install the 1.11 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 -rf ${pkgdir}/usr/share/doc
}
