#!/bin/sh
#
# Configures to build the Qt library
#
# Copyright (C) 1999-$THISYEAR$ Trolltech AS.  All rights reserved.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#

#-------------------------------------------------------------------------------
# script initialization
#-------------------------------------------------------------------------------

# the name of this script
relconf=`basename $0`
# the directory of this script is the "source tree"
relpath=`dirname $0`
relpath=`(cd $relpath; /bin/pwd)`
# the current directory is the "build tree" or "object tree"
outpath=`/bin/pwd`

# later cache the command line in config.status
OPT_CMDLINE=`echo $@ | sed "s,-v ,,g; s,-v$,,g"`

# initialize global variables
QMAKE_SWITCHES=
QMAKE_VARS=
QMAKE_CONFIG=
QT_CONFIG=

SUPPORTED=

#-------------------------------------------------------------------------------
# operating system detection
#-------------------------------------------------------------------------------

# need that throughout the script
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown


#-------------------------------------------------------------------------------
# window system detection
#-------------------------------------------------------------------------------

PLATFORM_X11=no
PLATFORM_MAC=no
PLATFORM_QWS=no

if [ -f $relpath/src/gui/kernel/qapplication_mac.cpp ] && [ -d /System/Library/Frameworks/Carbon.framework ]; then
    # Qt/Mac
    # ~ the Carbon SDK exists
    # ~ src/gui/base/qapplication_mac.cpp is present
    # ~ this is the internal edition and Qt/Mac sources exist
    PLATFORM_MAC=maybe
elif [ -f $relpath/src/gui/kernel/qapplication_qws.cpp ]; then
    # Qt/Embedded
    # ~ src/gui/base/qapplication_qws.cpp is present
    # ~ this is the free or commercial edition
    # ~ this is the internal edition and Qt/Embedded is explicitly enabled
    PLATFORM_QWS=maybe
fi


#-------------------------------------------------------------------------------
# check commercial license
#-------------------------------------------------------------------------------

# Open Source edition - may only be used under the terms of the QPL or GPL.
if [ -f $relpath/LICENSE.QPL -o -f $relpath/LICENSE.GPL ]; then
    [ "$PLATFORM_MAC" = "maybe" ] && PLATFORM_MAC=yes
    [ "$PLATFORM_QWS" = "maybe" ] && PLATFORM_QWS=yes
    Edition="free"
    Licensee="Free"
    Products="qt-free"
# Preview Edition.
elif [ -f $relpath/LICENSE.PREVIEW ]; then
    [ "$PLATFORM_MAC" = "maybe" ] && PLATFORM_MAC=yes
    [ "$PLATFORM_QWS" = "maybe" ] && PLATFORM_QWS=yes
    Edition="preview"
    Licensee="Preview"
    Products="qt-preview"
# Evaluation version.
elif [ -f $relpath/LICENSE.EVAL ]; then
    [ "$PLATFORM_QWS" = "maybe" ] && PLATFORM_QWS=yes
    Edition="eval"
    Licensee="Evaluation"
    Products="qt-eval"
# Internal Trolltech edition.
elif [ -f $relpath/LICENSE.TROLL ]; then
    [ "$PLATFORM_MAC" = "maybe" ] && PLATFORM_MAC=yes
    Edition="troll"
    Licensee="Trolltech"
    Products="qt-internal"
# Commercial edition - needs a license.
elif [ -f $relpath/.LICENSE ]; then
    [ "$PLATFORM_MAC" = "maybe" ] && PLATFORM_MAC=yes
    [ "$PLATFORM_QWS" = "maybe" ] && PLATFORM_QWS=yes
    echo
    Desc=""
    if [ -f $HOME/.qt-license ]; then
	. $HOME/.qt-license >/dev/null 2>&1
	if [ -z "$LicenseKey" ]; then
	    echo
	    echo "You are using an old license file."
	    echo
	    echo "Please install the license file supplied by Trolltech,"
	    echo "or install the Qt Open Source Edition if you intend to"
	    echo "develop free software."
	    exit 1
	fi
    else
	if [ -z "$LicenseKey" ]; then
	    echo
	    if echo '\c' | grep '\c' >/dev/null; then
		echo -n "Please enter your license key: "
	    else
		echo "Please enter your license key: \c"
	    fi
	    read LicenseKey
	fi
    fi
    if echo $LicenseKey | grep "....-....-...." >/dev/null 2>&1; then
	# get the first character of the key
	keyTest=`echo $LicenseKey | cut -b1`
	# this character should fit the platform
	if [ "$PLATFORM_QWS" = "yes" ]; then
	    case $keyTest in
	    A|B|C|D|E|F|G|H|a|b|c|d|e|f|g|h)
		# Qt/Embedded
		echo
		;;
	    *)
		echo
		echo "You are not licensed for the Qt/Embedded platform."
		echo
		echo "Please contact sales@trolltech.com to upgrade your license"
		echo "to include the Qt/Embedded platform, or install the"
		echo "Qt Open Source Edition if you intend to develop free software."
		exit 1
		;;
	    esac
	elif [ "$PLATFORM_MAC" = "yes" ]; then
	    case $keyTest in
	    *) ###
		# Qt/Mac
		echo
		;;
	    *)
		echo
		echo "You are not licensed for the Qt/Mac platform."
		echo
		echo "Please contact sales@trolltech.com to upgrade your license"
		echo "to include the Qt/Mac platform."
		exit 1
		;;
	    esac
	else
	    case $keyTest in
	    6|7|8|9|E|F|G|H|e|f|g|h)
		# Qt/X11
		echo
		;;
	    *)
		echo
		echo "You are not licensed for the Qt/X11 platform."
		echo
		echo "Please contact sales@trolltech.com to upgrade your license to"
		echo "include the Qt/X11 platform, or install the Qt Open Source Edition"
		echo "if you intend to develop free software."
		exit 1
		;;
	    esac
	fi
	case $keyTest in
	4|5|8|9|C|D|G|H|c|d|g|h)
	    # Enterprise
	    Products=qt-enterprise
	    Desc="Enterprise"
	    Edition="ent"
	    ;;
	*)
	    # Professional
	    Products=qt-professional
	    Desc="Professional"
	    Edition="pro"
	    ;;
	esac
	case $keyTest in
	3|5|7|9|B|D|F|H|b|d|f|h)
	    # US
	    cp -f $relpath/.LICENSE-US $relpath/LICENSE
	    ;;
	*)
	    cp -f $relpath/.LICENSE $relpath/LICENSE
	    ;;
	esac
    else
	echo
	echo "Invalid license key. Please check the license key."
	exit 1
    fi
else
    echo "The LICENSE, LICENSE.QPL, or LICENSE.GPL file shipped with"
    echo "this software has disappeared."
    echo
    echo "Sorry, you are not licensed to use this software."
    echo "Try re-installing."
    echo
    exit 1
fi

QMAKE_VARS="$QMAKE_VARS \"styles += cde mac motif motifplus platinum pocketpc sgi windows windowsxp\""
QMAKE_VARS="$QMAKE_VARS \"decorations += default windows styled beos hydro\""
QMAKE_VARS="$QMAKE_VARS \"kbd-drivers += tty\" \"mouse-drivers += pc\"" # adjust below as well
QMAKE_VARS="$QMAKE_VARS \"styles -= pocketpc\""  # experimental
QMAKE_VARS="$QMAKE_VARS \"styles -= windowsxp\"" # only on Windows

# Temporary until all the styles are ported over..
QMAKE_VARS="$QMAKE_VARS \"styles -= cde\""
QMAKE_VARS="$QMAKE_VARS \"styles -= motif\""
QMAKE_VARS="$QMAKE_VARS \"styles -= motifplus\""
QMAKE_VARS="$QMAKE_VARS \"styles -= platinum\""
QMAKE_VARS="$QMAKE_VARS \"styles -= sgi\""
QMAKE_VARS="$QMAKE_VARS \"styles -= compact\""


#-------------------------------------------------------------------------------
# initalize variables
#-------------------------------------------------------------------------------

# QTDIR may be set and point to an old or system-wide Qt installation
unset QTDIR

# initalize internal variables
CFG_CONFIGURE_EXIT_ON_ERROR=yes
CFG_PROFILE=no
CFG_EXCEPTION_SUPPORT=unspecified
CFG_INCREMENTAL=auto
CFG_QCONFIG=full
CFG_EMBEDDED=no
CFG_DEBUG=auto
CFG_SHARED=yes
CFG_GIF=no
CFG_SM=auto
CFG_XSHAPE=auto
CFG_XINERAMA=auto
CFG_ZLIB=auto
CFG_PNG=auto
CFG_LIBPNG=auto
CFG_JPEG=auto
CFG_LIBJPEG=auto
CFG_XCURSOR=auto
CFG_XRANDR=auto
CFG_XRENDER=auto
CFG_OPENGL=auto
CFG_XFT=auto
CFG_QWS_FREETYPE=yes
CFG_SQL_AVAILABLE=
CFG_SQL_ON=
CFG_SQL_AUTODETECTED=
CFG_GFX_AVAILABLE="repeater"
CFG_GFX_ON=""
CFG_GFX_OFF=""
CFG_KBD_AVAILABLE="tty usb sl5000 yopy vr41xx"
CFG_KBD_ON="tty"    #default, see QMAKE_VARS above
CFG_KBD_OFF=
CFG_MOUSE_AVAILABLE="pc bus linuxtp yopy vr41xx"
CFG_MOUSE_ON="pc"   #default, see QMAKE_VARS above
CFG_MOUSE_OFF=
CFG_STYLE_AVAILABLE=
CFG_USE_GNUMAKE=no
CFG_IM=yes
CFG_IM_EXT=no
CFG_DECORATION_AVAILABLE=
CFG_DECORATION_ON=
CFG_DECORATION_PLUGIN=
CFG_TABLET=auto
CFG_XKB=auto
CFG_NIS=auto
CFG_CUPS=auto
CFG_LARGEFILE=auto
CFG_STL=auto
CFG_PRECOMPILE=no
CFG_REDUCE_EXPORTS=no
CFG_IPV6=auto
CFG_NAS=no
CFG_QWS_DEPTHS=prompted
CFG_USER_BUILD_KEY=
CFG_ACCESSIBILITY=auto
CFG_COMPAT=yes
CFG_ENDIAN=auto
CFG_GETADDRINFO=auto
D_FLAGS=
I_FLAGS=
L_FLAGS=
R_FLAGS=
l_FLAGS=
QCONFIG_FLAGS=
XPLATFORM=
PLATFORM=$QMAKESPEC
QMAKE_PROJECTS=
QMAKE_IGNORE_PROJECTS=
OPT_CONFIRM_LICENSE=no
OPT_SHADOW=maybe
OPT_FAST=auto
OPT_VERBOSE=no
OPT_HELP=

# initalize variables used for installation
QT_INSTALL_PREFIX=
QT_INSTALL_DOCS=
QT_INSTALL_HEADERS=
QT_INSTALL_LIBS=
QT_INSTALL_BINS=
QT_INSTALL_PLUGINS=
QT_INSTALL_DATA=
QT_INSTALL_TRANSLATIONS=
QT_INSTALL_SYSCONF=


#-------------------------------------------------------------------------------
# check SQL drivers, styles and decorations available in this package
#-------------------------------------------------------------------------------

CFG_SQL_AVAILABLE=`find $relpath/src/plugins/sqldrivers/* -prune -type d -exec basename {} \;`
CFG_SQL_AVAILABLE=`echo $CFG_SQL_AVAILABLE`               # normalize whitespace
CFG_STYLE_AVAILABLE=`find $relpath/src/plugins/styles/* -prune -type d -exec basename {} \;`
CFG_STYLE_AVAILABLE=`echo $CFG_STYLE_AVAILABLE`           # normalize whitespace
CFG_DECORATION_AVAILABLE=""
if [ -d "$relpath/src/plugins/decorations" ]; then
    CFG_DECORATION_AVAILABLE=`find $relpath/src/plugins/decorations/* -prune -type d -exec basename {} \;`
fi
CFG_DECORATION_AVAILABLE=`echo $CFG_DECORATION_AVAILABLE` # normalize whitespace
CFG_DECORATION_ON=`echo $CFG_DECORATION_AVAILABLE`        # All on by default


#-------------------------------------------------------------------------------
# parse command line arguments
#-------------------------------------------------------------------------------

