#!/bin/sh
CWD=`pwd` 
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-gmp

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

cd $TMP
tar xzvf $CWD/gmp-3.1.1.tar.gz
cd gmp-3.1.1
CFLAGS=-O2 ./configure --prefix=/usr \
                       --with-gnu-ld #\
#                       sparc-slackware-linux-gnu
make
make DESTDIR=$PKG install
mkdir -p $PKG/usr/doc/gmp-3.1.1
cp -a AUTHORS COPYING COPYING.LIB ChangeLog INSTALL NEWS README \
   $PKG/usr/doc/gmp-3.1.1
chown -R root.root $PKG/usr/doc/gmp-3.1.1
chmod 644 $PKG/usr/doc/gmp-3.1.1/*
rm $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*

# Build the package:
cd $PKG
echo "y
n" | makepkg $TMP/gmp.tgz

# Warn of zero-length files:
for file in `find . -type f -print` ; do
 if [ "`filesize $file`" = "0" ]; then
  echo "WARNING: zero length file $file"
 fi
 if [ "`filesize $file`" = "20" ]; then
  echo "WARNING: possible empty gzipped file $file"
 fi
done

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/gmp-3.1.1
  rm -rf $PKG
fi
