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

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/galeon-0.11.0.tar.gz
cd galeon-0.11.0
CFLAGS=-O2 CXXFLAGS=-O2 ./configure --prefix=/opt/gnome \
            --sysconfdir=/etc/opt/gnome \
            --with-mozilla-libs=/opt/gnome/lib \
            --with-mozilla-home=/opt/gnome/lib/mozilla \
            --with-mozilla-includes=/opt/gnome/include/mozilla \
            sparc-slackware-linux
make
make DESTDIR=$PKG install
cat $CWD/galeon > $PKG/opt/gnome/bin/galeon
mkdir -p $PKG/usr/doc/galeon-0.11.0
cp -a ABOUT-NLS AUTHORS COPYING COPYING.README ChangeLog FAQ INSTALL NEWS \
      README THANKS TODO $PKG/usr/doc/galeon-0.11.0
chmod 644 $PKG/usr/doc/galeon-0.11.0/*
chown root.root $PKG/usr/doc/galeon-0.11.0/*

# Build the package:
cd $PKG
echo "y
n" | makepkg $TMP/galeon.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/galeon-0.11.0
  rm -rf $PKG
fi
