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

pkgname=automake1.8
pkgver=1.8.5
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.bz2
        automake-1.8.5-gentoo-test-fixes.patch
        automake1.8-vs-modern-libtool.patch
        automake1.8-documentation.patch
        automake1.8-cygwin-test-fixes.patch
        automake-1.8-msys2.patch)
sha256sums=('84c93aaa3c3651a9e7474b721b0e6788318592509e7de604bafe4ea8049dc410'
            '1a94bcc5a8e33b4c187e6291ad672daf3dca7b2e2995586d6af39f653678cebd'
            'c0ca85be7ad22ff5cb03e80ea580b8fef1c3298d542f8f830bd2c58b7bb7d6d7'
            'dfe9e2f80dd62d882e45f8e85e53d6a8e1d3cdb02009a1ccc425c671ba540324'
            '54bc2161ee647c27dfcb0fcf8d4bd5b8bf609cb74caeadfae6aee0879da7e5b6'
            '1729fdf71bdde8d8696388038eaa9ede0f8e8c66d9c797b19202b619bfe0d53c')

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

  patch -p1 -i ${srcdir}/automake-1.8.5-gentoo-test-fixes.patch
  patch -p2 -i ${srcdir}/automake1.8-vs-modern-libtool.patch
  patch -p2 -i ${srcdir}/automake1.8-documentation.patch
  patch -p2 -i ${srcdir}/automake1.8-cygwin-test-fixes.patch

  patch -p1 -i ${srcdir}/automake-1.8-msys2.patch
}

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

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