# sbcl build system expect these environment variables
export CFLAGS="${CPPFLAGS} ${CFLAGS} -DSBCL_HOME=/usr/lib/sbcl"
export GNUMAKE="make"
export LINKFLAGS="$LDFLAGS"

abinfo "Building sbcl ..."
sh "$SRCDIR"/make.sh sbcl \
    --prefix=/usr \
    --fancy

abinfo "Building sbcl documentation ..."
make info \
    -C "$SRCDIR"/doc/manual

abinfo "Installing sbcl ..."
SBCL_HOME="" \
INSTALL_ROOT="$PKGDIR"/usr \
    sh "$SRCDIR"/install.sh

abinfo "Apply core fixes ..."
"$SRCDIR"/src/runtime/sbcl \
    --core "$SRCDIR"/output/sbcl.core \
    --script $SRCDIR/autobuild/fixes.lisp
mv -v "$SRCDIR"/sbcl-new.core \
    "$PKGDIR"/usr/lib/sbcl/sbcl.core

abinfo "Installing sbcl sources ..."
mkdir -pv "$PKGDIR"/usr/share/sbcl-source
cp -rv "$SRCDIR"/{src,contrib} \
    "$PKGDIR"/usr/share/sbcl-source/

abinfo "Removing unwanted files ..."
find "$PKGDIR" \
    \( -name Makefile \
        -o -name .cvsignore \) \
    -delete
find "$PKGDIR"/usr/share/sbcl-source \
    -type f \
    \( -name \*.fasl \
        -o -name \*.o \
        -o -name \*.log \
        -o -name \*.so \
        -o -name a.out \) \
    -delete

abinfo "Removing redundant sbcl runtime files ..."
rm -v "$PKGDIR"/usr/share/sbcl-source/src/runtime/sbcl
