# Maintainer: Jan de Groot <jgc@archlinux.org>
# Contributor: Arjan Timmerman <arjan@soufly.nl>
# Contributor: Tor Krill

pkgname=autogen
pkgver=5.18.16
pkgrel=5
pkgdesc="A tool designed to simplify the creation and maintenance of programs that contain large amounts of repetitious text"
arch=('x86_64')
url="https://www.gnu.org/software/autogen/"
license=('GPL3')
depends=('guile' 'libxml2' 'perl')
makedepends=('autogen' 'chrpath')
source=(https://ftp.gnu.org/gnu/${pkgname}/rel${pkgver}/${pkgname}-${pkgver}.tar.xz{,.sig}
        guile-3.0.patch
        10_libopts_tarball_perms.diff)
validpgpkeys=('44A088E295C3A722C450590EC9EF76DEB74EE762'
              '3EEE51D1355B8EC40D9F3122495143D05D0712D1') # Bruce Korb <bkorb@gnu.org>
sha512sums=('5f12c982dbe27873f5649a96049bf019ff183c90cc0c8a9196556b0ca02e72940cd422f6d6601f68cc7d8763b1124f2765c3b1a6335fc92ba07f84b03d2a53a1'
            'SKIP'
            '4864c9f20448b7eea0e36b35b15408baf5485f77fe7b1e9181c5636ab30c6871c74c654da05c6b84c8e6a057531c234a6a1e263b7465d54842c04bfc9c5b821d'
            '687a725cc901b4acaa73e4503c933b949a99264647e0829902f3d9c7bc62867268cabdf2c31fe10dcfdec9b69397ef27592196b097e3c19c6b714ef84d4060a4')

prepare() {
  cd $pkgname-$pkgver
  patch -Np1 -i ${srcdir}/guile-3.0.patch
  # Reproducible man page generation
  export MAN_PAGE_DATE=$(LC_ALL=C date -u -d '@$(SOURCE_DATE_EPOCH)' +%Y-%m-%d)
  patch -Np1 -i ${srcdir}/10_libopts_tarball_perms.diff
  sed -i 's/ -Werror / /' configure
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

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

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install

  # Remove unrequired RPATH from binaries
  for i in ${pkgdir}/usr/bin/*; do
    if chrpath --list "$i"; then
      chrpath --delete "$i";
    fi
  done
}