# parse the arguments, setting things to "yes" or "no"
while [ "$#" -gt 0 ]; do
    CURRENT_OPT="$1"
    UNKNOWN_ARG=no
    case $1 in
    #Autoconf style options
    --enable-*)
	VAR=`echo $1 | sed "s,^--enable-\(.*\),\1,"`
	VAL=yes
	;;
    --disable-*)
	VAR=`echo $1 | sed "s,^--disable-\(.*\),\1,"`
	VAL=no
	;;
    --*=*)
	VAR=`echo $1 | sed "s,^--\(.*\)=.*,\1,"`
	VAL=`echo $1 | sed "s,^--.*=\(.*\),\1,"`
	;;
    --no-*)
	VAR=`echo $1 | sed "s,^--no-\(.*\),\1,"`
	VAL=no
	;;
    --*)
	VAR=`echo $1 | sed "s,^--\(.*\),\1,"`
	VAL=yes
	;;
    #Qt plugin options
    -no-*-*|-plugin-*-*|-qt-*-*)
	VAR=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
	VAL=`echo $1 | sed "s,^-\([^-]*\).*,\1,"`
	;;
    #Qt style no options
    -no-*)
	VAR=`echo $1 | sed "s,^-no-\(.*\),\1,"`
	VAL=no
	;;
    #Qt style yes options
    -incremental|-qvfb|-profile|-shared|-static|-sm|-xinerama|-xshape|-tablet|-reduce-exports|-pch|-stl|-freetype|-xcursor|-xrandr|-xrender|-xft|-xkb|-nis|-cups|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-version-script|-opengl|-accessibility|-inputmethod|-inputmethod-ext|-confirm-license|-gnumake)
	VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	VAL=yes
	;;
    #Qt style options that pass an argument
    -qconfig)
	if [ "$PLATFORM_QWS" = "yes" ]; then
	    CFG_QCONFIG="$VAL"
	    VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	    shift
	    VAL=$1
	else
	    UNKNOWN_ARG=yes
	fi
	;;
    -prefix|-docdir|-headerdir|-plugindir|-datadir|-libdir|-bindir|-translationdir|-sysconfdir|-depths|-make|-nomake|-platform|-xplatform|-buildkey)
	VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	shift
	VAL=$1
	;;
    #Qt style complex options in one command
    -enable-*|-disable-*)
	VAR=`echo $1 | sed "s,^-\([^-]*\)-.*,\1,"`
	VAL=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
	;;
    #Qt Builtin/System style options
    -no-*|-system-*|-qt-*)
	VAR=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
	VAL=`echo $1 | sed "s,^-\([^-]*\)-.*,\1,"`
	;;
    #Options that cannot be generalized
    -k|-continue)
	VAR=fatal_error
	VAL=no
	;;
    -embedded)
	VAR=embedded
	# this option may or may not be followed by an argument
	if [ -z $2 ] || echo $2 | grep '^-' >/dev/null 2>&1; then
	    VAL=auto
	else
	    shift;
	    VAL=$1
	fi
	;;
    -*-endian)
	VAR=endian
	VAL=`echo $1 | sed "s,^-\(.*\)-.*,\1,"`
	;;
    -D?*|-D)
	VAR="define"
	if [ "$1" = "-D" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-D,,'`
        fi
	;;
    -I?*|-I)
	VAR="ipath"
	if [ "$1" = "-I" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-I,,'`
        fi
	;;
    -L?*|-L)
	VAR="lpath"
	if [ "$1" = "-L" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-L,,'`
        fi
	;;
    -R?*|-R)
	VAR="rpath"
	if [ "$1" = "-R" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-R,,'`
        fi
	;;
    -l?*)
	VAR="link"
	VAL=`echo $1 | sed 's,-l,,'`
	;;
    -*)
	VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	VAL="unknown"
	;;
    *)
	UNKNOWN_ARG=yes
	;;
    esac
    if [ "$UNKNOWN_ARG" = "yes" ]; then
	echo "$1: unknown argument"
	OPT_HELP=yes
	ERROR=yes
	shift
	continue
     fi
    shift

    UNKNOWN_OPT=no
    case $VAR in
    compat)
        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_COMPAT="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    accessibility)
       	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_ACCESSIBILITY="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    inputmethod)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_IM="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    inputmethod-ext)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_IM_EXT="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    gnumake)
	CFG_USE_GNUMAKE="$VAL"
        ;;
    prefix)
	QT_INSTALL_PREFIX="$VAL"
	;;
    docdir)
	QT_INSTALL_DOCS="$VAL"
	;;
    headerdir)
	QT_INSTALL_HEADERS="$VAL"
	;;
    plugindir)
	QT_INSTALL_PLUGINS="$VAL"
	;;
    datadir)
	QT_INSTALL_DATA="$VAL"
	;;
    libdir)
	QT_INSTALL_LIBS="$VAL"
	;;
    translationdir)
	QT_INSTALL_TRANSLATIONS="$VAL"
	;;
    sysconfdir)
	QT_INSTALL_SYSCONF="$VAL"
	;;
    qconfig)
	CFG_QCONFIG="$VAL"
	;;
    bindir)
	QT_INSTALL_BINS="$VAL"
	;;
    buildkey)
	CFG_USER_BUILD_KEY="$VAL"
	;;
    embedded)
	CFG_EMBEDDED="$VAL"
	if [ "$PLATFORM_QWS" != "no" ]; then
	    if [ "$PLATFORM_QWS" = "maybe" ]; then
		PLATFORM_QWS=yes
	    fi
	else
	    echo "No license exists to enable Qt/Embedded. Disabling."
	    CFG_EMBEDDED=no
	fi
	;;
    endian)
        if [ "$VAL" = "little" ]; then
            CFG_ENDIAN="Q_LITTLE_ENDIAN"
        elif [ "$VAL" = "big" ]; then
	    CFG_ENDIAN="Q_BIG_ENDIAN"
        else
	    UNKNOWN_OPT=yes
	fi
        ;;
    depths)
	CFG_QWS_DEPTHS="$VAL"
	;;
    opengl)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_OPENGL="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    qvfb) # left for commandline compatibility, not documented
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    [ "$VAL" = "yes" ] && QMAKE_VARS="$QMAKE_VARS \"gfx-drivers += qvfb\"" && CFG_GFX_ON="$CFG_GFX_ON qvfb"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    nomake)
	QMAKE_IGNORE_PROJECTS="$QMAKE_IGNORE_PROJECTS $VAL"
	;;
    make)
	if [ -f $relpath/$VAL ]; then
	    QMAKE_PROJECTS="$QMAKE_PROJECTS $relpath/$VAL"
	else
	    if [ -d $relpath/$VAL ]; then
		QMAKE_PROJECTS="$QMAKE_PROJECTS `find $relpath/$VAL -name '*.pro' -print`"
	    else
		QMAKE_PROJECTS="$QMAKE_PROJECTS `find $relpath/. -name '*.pro' -print`"
	    fi
	fi
	QMAKE_PROJECTS=`echo $QMAKE_PROJECTS | sort | uniq`
	;;
    x11)
        if [ "$Edition" = "troll" ] && [ "$VAL" = "yes" ]; then
	    if [ "$PLATFORM_MAC" = "yes" ]; then
		PLATFORM_MAC=no
	    elif [ "$PLATFORM_QWS" = "yes" ]; then
		PLATFORM_QWS=no
	    fi
	    PLATFORM_X11=yes
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    profile)
	if [ "$VAL" = "yes" ]; then
	    CFG_PROFILE=yes
	    QMAKE_VARS="$QMAKE_VARS QMAKE_CFLAGS+=-pg QMAKE_CXXFLAGS+=-pg"
	    QMAKE_VARS="$QMAKE_VARS QMAKE_LFLAGS+=-pg"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    exceptions|g++-exceptions)
	if [ "$VAL" = "no" ]; then
	    CFG_EXCEPTION_SUPPORT=no
	elif [ "$VAL" = "yes" ]; then
	    CFG_EXCEPTION_SUPPORT=yes
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    platform)
	PLATFORM="$VAL"
	# keep compatibility with old platform names
	case $PLATFORM in
	aix-64)
	    PLATFORM=aix-xlc-64
	    ;;
	hpux-o64)
	    PLATFORM=hpux-acc-o64
	    ;;
	hpux-n64)
	    PLATFORM=hpux-acc-64
	    ;;
	hpux-acc-n64)
	    PLATFORM=hpux-acc-64
	    ;;
	irix-o32)
	    PLATFORM=irix-cc-o32
	    ;;
	irix-n32)
	    PLATFORM=irix-cc
	    ;;
	irix-64)
	    PLATFORM=irix-cc-64
	    ;;
	irix-cc-n64)
	    PLATFORM=irix-cc-64
	    ;;
	reliant-64)
	    PLATFORM=reliant-cds-64
	    ;;
	solaris-64)
	    PLATFORM=solaris-cc-64
	    ;;
	solaris-64)
	    PLATFORM=solaris-cc-64
	    ;;
	openunix-cc)
	    PLATFORM=unixware-cc
	    ;;
	openunix-g++)
	    PLATFORM=unixware-g++
	    ;;
	unixware7-cc)
	    PLATFORM=unixware-cc
	    ;;
	unixware7-g++)
	    PLATFORM=unixware-g++
	    ;;
	esac
	;;
    xplatform)
	XPLATFORM="$VAL"
	;;
    release)
	if [ "$VAL" = "yes" ]; then
	    CFG_DEBUG=no
	elif [ "$VAL" = "no" ]; then
	    CFG_DEBUG=yes
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    debug)
	CFG_DEBUG="$VAL"
	;;
    static)
	if [ "$VAL" = "yes" ]; then
	    CFG_SHARED=no
	elif [ "$VAL" = "no" ]; then
	    CFG_SHARED=yes
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    incremental)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_INCREMENTAL="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    fatal_error)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_CONFIGURE_EXIT_ON_ERROR="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    feature-*)
	if [ "$PLATFORM_QWS" = "yes" ]; then
	    FEATURE=`echo $VAR | sed "s,^[^-]*-\([^-]*\),\1," | tr '[:lower:]-' '[:upper:]_'`
	    if [ "$VAL" = "no" ]; then
		QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_$FEATURE"
	    elif [ "$VAL" = "yes" ] || [ "$VAL" = "unknown" ]; then
		QCONFIG_FLAGS="$QCONFIG_FLAGS QT_$FEATURE"
	    else
		UNKNOWN_OPT=yes
	    fi
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    shared)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_SHARED="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    gif)
	[ "$VAL" = "qt" ] && VAL=yes
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_GIF="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    sm)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_SM="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi

	;;
    xinerama)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XINERAMA="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xshape)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XSHAPE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    tablet)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_TABLET="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    stl)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_STL="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    pch)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_PRECOMPILE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
        ;;
    reduce-exports)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_REDUCE_EXPORTS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
        ;;
    freetype)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_QWS_FREETYPE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    zlib)
	[ "$VAL" = "qt" ] && VAL=yes
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_ZLIB="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	[ "$VAL" = "no" ] && CFG_LIBPNG=no
	;;
    libpng)
	[ "$VAL" = "yes" ] && VAL=qt
	if [ "$VAL" = "no " ]; then
	    echo "-no-png is left for compatibility, in the future please use -no-imgfmt-png"
	    CFG_PNG=no
	fi
	if [ "$VAL" = "qt" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_LIBPNG="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    libjpeg|jpeg)
	[ "$VAL" = "yes" ] && VAL=qt
	if [ "$VAR" = "jpeg" ]; then
	    echo "-${VAL}-jpeg is left for compatibility, in the future please use -${VAL}-libjpeg"
	fi
	if [ "$VAL" = "qt" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_LIBJPEG="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	if [ "$VAL" = "no " ]; then
	    echo "-no-jpeg is left for compatibility, in the future please use -no-imgfmt-jpeg"
	    CFG_JPEG=no
	fi
	;;
    nas-sound)
	if [ "$VAL" = "system" ] || [ "$VAL" = "no" ]; then
	    CFG_NAS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xcursor)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XCURSOR="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xrandr)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XRANDR="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xrender)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XRENDER="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xft)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XFT="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xkb)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XKB="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    cups)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_CUPS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    nis)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_NIS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    largefile)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_LARGEFILE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    confirm-license)
	if [ "$VAL" = "yes" ]; then
	    OPT_CONFIRM_LICENSE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    h|help)
	if [ "$VAL" = "yes" ]; then
	    OPT_HELP="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    imgfmt-*|style-*|sql-*|gfx-*|decoration-*|kbd-*|mouse-*)
	# if Qt style options were used, $VAL can be "no", "qt", or "plugin"
	# if autoconf style options were used, $VAL can be "yes" or "no"
	[ "$VAL" = "yes" ] && VAL=qt
	# now $VAL should be "no", "qt", or "plugin"... double-check
	if [ "$VAL" != "no" ] && [ "$VAL" != "qt" ] && [ "$VAL" != "plugin" ]; then
	    UNKNOWN_OPT=yes
	fi
	# now $VAL is "no", "qt", or "plugin"
	OPT="$VAL"
	VAL=`echo $VAR | sed "s,^[^-]*-\([^-]*\).*,\1,"`
	VAR=`echo $VAR | sed "s,^\([^-]*\).*,\1,"`
	ERROR=no
	# now $OPT is "no", "qt", or "plugin"
	if [ "$VAR" = "imgfmt" ]; then
	    [ "$OPT" = "qt" ] && OPT=yes
	    # now $OPT is "no", "yes", or "plugin"
	    case "$VAL" in
	    jpeg) CFG_JPEG=$OPT ;;
	    png) CFG_PNG=$OPT ;;
	    *) ERROR=yes ;;
	    esac
	else
	    if [ "$VAR" = "style" ]; then
		ERROR=yes
		for d in $CFG_STYLE_AVAILABLE; do
		    if [ "$VAL" = "$d" ]; then
			ERROR=no
			break
		    fi
		done
	    elif [ "$VAR" = "decoration" ]; then
		ERROR=yes
		for d in $CFG_DECORATION_AVAILABLE; do
		    if [ "$VAL" = "$d" ]; then
			ERROR=no
			break
		    fi
		done
	    elif [ "$VAR" = "sql" ]; then
		ERROR=yes
		for d in $CFG_SQL_AVAILABLE; do
		    if [ "$VAL" = "$d" ]; then
			ERROR=no
			break
		    fi
		done
	    fi
	    if [ "$OPT" = "plugin" ] || [ "$OPT" = "qt" ]; then
		if [ "$OPT" = "plugin" ]; then
		    [ "$VAR" = "style" -o  "$VAR" = "decoration" ] && QMAKE_VARS="$QMAKE_VARS \"${VAR}s -= $VAL\""
		    [ "$VAR" = "decoration" ] && CFG_DECORATION_ON=`echo "${CFG_DECORATION_ON} " | sed "s,${VAL} ,,g"` && CFG_DECORATION_PLUGIN="$CFG_DECORATION_PLUGIN ${VAL}"
		    VAR="${VAR}-${OPT}"
		else
		    if [ "$VAR" = "sql" ] || [ "$VAR" = "gfx" ] || [ "$VAR" = "kbd" ] || [ "$VAR" = "mouse" ]; then
                        [ "$VAR" = "sql" ] && CFG_SQL_ON="$CFG_SQL_ON $VAL"
                        [ "$VAR" = "gfx" ] && CFG_GFX_ON="$CFG_GFX_ON $VAL"
                        [ "$VAR" = "kbd" ] && CFG_KBD_ON="$CFG_KBD_ON $VAL"
                        [ "$VAR" = "mouse" ] && CFG_MOUSE_ON="$CFG_MOUSE_ON $VAL"
                        VAR="${VAR}-driver"
                    fi
		fi
		QMAKE_VARS="$QMAKE_VARS \"${VAR}s += $VAL\""
	    elif [ "$OPT" = "no" ]; then
		PLUG_VAR="${VAR}-plugin"
		if [ "$VAR" = "sql" ] || [ "$VAR" = "gfx" ] || [ "$VAR" = "kbd" ] || [ "$VAR" = "mouse" ]; then
		    IN_VAR="${VAR}-driver"
		else
		    IN_VAR="${VAR}"
		fi
	        [ "$VAR" = "decoration" ] && CFG_DECORATION_ON=`echo "${CFG_DECORATION_ON} " | sed "s,${VAL} ,,g"`
                [ "$VAR" = "sql" ] && CFG_SQL_ON=`echo "${CFG_SQL_ON} " | sed "s,${VAL} ,,g"`
                [ "$VAR" = "gfx" ] && CFG_GFX_ON=`echo "${CFG_GFX_ON} " | sed "s,${VAL} ,,g"`
                [ "$VAR" = "kbd" ] && CFG_KBD_ON=`echo "${CFG_KBD_ON} " | sed "s,${VAL} ,,g"`
                [ "$VAR" = "mouse" ] && CFG_MOUSE_ON=`echo "${CFG_MOUSE_ON} " | sed "s,${VAL} ,,g"`
		QMAKE_VARS="$QMAKE_VARS \"${IN_VAR}s -= $VAL\" \"${PLUG_VAR}s -= $VAL\""
	    fi
	fi
        if [ "$ERROR" = "yes" ]; then
	   echo "$CURRENT_OPT: unknown argument"
	   OPT_HELP=yes;
	fi
	;;
    v|verbose)
	if [ "$VAL" = "yes" ]; then
	    if [ "$OPT_VERBOSE" = "$VAL" ]; then 	    # takes two verboses to turn on qmake debugs
		QMAKE_SWITCHES="$QMAKE_SWITCHES -d"
            else
		OPT_VERBOSE=yes
	    fi
        elif [ "$VAL" = "no" ]; then
	    if [ "$OPT_VERBOSE" = "$VAL" ] && echo "$QMAKE_SWITCHES" | grep ' -d' >/dev/null 2>&1; then
		QMAKE_SWITCHES=`echo $QMAKE_SWITCHES | sed "s, -d,,"`
	    else
		OPT_VERBOSE=no
            fi
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    fast)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    OPT_FAST="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    define)
	D_FLAGS="$D_FLAGS $VAL"
	;;
    ipath)
	I_FLAGS="$I_FLAGS -I${VAL}"
	;;
    lpath)
	L_FLAGS="$L_FLAGS -L${VAL}"
	;;
    rpath)
	R_FLAGS="$R_FLAGS \$\${QMAKE_RPATH}${VAL}"
	;;
    link)
	l_FLAGS="$l_FLAGS -l${VAL}"
	;;
    *)
	UNKNOWN_OPT=yes
	;;
    esac
    if [ "$UNKNOWN_OPT" = "yes" ]; then
	echo "${CURRENT_OPT}: invalid command-line switch"
	OPT_HELP=yes
	ERROR=yes
    fi
done

#-------------------------------------------------------------------------------
# post initialize QT_INSTALL_* variables, and generate qconfig.cpp
#-------------------------------------------------------------------------------

# default $outpath
[ -z "$QT_INSTALL_PREFIX" ]       && QT_INSTALL_PREFIX=$outpath
# default PREFIX/doc
[ -z "$QT_INSTALL_DOCS" ]         && QT_INSTALL_DOCS=$QT_INSTALL_PREFIX/doc
# default PREFIX/include
[ -z "$QT_INSTALL_HEADERS" ]      && QT_INSTALL_HEADERS=$QT_INSTALL_PREFIX/include
# default PREFIX/lib
[ -z "$QT_INSTALL_LIBS" ]         && QT_INSTALL_LIBS=$QT_INSTALL_PREFIX/lib
# default PREFIX/bin
[ -z "$QT_INSTALL_BINS" ]         && QT_INSTALL_BINS=$QT_INSTALL_PREFIX/bin
# default PREFIX/plugins
[ -z "$QT_INSTALL_PLUGINS" ]      && QT_INSTALL_PLUGINS=$QT_INSTALL_PREFIX/plugins
# default PREFIX
[ -z "$QT_INSTALL_DATA" ]         && QT_INSTALL_DATA=$QT_INSTALL_PREFIX
# default PREFIX/translations
[ -z "$QT_INSTALL_TRANSLATIONS" ] && QT_INSTALL_TRANSLATIONS=$QT_INSTALL_PREFIX/translations
# default PREFIX/etc/settings
[ -z "$QT_INSTALL_SYSCONF" ]      && QT_INSTALL_SYSCONF=$QT_INSTALL_PREFIX/etc/settings

# generate qconfig.cpp
[ -d $outpath/src/core/global ] || mkdir -p $outpath/src/core/global
INSTALL_PREFIX_STR=`$relpath/config.tests/unix/padstring 256 "qt_nstpath=$QT_INSTALL_PREFIX" "\\0"`
INSTALL_BINS_STR=`$relpath/config.tests/unix/padstring 256 "qt_binpath=$QT_INSTALL_BINS" "\\0"`
INSTALL_DOCS_STR=`$relpath/config.tests/unix/padstring 256 "qt_docpath=$QT_INSTALL_DOCS" "\\0"`
INSTALL_HEADERS_STR=`$relpath/config.tests/unix/padstring 256 "qt_hdrpath=$QT_INSTALL_HEADERS" "\\0"`
INSTALL_LIBS_STR=`$relpath/config.tests/unix/padstring 256 "qt_libpath=$QT_INSTALL_LIBS" "\\0"`
INSTALL_PLUGINS_STR=`$relpath/config.tests/unix/padstring 256 "qt_plgpath=$QT_INSTALL_PLUGINS" "\\0"`
INSTALL_DATA_STR=`$relpath/config.tests/unix/padstring 256 "qt_datpath=$QT_INSTALL_DATA" "\\0"`
INSTALL_TRANSLATIONS_STR=`$relpath/config.tests/unix/padstring 256 "qt_trnpath=$QT_INSTALL_TRANSLATIONS" "\\0"`
INSTALL_SYSCONF_STR=`$relpath/config.tests/unix/padstring 256 "qt_cnfpath=$QT_INSTALL_SYSCONF" "\\0"`
LICENSE_USER_STR=`$relpath/config.tests/unix/padstring 256 "qt_lcnsuser=$Licensee" "\\0"`
LICENSE_PRODUCTS_STR=`$relpath/config.tests/unix/padstring 256 "qt_lcnsprod=$Products" "\\0"`

cat > $outpath/src/core/global/qconfig.cpp.new <<EOF
/* Install paths from configure */
static const char QT_INSTALL_PREFIX      [256] = "$INSTALL_PREFIX_STR";
static const char QT_INSTALL_BINS        [256] = "$INSTALL_BINS_STR";
static const char QT_INSTALL_DOCS        [256] = "$INSTALL_DOCS_STR";
static const char QT_INSTALL_HEADERS     [256] = "$INSTALL_HEADERS_STR";
static const char QT_INSTALL_LIBS        [256] = "$INSTALL_LIBS_STR";
static const char QT_INSTALL_PLUGINS     [256] = "$INSTALL_PLUGINS_STR";
static const char QT_INSTALL_DATA        [256] = "$INSTALL_DATA_STR";
static const char QT_INSTALL_TRANSLATIONS[256] = "$INSTALL_TRANSLATIONS_STR";
static const char QT_INSTALL_SYSCONF     [256] = "$INSTALL_SYSCONF_STR";

