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

VERSION=4.3.3
ARCH=sparc
BUILD=1


# compile php
cd $TMP
rm -rf php-$VERSION
tar xjvf $CWD/php-$VERSION.tar.bz2
cd php-$VERSION
# Fixup perms/owners:
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -name "*.h" -exec chmod 644 {} \;
# Sometimes they ship a few of these:
find . -name "*.orig" -exec rm {} \;

EXTENSION_DIR=/usr/lib/php/extensions \
CFLAGS="-O2" \
./configure --prefix=/usr \
  --sysconfdir=/etc \
  --enable-discard-path \
  --with-config-file-path=/etc/apache \
  --enable-safe-mode \
  --with-pgsql=shared,/usr \
  --enable-shared \
  --disable-debug \
  --disable-static \
  --without-mysql --disable-cli # Just to save some time

make
mkdir -p $PKG/usr/lib/php/extensions
cp -a modules/pgsql.so $PKG/usr/lib/php/extensions

mkdir -p $PKG/usr/doc/php-pgsql-$VERSION
cp -a \
  ext/pgsql/CREDITS ext/pgsql/README \
  $PKG/usr/doc/php-pgsql-$VERSION
chown -R root.root $PKG/usr/doc/php-pgsql-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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