CWD=`pwd`
PKG=/tmp/package-popt
rm -rf $PKG
mkdir -p $PKG/usr

VERSION=1.7
ARCH=sparc
BUILD=0

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mcpu=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "sparc" ]; then
  SLKCFLAGS="-O2"
fi

cd /tmp
tar xzvf $CWD/popt-$VERSION.tar.gz
cd popt-$VERSION
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 775 -exec chmod 755 {} \;
CFLAGS="$SPKCFLAGS" \
./configure --prefix=/usr \
            --sysconfdir=/etc
make
make install DESTDIR=$PKG

# Note: you'll get errors here.  
# Why are we doing this?  $PKG/usr/bin/* doesn't exist, even in x86
strip $PKG/usr/bin/*
chown -R root.bin $PKG/usr/bin

if [ "$ARCH" = "sparc" ]; then
( cd $PKG
  find . | xargs file | grep "ELF 32-bit MSB executable" | grep SPARC | cut -f 1 -d : | xargs strip --strip-unneeded
  find . | xargs file | grep "ELF 32-bit MSB shared object" | grep SPARC | cut -f 1 -d : | xargs strip --strip-unneeded
)
else
( cd $PKG
  find . | xargs file | grep "ELF 32-bit LSB executable" | grep 80386 | cut -f 1 -d : | xargs strip --strip-unneeded
  find . | xargs file | grep "ELF 32-bit LSB shared object" | grep 80386 | cut -f 1 -d : | xargs strip --strip-unneeded
)
fi

gzip -9 $PKG/usr/man/man?/*
mkdir -p $PKG/usr/doc/popt-$VERSION
cp -a \
  COPYING README \
  $PKG/usr/doc/popt-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd /tmp/package-popt
makepkg -l y -c n ../popt-$VERSION-$ARCH-$BUILD.tgz