/* strlen( "qt_xxxpath=" ) == 11 */
const char *qInstallPath()             { return QT_INSTALL_PREFIX       + 11; }
const char *qInstallPathDocs()         { return QT_INSTALL_DOCS         + 11; }
const char *qInstallPathHeaders()      { return QT_INSTALL_HEADERS      + 11; }
const char *qInstallPathLibs()         { return QT_INSTALL_LIBS         + 11; }
const char *qInstallPathBins()         { return QT_INSTALL_BINS         + 11; }
const char *qInstallPathPlugins()      { return QT_INSTALL_PLUGINS      + 11; }
const char *qInstallPathData()         { return QT_INSTALL_DATA         + 11; }
const char *qInstallPathTranslations() { return QT_INSTALL_TRANSLATIONS + 11; }
const char *qInstallPathSysconf()      { return QT_INSTALL_SYSCONF      + 11; }

/* Licensed */
static const char QT_INSTALL_LICENSEE  [256] = "$LICENSE_USER_STR";
static const char QT_INSTALL_PRODUCTS  [256] = "$LICENSE_PRODUCTS_STR";

/* strlen( "qt_lcnsxxxx" ) == 12 */
const char *qInstallLicensee()             { return QT_INSTALL_LICENSEE + 12; }
const char *qInstallLicensedProducts()     { return QT_INSTALL_PRODUCTS + 12; }
EOF

# avoid unecessary rebuilds by copying only if qconfig.cpp has changed
if cmp -s $outpath/src/core/global/qconfig.cpp $outpath/src/core/global/qconfig.cpp.new; then
    rm -f $outpath/src/core/global/qconfig.cpp.new
else
    [ -f $outpath/src/core/global/qconfig.cpp ] && chmod +w $outpath/src/core/global/qconfig.cpp
    mv $outpath/src/core/global/qconfig.cpp.new $outpath/src/core/global/qconfig.cpp
    chmod -w $outpath/src/core/global/qconfig.cpp
fi


#-------------------------------------------------------------------------------
# build tree initialization
#-------------------------------------------------------------------------------

#where to find which..
unixtests=$relpath/config.tests/unix
WHICH=$unixtests/which.test

### skip this if the user just needs help...
if [ "$OPT_HELP" != "yes" ]; then

# is this a shadow build?
if [ "$OPT_SHADOW" = "maybe" ]; then
    OPT_SHADOW=no
    if [ "$relpath" != "$outpath" ] && [ '!' -f "$outpath/configure" ]; then
	if [ -h "$outpath" ]; then
	    [ "$relpath" -ef "$outpath" ] || OPT_SHADOW=yes
	else
	    OPT_SHADOW=yes
        fi
    fi
fi
if [ "$OPT_VERBOSE" = "yes" -a "$OPT_SHADOW" = "yes" ]; then
    echo "Performing shadow build..."
fi

#detect build style
if [ "$CFG_DEBUG" = "auto" ]; then
    CFG_DEBUG=yes
    QMAKE_CONFIG="$QMAKE_CONFIG build_all"
fi

#detect how jpeg should be built
if [ "$CFG_JPEG" = "auto" ]; then
    if [ "$CFG_SHARED" = "yes" ]; then
	CFG_JPEG=plugin
    else
	CFG_JPEG=yes
    fi
fi
if [ "$CFG_LIBJPEG" = "auto" ]; then
    if $unixtests/checkavail "libjpeg" $OPT_VERBOSE -ljpeg jpeglib.h; then
       CFG_LIBJPEG=system
    else
       CFG_LIBJPEG=qt
    fi
fi

#detect zlib
if [ "$CFG_ZLIB" = "auto" ]; then
    if $unixtests/checkavail "libzlib" $OPT_VERBOSE -lz zlib.h; then
       CFG_ZLIB=system
    else
       CFG_ZLIB=yes
    fi
fi

#detect how png should be built
if [ "$CFG_PNG" = "auto" ]; then
    if [ "$CFG_SHARED" = "yes" ]; then
	CFG_PNG=plugin
    else
	CFG_PNG=yes
    fi
fi
if [ "$CFG_LIBPNG" = "auto" ]; then
    if $unixtests/checkavail "libpng" $OPT_VERBOSE -lpng png.h; then
       CFG_LIBPNG=system
    else
       CFG_LIBPNG=qt
    fi
fi

#detect accessibility
if [ "$CFG_ACCESSIBILITY" = "auto" ]; then
    CFG_ACCESSIBILITY=yes
fi

