NAME="guile"
DESC="GNU Project's extension language library"
VERSION="3.0.9"
FILES=("https://ftp.gnu.org/gnu/guile/guile-$VERSION.tar.xz")
HASHES=("258983e0156c2bc66539dcbcb96f2bd2")
DEPENDS=("gc" "libunistring")

PACKAGE() {
  tar xf $NAME-$VERSION.tar.xz
  cd $NAME-$VERSION

  ./configure --prefix=/usr  \
            --disable-static \
            --docdir=/usr/share/doc/guile-$VERSION
  make && make html
  makeinfo --plaintext -o doc/r5rs/r5rs.txt doc/r5rs/r5rs.texi
  makeinfo --plaintext -o doc/ref/guile.txt doc/ref/guile.texi

  make DESTDIR="$ROOTDIR" install && make DESTDIR="$ROOTDIR" install-html
  mkdir -p "$ROOTDIR/usr/share/gdb/auto-load/usr/lib"
  mv "$ROOTDIR/usr/lib/libguile"-*-gdb.scm "$ROOTDIR/usr/share/gdb/auto-load/usr/lib"
  mv "$ROOTDIR/usr/share/doc/guile-$VERSION"/{guile.html,ref}
  mv "$ROOTDIR/usr/share/doc/guile-$VERSION"/r5rs{.html,}

  find examples -name "Makefile*" -delete
  cp -vR examples "$ROOTDIR/usr/share/doc/guile-$VERSION"

  for DIRNAME in r5rs ref; do
    install -v -m644  doc/${DIRNAME}/*.txt \
                    "$ROOTDIR/usr/share/doc/guile-$VERSION/${DIRNAME}"
  done &&
  unset DIRNAME

  cd .. && rm -r $NAME-$VERSION
}
