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

pkgname=automake1.15
pkgver=1.15.1
pkgrel=4
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
        automake1.15-documentation.patch
        automake-1.15.1-msys2.patch
        automake-1.15.1-perl-escape-curly-bracket.patch)
sha256sums=('af6ba39142220687c500f79b4aa2f181d9b24e4f8d8ec497cea4ba26c64bedaf'
            'e5ca855db96fab8106239cec2dcee48ea3f7d2ab5745b116f7d85dfd962b7553'
            '0c2560b6c58446f43552e3cd43f2f9d82f1bbe6ff993d358365a77a4b460ae37'
            '18073dbcf0939419906cdb9714171f5da0ad899af229304e50321d07a19e0d26')
validpgpkeys=('E1622F96D2BB4E58018EEF9860F906016E407573'   # Stefano Lattarini
              'F2A38D7EEB2B66405761070D0ADEE10094604D37')  # Mathieu Lirzin
replace=('automake')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -i "${srcdir}"/${_fname}
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ] || [ -d $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #


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

  apply_patch_with_msg  automake1.15-documentation.patch \
    automake-1.15.1-msys2.patch \
    automake-1.15.1-perl-escape-curly-bracket.patch
}

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

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

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