# if the source tree is different from the build tree,
# symlink or copy part of the sources
if [ "$OPT_SHADOW" = "yes" ]; then
    echo "Preparing build tree..."
    [ -d $outpath/bin ] || mkdir -p $outpath/bin

    # symlink the qmake directory
    for a in `find $relpath/qmake`; do
	my_a=`echo $a | sed "s,^${relpath}/,${outpath}/,"`
	if [ '!' -f $my_a ]; then
	    if [ -d $a ]; then
		# directories are created...
		mkdir -p $my_a
	    else
		a_dir=`dirname $my_a`
		[ -d $a_dir ] || mkdir -p $a_dir
		# ... and files are symlinked
		case `basename $a` in
		*.o|*.d|GNUmakefile*|qmake)
		    ;;
		*)
		    rm -f $my_a
		    ln -s $a $my_a
		    ;;
		esac
	    fi
	fi
    done

    # make a syncqt script that can be used in the shadow
    rm -f "$outpath/bin/syncqt"
    if [ -x "/usr/bin/perl" ] && [ -x "$relpath/bin/syncqt" ]; then
	mkdir -p "$outpath/bin"
	echo "#!/bin/sh" >$outpath/bin/syncqt
	echo "export QTDIR=$relpath" >>$outpath/bin/syncqt
	[ "$Edition" = "troll" ] && echo "perl $relpath/bin/syncqt -inc $relpath/include" >>$outpath/bin/syncqt
	echo "perl $relpath/bin/syncqt -inc $outpath/include" >>$outpath/bin/syncqt
	chmod 755 $outpath/bin/syncqt
    fi

    # symlink the mkspecs directory
    mkdir -p $outpath/mkspecs
    rm -f $outpath/mkspecs/*
    ln -s $relpath/mkspecs/* $outpath/mkspecs
    rm -f $outpath/mkspecs/default

    # symlink the linguist/doc directory (to make the assistant happy)
    mkdir -p $outpath/tools/linguist
    rm -f $outpath/tools/linguist/doc
    ln -s $relpath/tools/linguist/doc $outpath/tools/linguist/doc

    # symlink the doc directory
    rm -f $outpath/doc
    ln -s $relpath/doc $outpath/doc
fi

# things used to build inside of QTDIR (without QTDIR set)
QMAKE_VARS="$QMAKE_VARS \"QMAKE_MOC=$outpath/bin/moc\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_UIC=$outpath/bin/uic\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_UIC3=$outpath/bin/uic3\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_QMAKE=$outpath/bin/qmake\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_RCC=$outpath/bin/rcc\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_QT_CONFIG=$outpath/mkspecs/.qt.config\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_MOC_SRC=$outpath/src/moc\""

# find out which awk we want to use, prefer gawk, then nawk, then regular awk
AWK=
for e in gawk nawk awk; do
    if $WHICH $e >/dev/null 2>&1 && ( $e -f /dev/null /dev/null ) >/dev/null 2>&1; then
	AWK=$e
    	break
    fi
done
if [ "$OPT_FAST" = "auto" ]; then
   if [ '!' -z "$AWK" ] && [ "$Edition" = "troll" ]; then
       OPT_FAST=yes
   else
       OPT_FAST=no
   fi
fi

# find a make command
if [ -z "$MAKE" ]; then
    MAKE=
    for mk in gmake make; do
        if $WHICH $mk >/dev/null 2>&1; then
	    MAKE=`$WHICH $mk`
	    break
        fi
    done
    if [ -z "$MAKE" ]; then
	echo "You don't seem to have 'make' or 'gmake' in your PATH."
	echo "Cannot proceed."
	exit 1
    fi
fi

fi ### help

#-------------------------------------------------------------------------------
# auto-detect all that hasn't been specified in the arguments
#-------------------------------------------------------------------------------

[ "$PLATFORM_QWS" = "yes" -a "$CFG_EMBEDDED" = "no" ] && CFG_EMBEDDED=auto
if [ "$CFG_EMBEDDED" != "no" ]; then
    case "$UNAME_SYSTEM:$UNAME_RELEASE" in
    Darwin:*)
	[ -z "$PLATFORM" ] && PLATFORM=qws/macx-generic-g++
	if [ -z "$XPLATFORM" ]; then
	    [ "$CFG_EMBEDDED" = "auto" ] && CFG_EMBEDDED=generic
	    XPLATFORM="qws/macx-$CFG_EMBEDDED-g++"
	fi
	;;
    FreeBSD:*)
	[ -z "$PLATFORM" ] && PLATFORM=qws/freebsd-generic-g++
	if [ -z "$XPLATFORM" ]; then
	    [ "$CFG_EMBEDDED" = "auto" ] && CFG_EMBEDDED=generic
	    XPLATFORM="qws/freebsd-$CFG_EMBEDDED-g++"
	fi
	;;
    SunOS:5*)
	[ -z "$PLATFORM" ] && PLATFORM=qws/solaris-generic-g++
	if [ -z "$XPLATFORM" ]; then
	    [ "$CFG_EMBEDDED" = "auto" ] && CFG_EMBEDDED=generic
	    XPLATFORM="qws/solaris-$CFG_EMBEDDED-g++"
	fi
	;;
    Linux:*)
	if [ -z "$PLATFORM" ]; then
	    case "$UNAME_MACHINE" in
	    *86)
		PLATFORM=qws/linux-x86-g++
		;;
	    *)
		PLATFORM=qws/linux-generic-g++
		;;
	    esac
	fi
	if [ -z "$XPLATFORM" ]; then
	    if [ "$CFG_EMBEDDED" = "auto" ]; then
		case "$UNAME_MACHINE" in
		*86)
		    CFG_EMBEDDED=x86
		    ;;
		*)
		    CFG_EMBEDDED=generic
		    ;;
		esac
	    fi
	    XPLATFORM="qws/linux-$CFG_EMBEDDED-g++"
	fi
	;;
    *)
	echo "Qt/Embedded is not supported on this platform. Disabling."
	CFG_EMBEDDED=no
	PLATFORM_QWS=no
	;;
    esac
fi
if [ -z "$PLATFORM" ]; then
    PLATFORM_NOTES=
    case "$UNAME_SYSTEM:$UNAME_RELEASE" in
     Darwin:*)
	if [ "$PLATFORM_MAC" = "yes" ]; then
	  PLATFORM=macx-g++
	# PLATFORM=macx-pbuilder
	else
	  PLATFORM=darwin-g++
	fi
	;;
     AIX:*)
	#PLATFORM=aix-g++
	#PLATFORM=aix-g++-64
	PLATFORM=aix-xlc
	#PLATFORM=aix-xlc-64
	PLATFORM_NOTES="
	    - Also available for AIX: aix-g++ aix-g++-64 aix-xlc-64
	"
	;;
     GNU:*)
	PLATFORM=hurd-g++
	;;
     dgux:*)
	PLATFORM=dgux-g++
	;;
#     DYNIX/ptx:4*)
#	PLATFORM=dynix-g++
#	;;
     ULTRIX:*)
	PLATFORM=ultrix-g++
	;;
     FreeBSD:*)
	PLATFORM=freebsd-g++
	PLATFORM_NOTES="
	    - Also available for FreeBSD: freebsd-icc
	"
	;;
     OpenBSD:*)
	PLATFORM=openbsd-g++
	;;
     NetBSD:*)
	PLATFORM=netbsd-g++
	;;
     BSD/OS:*|BSD/386:*)
	PLATFORM=bsdi-g++
	;;
     IRIX*:*)
	#PLATFORM=irix-g++
	PLATFORM=irix-cc
	#PLATFORM=irix-cc-64
	PLATFORM_NOTES="
	    - Also available for IRIX: irix-g++ irix-cc-64
	"
	;;
     HP-UX:*)
	#PLATFORM=hpux-g++
	PLATFORM=hpux-acc
	#PLATFORM=hpux-acc-64
	#PLATFORM=hpux-cc
	#PLATFORM=hpux-acc-o64
	PLATFORM_NOTES="
	    - Also available for HP-UX: hpux-g++ hpux-acc-64 hpux-acc-o64
	"
	;;
     OSF1:*)
	#PLATFORM=tru64-g++
	PLATFORM=tru64-cxx
	PLATFORM_NOTES="
	    - Also available for Tru64: tru64-g++
	"
	;;
     Linux:*)
	case "$UNAME_MACHINE" in
	    x86_64)
		PLATFORM=linux-g++-64
		;;
	    *)
		PLATFORM=linux-g++
		;;
	esac
	PLATFORM_NOTES="
	    - Also available for Linux: linux-kcc linux-icc linux-cxx
	"
	;;
     SunOS:5*)
	#PLATFORM=solaris-g++
	PLATFORM=solaris-cc
	#PLATFORM=solaris-cc64
	PLATFORM_NOTES="
	    - Also available for Solaris: solaris-g++ solaris-cc-64
	"
	;;
     ReliantUNIX-*:*|SINIX-*:*)
	PLATFORM=reliant-cds
	#PLATFORM=reliant-cds-64
	PLATFORM_NOTES="
	    - Also available for Reliant UNIX: reliant-cds-64
	"
	;;
     CYGWIN*:*)
	PLATFORM=cygwin-g++
	;;
     LynxOS*:*)
	PLATFORM=lynxos-g++
	;;
     OpenUNIX:*)
	#PLATFORM=unixware-g++
        PLATFORM=unixware-cc
	PLATFORM_NOTES="
	    - Also available for OpenUNIX: unixware-g++
	"
        ;;
     UnixWare:*)
	#PLATFORM=unixware-g++
	PLATFORM=unixware-cc
	PLATFORM_NOTES="
	    - Also available for UnixWare: unixware-g++
	"
	;;
     SCO_SV:*)
	#PLATFORM=sco-g++
	PLATFORM=sco-cc
	PLATFORM_NOTES="
	    - Also available for SCO OpenServer: sco-g++
	"
	;;
     UNIX_SV:*)
	PLATFORM=unixware-g++
	;;
     *)
	if [ "$OPT_HELP" != "yes" ]; then
	    echo
	    for p in $PLATFORMS; do
		echo "    $relconf $* -platform $p"
	    done
	    echo >&2
	    echo "   The build script does not currently recognize all" >&2
	    echo "   platforms supported by Qt." >&2
	    echo "   Rerun this script with a -platform option listed to" >&2
	    echo "   set the system/compiler combination you use." >&2
	    echo >&2
	    exit 2
	fi
    esac
fi

if [ "$PLATFORM_QWS" = "yes" ]; then
    CFG_SM=no
    PLATFORMS=`find $relpath/mkspecs/qws | sed "s,$relpath/mkspecs/qws/,,"`
else
    PLATFORMS=`find $relpath/mkspecs/ -type f | grep -v qws | sed "s,$relpath/mkspecs/qws/,,"`
fi

[ -z "$XPLATFORM" ] && XPLATFORM="$PLATFORM"
if [ -d "$PLATFORM" ]; then
  QMAKESPEC="$PLATFORM"
else
  QMAKESPEC="$relpath/mkspecs/${PLATFORM}"
fi
if [ -d "$XPLATFORM" ]; then
  XQMAKESPEC="$XPLATFORM"
else
  XQMAKESPEC="$relpath/mkspecs/${XPLATFORM}"
fi

if [ "$PLATFORM_MAC" = "yes" ]; then
   if [ `basename $QMAKESPEC` = "macx-pbuilder" ] || [ `basename $XQMAKESPEC` = "macx-pbuilder" ]; then
      echo >&2
      echo "   Platform 'macx-pbuilder' should not be used when building Qt/Mac." >&2
      echo "   Please build Qt/Mac with 'macx-g++', then if you would like to" >&2
      echo "   use mac-pbuilder on your application code it can link to a Qt/Mac" >&2
      echo "   built with 'macx-g++'" >&2
      echo >&2
      exit 2
  fi
fi

# check specified platforms are supported
if [ '!' -d "$QMAKESPEC" ]; then
    echo
    echo "   The specified system/compiler is not supported:"
    echo
    echo "   	$QMAKESPEC"
    echo
    echo "   Please see the PLATFORMS file for a complete list."
    echo
    exit 2
fi
if [ '!' -d "$XQMAKESPEC" ]; then
    echo
    echo "   The specified system/compiler is not supported:"
    echo
    echo "   	$XQMAKESPEC"
    echo
    echo "   Please see the PLATFORMS file for a complete list."
    echo
    exit 2
fi
if [ '!' -f "${XQMAKESPEC}/qplatformdefs.h" ]; then
    echo
    echo "   The specified system/compiler port is not complete:"
    echo
    echo "   	$XQMAKESPEC/qplatformdefs.h"
    echo
    echo "   Please contact qt-bugs@trolltech.com."
    echo
    exit 2
fi

# now look at the configs and figure out what platform we are config'd for
[ '!' -z "`grep QMAKE_LIBS_X11 $XQMAKESPEC/qmake.conf | awk '{print $3;}'`" ] && PLATFORM_X11=yes
### echo "$XQMAKESPEC" | grep mkspecs/qws >/dev/null 2>&1 && PLATFORM_QWS=yes

#-------------------------------------------------------------------------------
# determine the system architecture
#-------------------------------------------------------------------------------
if [ "$OPT_VERBOSE" = "yes" ]; then
    echo "Determining system architecture... ($UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_MACHINE)"
fi

if [ "$PLATFORM" != "$XPLATFORM" -a "$CFG_EMBEDDED" != "no" ]; then
    case "$CFG_EMBEDDED" in
    x86)
        ARCH=i386
        ;;
    ipaq|sharp)
        ARCH=arm
        ;;
    *)
        ARCH="$CFG_EMBEDDED"
        ;;
    esac
else
    case "$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_MACHINE" in
    IRIX*:*:*)
        ARCH=`uname -p`
        if [ "$OPT_VERBOSE" = "yes" ]; then
            echo "    SGI ($ARCH)"
        fi
        ;;
    SunOS:5*:sun4*)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    Sun SPARC (sparc)"
        fi
        ARCH=sparc
        ;;
    Darwin:*:Power?Macintosh)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    32-bit Apple PowerPC (powerpc)"
        fi
        ARCH=powerpc
        ;;
    AIX:*:00????????00)
        if [ "$OPT_VERBOSE" = "yes" ]; then
            echo "    IBM POWER (powerpc)"
        fi
        ARCH=powerpc
        ;;
    HP-UX:*:9000*)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    HP PA-RISC (parisc)"
        fi
        ARCH=parisc
        ;;
    *:*:i?86)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    32-bit Intel 80x86 (i386)"
        fi
        ARCH=i386
        ;;
    *:*:x86_64)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    64-bit AMD 80x86 (x86_64)"
        fi
        ARCH=x86_64
        ;;
    *:*:ppc)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    32-bit PowerPC (powerpc)"
        fi
        ARCH=powerpc
        ;;
    *:*:*)
        if [ "$OPT_VERBOSE" = "yes" ]; then
    	echo "    Trying '$UNAME_MACHINE'..."
        fi
        ARCH="$UNAME_MACHINE"
        ;;
    esac
fi

if [ -d "$relpath/src/core/arch/$ARCH" ]; then
    if [ "$OPT_VERBOSE" = "yes" ]; then
	echo "    '$ARCH' is supported"
    fi
else
    if [ "$OPT_VERBOSE" = "yes" ]; then
	echo "    '$ARCH' is unsupported, using 'generic'"
    fi
    ARCH=generic
fi

if [ "$OPT_VERBOSE" = "yes" ]; then
	echo "System architecture: '$ARCH'"
fi

# symlink the arch/$ARCH/arch/ include directory to include/QtCore/arch/
if [ -d "$outpath/src/core/global/arch" ]; then
    rm -f "$outpath/src/core/global/arch"
else
    mkdir -p "$outpath/src/core/global/"
fi
ln -s "$relpath/src/core/arch/$ARCH/arch" "$outpath/src/core/global/arch"
for arch in "$outpath/include/QtCore/arch" "$outpath/include/Qt/arch"; do
   if [ -d "$arch" ]; then
       rm -f "$arch"
   else
       mkdir -p `dirname $arch`
   fi
   ln -s "$relpath/src/core/arch/$ARCH/arch" "$arch"
done

#-------------------------------------------------------------------------------
# tests that don't need qmake (must be run before displaying help)
#-------------------------------------------------------------------------------

# auto-detect precompiled header support
if [ "$CFG_PRECOMPILE" = "auto" ]; then
    if $unixtests/precomp.test $XQMAKESPEC $OPT_VERBOSE; then
       CFG_PRECOMPILE=no
    else
       CFG_PRECOMPILE=yes
    fi
fi

# auto-detect -fvisibility support
if [ "$CFG_REDUCE_EXPORTS" = "auto" ]; then
    if $unixtests/fvisibility.test $XQMAKESPEC $OPT_VERBOSE; then
       CFG_REDUCE_EXPORTS=yes
    else
       CFG_REDUCE_EXPORTS=no
    fi
fi

# auto-detect SQL-modules support
MYSQL_REQ="-lmysqlclient mysql.h"
OCI_REQ="-lclntsh -lwtc8 oci.h"
PSQL_REQ="-lpq postgres.h libpq/libpq-fs.h catalog/pg_type.h libpq-fe.h"
ODBC_REQ="-lodbc sql.h sqlext.h"
TDS_REQ="-lsybdb sybfront.h sybdb.h"
DB2_REQ="-ldb2 sqlcli.h sqlcli1.h"
IBASE_REQ="-lgds ibase.h"
for _SQLDR in $CFG_SQL_AVAILABLE; do
	case $_SQLDR in
	mysql)
	    $unixtests/checkavail "MySQL" $OPT_VERBOSE $MYSQL_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED mysql"
	;;
	psql)
	    $unixtests/checkavail "PostgreSQL" $OPT_VERBOSE $PSQL_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED psql"
	    ;;
	odbc)
	    $unixtests/checkavail "ODBC" $OPT_VERBOSE $ODBC_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED odbc"
	    ;;
	oci)
	    $unixtests/checkavail "OCI" $OPT_VERBOSE $OCI_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED oci"
	    ;;
	tds)
	    $unixtests/checkavail "TDS" $OPT_VERBOSE $TDS_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED tds"
	    ;;
	db2)
	    $unixtests/checkavail "DB2" $OPT_VERBOSE $DB2_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED db2"
	    ;;
	ibase)
	    $unixtests/checkavail "IBASE" $OPT_VERBOSE $IBASE_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED ibase"
	    ;;
	sqlite)
	    if [ -f $relpath/src/3rdparty/sqlite/sqlite3.h ]; then
		CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED sqlite"
	    fi
	    ;;
	*)
	    if [ "$OPT_VERBOSE" = "yes" ]; then
		echo "unknown SQL driver: $_SQLDR"
	    fi
	    ;;
	esac
done

# auto-detect NIS support
if [ "$CFG_NIS" != "no" ]; then
    if $unixtests/nis.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	if [ "$CFG_NIS" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "NIS support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_NIS=no
        fi
    else
	CFG_NIS=yes
    fi
fi
# auto-detect CUPS support
if [ "$CFG_CUPS" != "no" ]; then
    if $unixtests/cups.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	if [ "$CFG_CUPS" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "Cups support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_CUPS=no
        fi
    else
	CFG_CUPS=yes
    fi
fi
#auto-detect GNU make support
if [ "$CFG_USE_GNUMAKE" = "auto" ] && $MAKE -v | grep "GNU Make" >/dev/null 2>&1; then
   CFG_USE_GNUMAKE=yes
fi

#mac
if [ "$PLATFORM_MAC" = "yes" ]; then
    if [ "$CFG_OPENGL" = "auto" ]; then
	CFG_OPENGL=yes
    fi
fi

# x11
if [ "$PLATFORM_X11" = "yes" ]; then
    x11tests=$relpath/config.tests/x11

    # auto-detect OpenGL support
    if [ "$CFG_OPENGL" = "auto" ]; then
	if $x11tests/opengl.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    CFG_OPENGL=no
	else
	    CFG_OPENGL=yes
	fi
    fi
    # auto-detect Xcursor support
    if [ "$CFG_XCURSOR" != "no" ]; then
        if $x11tests/xcursor.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XCURSOR" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Xcursor support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
            else
                CFG_XCURSOR=no
            fi
	else
            CFG_XCURSOR=yes
        fi
    fi
    # auto-detect XRandR support (resize and rotate extension)
    if [ "$CFG_XRANDR" != "no" ]; then
	if $x11tests/xrandr.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XRANDR" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XRandR support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XRANDR=no
	    fi
	else
	    CFG_XRANDR=yes
	fi
    fi
    # auto-detect XRender support
    if [ "$CFG_XRENDER" != "no" ]; then
	if $x11tests/xrender.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XRENDER" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XRender support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XRENDER=no
	    fi
	else
	    CFG_XRENDER=yes
	fi
    fi
    # auto-detect Xft support
    if [ "$CFG_XFT" != "no" ]; then
	mkdir -p $outpath/config.tests/x11
	if $x11tests/xft.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XFT" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Xft support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XFT=no
	    fi
	else
	    CFG_XFT=yes
	fi
    fi
    # add freetype2 include path
    if [ "$CFG_XFT" = "yes" ] && [ -f $outpath/config.tests/x11/xft.inc ];then
	QMAKE_VARS="$QMAKE_VARS \"FREETYPE2_INCDIR=`cat $outpath/config.tests/x11/xft.inc`\""
    fi
    rm -f $outpath/config.tests/x11/xft.inc
    # add Xft specific libraries
    if [ "$CFG_XFT" = "yes" ] && [ -f $outpath/config.tests/x11/xft.lib ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11=`cat $outpath/config.tests/x11/xft.lib` \$\$QMAKE_LIBS_X11\""
    fi
    rm -f $outpath/config.tests/x11/xft.lib
    # add Xft specific config options
    if [ "$CFG_XFT" = "yes" ] && [ -f $outpath/config.tests/x11/xft.cfg ]; then
	QT_LIBXFT=`cat $outpath/config.tests/x11/xft.cfg`
    fi
    rm -f $outpath/config.tests/x11/xft.cfg
    # auto-detect Session Management support
    if [ "$CFG_SM" = "auto" ]; then
	if $x11tests/sm.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_SM" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Session Management support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_SM=no
	    fi
	else
	    CFG_SM=yes
	fi
    fi
    # auto-detect SHAPE support
    if [ "$CFG_XSHAPE" != "no" ]; then
	if $x11tests/xshape.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XSHAPE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XShape support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
            else
                CFG_XSHAPE=no
            fi
	else
	    CFG_XSHAPE=yes
	fi
    fi
    # auto-detect Xinerama support
    if [ "$CFG_XINERAMA" != "no" ]; then
	if $x11tests/xinerama.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XINERAMA" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Xinerama support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XINERAMA=no
	    fi
	else
	    CFG_XINERAMA=yes
	fi
    fi
    # auto-detect tablet support (currenlty only in IRIX)
    if [ "$CFG_TABLET" != "no" ]; then
        if $x11tests/xinput.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
            if [ "$CFG_TABLET" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
                echo "Tablet support cannot be enabled due to functionality tests!"
                echo " Turn on verbose messaging (-v) to $0 to see the final report."
                echo " If you believe this message is in error you may use the continue"
                echo " switch (-continue) to $0 to continue."
                exit 101
            else
                CFG_TABLET=no
            fi
        else
            CFG_TABLET=yes
        fi
    else
        CFG_TABLET=yes
    fi
    # auto-detect XKB support
    if [ "$CFG_XKB" != "no" ]; then
	if $x11tests/xkb.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XKB" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XKB support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XKB=no
	    fi
	else
	    CFG_XKB=yes
	fi
    fi
fi # X11

# embedded graphics
if [ "$PLATFORM_QWS" = "yes" ]; then
    CFG_GFX_PLUGINS_AVAILABLE=`find $relpath/src/plugins/gfxdrivers/* -prune -type d -print | awk -F/ '{print $NF}'`
    CFG_GFX_AVAILABLE=`echo $CFG_GFX_PLUGINS_AVAILABLE $CFG_GFX_AVAILABLE`
    CFG_GFX_OFF=`echo $CFG_GFX_AVAILABLE` # assume all off
    # No OpenGL for Qt/Embedded
    if [ "$CFG_OPENGL" = "auto" ]; then
	CFG_OPENGL=no
    fi
fi # QWS

# immodule extensions
if [ "$CFG_IM" = "no" ]; then
    CFG_IM_EXT=no
fi
if [ "$CFG_IM_EXT" = "yes" ]; then
    CFG_IM=yes
fi


#-------------------------------------------------------------------------------
# help - interactive parts of the script _after_ this section please
#-------------------------------------------------------------------------------

# next, emit a usage message if something failed.
if [ "$OPT_HELP" = "yes" ]; then
    [ "x$ERROR" = "xyes" ] && echo
    if [ "$CFG_NIS" = "no" ]; then
	NSY=" "
	NSN="*"
    else
	NSY="*"
	NSN=" "
    fi
    if [ "$CFG_CUPS" = "no" ]; then
	CUY=" "
	CUN="*"
    else
	CUY="*"
	CUN=" "
    fi
    if [ "$CFG_LARGEFILE" = "no" ]; then
	LFSY=" "
	LFSN="*"
    else
	LFSY="*"
	LFSN=" "
    fi
    if [ "$CFG_STL" = "auto" ]; then
	SHY="*"
	SHN=" "
    else
	SHY=" "
	SHN="*"
    fi
    if [ "$CFG_IPV6" = "auto" ]; then
	I6Y="*"
	I6N=" "
    fi
    if [ "$CFG_PRECOMPILE" = "auto" ]; then
	PHY=" "
	PHN="*"
    else
	PHY="*"
	PHN=" "
    fi

    cat <<EOF
Usage:  $relconf [-prefix dir] [-buildkey key] [-docdir dir] [-headerdir dir]
	[-libdir dir] [-bindir dir] [-plugindir dir ] [-datadir dir]
	[-translationdir dir] [-sysconfdir dir] [-debug] [-release]
	[-no-gif] [-qt-gif] [-no-sm] [-sm] [-qt-zlib] [-system-zlib]
	[-qt-libjpeg] [-system-libjpeg] [-qt-libpng] [-system-libpng]
	[-no-nis] [-nis] [-no-cups] [-cups] [-no-largefile] [-largefile]
	[-no-stl] [-stl] [-no-pch] [-pch] [-Istring] [-lstring]
	[-Lstring] [-Rstring] [-disable-<module>] [-with-<module setting>]
	[-without-<module setting>] [-fast] [-no-fast]

Installation options:

 These are optional, but you may specify install directories.

    -prefix dir ........ This will install everything relative dir
			  (default $QT_INSTALL_PREFIX)

 You may use these to separate different parts of the install:

    -bindir dir ........ Executables will be installed to dir
			  (default PREFIX/bin)
    -libdir dir ........ Libraries will be installed to dir
			  (default PREFIX/lib)
    -docdir dir ........ Documentation will be installed to dir
			  (default PREFIX/doc)
    -headerdir dir ..... Headers will be installed to dir
			  (default PREFIX/include)
    -plugindir dir ..... Plugins will be installed to dir
                          (default PREFIX/plugins)
    -datadir dir ....... Data used by Qt programs will be installed to dir
                          (default PREFIX)
    -translationdir dir  Translations of Qt programs will be installed to dir
                          (default PREFIX/translations)
    -sysconfdir dir ...  Settings used by Qt programs will be looked for in dir
                          (default PREFIX/etc/settings)

 You may use these options to turn on strict plugin loading.

    -buildkey key ...... Build the Qt library and plugins using the specified
			 key.  When the library loads plugins, it will only
			 load those that have a matching key.

Configure options:

 The defaults (*) are usually acceptable.  If marked with a plus (+) a test
 for that feature has not been done yet, but will be evaluated later, the
 plus simply denotes the default value. Here is a short explanation of each
 option:

 *  -release ........... Compile and link Qt with debugging turned off.
    -debug ............. Compile and link Qt with debugging turned on.

 *  -shared ............ Create and use a shared Qt library (libqt.so).
    -static ............ Create and use a static Qt library (libqt.a).

 *  -no-gif ............ Do not compile in GIF reading support.
    -qt-gif ............ Compile in GIF reading support.
			 See src/gui/image/qgif.h

 *  -qt-zlib ........... Use the zlib bundled with Qt.
    -system-zlib ....... Use zlib from the operating system.
			 See http://www.info-zip.org/pub/infozip/zlib

    -fast .............. Configure Qt quickly by generating Makefiles only for
			 library and subdirectory targets.  All other Makefiles
			 are created as wrappers, which will in turn run qmake.
 *  -no-fast ........... Configure Qt normally by generating Makefiles for all
			 project files.

EOF
if [ "$PLATFORM_QWS" = "yes" ]; then
    cat << EOF
    -exceptions ........ Enable exceptions on platforms that support it.
 *  -no-exceptions ..... Disable exceptions on platforms that support it.

EOF
else
    cat << EOF
    -no-exceptions ..... Disable exceptions on platforms that support it.

EOF
fi
    cat << EOF
    -platform target ... The operating system and compiler you are building
			 on ($PLATFORM).
    -xplatform target .. The target platform when cross-compiling.

			 See the PLATFORMS file for a list of supported
			 operating systems and compilers.

    -Dstring ........... Add an explicit define to the preprocessor.
    -Istring ........... Add an explicit include path.
    -Lstring ........... Add an explicit library path.
    -Rstring ........... Add an explicit dynamic library runtime search path.
    -lstring ........... Add an explicit library.

    -qt-sql-<driver> ...... Enable a SQL <driver> in the Qt Library, by default
                            none are turned on.
    -plugin-sql-<driver> .. Enable SQL <driver> as a plugin to be linked to
                            at run time.
    -no-sql-<driver> ...... Disable SQL <driver> entirely.

                            Possible values for <driver>:
                            [ $CFG_SQL_AVAILABLE ]

                            Auto-Detected on this system:
                            [$CFG_SQL_AUTODETECTED ]

                            By default none of the SQL drivers are built,
			    even if they are auto-detected.

    -qt-style-<style> ..... Enable a GUI <style> in the Qt Library, by default
                            all available styles are on.
    -plugin-style-<style> . Enable GUI <style> as a plugin to be linked to
                            at run time.
    -no-style-<style> ..... Disable GUI <style> entirely.

                            Possible values for <style>:
                            [ $CFG_STYLE_AVAILABLE ]

 $NSN  -no-nis ............... Do not compile NIS support.
 $NSY  -nis .................. Compile NIS support.

 $CUN  -no-cups............... Do not compile CUPS support.
 $CUY  -cups ................. Compile CUPS support.

 $SHN  -no-stl ............... Do not compile STL support.
 $SHY  -stl .................. Compile STL support.

 $PHN  -no-pch ............... Do not use precompiled header support.
 $PHY  -pch .................. Use precompiled header support.

    -no-accessibility ..... Do not compile Accessibility support.
 *  -accessibility ........ Compile Accessibility support.

    -verbose .............. Print verbose information about each step of the
    -v .................... configure process.

    -continue.............. Continue as far as possible if an error occurs.

    -help ................. Print help and usage information.
    -h .................... Print help and usage information.

Image Formats:

    -plugin-imgfmt-<format> Enable <format> to be linked to at runtime.
                            Uses specified lib<format>.
    -qt-imgfmt-<format> ... Enable <format> to be linked into Qt.
                            Uses specified lib<format>.
    -no-imgfmt-<format> ... Fully disable <format> from Qt.

                            Possible values for <format>:
                            [ png jpeg ]

Third Party Image Loading Libraries:

    -qt-libpng ......... Use the libpng bundled with Qt.
 *  -system-libpng ..... Use libpng from the operating system.
			 See http://www.libpng.org/pub/png

    -qt-libjpeg ........ Use the libjpeg bundled with Qt.
 *  -system-libjpeg .... Use jpeglib from the operating system.
			 See http://www.ijg.org

EOF

if [ "$PLATFORM_X11" = "yes" ]; then
    if [ "$CFG_SM" = "no" ]; then
	SMY=" "
	SMN="*"
    else
	SMY="*"
	SMN=" "
    fi
    if [ "$CFG_XSHAPE" = "no" ]; then
        SHY=" "
        SHN="*"
    else
        SHY="*"
        SHN=" "
    fi
    if [ "$CFG_XINERAMA" = "no" ]; then
	XRY=" "
	XRN="*"
    else
	XRY="*"
	XRN=" "
    fi
    if [ "$CFG_XFT" = "no" ]; then
	XFTY=" "
	XFTN="*"
    else
	XFTY="*"
	XFTN=" "
    fi
    if [ "$CFG_XCURSOR" = "no" ]; then
        XCY=" "
        XCN="*"
    else
        XCY="*"
        XCN=" "
    fi
    if [ "$CFG_XRANDR" = "no" ]; then
        XZY=" "
        XZN="*"
    else
        XZY="*"
        XZN=" "
    fi
    if [ "$CFG_XRENDER" = "no" ]; then
	XRY=" "
	XRN="*"
    else
	XRY="*"
	XRN=" "
    fi
    if [ "$CFG_TABLET" = "no" ]; then
	XIY=" "
	XIN="*"
    else
	XIY="*"
	XIN=" "
    fi
    if [ "$CFG_XKB" = "no" ]; then
        XKY=" "
        XKN="*"
    else
        XKY="*"
        XKN=" "
    fi
    if [ "$CFG_IM" = "no" ]; then
        IMY=" "
        IMN="*"
    else
        IMY="*"
        IMN=" "
    fi
    if [ "$CFG_IM_EXT" = "no" ]; then
        IXY=" "
        IXN="*"
    else
        IXY="*"
        IXN=" "
    fi
    cat << EOF

Qt/X11 only:

 *  -no-nas-sound ...... Do not compile in NAS sound support.
    -system-nas-sound .. Use NAS libaudio from the operating system.
			 See http://radscan.com/nas.html

 $SMN  -no-sm ............. Do not support X Session Management.
 $SMY  -sm ................ Support X Session Management, links in -lSM -lICE.

 $SHN  -no-xshape ......... Do not compile XShape support.
 $SHY  -xshape ............ Compile XShape support.
                         Requires X11/extensions/shape.h.

 $XRN  -no-xinerama ....... Do not compile Xinerama (multihead) support.
 $XRY  -xinerama .......... Compile Xinerama support.
			 Requires X11/extensions/Xinerama.h and libXinerama.

 $XCN  -no-xcursor ........ Do not compile Xcursor support.
 $XCY  -xcursor ........... Compile Xcursor support.
                         Requires X11/Xcursor/Xcursor.h and libXcursor.

 $XZN  -no-xrandr ......... Do not compile XRandR (resize and rotate) support.
 $XZY  -xrandr ............ Compile XRandR support.
                         Requires X11/extensions/Xrandr.h and libXrandr.

 $XRN  -no-xrender ........ Do not compile XRender support.
 $XRY  -xrender ........... Compile XRender support.
			 Requires Xft support (see -xft below),
			 X11/extensions/Xrender.h and libXrender

 $XFTN  -no-xft ............ Do not compile Xft (anti-aliased font) support.
 $XFTY  -xft ............... Compile Xft support.
			 Requires X11/Xft/Xft.h and libXft.

 $XIN  -no-tablet ......... Do not compile Tablet support.
 $XIY  -tablet ............ Compile Tablet support.
			 Requires IRIX with wacom.h and libXi or
			 XFree86 with X11/extensions/XInput.h and libXi.

 $XKN  -no-xkb ............ Do not compile XKB (X KeyBoard extension) support.
 $XKY  -xkb ............... Compile XKB support.

 $IMN  -no-inputmethod .... Do not compile immodule (extensible input method)
			 support.
 $IMY  -inputmethod ....... Compile immodule support.

 $IXN  -no-inputmethod-ext  Do not compile more immodule extensions support.
 $IXY  -inputmethod-ext ... Compile more immodule extensions support.
EOF
fi

if [ "$PLATFORM_QWS" = "yes" ]; then
    cat << EOF

Qt/Embedded only:

    -embedded arch...... This will enable the embedded build, you must have a
			 proper license for this switch to work.

    -little-endian ..... Target platform is little endian (LSB first).
    -big-endian ........ Target platform is big endian (MSB first).

                         You only need to specify the endianness when
                         cross-compiling, otherwise the host
                         endianness will be used.

    -no-freetype ....... Qt/Embedded only: do not compile in FreeType2 support.
 *  -freetype .......... Qt/Embedded only: add FreeType2 font support.

    -no-zlib ........... No compression library -- implies -no-libpng

    -qconfig local ..... Use src/tools/qconfig-local.h rather than the
			 default ($CFG_QCONFIG).

    -depths list ....... Comma-separated list of supported bit-per-pixel
			 depths, from:  4, 8, 16, 24, and 32.
			 (8bpp is required by the VGA16 driver)

    -qt-decoration-<style> ....Enable a decoration <style> in the Qt Library,
                               by default all available decorations are on.
    -plugin-decoration-<style> Enable decoration <style> as a plugin to be
                               linked to at run time.
    -no-decoration-<style> ....Disable decoration <style> entirely.

                               Possible values for <style>:
                               [ $CFG_DECORATION_AVAILABLE ]

    -qt-gfx-<driver> ... Enable a graphics <driver> in the Qt Library.
    -plugin-gfx-<driver> Enable graphics <driver> as a plugin to be
                         linked to at run time.
    -no-gfx-<driver> ... Disable graphics <driver> entirely.

                         Possible values for <driver>: [ $CFG_GFX_AVAILABLE ]

    -qt-kbd-<driver> ... Enable a keyboard <driver> in the Qt Library.
    -no-kbd-<driver> ... Disable keyboard <driver> entirely.

                         Possible values for <driver>: [ sl5000 tty usb yopy vr41xx ]

    -qt-mouse-<driver> . Enable a mouse <driver> in the Qt Library.
    -no-mouse-<driver> . Disable mouse <driver> entirely.

                         Possible values for <driver>: [ pc bus linuxtp yopy vr41xx ]

EOF
fi

   [ "x$ERROR" = "xyes" ] && exit 1
   exit 0
fi # Help


# -----------------------------------------------------------------------------
# LICENSING, INTERACTIVE PART
# -----------------------------------------------------------------------------

# check for license confirmation
if [ "$Edition" = "free" ]; then
    while true; do
	if [ "$PLATFORM_QWS" = "yes" ]; then
	    echo
	    echo "This is the Qt/Embedded Open Source Edition."
	    echo
	    echo "You are licensed to use this software under the terms of"
	    echo "the GNU General Public License (GPL)."
	    echo
	    affix="the"
	elif [ "$PLATFORM_MAC" = "yes" ]; then
	    echo
	    echo "This is the Qt/Mac Open Source Edition."
	    echo
	    echo "You are licensed to use this software under the terms of"
	    echo "the GNU General Public License (GPL)."
	    echo
	    affix="the"
	elif [ "$PLATFORM_X11" = "yes" ]; then
	    echo
	    echo "This is the Qt/X11 Open Source Edition."
	    echo
	    echo "You are licensed to use this software under the terms of either"
	    echo "the Q Public License (QPL) or the GNU General Public License (GPL)."
	    echo
	    [ "$OPT_CONFIRM_LICENSE" = "no" ] && echo "Type 'Q' to view the Q Public License."
	    affix="either"
	else
	    echo
	    echo "Internal error."
	    echo
	    exit 2
	fi
        if [ "$OPT_CONFIRM_LICENSE" = "yes" ]; then
	    acceptance=yes
        else
	    echo "Type 'G' to view the GNU General Public License."
	    echo "Type 'yes' to accept this license offer."
	    echo "Type 'no' to decline this license offer."
	    echo
	    if echo '\c' | grep '\c' >/dev/null; then
		echo -n "Do you accept the terms of $affix license? "
	    else
		echo "Do you accept the terms of $affix license? \c"
	    fi
	    read acceptance
        fi
	echo
	if [ "$acceptance" = "yes" ]; then
	    break
	elif [ "$acceptance" = "no" ]; then
	    echo "You are not licensed to use this software."
	    echo
	    exit 0
	elif [ "$acceptance" = "G" -o "$acceptance" = "g" ]; then
	    more $relpath/LICENSE.GPL
	elif [ "$acceptance" = "Q" -o "$acceptance" = "q" ]; then
	    if [ "$PLATFORM_QWS" != "yes" ]; then
		more $relpath/LICENSE.QPL
	    fi
	fi
    done
elif [ "$Edition" = "preview" ]; then
    if [ "$PLATFORM_QWS" = "yes" ]; then
	Platform="Qt/Embedded"
    elif [ "$PLATFORM_MAC" = "yes" ]; then
	Platform="Qt/Mac"
    elif [ "$PLATFORM_X11" = "yes" ]; then
	Platform="Qt/X11"
    else
	echo
	echo "Internal error: unknown platform."
	echo
	exit 2
    fi
    FIRST_LOOP=yes
    while true; do
	echo
	echo "This is the Trolltech preview version of $Platform."
	echo

	if [ "$OPT_CONFIRM_LICENSE" = "yes" ]; then
	    acceptance=yes
        else
	    if [ "$FIRST_LOOP" = "yes" ]; then
		more $relpath/LICENSE.PREVIEW
		FIRST_LOOP=no
		echo
            fi
	    echo "You are licensed to use this software under the terms of"
	    echo "the Qt PREVIEW VERSION LICENSE AGREEMENT"
	    echo
	    echo "Type '?' to re-read the Preview License."
	    echo "Type 'yes' to accept this license offer."
	    echo "Type 'no' to decline this license offer."
	    echo
	    if echo '\c' | grep '\c' >/dev/null; then
		echo -n "Do you accept the terms of the license? "
	    else
		echo "Do you accept the terms of the license? \c"
	    fi
	    read acceptance
	fi
	echo
	if [ "$acceptance" = "yes" ]; then
	    break
	elif [ "$acceptance" = "no" ] ;then
	    echo "You are not licensed to use this software."
	    echo
	    exit 0
	elif [ "$acceptance" = "?" ]; then
	    more $relpath/LICENSE.PREVIEW
	fi
    done

elif [ "$Edition" = "eval" ]; then
    while true; do
	if [ "$PLATFORM_QWS" = "yes" ]; then
	    echo
	    echo "This is the Qt/Embedded Evaluation version."
	    echo
	elif [ "$PLATFORM_X11" = "yes" ]; then
	    echo
	    echo "This is the Qt/X11 Evaluation version."
	    echo
	else
	    echo >&2
	    echo "Internal error." >&2
	    echo >&2
	    exit 2
	fi
	if [ "$OPT_CONFIRM_LICENSE" = "yes" ]; then
	    acceptance=yes
        else
	    echo "You are licensed to use this software under the terms of"
	    echo "the Qt EVALUATION VERSION LICENSE AGREEMENT"
	    echo
	    echo "Type '?' to view the Evaluation License."
	    echo "Type 'yes' to accept this license offer."
	    echo "Type 'no' to decline this license offer."
	    echo
	    if echo '\c' | grep '\c' >/dev/null; then
		echo -n "Do you accept the terms of the license? "
	    else
		echo "Do you accept the terms of the license? \c"
	    fi
	    read acceptance
	fi
	echo
	if [ "$acceptance" = "yes" ]; then
	    break
	elif [ "$acceptance" = "no" ] ;then
	    echo "You are not licensed to use this software."
	    echo
	    exit 0
	elif [ "$acceptance" = "?" ]; then
	    more $relpath/LICENSE.EVAL
	fi
    done
elif [ "$Edition" = "troll" ]; then
    if [ "$PLATFORM_QWS" = "yes" ]; then
	Platform="Qt/Embedded"
    elif [ "$PLATFORM_MAC" = "yes" ]; then
	Platform="Qt/Mac"
    elif [ "$PLATFORM_X11" = "yes" ]; then
	Platform="Qt/X11"
    else
	echo
	echo "Internal error: unknown platform."
	echo
	exit 2
    fi
    echo
    echo "This is the Trolltech in-house version of $Platform."
    echo
else
    if [ -f $HOME/.qt-license ]; then
	ExpiryDate=`echo $ExpiryDate | sed -e "s,-,,g" | tr -d "\n\r"`
	[ -z "$ExpiryDate" ] && ExpiryDate="0"
	Today=`date +%Y%m%d`
	if [ "$Today" -gt "$ExpiryDate" ]; then
	    echo
	    echo "WARNING  WARNING  WARNING  WARNING"
	    echo
	    echo "  Your support and upgrade period has expired."
	    echo
	    echo "  You may continue to use your last licensed release"
	    echo "  of Qt under the terms of your existing license"
	    echo "  agreement. But you are not entitled to technical"
	    echo "  support, nor are you entitled to use any more recent"
	    echo "  Qt releases."
	    echo
	    echo "  Please contact sales@trolltech.com to renew your"
	    echo "  support and upgrades for this license."
	    echo
	    echo "WARNING  WARNING  WARNING  WARNING"
	    echo
	    sleep 3
	fi
    fi
    if [ "$PLATFORM_QWS" = "yes" ]; then
	Platform="Qt/Embedded"
    elif [ "$PLATFORM_MAC" = "yes" ]; then
	Platform="Qt/Mac"
    elif [ "$PLATFORM_X11" = "yes" ]; then
	Platform="Qt/X11"
    else
	echo >&2
	echo "Internal error." >&2
	echo >&2
	exit 2
    fi
    echo
    echo "This is the $Platform $Desc Edition."
    echo
    while true; do
	if [ "$OPT_CONFIRM_LICENSE" = "yes" ]; then
	    acceptance=yes
        else
	    echo
	    echo "Type '?' to view the $Platform License."
	    echo "Type 'yes' to accept this license offer."
	    echo "Type 'no' to decline this license offer."
	    echo
	    if echo '\c' | grep '\c' >/dev/null; then
		echo -n "Do you accept the terms of the $Platform License? "
	    else
		echo "Do you accept the terms of the $Platform License? \c"
	    fi
	    read acceptance
        fi
	echo
	if [ "$acceptance" = "yes" ]; then
	    break
	elif [ "$acceptance" = "no" ]; then
	    echo "You are not licensed to use this software."
	    echo
	    exit 0
	else [ "$acceptance" = "?" ]
	    more $relpath/LICENSE
	fi
    done
fi

# work around for broken system header files in IRIX > 6.5.18
case "$PLATFORM" in
irix-cc*)
    IRIX_VERSION=`uname -R | awk '{FS=".";print $4}' | sed s/\[m\|f\]//g`
    MIPSPRO_MINOR_VERSION=`CC -version 2>&1 | awk '{FS=".";print $2}'`
    if [ "$MIPSPRO_MINOR_VERSION" -gt "3" -a "$IRIX_VERSION" -ge "18" ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-LANG:libc_in_namespace_std=off\""
    fi
    ;;
*)
    IRIX_VERSION=-1
    MIPSPRO_MINOR_VERSION=-1
    ;;
esac

# -----------------------------------------------------------------------------
# build qmake
# -----------------------------------------------------------------------------

# symlink includes
if [ -x "/usr/bin/perl" ] && [ -x "$relpath/bin/syncqt" ]; then
    [ "$Edition" = "troll" ] && QTDIR=$relpath perl $relpath/bin/syncqt -inc $relpath/include
    [ "$OPT_SHADOW" = "yes" ] && QTDIR=$relpath perl $relpath/bin/syncqt -inc $outpath/include
fi

if [ "$OPT_SHADOW" = "yes" ]; then
    # we are doing a shadow build, so we need to use the includes from
    # $outpath/include as well
    QMAKE_VARS="$QMAKE_VARS \"INCLUDEPATH+=${outpath}/include\""
fi

# build qmake
if true; then ###[ '!' -f "$outpath/bin/qmake" ];
    echo "Creating qmake. Please wait..."

    OLD_QCONFIG_H=
    QCONFIG_H="$outpath/src/core/global/qconfig.h"
    QMAKE_QCONFIG_H="${QCONFIG_H}.qmake"
    if [ -f "$QCONFIG_H" ]; then
         OLD_QCONFIG_H=$QCONFIG_H
         mv -f "$OLD_QCONFIG_H" "${OLD_QCONFIG_H}.old"
    fi

    # create temporary qconfig.h for compiling qmake, if it doesn't exist
    # when building qmake, we use #defines for the install paths,
    # however they are real functions in the library
    if [ '!' -f "$QMAKE_QCONFIG_H" ]; then
	mkdir -p "$outpath/src/core/global"
	[ -f "$QCONFIG_H" ] && chmod +w "$QCONFIG_H"
	echo "/* All features enabled while building qmake */" >"$QMAKE_QCONFIG_H"
    fi

    mv -f "$QMAKE_QCONFIG_H" "$QCONFIG_H"
    for conf in "$outpath/include/QtCore/qconfig.h" "$outpath/include/Qt/qconfig.h"; do
        if [ '!' -f "$conf" ]; then
	    ln -s "$QCONFIG_H" "$conf"
        fi
    done

    #mkspecs/default is used as a (gasp!) default mkspec so QMAKESPEC needn't be set once configured
    rm -f mkspecs/default
    ln -s `echo $QMAKESPEC | sed "s,^${relpath}/mkspecs/,,"` mkspecs/default
    # fix makefiles
    for mkfile in GNUmakefile Makefile; do
	EXTRA_LFLAGS=
	EXTRA_CFLAGS=
	in_mkfile="${mkfile}.in"
	if [ "$mkfile" = "Makefile" ]; then
