# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Tom Newsom <Jeepster@gmx.co.uk>

pkgname=guile
pkgver=3.0.9
pkgrel=1.1
pkgdesc='Portable, embeddable Scheme implementation written in C'
url='https://www.gnu.org/software/guile/'
license=(GPL)
ncxfat_makedepends=(binutils gmp ncurses libunistring libffi libxcrypt gcc gc glibc readline)
ncxfab_makedepends=(base-devel texinfo make sh crosspacman sed gperf)
source=(https://ftp.gnu.org/pub/gnu/guile/guile-$pkgver.tar.gz{,.sig})
validpgpkeys=('3CE464558A84FDC69DB40CFB090B11993D9AEBB5' # Ludovic Courtès <ludo@gnu.org>
              'FF478FB264DE32EC296725A3DDC0F5358812F8F2' # Andy Wingo
              '4FD4D288D445934E0A14F9A5A8803732E4436885') # Andy Wingo <wingo@pobox.com>"
sha256sums=('18525079ad29a0d46d15c76581b5d91c8702301bfd821666d2e1d13726162811'
            'SKIP')

build() {

  if (( MPKG_CROSSCOMPILED )); then
      mkdir -p build-native
      cd build-native

      ../guile-$pkgver/configure --prefix=/usr \
                                 --disable-static  \
                                 --disable-error-on-warning
      sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
      make -j$(nproc)
      _CROSS_ARG='GUILE_FOR_BUILD=../build-native/meta/guile'
      cd ..
  fi

  cd guile-$pkgver
  ./configure --prefix=$MPKG_USRPATH \
    --build=$MPKG_BUILDMACHINE \
    --host=$MPKG_TARGETMACHINE \
    --disable-static  \
    --disable-error-on-warning \
    --disable-rpath \
    --with-libgmp-prefix=$MPKG_BUILDSYSROOT \
    --with-libunistring-prefix=$MPKG_BUILDSYSROOT \
    $_CROSS_ARG

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make -j$(nproc)
}

check() {
  cd guile-$pkgver
  make check
}

package() {
  ncxfat_depends=(gmp ncurses libunistring libffi libxcrypt gc glibc)
  make -C guile-$pkgver DESTDIR="$pkgdir" install
  rm "$pkgdir"$MPKG_USRPATH/lib/libguile-3.?.so.*-gdb.scm
}
