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

pkgname=automake1.7
pkgver=1.7.9
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.7.9-gentoo-test-fixes.patch
        automake1.7-cygwin-test-fixes.patch
        automake1.7-documentation.patch
        automake-1.7-msys2.patch)
sha256sums=('32c13b6ad38ed5e7bfd1756cbc19cf5efd67b7ade2d06000a4c99b0ce94bd46d'
            '44221e4c945b0cb61663cb2857a3238e50800d228e7612203529726c53272dbb'
            '3c9a2fb1f54af14730308e5a06b4b507f91f63eacb6655fd771a4e554895023b'
            'c5f4c7119e484cb3f8dcbb55b2deaa682247ee2d8fab934013cc612e3e273274'
            'e3d7a2ce2942b341dfda226a38e814e2632600ac4be5044fda0c579420e54094')

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

  patch -p1 -i ${srcdir}/automake-1.7.9-gentoo-test-fixes.patch
  patch -p2 -i ${srcdir}/automake1.7-cygwin-test-fixes.patch
  patch -p2 -i ${srcdir}/automake1.7-documentation.patch
  patch -p1 -i ${srcdir}/automake-1.7-msys2.patch
}

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

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

  mv ${pkgdir}/usr/info ${pkgdir}/usr/share/

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