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

pkgname=automake1.13
pkgver=1.13.4
pkgrel=7
pkgdesc="A GNU tool for automatically creating Makefiles"
arch=('any')
license=('GPL')
url="https://www.gnu.org/software/automake"
msys2_references=(
  "cpe: cpe:/a:gnu:automake"
)
depends=('perl' 'bash')
makedepends=('autoconf' 'make')
checkdepends=('dejagnu')
source=(https://ftp.gnu.org/gnu/automake/automake-${pkgver}.tar.xz
        automake-1.14-msys2.patch
        automake1.13-documentation.patch
        automake-1.13-perl-escape-curly-bracket.patch)
sha256sums=('89ce4933f59b8f0c20115c39cfe450a595cca74ede27b6881e88ec27720d1d66'
            '76ac48cce5b6d48dfbd2659e3aeb10144acc932269c94fbed8d6335da773090b'
            'ab0bba1beba0a9160d56bb46fd52449aa01ed9e1c3a5e75cc2d095d5513a8ecf'
            '6538290dc53c6f8da0dd67567ca2466c7155095619547e3988da4dc492e3bdd6')

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

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

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

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

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