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

pkgname=automake1.14
pkgver=1.14.1
pkgrel=4
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
        automake1.14-documentation.patch
        automake-1.14-msys2.patch
        automake-1.14-perl-escape-curly-bracket.patch)
sha256sums=('a9b4f04b8b69cac2e832a38a718943aa976dbdad0097211f8b3448afdacf0669'
            'd08bf56f22e948896a93fb33c81a2a1b3c469487d99b56da60fa915b61cafb09'
            '76ac48cce5b6d48dfbd2659e3aeb10144acc932269c94fbed8d6335da773090b'
            '34ec3ef555b78e8f19cd87d582102f07a705cd3b98919489274f2dabbd6aade6')
replace=('automake')

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

  patch -p2 -i ${srcdir}/automake1.14-documentation.patch
  patch -p1 -i ${srcdir}/automake-1.14-msys2.patch
  patch -p1 -i ${srcdir}/automake-1.14-perl-escape-curly-bracket.patch
}

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

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

  # install the 1.14 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
}
