#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-clisp
VERSION=2.48
DIRNAME=2.48
ARCH=alpha
BUILD=2

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf clisp-$VERSION
tar xjf $CWD/clisp-$VERSION.tar.bz2
cd clisp-$DIRNAME
zcat $CWD/makemake.in.diff.gz | patch -p0 --verbose || exit 1
chown -R root.root .
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --docdir=/usr/doc/clisp-$VERSION \
 --with-module=clx/new-clx \
 --with-module=pcre \
 --with-module=rawsock \
 --with-module=wildcard \
 --with-module=zlib \
 --disable-mmap \
 --with-dynamic-ffi \
 --cbc with-gcc-wall

cd with-gcc-wall
./makemake \
 --with-dynamic-ffi \
 --prefix=/usr \
 --with-module=clx/new-clx \
 --with-module=pcre \
 --with-module=rawsock \
 --with-module=wildcard \
 --with-module=zlib \
 --disable-mmap \
 --srcdir=../src \
 > Makefile

make config.lisp || exit 1
make init || exit 1
make allc || exit 1
make lisp.run || exit 1
make interpreted.mem || exit 1
make halfcompiled.mem || exit 1
make lispinit.mem || exit 1
make manual || exit 1
make modular || exit 1
make || exit 1

make install DESTDIR=$PKG
# Strip stuff:
( cd $PKG
 find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/doc/clisp-$VERSION
mv $PKG/usr/share/doc/* $PKG/usr/doc/clisp-$VERSION
rm -rf $PKG/usr/share/doc $PKG/usr/doc/clisp-$VERSION/doc
mv $PKG/usr/share/man $PKG/usr/man
gzip -9 $PKG/usr/man/man1/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/clisp-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/clisp.build.log
