#!/bin/sh

print_help()
{
    echo "Usage: DSLrunConfigure [ --compiletype=optimised/debug/profile ] [ --buildtype=internal/external ]"
    echo "                    [ --help ] [ configure-options ]"
    echo
    echo "   --help              this help screen"
    echo "   --help-configure    configure help screen"
    echo "   --compiletype"
    echo "                       debug     (unoptimised debugging build [default])"
    echo "                       optimised (optimised build)"
    echo "                       profiling (profiling build)"
    echo "   --buildtype"
    echo "                       internal [default]"
    echo "                       external"
    echo "                       static"
    echo "                       shared"
    echo
    echo "       all other options passed to configure"
}

# Set default options

configureoptions=""
buildtype="internal" #internal build by default
targetoptions="-g" #debug by default. Werror is not included by runConfigure since optimisation can produce random `not used' errors. There are now STL warnings too, so Werror is switched off here.

# Parse command line arguments

until [ -z "$1" ]
do
    case $1 in

      --compiletype=optimised)
	  targetoptions="-O2";;

      --compiletype=profiling)
	  targetoptions="-pg -g";;

      --compiletype=profile)
	  targetoptions="-pg -g";;

      --compiletype=debug)
	  ;;

      --buildtype=internal)
          buildtype="internal";;

      --buildtype=external)
          buildtype="external";;

      --buildtype=static)
          buildtype="static";;

      --buildtype=shared)
          buildtype="internal";;

      --help)
          print_help
	  exit 0;;

      --help-configure)
          ./configure --help
	  exit 0;;

      *)
	  configureoptions="$configureoptions $1";;
    esac

    shift
done

# Internal build: disable shared libraries for compilation speed and debugging ease
# External build: build all libraries for testing purposes

if test "$buildtype" = "internal"
    then configureoptions="$configureoptions --disable-static --disable-fast-install"
fi
if test "$buildtype" = "static"
    then configureoptions="$configureoptions --disable-shared --disable-fast-install"
fi

# Export variables to be read by ./configure

export targetoptions

# Run ./configure

rm -f config.cache config.log config.status
./configure $configureoptions

# Create output directories

mkdir -p lib
mkdir -p objs

exit 0;