#	    if which qmake >/dev/null 2>&1 && [ -f qmake/qmake.pro ]; then
#		(cd qmake && qmake) >/dev/null 2>&1 && continue
#	    fi
	    in_mkfile="${mkfile}.unix"
	fi
	in_mkfile="$relpath/qmake/$in_mkfile"
	mkfile="$outpath/qmake/$mkfile"
	if [ -f "$mkfile" ]; then
	    [ "$Edition" = "troll" ] && $WHICH chflags >/dev/null 2>&1 && chflags nouchg $mkfile
	    rm -f $mkfile
	fi
	[ -f "$in_mkfile" ] || continue

	echo "########################################################################" >$mkfile
	echo "## This file was autogenerated by configure, all changes will be lost ##" >>$mkfile
	echo "########################################################################" >>$mkfile
	EXTRA_CFLAGS="\$(QMAKE_CFLAGS)"
	EXTRA_CXXFLAGS="\$(QMAKE_CXXFLAGS)"
	EXTRA_LFLAGS="\$(QMAKE_LFLAGS)"
	grep "QMAKE_CC[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,QMAKE_CC,CC," >>$mkfile
	grep "QMAKE_CXX[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,QMAKE_CXX,CXX," >>$mkfile
	grep "QMAKE_CFLAGS[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
	grep "QMAKE_CXXFLAGS[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,\$\$QMAKE_CFLAGS,\$(QMAKE_CFLAGS)," >>$mkfile
	grep "QMAKE_LFLAGS[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
	if [ "$Products" = "qt-free" ]; then
            EXTRA_CFLAGS="$EXTRA_CFLAGS -DQMAKE_OPENSOURCE_EDITION"
            EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -DQMAKE_OPENSOURCE_EDITION"
        else
	    echo "include Makefile.commercial" >>$mkfile
        fi
	if [ "$CFG_DEBUG" = "yes" ]; then
            grep "QMAKE_CFLAGS_DEBUG[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
            grep "QMAKE_CXXFLAGS_DEBUG[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,\$\$QMAKE_CFLAGS_DEBUG,\$(QMAKE_CFLAGS_DEBUG),"  >>$mkfile
	    EXTRA_CFLAGS="$EXTRA_CFLAGS \$(QMAKE_CFLAGS_DEBUG)"
	    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS \$(QMAKE_CXXFLAGS_DEBUG)"
        fi
	if [ "$PLATFORM_MAC" = "yes" ]; then
	    echo "export MACOSX_DEPLOYMENT_TARGET = 10.2" >>$mkfile
	    echo "CARBON_LFLAGS +=-framework CoreServices -framework CoreFoundation" >>$mkfile
	    EXTRA_LFLAGS="$EXTRA_LFLAGS \$(CARBON_LFLAGS)"
	    EXTRA_CFLAGS="$EXTRA_CFLAGS \$(CARBON_CFLAGS)"
	    EXTRA_SOURCES="qsettings_mac.o qcore_mac.o"
	fi
	[ "$CFG_EMBEDDED" != "no" ] && EXTRA_CFLAGS="$EXTRA_CFLAGS -DQWS"
	if [ '!' -z "$D_FLAGS" ]; then
	    for DEF in $D_FLAGS; do
		EXTRA_CFLAGS="$EXTRA_CFLAGS -D${DEF}"
	    done
        fi
	if [ "$MIPSPRO_MINOR_VERSION" -gt "3" -a "$IRIX_VERSION" -ge "18" ]; then
	    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -LANG:libc_in_namespace_std=off"
	fi
	QMAKE_BIN_DIR="$QT_INSTALL_BINS"
	[ -z "$QMAKE_BIN_DIR" ] && QMAKE_BIN_DIR="${QT_INSTALL_PREFIX}/bin"
	QMAKE_DATA_DIR="$QT_INSTALL_DATA"
	[ -z "$QMAKE_DATA_DIR" ] && QMAKE_DATA_DIR="${QT_INSTALL_PREFIX}"
        echo >>$mkfile
	sed -e "s,@SOURCE_PATH@,$relpath,g" -e "s,@BUILD_PATH@,$outpath,g" \
	    -e "s,@QMAKE_CFLAGS@,$EXTRA_CFLAGS,g" -e "s,@QMAKE_LFLAGS@,$EXTRA_LFLAGS,g" \
	    -e "s,@QMAKE_CXXFLAGS@,$EXTRA_CXXFLAGS,g" \
	    -e "s,@QT_INSTALL_BINS@,\$(INSTALL_ROOT)$QMAKE_BIN_DIR,g" \
	    -e "s,@QT_INSTALL_DATA@,\$(INSTALL_ROOT)$QMAKE_DATA_DIR,g" \
	    -e "s,@QMAKE_QTOBJS@,$EXTRA_SOURCES,g" -e "s,@QMAKESPEC@,$QMAKESPEC,g" $in_mkfile >>$mkfile

	if [ "$Edition" = "troll" ] &&
	    $WHICH makedepend >/dev/null 2>&1 && grep 'depend:' "$mkfile" >/dev/null 2>&1; then
	    (cd $outpath/qmake && $MAKE -f $mkfile depend) >/dev/null 2>&1
	fi
    done

    QMAKE_BUILD_ERROR=no
    (cd $outpath/qmake; $MAKE) || QMAKE_BUILD_ERROR=yes
    [ '!' -z "$QCONFIG_H" ] && mv -f "$QCONFIG_H" "$QMAKE_QCONFIG_H" #move qmake's qconfig.h to qconfig.h.qmake
    [ '!' -z "$OLD_QCONFIG_H" ] && mv -f "${OLD_QCONFIG_H}.old" "$OLD_QCONFIG_H" #put back qconfig.h
    [ "$QMAKE_BUILD_ERROR" = "yes" ] && exit 2
fi # Build qmake

#-------------------------------------------------------------------------------
# tests that need qmake
#-------------------------------------------------------------------------------

# work around broken X11 headers when using GCC 2.95 or later
if [ "$PLATFORM_X11" = "yes" ]; then
    NOTYPE=no
    $x11tests/notype.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath && NOTYPE=yes
    [ $NOTYPE = "yes" ] && QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-fpermissive\""
fi

if [ "$CFG_ENDIAN" = "auto" ]; then
    if $unixtests/endian.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
        CFG_ENDIAN="Q_LITTLE_ENDIAN"
    else
        CFG_ENDIAN="Q_BIG_ENDIAN"
    fi
fi

if [ "$CFG_STL" = "auto" ]; then
    if $unixtests/stl.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
	if [ "$CFG_STL" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "STL support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_STL=no
	fi
    else
	CFG_STL=yes
    fi
fi

# find if the platform supports IPv6
if [ "$CFG_IPV6" = "auto" ]; then
    if $unixtests/ipv6.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
	if [ "$CFG_IPV6" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "IPv6 support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_IPV6=no
	fi
    else
	CFG_IPV6=yes
    fi
fi

# find if the platform provides getaddrinfo (ipv6 dns lookups)
if [ "$CFG_GETADDRINFO" = "auto" ]; then
    if $unixtests/getaddrinfo.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
        CFG_GETADDRINFO=no
    else
        CFG_GETADDRINFO=yes
    fi
fi

# find if the platform supports X/Open Large File compilation environment
if [ "$CFG_LARGEFILE" = "auto" ]; then
    if $unixtests/largefile.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
	if [ "$CFG_LARGEFILE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "Large file support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_LARGEFILE=no
	fi
    else
	CFG_LARGEFILE=yes
    fi
fi


#-------------------------------------------------------------------------------
# ask for all that hasn't been auto-detected or specified in the arguments
#-------------------------------------------------------------------------------

### fix this: user input should be validated in a loop
if [ "$CFG_QWS_DEPTHS" = "prompted" -a "$PLATFORM_QWS" = "yes" ]; then
    echo
    echo "Choose pixel-depths to support:"
    echo
    echo "   4. 4bpp grayscale - also enables 8bpp"
    echo "   8. 8bpp"
    echo "  16. 16bpp"
    echo "  24. 24bpp - also enables 32bpp"
    echo "  32. 32bpp"
    echo
    echo "Each depth adds around 100Kb on 80386."
    echo
    echo "Your choices (default 8,16,32):"
    read CFG_QWS_DEPTHS
    if [ -z "$CFG_QWS_DEPTHS" ] || [ "$CFG_QWS_DEPTHS" = "yes" ]; then
	CFG_QWS_DEPTHS=8,16,32
    fi
fi
if [ -n "$CFG_QWS_DEPTHS" -a "$PLATFORM_QWS" = "yes" ]; then
    D4=;D8=;D16=;D24=;D32=
    for D in `echo "$CFG_QWS_DEPTHS" | sed -e 's/,/ /g'`; do
	case "$D" in
	    4) D4=y; D8=y
	;;  8) D8=y
	;; 16) D16=y
	;; 24) D24=y; D32=y
	;; 32) D32=y
	esac
    done
    if [ -z "$D4" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_DEPTH_4"
    fi
    if [ -z "$D8" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_DEPTH_8"
    fi
    if [ -z "$D16" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_DEPTH_16"
    fi
    if [ -z "$D24" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_DEPTH_24"
    fi
    if [ -z "$D32" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_DEPTH_32"
    fi
fi

# disable compat
if [ "$CFG_COMPAT" = "no" ]; then
    QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_COMPAT"
else
    QT_CONFIG="$QT_CONFIG compat"
fi

# disable accessibility
if [ "$CFG_ACCESSIBILITY" = "no" ]; then
    QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_ACCESSIBILITY"
else
    QT_CONFIG="$QT_CONFIG accessibility"
fi

# enable opengl
if [ "$CFG_OPENGL" = "no" ]; then
    QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_OPENGL"
else
    QT_CONFIG="$QT_CONFIG opengl"
fi

# update QT_CONFIG to show our current predefined configuration
case "$CFG_QCONFIG" in
minimal|small|medium|large|full)
    # these are a sequence of increasing functionality
    for c in minimal small medium large full; do
	QT_CONFIG="$QT_CONFIG $c-config"
	[ "$CFG_QCONFIG" = $c ] && break
    done
    ;;
*)
    # not known to be sufficient for anything
    if [ '!' -f $relpath/src/tools/qconfig-$CFG_QCONFIG.h ]; then
	echo >&2 "No such configuration: $CFG_QCONFIG"
	OPT_HELP=yes
    fi
esac

# build up the variables for output
if [ "$CFG_DEBUG" = "yes" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}debug"
    QMAKE_CONFIG="$QMAKE_CONFIG debug"
elif [ "$CFG_DEBUG" = "no" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}release"
    QMAKE_CONFIG="$QMAKE_CONFIG release"
fi
if [ "$CFG_SHARED" = "yes" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}-shared"
    QMAKE_CONFIG="$QMAKE_CONFIG shared dll"
elif [ "$CFG_SHARED" = "no" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}-static"
    QMAKE_CONFIG="$QMAKE_CONFIG staticlib"
fi
if [ "$PLATFORM_QWS" = "yes" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}-emb-$CFG_EMBEDDED"
    QMAKE_CONFIG="$QMAKE_CONFIG embedded"
    rm -f src/.moc/$QMAKE_OUTDIR/allmoc.cpp # needs remaking if config changes
fi
QMAKE_VARS="$QMAKE_VARS \"QMAKE_INCDIR_QT=$outpath/include\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBDIR_QT=$outpath/lib\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_RTLDIR_QT=$QT_INSTALL_LIBS\""
QMAKE_VARS="$QMAKE_VARS \"OBJECTS_DIR=.obj/$QMAKE_OUTDIR\""
QMAKE_VARS="$QMAKE_VARS \"MOC_DIR=.moc/$QMAKE_OUTDIR\""
QMAKE_VARS="$QMAKE_VARS \"RCC_DIR=.rcc/$QMAKE_OUTDIR\""
if [ "$CFG_LARGEFILE" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG largefile"
fi
if [ "$CFG_STL" = "no" ]; then
    QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_STL"
else
    QMAKE_CONFIG="$QMAKE_CONFIG stl"
fi
if [ "$CFG_USE_GNUMAKE" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG GNUmake"
fi
[ "$CFG_REDUCE_EXPORTS" = "yes" ] && QT_CONFIG="$QT_CONFIG reduce_exports"
[ "$CFG_PRECOMPILE" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG precompile_header"
if [ "$CFG_IPV6" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG ipv6"
fi
if [ "$CFG_GETADDRINFO" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG getaddrinfo"
fi
if [ "$CFG_LIBJPEG" = "system" ]; then
    QT_CONFIG="$QT_CONFIG system-jpeg"
fi
if [ "$CFG_JPEG" = "no" ]; then
    QT_CONFIG="$QT_CONFIG no-jpeg"
elif [ "$CFG_JPEG" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG jpeg"
fi
if [ "$CFG_LIBPNG" = "no" ]; then
    CFG_PNG="no"
fi
if [ "$CFG_LIBPNG" = "system" ]; then
    QT_CONFIG="$QT_CONFIG system-png"
fi
if [ "$CFG_PNG" = "no" ]; then
    QT_CONFIG="$QT_CONFIG no-png"
elif [ "$CFG_PNG" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG png"
fi
if [ "$CFG_GIF" = "no" ]; then
    QT_CONFIG="$QT_CONFIG no-gif"
elif [ "$CFG_GIF" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG gif"
fi
if [ "x$PLATFORM_MAC" = "xyes" ]; then
    #On Mac we implicitly link against libz, so we
    #never use the 3rdparty stuff.
    [ "$CFG_ZLIB" = "yes" ] && CFG_ZLIB="system"
fi
if [ "$CFG_ZLIB" = "no" ]; then
    QT_CONFIG="$QT_CONFIG no-zlib"
    QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_COMPRESS"
elif [ "$CFG_ZLIB" = "yes" ]; then
    QT_CONFIG="$QT_CONFIG zlib"
elif [ "$CFG_ZLIB" = "system" ]; then
    QT_CONFIG="$QT_CONFIG system-zlib"
fi
[ "$CFG_NIS" = "yes" ] && QT_CONFIG="$QT_CONFIG nis"
[ "$CFG_CUPS" = "yes" ] && QT_CONFIG="$QT_CONFIG cups"
[ "$CFG_NAS" = "system" ] && QT_CONFIG="$QT_CONFIG nas"

[ "$CFG_QWS_FREETYPE" = "yes" -a "x$CFG_EMBEDDED" != "xno" ] && QT_CONFIG="$QT_CONFIG ft"
if [ "$PLATFORM_X11" = "yes" ]; then
    [ "$CFG_SM" = "yes" ] && QT_CONFIG="$QT_CONFIG x11sm"

    # for some reason, the following libraries are not always built shared,
    # so *every* program/lib (including Qt) has to link against them
    if [ "$CFG_XSHAPE" = "yes" ]; then
        QT_CONFIG="$QT_CONFIG xshape"
    fi
    if [ "$CFG_XINERAMA" = "yes" ]; then
	QT_CONFIG="$QT_CONFIG xinerama"
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXinerama \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XCURSOR" = "yes" ]; then
        QT_CONFIG="$QT_CONFIG xcursor"
        QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXcursor \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XRANDR" = "yes" ]; then
        QT_CONFIG="$QT_CONFIG xrandr"
        QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXrandr \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XRENDER" = "yes" ]; then
	QT_CONFIG="$QT_CONFIG xrender"
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXrender \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XFT" = "yes" ]; then
	QT_CONFIG="$QT_CONFIG xft"
    fi
    if [ "$CFG_TABLET" = "yes" ]; then
	QT_CONFIG="$QT_CONFIG tablet"
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXi \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XKB" = "yes" ]; then
        QT_CONFIG="$QT_CONFIG xkb"
    fi

    if [ "$CFG_IM" = "yes" ]; then
        QT_CONFIG="$QT_CONFIG inputmethod"
    elif [ "$CFG_IM" = "no" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_IM"
    fi
    if [ "$CFG_IM_EXT" = "yes" ]; then
        QT_CONFIG="$QT_CONFIG inputmethod-ext"
    elif [ "$CFG_IM_EXT" = "no" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_IM_EXTENSIONS"
    fi
elif [ "$PLATFORM_MAC" = "yes" ]; then
    if [ "$CFG_TABLET" = "yes" ]; then
	QT_CONFIG="$QT_CONFIG tablet"
    fi
fi

[ '!' -z "$D_FLAGS" ] && QMAKE_VARS="$QMAKE_VARS \"DEFINES+=$D_FLAGS\""
[ '!' -z "$L_FLAGS" ] && QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBDIR_FLAGS+=$L_FLAGS\""
[ '!' -z "$l_FLAGS" ] && QMAKE_VARS="$QMAKE_VARS \"LIBS+=$l_FLAGS\""

if [ '!' -z "$R_FLAGS" ]; then
    if grep QMAKE_RPATH $XQMAKESPEC/qmake.conf >/dev/null; then
	echo # Using -R/-rpath, so no need to warn
    else
	echo
	echo "ERROR: -R cannot be used on this platform as \$QMAKE_RPATH is"
	echo "       undefined."
	echo
	exit 1
    fi
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LFLAGS+=$R_FLAGS\""
fi

if [ '!' -z "$I_FLAGS" ]; then
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS+=$I_FLAGS\""
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=$I_FLAGS\""
fi

# install things
QMAKE_VARS="$QMAKE_VARS \"QT_INSTALL_PREFIX=${QT_INSTALL_PREFIX}\""
QMAKE_VARS="$QMAKE_VARS \"docs.path=${QT_INSTALL_DOCS}\""
QMAKE_VARS="$QMAKE_VARS \"headers.path=${QT_INSTALL_HEADERS}\""
QMAKE_VARS="$QMAKE_VARS \"plugins.path=${QT_INSTALL_PLUGINS}\""
QMAKE_VARS="$QMAKE_VARS \"libs.path=${QT_INSTALL_LIBS}\""
QMAKE_VARS="$QMAKE_VARS \"bins.path=${QT_INSTALL_BINS}\""
QMAKE_VARS="$QMAKE_VARS \"data.path=${QT_INSTALL_DATA}\""
QMAKE_VARS="$QMAKE_VARS \"translations.path=${QT_INSTALL_TRANSLATIONS}\""

# turn off exceptions for the compilers that support it
COMPILER=`echo $PLATFORM | cut -f 2- -d-`
if [ "$CFG_EXCEPTION_SUPPORT" = "unspecified" -a "$PLATFORM_QWS" = "yes" ]; then
    CFG_EXCEPTION_SUPPORT=no
fi

if [ "$CFG_EXCEPTION_SUPPORT" = "no" ]; then
    case "$COMPILER" in
    g++*)
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS+=-fno-exceptions\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-fno-exceptions\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LFLAGS+=-fno-exceptions\""
	;;
    cc*)
	case "$PLATFORM" in
	irix-cc*)
	    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS+=-LANG:exceptions=off\""
	    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-LANG:exceptions=off\""
	    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LFLAGS+=-LANG:exceptions=off\""
	    ;;
	*) ;;
	esac
	;;
    *) ;;
    esac
fi

#-------------------------------------------------------------------------------
# generate QT_BUILD_KEY
#-------------------------------------------------------------------------------

# some compilers generate binary incompatible code between different versions,
# so we need to generate a build key that is different between these compilers
case "$COMPILER" in
g++*)
    # GNU C++
    QMAKE_CONF_COMPILER=`grep "QMAKE_CXX[^_A-Z0-9a-z]" $QMAKESPEC/qmake.conf | sed "s,.* *= *\(.*\)$,\1,"`
    COMPILER_VERSION=`${QMAKE_CONF_COMPILER} --version 2>/dev/null`
    case "$COMPILER_VERSION" in
    *2.95.*)
	COMPILER_VERSION="2.95.*"
	;;
    *3.*)
	COMPILER_VERSION="3.*"
	;;
    *)
	;;
    esac
    [ '!' -z "$COMPILER_VERSION" ] && COMPILER="g++-${COMPILER_VERSION}"
    ;;
*)
    #
    ;;
esac

# QT_CONFIG can contain the following:
#
# Things that affect the Qt API/ABI:
#
#   Options:
#     minimal-config small-config medium-config large-config full-config
#
#   Modules:
#     styles tools kernel widgets dialogs iconview workspace inputmethod
#
#   Enterprise/Open Source edition modules:
#     network canvas table xml opengl sql
#
#   Options:
#     stl
#
#     X11     : inputmethod-ext
#
# Things that do not affect the Qt API/ABI:
#     system-jpeg no-jpeg jpeg
#     system-png no-png png
#     system-zlib no-zlib zlib
#     no-gif gif
#     debug release
#     dll staticlib
#
#     internal
#     nocrosscompiler
#     enterprise
#     GNUmake
#     largefile
#     nis
#     nas
#     tablet
#     ipv6
#
#     X11     : xftnameunparse x11sm xinerama xcursor xrandr xrender xftfreetype xkb inputmethod
#     Embedded: embedded ft
#
ALL_OPTIONS="stl"
BUILD_CONFIG=
BUILD_OPTIONS=

# determine the build options
for config_option in $QMAKE_CONFIG $QT_CONFIG; do
    SKIP="yes"
    case "$config_option" in
    *-config)
	# take the last *-config setting.  this is the highest config being used,
	# and is the one that we will use for tagging plugins
	BUILD_CONFIG="$config_option"
	;;

    stl)
	# these config options affect the Qt API/ABI. they should influence
	# the generation of the buildkey, so we don't skip them
   	SKIP="no"
	;;

    *) # skip all other options since they don't affect the Qt API/ABI.
	;;
    esac

    if [ "$SKIP" = "no" ]; then
	BUILD_OPTIONS="$BUILD_OPTIONS $config_option"
    fi
done

# put the options that we are missing into .options
rm -f .options
for opt in `echo $ALL_OPTIONS`; do
    SKIP="no"
    if echo $BUILD_OPTIONS | grep $opt >/dev/null 2>&1; then
	SKIP="yes"
    fi
    if [ "$SKIP" = "no" ]; then
	echo "$opt" >> .options
    fi
done

# reconstruct BUILD_OPTIONS with a sorted negative feature list
# (ie. only things that are missing are will be put into the build key)
BUILD_OPTIONS=
if [ -f .options ]; then
    for opt in `sort -f .options | uniq`; do
	BUILD_OPTIONS="$BUILD_OPTIONS no-$opt"
    done
fi
rm -f .options

# QT_NO* defines affect the Qt API (and binary compatibility).  they need
# to be included in the build key
for build_option in $D_FLAGS; do
    case "$build_option" in
    QT_NO*)
	echo "$build_option" >> .options
	;;
    *)
	# skip all other compiler defines
	;;
    esac
done

# sort the compile time defines (helps ensure that changes in this configure
# script don't affect the QT_BUILD_KEY generation)
if [ -f .options ]; then
    for opt in `sort -f .options | uniq`; do
	BUILD_OPTIONS="$BUILD_OPTIONS $opt"
    done
fi
rm -f .options

BUILD_OPTIONS="$BUILD_CONFIG $BUILD_OPTIONS"
QT_BUILD_KEY="$CFG_USER_BUILD_KEY $UNAME_MACHINE $UNAME_SYSTEM $COMPILER $BUILD_OPTIONS"
# strip out leading/trailing/extra whitespace
QT_BUILD_KEY=`echo $QT_BUILD_KEY | sed -e "s,  *, ,g" -e "s,^  *,," -e "s,  *$,,"`

#-------------------------------------------------------------------------------
# part of configuration information goes into qconfig.h
#-------------------------------------------------------------------------------

case "$CFG_QCONFIG" in
full)
    echo "/* Everything */" >$outpath/src/core/global/qconfig.h.new
    ;;
*)
    QCONFIGFILE=qconfig-$CFG_QCONFIG.h
    echo "/* Copied from $QCONFIGFILE */" >$outpath/src/core/global/qconfig.h.new
    cat $relpath/src/tools/$QCONFIGFILE >>$outpath/src/core/global/qconfig.h.new
    ;;
esac
cat >> $outpath/src/core/global/qconfig.h.new <<EOF

/* Generated functions */
extern const char *qInstallPath();
extern const char *qInstallPathDocs();
extern const char *qInstallPathHeaders();
extern const char *qInstallPathLibs();
extern const char *qInstallPathBins();
extern const char *qInstallPathPlugins();
extern const char *qInstallPathData();
extern const char *qInstallPathTranslations();
extern const char *qInstallPathSysconf();
extern const char *qInstallLicensee();
extern const char *qInstallLicensedProducts();

/* License information */
#define QT_PRODUCT_LICENSEE qInstallLicensee()
#define QT_PRODUCT_LICENSE  qInstallLicensedProducts()

/* Build key */
#define QT_BUILD_KEY "$QT_BUILD_KEY"

/* Machine byte-order */
#define Q_BIG_ENDIAN 4321
#define Q_LITTLE_ENDIAN 1234
#define Q_BYTE_ORDER $CFG_ENDIAN

/* Compile time features */
EOF
[ '!' -z "$LicenseKey" ] && echo "#define QT_PRODUCT_LICENSEKEY \"$LicenseKey\"" >>$outpath/src/core/global/qconfig.h.new

if [ "$CFG_LARGEFILE" = "yes" ]; then
    echo "#define QT_LARGEFILE_SUPPORT 64" >>$outpath/src/core/global/qconfig.h.new
fi

$unixtests/ptrsize.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath
echo "#define QT_POINTER_SIZE $?" >>$outpath/src/core/global/qconfig.h.new
echo "" >>$outpath/src/core/global/qconfig.h.new

## find excluded styles and add this to $QCONFIG_FLAGS
VSTYLE=no
VNO=no
for QMVAR in $QMAKE_VARS; do
    STRIPPED=`echo $QMVAR | sed 's,^",,' | sed 's,"$,,'`
    if [ "$VSTYLE" = "yes" ]; then
        if [ "$VNO" = "yes" ]; then
            NOSTYLE=`echo $STRIPPED | tr '[:lower:]' '[:upper:]'`
            QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_STYLE_$NOSTYLE"
            VSTYLE=no
            VNO=no
        else
            if [ "$STRIPPED" = "-=" ]; then
                VNO=yes
            else
                VSTYLE=no
            fi
        fi
    else
        if [ "$STRIPPED" = "styles" ]; then
            VSTYLE=yes
        fi
    fi
done

# Embedded compile time options
if [ "$PLATFORM_QWS" = "yes" ]; then
    # Add QWS to config.h
    QCONFIG_FLAGS="$QCONFIG_FLAGS Q_WS_QWS"

    # Add excluded decorations to $QCONFIG_FLAGS
    VDECORATION=no
    VNO=no
    for QMVAR in $QMAKE_VARS; do
        STRIPPED=`echo $QMVAR | sed 's,^",,' | sed 's,"$,,'`
        if [ "$VDECORATION" = "yes" ]; then
            if [ "$VNO" = "yes" ]; then
                NODECORATION=`echo $STRIPPED | tr '[:lower:]' '[:upper:]'`
                QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_DECORATION_$NODECORATION"
                VDECORATION=no
                VNO=no
            else
                if [ "$STRIPPED" = "-=" ]; then
                    VNO=yes
                else
                    VDECORATION=no
                fi
            fi
        else
            if [ "$STRIPPED" = "decorations" ]; then
                VDECORATION=yes
            fi
        fi
    done

    # Figure which embedded drivers which are turned off
    CFG_GFX_OFF="$CFG_GFX_AVAILABLE"
    for ADRIVER in $CFG_GFX_ON; do
        CFG_GFX_OFF=`echo "${CFG_GFX_OFF} " | sed "s,${ADRIVER} ,,g"`
    done

    CFG_KBD_OFF="$CFG_KBD_AVAILABLE"
    for ADRIVER in $CFG_KBD_ON; do
        CFG_KBD_OFF=`echo "${CFG_KBD_OFF} " | sed "s,${ADRIVER} ,,g"`
    done

    CFG_MOUSE_OFF="$CFG_MOUSE_AVAILABLE"
    for ADRIVER in $CFG_MOUSE_ON; do
        CFG_MOUSE_OFF=`echo "${CFG_MOUSE_OFF} " | sed "s,${ADRIVER} ,,g"`
    done

    for DRIVER in $CFG_GFX_OFF; do
        NODRIVER=`echo $DRIVER | tr '[:lower:]' '[:upper:]'`
        QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_$NODRIVER"
    done

    for DRIVER in $CFG_KBD_OFF; do
        NODRIVER=`echo $DRIVER | tr '[:lower:]' '[:upper:]'`
        QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_KBD_$NODRIVER"
    done

    for DRIVER in $CFG_MOUSE_OFF; do
        NODRIVER=`echo $DRIVER | tr '[:lower:]' '[:upper:]'`
        QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_QWS_MOUSE_$NODRIVER"
    done
fi # QWS

# Add turned on SQL drivers
for DRIVER in $CFG_SQL_ON; do
    ONDRIVER=`echo $DRIVER | tr '[:lower:]' '[:upper:]'`
    QCONFIG_FLAGS="$QCONFIG_FLAGS QT_SQL_$ONDRIVER"
done

# Add other configuration options to the qconfig.h file
[ "$CFG_GIF" = "yes" ]       && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_BUILTIN_GIF_READER=1"
[ "$CFG_PNG" != "yes" ]      && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_IMAGEIO_PNG"
[ "$CFG_JPEG" != "yes" ]     && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_IMAGEIO_JPEG"
[ "$CFG_ZLIB" != "yes" ]     && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_ZLIB"

[ "$CFG_EXCEPTION_SUPPORT" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_EXCEPTIONS"
[ "$CFG_TABLET" = "no" ]    && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_TABLET_SUPPORT"
[ "$CFG_IPV6" = "no" ]       && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_IPV6"

# X11/Unix/Mac only configs
[ "$CFG_CUPS" = "no" ]       && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_CUPS"
[ "$CFG_GETADDRINFO" = "no" ]&& QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_GETADDRINFO"
[ "$CFG_NAS" = "yes" ]       && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NAS_SUPPORT"
[ "$CFG_NIS" = "no" ]        && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_NIS"
[ "$CFG_SM" = "no" ]         && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_SM_SUPPORT"
[ "$CFG_XCURSOR" = "no" ]    && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XCURSOR"
[ "$CFG_XFT" = "no" ]        && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XFT"
[ "$CFG_XINERAMA" = "no" ]   && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XINERAMA"
[ "$CFG_XKB" = "no" ]        && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XKB"
[ "$CFG_XRANDR" = "no" ]     && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XRANDR"
[ "$CFG_XRENDER" = "no" ]    && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XRENDER"
[ "$CFG_XSHAPE" = "no" ]     && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_SHAPE"

# sort QCONFIG_FLAGS for neatness if we can
[ '!' -z "$AWK" ] && QCONFIG_FLAGS=`echo $QCONFIG_FLAGS | $AWK '{ gsub(" ", "\n"); print }' | sort`
QCONFIG_FLAGS=`echo $QCONFIG_FLAGS`

if [ -n "$QCONFIG_FLAGS" ]; then
    for cfg in $QCONFIG_FLAGS; do
        cfgd=`echo $cfg | sed 's/=.*$//'` # trim pushed 'Foo=Bar' defines
        cfg=`echo $cfg | sed 's/=/ /'`    # turn first '=' into a space
        # figure out define logic, so we can output the correct
        # ifdefs to override the global defines in a project
        cfgdNeg=
        if [ true ] && echo "$cfgd" | grep 'QT_NO_' >/dev/null 2>&1; then
            # QT_NO_option can be forcefully turned on by QT_option
            cfgdNeg=`echo $cfgd | sed "s,QT_NO_,QT_,"`
        elif [ true ] && echo "$cfgd" | grep 'QT_' >/dev/null 2>&1; then
            # QT_option can be forcefully turned off by QT_NO_option
            cfgdNeg=`echo $cfgd | sed "s,QT_,QT_NO_,"`
        fi

        if [ -z $cfgdNeg ]; then
cat >>$outpath/src/core/global/qconfig.h.new << EOF
#ifndef $cfgd
# define $cfg
#endif

EOF
        else
cat >>$outpath/src/core/global/qconfig.h.new << EOF
#if defined($cfgd) && defined($cfgdNeg)
# undef $cfgd
#elif !defined($cfgd) && !defined($cfgdNeg)
# define $cfg
#endif

EOF
        fi
    done
fi

# avoid unecessary rebuilds by copying only if qconfig.h has changed
if cmp -s "$outpath/src/core/global/qconfig.h" "$outpath/src/core/global/qconfig.h.new"; then
    rm -f "$outpath/src/core/global/qconfig.h.new"
else
    [ -f "$outpath/src/core/global/qconfig.h" ] && chmod +w "$outpath/src/core/global/qconfig.h"
    mv "$outpath/src/core/global/qconfig.h.new" "$outpath/src/core/global/qconfig.h"
    chmod -w "$outpath/src/core/global/qconfig.h"
    for conf in "$outpath/include/QtCore/qconfig.h" "$outpath/include/Qt/qconfig.h"; do
        if [ '!' -f "$conf" ]; then
	    ln -s "$outpath/src/core/global/qconfig.h" "$conf"
        fi
    done
fi

#-------------------------------------------------------------------------------
# save configuration into .qt.config
#-------------------------------------------------------------------------------

[ -f "$outpath/mkspecs/.qt.config" ] && rm -f "$outpath/mkspecs/.qt.config"
QTCONFIG=$outpath/mkspecs/.qt.config
[ -f $QTCONFIG.tmp ] && rm -f $QTCONFIG.tmp
QTCONFIG_CONFIG=
if [ "$CFG_DEBUG" = "yes" ]; then
    QTCONFIG_CONFIG="$QTCONFIG_CONFIG debug"
elif [ "$CFG_DEBUG" = "no" ]; then
    QTCONFIG_CONFIG="$QTCONFIG_CONFIG release"
fi
if [ "$CFG_STL" = "yes" ]; then
    QTCONFIG_CONFIG="$QTCONFIG_CONFIG stl"
fi
cat >>$QTCONFIG.tmp <<EOF
CONFIG += $QTCONFIG_CONFIG qt_no_framework
QT_PRODUCT = $Products
QT_CONFIG += $QT_CONFIG
EOF
# replace .qt.config if it differs from the newly created temp file
if cmp -s $QTCONFIG.tmp $QTCONFIG; then
    rm -f $QTCONFIG.tmp
else
    mv -f $QTCONFIG.tmp $QTCONFIG
fi

#-------------------------------------------------------------------------------
# save configuration into .qmake.cache
#-------------------------------------------------------------------------------

CACHEFILE=$outpath/.qmake.cache
[ -f $CACHEFILE.tmp ] && rm -f $CACHEFILE.tmp
cat >>$CACHEFILE.tmp <<EOF
CONFIG += $QMAKE_CONFIG dylib create_prl link_prl depend_includepath QTDIR_build
QT_SOURCE_TREE = $relpath
QT_BUILD_TREE = $outpath
QMAKE_ABSOLUTE_SOURCE_ROOT = \$\$QT_SOURCE_TREE
ARCH = $ARCH
EOF

#dump the qmake spec
if [ -d "$outpath/mkspecs/$XPLATFORM" ]; then
   echo "QMAKESPEC = \$\$QT_BUILD_TREE/mkspecs/$XPLATFORM" >>$CACHEFILE.tmp 
else
   echo "QMAKESPEC = $XPLATFORM" >>$CACHEFILE.tmp 
fi

# cmdline args
quoted=no
tmp=""
for i in $QMAKE_VARS; do
    if [ "$quoted" = "no" ]; then
	case "$i" in
	\"*\") echo $i | sed 's,^",,' | sed 's,"$,,' >>$CACHEFILE.tmp ;;
	\"*) quoted=yes ; tmp=$i ;;
	*) echo $i >>$CACHEFILE.tmp ;;
	esac
    else
	case "$i" in
	*\") quoted=no
	   echo $tmp $i | sed 's,^",,' | sed 's,"$,,' >>$CACHEFILE.tmp
	   tmp="" ;;
	*) tmp="$tmp $i" >>$CACHEFILE.tmp ;;
    esac
    fi
