# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=autoconf
pkgname=${_realname}2.69
pkgver=2.69
pkgrel=4
pkgdesc="A GNU tool for automatically configuring source code"
arch=('any')
license=('spdx:GPL-2.0-or-later' 'spdx:GPL-3.0-or-later' 'spdx:Autoconf-exception-3.0')
url="https://www.gnu.org/software/autoconf"
depends=('awk' 'm4' 'diffutils' 'bash' 'perl')
makedepends=('make')
source=(https://ftp.gnu.org/pub/gnu/${_realname}/${_realname}-${pkgver}.tar.xz
        0001-fix-texinfo.patch
        0002-msys2.patch
        0003-autotest-remove-cr-from-prog-stdout-stderr.patch
        0004-docs.patch
        0005-package.patch
        autoconf-2.69-K-R-decls-clang.patch
        autoconf-2.69-fix-libtool-test.patch
        autoconf-2.69-make-tests-bash5-compatible.patch
        autoconf-2.69-perl-5.26-2.patch
        autoconf-2.69-perl-5.26.patch)
sha256sums=('64ebcec9f8ac5b2487125a86a7760d2591ac9e1d3dbd59489633f9de62a57684'
            'ad42ff57d1ff3dd6ba06fe94f913a369f9210963856e8c955efed9a164609a64'
            '9f31df02eb41df57a05ceea1d1442424d1cca63cd9304c953732fa6c65279a5a'
            '74e2135a3f34f5692a77de85c21cb2f0fd8a1dcf396f7fbba7deb0c59faa54eb'
            'bc973e76f3ea3941818099cb5a22081c8a9703338b3194fce3534a07ac32c078'
            'a9bd30264a812672bf7fa7b67135871ccac4c84b30113b82ea7c2f5987e0d951'
            '1253d17e557310f538b0a37fff8c36061a99c43158ed97a68cdf109cd58686b6'
            '7793209b33013dc0f81208718c68440c5aae80e7a1c4b8d336e382525af791a7'
            '176d4bf66920f66115aba6c44a71a7197b3d65038aac51ba51f61e241bc3e398'
            'a49dd5bac3b62daa0ff688ab4d508d71dbd2f4f8d7e2a02321926346161bf3ee'
            '35c449281546376449766f92d49fc121ca50e330e60fefcfc9be2af3253082c2')

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

  # MSYS2
  patch -p1 -i ${srcdir}/0001-fix-texinfo.patch
  patch -p1 -i ${srcdir}/0002-msys2.patch
  patch -p1 -i ${srcdir}/0003-autotest-remove-cr-from-prog-stdout-stderr.patch
  patch -p1 -i ${srcdir}/0004-docs.patch
  patch -p1 -i ${srcdir}/0005-package.patch

  # from gentoo: https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-devel/autoconf/files
  patch -p1 -i ${srcdir}/autoconf-2.69-perl-5.26.patch
  patch -p1 -i ${srcdir}/autoconf-2.69-fix-libtool-test.patch
  patch -p1 -i ${srcdir}/autoconf-2.69-perl-5.26-2.patch
  patch -p1 -i ${srcdir}/autoconf-2.69-make-tests-bash5-compatible.patch
  patch -p1 -i ${srcdir}/autoconf-2.69-K-R-decls-clang.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --prefix=/usr \
    --program-suffix=-2.69

  make
}

check() {
  cd ${srcdir}/build-${MSYSTEM}
  make check
}

package() {
  cd ${srcdir}/build-${MSYSTEM}
  make DESTDIR=${pkgdir} install

  # license exception
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING.EXCEPTION \
    $pkgdir/usr/share/licenses/autoconf${pkgver}/COPYING.EXCEPTION

  # conflicts with autoconf
  rm -rf ${pkgdir}/usr/share/{emacs,info}
}
