# Maintainer: Phillip Smith <fukawi2@archserver.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>

pkgname=postgresql-libs
pkgver=8.4.2
pkgrel=1
pkgdesc="Libraries for use with PostgreSQL"
arch=('i686' 'x86_64')
license=('BSD')
url="http://www.postgresql.org/"
depends=('openssl>=0.9.8b' 'zlib' 'readline>=6.0')
options=('!makeflags')
source=("ftp://ftp.postgresql.org/pub/source/v${pkgver}/postgresql-${pkgver}.tar.bz2")
md5sums=('d738227e2f1f742d2f2d4ab56496c5c6')

build() {
  cd $srcdir/postgresql-$pkgver || return 1
  
  ./configure \
    --prefix=/usr \
    --with-system-tzdata=/usr/share/zoneinfo \
    --with-openssl \
    --datadir=/usr/share/postgresql \
    --with-pam || return 1

  cd src/include || return 1
  make || return 1
}

package() {
  cd $srcdir/postgresql-$pkgver || return 1
  
  # Install the adminpack contrib
  # make and install
  for dir in src/interfaces src/bin/pg_config; do
    pushd ${dir} || return 1
    make || return 1
    make DESTDIR=$pkgdir install || return 1
    popd
  done
  
  cd src/include || return 1
  
  set -e
  mkdir -p $pkgdir/usr/include/postgresql/{internal,internal/libpq} || return 1
  mkdir -p $pkgdir/usr/include/libpq || return 1
  
  # These headers are needed by the public headers of the interfaces.
  install -m644 pg_config.h         $pkgdir/usr/include/ || return 1
  install -m644 pg_config_os.h      $pkgdir/usr/include/ || return 1
  install -m644 postgres_ext.h      $pkgdir/usr/include/ || return 1
  install -m644 libpq/libpq-fs.h    $pkgdir/usr/include/libpq/ || return 1
  install -m644 pg_config_manual.h  $pkgdir/usr/include/ || return 1
  
  # These headers are needed by the not-so-public headers of the interfaces.
  install -m644 c.h $pkgdir/usr/include/postgresql/internal/ || return 1
  install -m644 port.h $pkgdir/usr/include/postgresql/internal/ || return 1
  install -m644 postgres_fe.h $pkgdir/usr/include/postgresql/internal/ || return 1
  install -m644 libpq/pqcomm.h $pkgdir/usr/include/postgresql/internal/libpq/ || return 1
 
  install -D -m644 ../../COPYRIGHT $pkgdir/usr/share/licenses/$pkgname/LICENSE || return 1

  set +e
}
# vim:set ts=2 sw=2 et:
