#!/bin/sh
## ----------------------------------------------------------------------------
##									     --
##			GNADE  : GNu Ada Database Environment		     --
##									     --
##  Filename	    : $Source: /cvsroot/gnade/gnade/configure,v $	     --
##  Description	    : shell script to configure	the build environment.	     --
##  Author	    : Michael Erdmann <Michael.Erdmann@snafu.de>	     --
##  Created On	    : 03-Jan-2001					     --
##  Last Modified By: $Author: merdmann $
##  Last Modified On: $Date: 2006/12/26 17:43:12 $
##  Revision	    : $Revision: 1.48 $	
##  Status	    : $State: Exp $
##									     
##  Copyright (C) 2000-2004						     --
##									     --
##  GNADE is copyrighted by the	persons	and institutions enumerated in the   --
##  AUTHORS file. This file is located in the root directory of	the	     --
##  GNADE distribution.							     --
##									     --
##  GNADE is free software;  you can redistribute it  and/or modify it under --
##  terms of the  GNU General Public License as	published  by the Free Soft- --
##  ware  Foundation;  either version 2,  or (at your option) any later	ver- --
##  sion.  GNAT	is distributed in the hope that	it will	be useful, but WITH- --
##  OUT	ANY WARRANTY;  without even the	 implied warranty of MERCHANTABILITY --
##  or FITNESS FOR A PARTICULAR	PURPOSE.  See the GNU General Public License --
##  for	 more details.	You should have	 received  a copy of the GNU General --
##  Public License  distributed	with GNAT;  see	file COPYING.  If not, write --
##  to	the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
##  MA 02111-1307, USA.							     --
##									     --
##  As a special exception,  if	other files  instantiate  generics from	     --
##  GNADE Ada units, or	you link GNADE Ada units or libraries with other     --
##  files  to produce an executable, these  units or libraries do not by     --
##  itself cause the resulting	executable  to	be covered  by the  GNU	     --
##  General  Public  License.  This exception does not however invalidate    --
##  any	other reasons why  the executable file	might be covered by the	     --
##  GNU	Public License.							     --
##									     --
##									     --
##  GNADE is implemented to work with GNAT, the	GNU Ada	compiler.	     --
##									     --
## ----------------------------------------------------------------------------
##
. ./VERSION
VERS=$GNADE_MAJOR.$GNADE_MINOR.$GNADE_PATCHLEVEL
echo
echo "GNAT Data Base Developement Environment (GNADE) $VERS" 
echo "(C) Copyright 2000-2004; the GNADE Team (see --show-authors)"
echo 

## check for cygwin
buildenv=gnu
basedir=`pwd` ;	
if test -e /usr/bin/cygpath.exe ; then
   basedir=`cygpath -m $basedir`
   buildenv=cygwin
fi
export basedir

config_opt=""
sampledb="" 
build_samples_opt="--with-sample=samples"
odbc_opt="--with-odbc=y"
dboperator=$USER;
root="/usr/local/gnade"

for i in $* ; do
   case	"$1" in
    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
       *) optarg= ;;
   esac

   case	$1 in
      -D|--enable-debug) 
         config_opt="$config_opt --enable-debug";;
      -S|--enable-assert) 
         config_opt="$config_opt --enable-assert";;
      -a|--show-authors)
         cat AUTHORS
         exit 0
         ;;
      --help|-h)
         echo "configure [ option(s) ] [ native(s) ]"
         echo
         echo "option(s):"
         echo "   --help              this message"
         echo "   --enable-debug      compile with debugging code"
         echo "   --enable-assert     compile with assert option"
         echo "   --show-authors      display the authors of the GNADE team"
         echo "   --nosamples         do not include the samples in the	build"
         echo "   --dbadmin=<user>    Set the database administrator to	a different name as the	login"
         echo "   --sampledb=<db>     define the sample	db. If not given no sample"
         echo "                       database will be generated. Possible values are:"
         echo "				 mysql "
         echo "				 postgres "
         echo "				 mimer "
	 echo "   --all               configure all known native libraries"
	 echo "   --no-odbc           odbc/esql is not build or installed"
	 echo "   --unicode           force the usage of unicode"
	 echo "   --root=<dir>        define the target installation root (/usr/local/gnade)."
         echo 
         echo "native(s)"
         echo "   This optional parameter may contain one or more RDBMS products"
         echo "   for which native bindings may be build."
         echo
         echo "      postgres	- PostgreSQL [http://www.postgresql.org/]"
         echo "      mysql	- MySQL	     [http://www.mysql.com/]"
         echo "      oracle	- Oracle     [http://www.oracle.com/]"
	 echo "      sqlite	- SQLLite    [http://www.sqlite.org/]"
         echo 
         exit 0	
         ;;

      --nosamples)
         build_samples_opt=""
         ;;

      --no-odbc)
         odbc_opt=""
	 ;;

      --sampledb=*) 
         case $optarg in 
            postgres|mysql|mimer)
               sampledb=$optarg
               ;;
            *)
               echo "ERROR: No sample database available for $optarg."
               echo
               exit 1
               ;;
         esac
         ;;
      --dbadmin=*)
         dboperator=$optarg
         ;;
      --root=*)
         root=$optarg
	 ;;

      --unicode)
         config_opt="$config_opt --with-unicode=y"
	 ;;

      --all)
      	 for i in postgres mysql oracle sqlite ; do
            config_opt="$config_opt --with-$i"
	 done
	 ;;
 
      *) ## check the native bindings
         case $1 in 
            postgres|mysql|oracle|oci|adbc|sqlite)
	       if test "$1" = "oci" ; then
                  config_opt="$config_opt --with-oracle"
	       else
                  config_opt="$config_opt --with-$1"
	       fi
               ;;
            odbc)
	       ;;
            *)
               echo "ERROR: No native bindings available for $1; see --help switch."
	       echo 
               exit 1
               ;;
         esac
         ;;
      
   esac
   shift 
done

config_opt="$config_opt	$build_samples_opt"
( cd autoconf && make && ./configure --with-root=$root \
     --with-install-dir=$basedir/autoconf \
     --prefix=$basedir --with-dboperator=$dboperator \
     --with-sampledb=$sampledb $config_opt $odbc_opt ) 
if test	$? -ne 0
then
   echo	
   echo	"** CONFIGURE ABORTED **"
   echo
   exit	$?
fi
make -s directories
make -s -C./cfg ADAMAKE="gnatmake -q"
make -s -C./cfg/scripts-$buildenv install
rm -rf gnade.gpr
make -s gnade.gpr
chmod +x ./bin/*.sh
echo
echo " ** CONFIGURE COMPLETE **	"
echo
