#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-clisp

VERSION=2.31
ARCH=i486
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG # place for the package to be built

#=================================================================
# First we need this.  It used to ship with CLISP, but no longer does.
cd $TMP
rm -rf libsigsegv-2.0
tar xzf $CWD/libsigsegv-2.0.tar.gz
cd libsigsegv-2.0
chown -R root.root .
#./configure --prefix=/usr --enable-shared=yes --enable-static=yes
./configure --prefix=/usr --enable-static=yes
make
# Now I must install this.  Sorry, it's gotta happen.
make install
# Now add to the package:
mkdir -p $PKG/usr
make install prefix=$PKG/usr
strip --strip-unneeded $PKG/usr/lib/*.so
strip -g $PKG/usr/lib/*.a
mkdir -p $PKG/usr/doc/clisp-$VERSION/libsigsegv-2.0
cp -a \
  AUTHORS COPYING ChangeLog NEWS PORTING README \
  $PKG/usr/doc/clisp-$VERSION/libsigsegv-2.0
#=================================================================
 
cd $TMP
rm -rf clisp-$VERSION
tar xjvf $CWD/clisp-$VERSION.tar.bz2
cd clisp-$VERSION
chown -R root.root .
CFLAGS="-O2 -march=i486 -mcpu=i686" \
./configure --prefix=/usr with-gcc-wall
cd with-gcc-wall
./makemake --with-dynamic-ffi --prefix=/usr > Makefile
make
make install DESTDIR=$PKG
# Strip stuff:
( cd $PKG
 find . | xargs file | grep "ELF 32-bit LSB executable" | grep 80386 | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
chown -R root.bin $PKG/usr/bin
mv $PKG/usr/share/doc/clisp/* $PKG/usr/doc/clisp-$VERSION
rm -f $PKG/usr/doc/clisp-$VERSION/clisp.{dvi,html,ps}
rm -r $PKG/usr/share/{doc,dvi,html}
mv $PKG/usr/share/man $PKG/usr/man
gzip -9 $PKG/usr/man/man?/*.?
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/clisp-$VERSION-$ARCH-$BUILD.tgz

