#!/bin/bash
#
# This (poor) script builds the debian package for pgAdmin3
# If invoked without any parameter it assumes that all
# the required packages are installed (if not, dpkg-buildpackage
# will exit telling you missing dependencies)
#
# If you already have your own wxWindows 2.5 compiled and installed
# and don't want to use the binary snapshot that we provide, you can specify
# the name of your wxconfig script with the -wxconfig option. Be aware that
# by doing this, dependencies won't be checked anymore.
#
# Raphael Enrici - <pgadmin-hackers@postgresql.org> - 20030720
#
#( Personal Changelog:
#	20030807:
#	  - Added better handling of package version to create
#	  - Fixed debian package version scheme
#)

# These to environment variables can be set before
# calling make-deb
DCH_RELEASE=${DCH_RELEASE:-"0.0.1+makedeb"}
DCH_COMMENT=${DCH_COMMENT:-"make-deb release"}

#
HERE=`pwd`
TAR=tar
usage() {
        echo "Usage:`basename $0` [ -wxconfig wxconfig_name ]"
        exit 1
}

if [ ! -d $HERE/pkg/debian ]
then
        echo You must launch this script from the top level directory
        echo "of pgAdmin3's snapshot"
        echo "Example : cd pgadmin3-x.y.z ; ./pkg/debian/make-deb"
        exit 1
fi

while [ $# -ne 0 ]
do
echo $1
  case "$1" in
        -wxconfig|--wxconfig)
                shift
                _deb_wxconfig="$1"
                export _deb_wxconfig
                IGNOREDEP="-d"
                shift || usage
        ;;
        *)
                usage
        ;;
  esac
done

(cd pkg; $TAR cf - debian ) | tar xpf -
rm debian/make-deb
chmod 755 debian/rules
pgadmin3vers=`basename $HERE | awk -F- '{print $2}'`
set -x
touch TODO.txt
dch --newversion $pgadmin3vers-$DCH_RELEASE $DCH_COMMENT || exit 1
dpkg-buildpackage ${IGNOREDEP} -b -rfakeroot
