#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-postgresql
ARCH=alpha
VERSION=8.3.3
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf postgresql-$VERSION
tar xjf $CWD/postgresql-$VERSION.tar.bz2
cd postgresql-$VERSION
chown -R root.root .
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --with-tcl \
 --with-perl \
 --with-python \
 --with-ldap \
 --with-openssl \
 --enable-nls \
 --enable-integer-datetimes \
 --build=$TARGET || exit 1
make -j4 || exit 1
make DESTDIR=$PKG install
gzip -9 $PKG/usr/man/man?/*
( cd $PKG
 find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/etc/logrotate.d
zcat $CWD/postgresql.gz > $PKG/etc/logrotate.d/postgresql
mkdir -p $PKG/etc/rc.d
zcat $CWD/rc.postgresql.new > $PKG/etc/rc.d/rc.postgresql.new
mkdir -p $PKG/install
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/postgresql-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/postgresql.build.log
