#!/bin/sh

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

# Set default options

configureoptions=""
targetoptions="-O2" #optimised by default

# Parse command line arguments

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

      --compiletype=debug)
	  targetoptions="-g";;

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

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

      --compiletype=optimised)
          ;;

      --help)
          print_help
	  exit 0;;

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

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

    shift
done

# Export variables to be read by ./configure

export targetoptions

# Run ./configure

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

# Create directories

mkdir -p lib
mkdir -p objs

exit 0;