done
# incrementals
INCREMENTAL=""
[ "$CFG_INCREMENTAL" = "auto" ] && $WHICH p4 >/dev/null 2>&1 && [ "$Edition" = "troll" ] && CFG_INCREMENTAL="yes"
if [ "$CFG_INCREMENTAL" = "yes" ]; then
    openfiles=`find $relpath -perm u+w -mtime -3 | grep 'cpp$'`
    for f in $openfiles; do
	# don't need to worry about generated files
	[ -r `echo $f | sed "s,cpp$,ui,"` ] && continue
	basename $f | grep '^moc_' >/dev/null 2>&1 && continue
	# done
	INCREMENTAL="$INCREMENTAL `basename $f | sed 's,.cpp,.o,'`"
    done
    [ '!' -z "$INCREMENTAL" ] && echo "QMAKE_INCREMENTAL += $INCREMENTAL" >>$CACHEFILE.tmp
    [ -r "$outpath/.qmake.incremental" ] && echo "include($outpath/.qmake.incremental)" >>$CACHEFILE.tmp
fi

# replace .qmake.cache if it differs from the newly created temp file
if cmp -s $CACHEFILE.tmp $CACHEFILE; then
    rm -f $CACHEFILE.tmp
else
    mv -f $CACHEFILE.tmp $CACHEFILE
fi


#-------------------------------------------------------------------------------
# give feedback on configuration
#-------------------------------------------------------------------------------

case "$COMPILER" in
g++*)
    if [ "$CFG_EXCEPTION_SUPPORT" != "no" ]; then
	cat <<EOF

	This target is using the GNU C++ compiler ($PLATFORM).

	Recent versions of this compiler automatically include code for
	exceptions, which increase both the size of the Qt library and the
	amount of memory taken by your applications.

	You may choose to re-run `basename $0` with the -no-exceptions
	option to compile Qt without exceptions. This is completely binary
	compatible, and existing applications should continue to work.

EOF
    fi
    ;;
cc*)
    case "$PLATFORM" in
    irix-cc*)
	if [ "$CFG_EXCEPTION_SUPPORT" != "no" ]; then
	    cat <<EOF

	This target is using the MIPSpro C++ compiler ($PLATFORM).

	You may choose to re-run `basename $0` with the -no-exceptions
	option to compile Qt without exceptions. This will make the
	size of the Qt library smaller and reduce the amount of memory
	taken by your applications.

EOF
	fi
	;;
    *) ;;
    esac
    ;;
*) ;;
esac

echo
if [ "$XPLATFORM" = "$PLATFORM" ]; then
    echo "Build type:    $PLATFORM"
else
    echo "Building on:   $PLATFORM"
    echo "Building for:  $XPLATFORM"
fi
echo "Architecture:  $ARCH"

if [ -n "$PLATFORM_NOTES" ]; then
    echo "Platform notes:"
    echo "$PLATFORM_NOTES"
else
    echo
fi

if [ "$OPT_VERBOSE" = "yes" ]; then
    echo "qmake vars ...... $QMAKE_VARS"
    echo "qmake switches .. $QMAKE_SWITCHES"
fi

[ "$CFG_INCREMENTAL" = "yes" ] && [ '!' -z "$INCREMENTAL" ] && echo "Incremental ......... $INCREMENTAL"
echo "Configuration ....... $QMAKE_CONFIG $QT_CONFIG"
echo "Debug................ $CFG_DEBUG"
echo "Qt-3 compatibility... $CFG_COMPAT"
echo "STL support ......... $CFG_STL"
echo "PCH support ......... $CFG_PRECOMPILE"
echo "IPv6 support ........ $CFG_IPV6"
echo "getaddrinfo support . $CFG_GETADDRINFO"
echo "Accessibility ....... $CFG_ACCESSIBILITY"
echo "NIS support ......... $CFG_NIS"
echo "CUPS support ........ $CFG_CUPS"
echo "Large File support .. $CFG_LARGEFILE"
echo "GIF support ......... $CFG_GIF"
if [ "$CFG_JPEG" = "no" ]; then
    echo "JPEG support ........ $CFG_JPEG"
else
    echo "JPEG support ........ $CFG_JPEG ($CFG_LIBJPEG)"
fi
if [ "$CFG_PNG" = "no" ]; then
    echo "PNG support ......... $CFG_PNG"
else
    echo "PNG support ......... $CFG_PNG ($CFG_LIBPNG)"
fi
echo "zlib support ........ $CFG_ZLIB"
if [ "$PLATFORM_QWS" = "yes" ]; then
    echo "Embedded support .... $CFG_EMBEDDED"
    # Normalize the decoration output first
    CFG_DECORATION_ON=`echo ${CFG_DECORATION_ON}`
    CFG_DECORATION_PLUGIN=`echo ${CFG_DECORATION_PLUGIN}`
    echo "Decorations (qt) .... $CFG_DECORATION_ON"
    echo "Decorations (plugin)  $CFG_DECORATION_PLUGIN"
else
    echo "OpenGL support ...... $CFG_OPENGL"
fi
if [ "$PLATFORM_X11" = "yes" ]; then
    echo "NAS sound support ... $CFG_NAS"
    echo "Session management .. $CFG_SM"
    echo "XShape support ...... $CFG_XSHAPE"
    echo "Xinerama support .... $CFG_XINERAMA"
    echo "Xcursor support ..... $CFG_XCURSOR"
    echo "XRandR support ...... $CFG_XRANDR"
    echo "XRender support ..... $CFG_XRENDER"
    echo "Xft support ......... $CFG_XFT"
    echo "XKB Support ......... $CFG_XKB"
    echo "immodule support .... $CFG_IM"
    echo "immodule ext support  $CFG_IM_EXT"
fi

# complain about not being able to use plugins if we are using a static build
if [ "$CFG_SHARED" = "no" ]; then
    echo
    echo "WARNING: Using static linking will disable the use of plugins."
    echo "Make sure you compile ALL needed modules into the library."
    echo
fi
echo

sepath=`echo $relpath | sed -e 's/\\./\\\\./g'`
PROCS=1
EXEC=""


#-------------------------------------------------------------------------------
# build makefiles based on the configuration
#-------------------------------------------------------------------------------

echo "Finding project files. Please wait..."
if [ -z "$QMAKE_PROJECTS" ]; then
    QMAKE_PROJECTS=`find $relpath/. -name '*.pro' -print | sed 's-/\./-/-'`
else
    QT_PROJECTS=
    for a in `echo $QMAKE_PROJECTS`; do
	put_in="$a"
	for leave_out in `echo $QMAKE_IGNORE_PROJECTS`; do
	    if [ "$put_in" = "$leave_out" ]; then
		put_in=
		break;
	    fi
	done
	[ '!' -z "$put_in" ] && QT_PROJECTS="$QT_PROJECTS $put_in"
    done
fi
if [ -f "${relpath}/projects.pro" ]; then
    mkfile="${outpath}/Makefile"
    [ -f "$mkfile" ] && chmod +w "$mkfile"
    QTDIR="$outpath" $outpath/bin/qmake -spec "$XQMAKESPEC" "QT_PROJECTS=$QT_PROJECTS" ${relpath}/projects.pro -o $mkfile
fi

# .projects      -> projects to process
# .projects.1    -> qt and moc
# .projects.2    -> subdirs and libs
# .projects.3    -> the rest
rm -f .projects .projects.1 .projects.2 .projects.3

if [ -z "$AWK" ]; then
    for p in `echo $QMAKE_PROJECTS`; do
	echo $p >> .projects
    done
else
    cat >projects.awk <<EOF
BEGIN {
    files = 0
    target_file = ""
    input_file = ""

    first = "./.projects.1.tmp"
    second = "./.projects.2.tmp"
    third = "./.projects.3.tmp"
}

FNR == 1 {
    if ( input_file ) {
  if ( ! target_file )
      target_file = third
  print input_file >target_file
    }

    matched_target = 0
    template_lib = 0
    input_file = FILENAME
    target_file = ""
}

/^(TARGET.*=)/ {
    if ( \$3 == "moc" || \$3 ~ /^Qt/ ) {
  target_file = first
	matched_target = 1
    }
}

matched_target == 0 && /^(TEMPLATE.*=)/ {
    if ( \$3 == "subdirs" )
  target_file = second
    else if ( \$3 == "lib" )
  template_lib = 1
    else
  target_file = third
}

matched_target == 0 && template_lib == 1 && /^(CONFIG.*=)/ {
    if ( \$0 ~ /plugin/ )
	target_file = third
    else
  target_file = second
}

END {
    if ( input_file ) {
  if ( ! target_file )
      target_file = third
  print input_file >>target_file
    }
}

EOF

    rm -f .projects.all
    for p in `echo $QMAKE_PROJECTS`; do
       echo $p >> .projects.all
    done

    # if you get errors about the length of the command line to awk, change the -l arg
    # to split below
    split -l 100 .projects.all .projects.all.
    for p in .projects.all.*; do
       $AWK -f projects.awk `cat $p`
       [ -f .projects.1.tmp ] && cat .projects.1.tmp >> .projects.1
       [ -f .projects.2.tmp ] && cat .projects.2.tmp >> .projects.2
       [ -f .projects.3.tmp ] && cat .projects.3.tmp >> .projects.3
       rm -f .projects.1.tmp .projects.2.tmp .projects.3.tmp $p
    done
    rm -f .projects.all* projects.awk

    [ -f .projects.1 ] && cat .projects.1 >>.projects
    [ -f .projects.2 ] && cat .projects.2 >>.projects
    rm -f .projects.1 .projects.2
    if [ -f .projects.3 ] && [ "$OPT_FAST" = "no" ]; then
       cat .projects.3 >>.projects
       rm -f .projects.3
    fi
fi
# don't sort Qt and MOC in with the other project files
# also work around a segfaulting uniq(1)
if [ -f .sorted.projects.2 ]; then
    sort .sorted.projects.2 > .sorted.projects.2.new
    mv -f .sorted.projects.2.new .sorted.projects.2
    cat .sorted.projects.2 >> .sorted.projects.1
fi
[ -f .sorted.projects.1 ] && sort .sorted.projects.1 >> .sorted.projects
rm -f .sorted.projects.2 .sorted.projects.1
for p in `echo $QMAKE_IGNORE_PROJECTS`; do
    if [ -f .projects ]; then
	grep -v $p .projects > .tmp
	mv -f .tmp .projects
    fi
    if [ -f .projects.3 ]; then
	grep -v $p .projects.3 > .tmp
	mv -f .tmp .projects.3
    fi
done

NORM_PROJECTS=0
FAST_PROJECTS=0
if [ -f .projects ]; then
   uniq .projects >.tmp
   mv -f .tmp .projects
   NORM_PROJECTS=`cat .projects | wc -l | sed -e "s, ,,g"`
fi
if [ -f .projects.3 ]; then
   uniq .projects.3 >.tmp
   mv -f .tmp .projects.3
   FAST_PROJECTS=`cat .projects.3 | wc -l | sed -e "s, ,,g"`
fi
echo "  `expr $NORM_PROJECTS + $FAST_PROJECTS` projects found."
echo

echo "Creating makefiles. Please wait..."
for file in .projects .projects.3; do
    [ '!' -f "$file" ] && continue
    for a in `cat $file`; do
	case $a in
	*-kde.pro|*winmain/winmain.pro) continue ;;
	*/qmake/qmake.pro) continue ;;
	*-pro.pro)
	    [ "x$Edition" != "xpro" ] && continue
	;;
	*moc*) SPEC=$QMAKESPEC ;;
	*) SPEC=$XQMAKESPEC ;;
	esac
	dir=`dirname $a | sed -e "s;$sepath;.;g"`
	test -d $dir || mkdir -p $dir
	OUTDIR=$outpath/$dir
	if [ -f "${OUTDIR}/Makefile" ] && [ "$OPT_FAST" = "yes" ]; then
	    # fast configure - the makefile exists, skip it
	    # since the makefile exists, it was generated by qmake, which means we
	    # can skip it, since qmake has a rule to regenerate the makefile if the .pro
	    # file changes...
	    [ "$OPT_VERBOSE" = "yes" ] && echo "  skipping $a"
	    continue;
	fi
	QMAKE_SPEC_ARGS="-spec $SPEC"
	if echo '\c' | grep '\c' >/dev/null; then
	    echo -n "  for $a"
	else
	    echo "  for $a\c"
	fi

	QMAKE_EXEC="$outpath/bin/qmake $QMAKE_SWITCHES $QMAKE_SPEC_ARGS -o $OUTDIR $a"
	if [ "$file" = ".projects.3" ]; then
	    if echo '\c' | grep '\c' >/dev/null; then
		echo -n " (fast)"
	    else
		echo " (fast)\c"
	    fi
	    echo
	    cat >${OUTDIR}/Makefile <<EOF
# ${OUTDIR}/Makefile: generated by configure
#
# WARNING: This makefile will be replaced with a real makefile.
# All changes made to this file will be lost.

all clean install qmake first Makefile: FORCE
	$QMAKE_EXEC
	cd $OUTDIR
	\$(MAKE) \$@

FORCE:

EOF
	else
	    if [ "$OPT_VERBOSE" = "yes" ]; then
		echo " (`basename $SPEC`)"
		if echo '\c' | grep '\c' >/dev/null; then
		    echo -n "$QMAKE_EXEC"
		else
		    echo "$QMAKE_EXEC\c"
		fi
	    fi
	    echo

	    [ -f "${OUTDIR}/Makefile" ] && chmod +w ${OUTDIR}/Makefile
	    QTDIR="$outpath" $QMAKE_EXEC
       fi
    done
done
rm -f .projects .projects.3

#-------------------------------------------------------------------------------
# check for platforms that we don't yet know about
#-------------------------------------------------------------------------------
if [ "$ARCH" = "generic" ]; then
cat <<EOF

	NOTICE: Atomic operations are not yet supported for this
	architecture.

	Qt will use the 'generic' architecture instead, which will use
	non-atomic operations instead.  Applications that rely on atomic
	operation support will NOT work with this library!
EOF
fi

#-------------------------------------------------------------------------------
# finally save the executed command to another script
#-------------------------------------------------------------------------------
if [ `basename $0` != "config.status" ]; then
    CONFIG_STATUS="$relpath/$relconf $OPT_CMDLINE"
    echo "$CONFIG_STATUS" | grep '\-confirm\-license' >/dev/null 2>&1 || CONFIG_STATUS="$CONFIG_STATUS -confirm-license"

    [ -f $outpath/config.status ] && rm -f $outpath/config.status
    echo "#!/bin/sh" >$outpath/config.status
    echo "if [ \"\$#\" -gt 0 ]; then" >>$outpath/config.status
    echo "  $CONFIG_STATUS \"\$@\"" >>$outpath/config.status
    echo "else" >>$outpath/config.status
    echo "  $CONFIG_STATUS" >>$outpath/config.status
    echo "fi" >>$outpath/config.status
    chmod +x $outpath/config.status
fi

echo
echo Qt is now configured for building. Just run $MAKE.
echo To reconfigure, run $MAKE confclean and configure.
echo
