#!/bin/sh
#
# Copyright (c) 2001, Roland Jesse
# All rights reserved.
#
# This file is part of the Mango recipe management distribution.
# For license and copyright information see the file COPYRIGHT or 
# <http://www.opensource.org/licenses/bsd-license.html>.
#
# $Id: configure,v 1.5 2002/06/14 22:09:17 rjesse Exp $

# Note: Depends on qmake (which is included in Qt version 3 or later).

base_dir=`pwd`

# Defaults
RELEASEVERSION=no
FLAGS="CONFIG+=debug"
QEXTFLAGS=""
PLATFORM=$QMAKESPEC
PREFIX=/usr/local
VERBOSE=yes

# Programs used
ENV=/usr/bin/env
QMAKE=qmake

# Parse arguments. Set things to "yes" or "no".

while [ -n "$1" ]; do
    case $1 in
    -prefix)
	shift; PREFIX=$1
	;;
    -kde)
	QEXTFLAGS="CONFIG+=kde"
	;;
    -debug)
	RELEASEVERSION=no
	;;
    -release)
	RELEASEVERSION=yes
	;;
    -quiet)
	VERBOSE=no
	;;
    -verbose)
	VERBOSE=yes
	;;
    -platform)
	shift; PLATFORM=$1
	;;
    *)
	echo
	echo $1: unknown argument
	echo Usage: $0 [--release]
	echo Here is a short explanation of each option:
	echo \(defaults are marked with an asterix\)
	echo
	echo " -prefix <directory> ... Target directory."
	echo
	echo " -kde .................. Build with KDE integration."
	echo
	echo " -debug (*) ............ Build a debug version of the program."
	echo " -release .............. Build a release version of the program."
	echo
	echo " -quiet ................ Try not to fill the screen with noise."
	echo " -verbose (*) .......... Print lots of configure statements."
	echo
	echo " -platform <platform> .. Set operating system / compiler."
	echo
	echo In case of conflict, the last specified option wins.
	echo
	exit 0
	;;
    esac
    shift
done

# ------------------------------------------------------------------------
if [ -z $PLATFORM ]
then
    echo
    echo "The build script cannot determine your platform."
    echo "Please rerun this script with the -platform option to"
    echo "set the operating system / compiler combination you use."
    echo "See directory \$QTDIR/mkspecs/ for available options."
    echo
    echo "Alternativly, you might just want to set the \$QMAKESPEC"
    echo "environment variable. Please see the qmake documentation for"
    echo "details."
    echo
    exit 1
fi

# ------------------------------------------------------------------------
if [ $RELEASEVERSION = yes ]
then
    FLAGS="CONFIG+=release"
fi

# ------------------------------------------------------------------------
if [ $VERBOSE = yes ]
then
    echo
    echo Generating Makefile ...
    echo
fi

# ------------------------------------------------------------------------
$ENV PREFIX=$PREFIX QMAKESPEC=$PLATFORM $QMAKE mango.pro $FLAGS $QEXTFLAGS -o Makefile
if [ ! -e Makefile ]
then
    exit 1
fi
if [ Makefile -ot mango.pro ]
then
    exit 1
fi

# ------------------------------------------------------------------------
if [ $VERBOSE = yes ]
then
    echo
    echo --------------------------------------
    echo  configuration done
    echo
    echo  to build and install everything just
    echo  type:
    echo  % make
    echo  % make install.
    echo --------------------------------------
fi
