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

pkgname=autogen
pkgver=5.18.16
pkgrel=6
pkgdesc="A tool designed to simplify the creation and maintenance of programs that contain large amounts of repetitious text"
arch=('i686' 'x86_64')
url="https://autogen.sourceforge.io/"
license=('GPL3')
makedepends=('gcc' 'gmp-devel' 'libxcrypt-devel' 'libffi-devel' 'libgc-devel' 'libguile-devel' 'libxml2-devel' 'make' 'autoconf' 'automake-wrapper' 'libtool' 'gperf')
depends=('gcc-libs' 'gmp' 'libxcrypt' 'libffi' 'libgc' 'libguile' 'libxml2')
source=("https://ftp.gnu.org/gnu/${pkgname}/rel${pkgver}/${pkgname}-${pkgver}.tar.xz"{,.sig}
        autogen-guile-3.0.patch
        autogen-5.18.1-msys2.patch)
sha256sums=('f8a13466b48faa3ba99fe17a069e71c9ab006d9b1cfabe699f8c60a47d5bb49a'
            'SKIP'
            'f57152bb9b192ddd2ae31741b2b0bf43f8bea58211fcbf15fb3b7f4084e5aaa3'
            'ff3df8d191a6269a2f64b6ec19d24bb5d169d316104f97f14a094633aaa77386')
validpgpkeys=('3EEE51D1355B8EC40D9F3122495143D05D0712D1')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/autogen-guile-3.0.patch
  patch -p1 -i ${srcdir}/autogen-5.18.1-msys2.patch
  autoreconf -fiv
}

build() {
  LDFLAGS+=' -Wl,--export-all-symbols'
  CFLAGS+=" -Wno-implicit-fallthrough -Wno-format-overflow -Wno-format-truncation -Wno-char-subscripts"
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure \
    --build=${CHOST} \
    --host=${CHOST} \
    --prefix=/usr \
    --disable-dependency-tracking
  make all
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  #make -k check
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
  if [ -d ${pkgdir}/usr/share/pkgconfig ]; then
    mv ${pkgdir}/usr/share/pkgconfig ${pkgdir}/usr/lib/
  fi
}
