Index: trunk/configure.cmd
===================================================================
--- trunk/configure.cmd	(revision 10)
+++ trunk/configure.cmd	(revision 11)
@@ -19,6 +19,7 @@
 
 
-/* globals
- ******************************************************************************/
+/*------------------------------------------------------------------------------
+ globals
+------------------------------------------------------------------------------*/
 
 G.TAB           = '09'x
@@ -29,5 +30,14 @@
 
 
+/* initialize global variables */
+G.QMAKE_SWITCHES    = ""
+G.QMAKE_VARS        = ""
+G.QMAKE_CONFIG      = ""
+G.QTCONFIG_CONFIG   = ""
+G.QT_CONFIG         = ""
+G.SUPPORTED         = ""
 G.QMAKE_VARS_FILE   = ".qmake.vars"
+
+G.CFG_DEV           = "no"
 
 /* Qt for OS/2 is always the open source edition */
@@ -40,11 +50,14 @@
 G.PLATFORM      = "os2-g++"
 
+
 /* all globals to be exposed in procedures */
 Globals = 'G. Opt. Static.'
 
 
-/* init rexx lib
- ******************************************************************************/
-
+/*------------------------------------------------------------------------------
+ startup + main + termination
+------------------------------------------------------------------------------*/
+
+/* init system REXX library */
 if (RxFuncQuery('SysLoadFuncs')) then do
     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
@@ -52,13 +65,14 @@
 end
 
-
-/* startup + main + termination
- ******************************************************************************/
-
-parse value SysTextScreenSize() with G.!ScreenHeight G.!ScreenWidth
-if (G.!ScreenHeight < 25 | G.!ScreenWidth < 80) then do
+/* detect script file and directory */
+parse source . . G.ScriptFile
+G.ScriptDir = FixDir(filespec('D', G.ScriptFile) || filespec('P', G.ScriptFile))
+
+/* check text screen resolution */
+parse value SysTextScreenSize() with G.ScreenHeight G.ScreenWidth
+if (G.ScreenHeight < 25 | G.ScreenWidth < 80) then do
     address 'cmd' 'mode co80,25'
-    parse value SysTextScreenSize() with G.!ScreenHeight G.!ScreenWidth
-    if (G.!ScreenHeight < 25 | G.!ScreenWidth < 80) then do
+    parse value SysTextScreenSize() with G.ScreenHeight G.ScreenWidth
+    if (G.ScreenHeight < 25 | G.ScreenWidth < 80) then do
         call SayErr 'WARNING: Cannot set screen size to 80 x 25!'
         call SayErr 'Some messages can be unreadable.'
@@ -76,6 +90,7 @@
 
 
-/* functions
- ******************************************************************************/
+/*------------------------------------------------------------------------------
+ functions
+------------------------------------------------------------------------------*/
 
 /**
@@ -83,4 +98,7 @@
  */
 Main: procedure expose (Globals)
+
+    /* the directory of this script is the "source tree */
+    G.RelPath = G.ScriptDir
 
     /* reset the vars file */
@@ -95,4 +113,302 @@
     QMakeVar add mouse-drivers "pc linuxtp"
 */
+
+    /* QTDIR may be set and point to an old or system-wide Qt installation */
+    call UnsetEnv "QTDIR"
+
+    /* initalize internal variables */
+    G.CFG_CONFIGURE_EXIT_ON_ERROR = "yes"
+    G.CFG_PROFILE = "no"
+    G.CFG_EXCEPTIONS = "unspecified"
+    G.CFG_SCRIPTTOOLS = "auto" /* (yes|no|auto) */
+    G.CFG_XMLPATTERNS = "auto" /* (yes|no|auto) */
+    G.CFG_INCREMENTAL = "auto"
+    G.CFG_QCONFIG = "full"
+    G.CFG_DEBUG = "auto"
+    G.CFG_MYSQL_CONFIG = ""
+    G.CFG_DEBUG_RELEASE = "no"
+    G.CFG_SHARED = "yes"
+    G.CFG_SM = "auto"
+/* @todo
+    G.CFG_XSHAPE = "auto"
+    G.CFG_XINERAMA = "runtime"
+    G.CFG_XFIXES = "runtime"
+*/
+    G.CFG_ZLIB = "auto"
+    G.CFG_SQLITE = "qt"
+    G.CFG_GIF = "auto"
+    G.CFG_TIFF = "auto"
+    G.CFG_LIBTIFF = "auto"
+    G.CFG_PNG = "yes"
+    G.CFG_LIBPNG = "auto"
+    G.CFG_JPEG = "auto"
+    G.CFG_LIBJPEG = "auto"
+    G.CFG_MNG = "auto"
+    G.CFG_LIBMNG = "auto"
+/* @todo
+    G.CFG_XCURSOR = "runtime"
+    G.CFG_XRANDR = "runtime"
+    G.CFG_XRENDER = "auto"
+    G.CFG_MITSHM = "auto"
+*/
+    G.CFG_OPENGL = "auto"
+    G.CFG_SSE = "auto"
+    G.CFG_FONTCONFIG = "auto"
+    G.CFG_QWS_FREETYPE = "auto"
+    G.CFG_LIBFREETYPE = "auto"
+    G.CFG_SQL_AVAILABLE = ""
+    G.QT_DEFAULT_BUILD_PARTS = "libs tools examples demos docs translations"
+    G.CFG_BUILD_PARTS = ""
+    G.CFG_NOBUILD_PARTS = ""
+    G.CFG_RELEASE_QMAKE = "no"
+    G.CFG_PHONON = "auto"
+    G.CFG_PHONON_BACKEND = "yes"
+    G.CFG_SVG = "yes"
+    G.CFG_WEBKIT = "auto" /* (yes|no|auto) */
+
+/* @todo
+    CFG_GFX_AVAILABLE="linuxfb transformed qvfb vnc multiscreen"
+    CFG_GFX_ON="linuxfb multiscreen"
+    CFG_GFX_PLUGIN_AVAILABLE=
+    CFG_GFX_PLUGIN=
+    CFG_GFX_OFF=
+    CFG_KBD_AVAILABLE="tty usb sl5000 yopy vr41xx qvfb"
+    CFG_KBD_ON="tty"    #default, see QMakeVar above
+    CFG_MOUSE_AVAILABLE="pc bus linuxtp yopy vr41xx tslib qvfb"
+    CFG_MOUSE_ON="pc linuxtp"   #default, see QMakeVar above
+*/
+
+    G.CFG_ARCH = ""
+    G.CFG_HOST_ARCH = ""
+    G.CFG_KBD_PLUGIN_AVAILABLE = ""
+    G.CFG_KBD_PLUGIN = ""
+    G.CFG_KBD_OFF = ""
+    G.CFG_MOUSE_PLUGIN_AVAILABLE = ""
+    G.CFG_MOUSE_PLUGIN = ""
+    G.CFG_MOUSE_OFF = ""
+    G.CFG_USE_GNUMAKE = "no"
+    G.CFG_IM = "yes"
+    CFG_DECORATION_AVAILABLE = "styled windows default"
+    CFG_DECORATION_ON = "${CFG_DECORATION_AVAILABLE}" /* all on by default */
+    G.CFG_DECORATION_PLUGIN_AVAILABLE = ""
+    G.CFG_DECORATION_PLUGIN = ""
+    G.CFG_XINPUT = "runtime"
+    G.CFG_XKB = "auto"
+    G.CFG_NIS = "auto"
+    G.CFG_CUPS = "auto"
+    G.CFG_ICONV = "auto"
+    G.CFG_DBUS = "auto"
+    G.CFG_GLIB = "auto"
+    G.CFG_GSTREAMER = "auto"
+    G.CFG_QGTKSTYLE = "auto"
+    G.CFG_LARGEFILE = "auto"
+    G.CFG_OPENSSL = "auto"
+    G.CFG_PTMALLOC = "no"
+    G.CFG_STL = "auto"
+    G.CFG_PRECOMPILE = "auto"
+    G.CFG_SEPARATE_DEBUG_INFO = "auto"
+    G.CFG_REDUCE_EXPORTS = "auto"
+    G.CFG_MMX = "auto"
+    G.CFG_3DNOW = "auto"
+    G.CFG_SSE = "auto"
+    G.CFG_SSE2 = "auto"
+    G.CFG_REDUCE_RELOCATIONS = "no"
+    G.CFG_IPV6 = "auto"
+    G.CFG_NAS = "no"
+    G.CFG_QWS_DEPTHS = "all"
+    G.CFG_USER_BUILD_KEY = ""
+    G.CFG_ACCESSIBILITY = "auto"
+    G.CFG_QT3SUPPORT = "yes"
+    G.CFG_ENDIAN = "auto"
+    G.CFG_HOST_ENDIAN = "auto"
+    G.CFG_DOUBLEFORMAT = "auto"
+    G.CFG_ARMFPA = "auto"
+    G.CFG_IWMMXT = "no"
+    G.CFG_CLOCK_GETTIME = "auto"
+    G.CFG_CLOCK_MONOTONIC = "auto"
+    G.CFG_MREMAP = "auto"
+    G.CFG_GETADDRINFO = "auto"
+    G.CFG_IPV6IFNAME = "auto"
+    G.CFG_GETIFADDRS = "auto"
+    G.CFG_INOTIFY = "auto"
+    G.CFG_RPATH = "yes"
+    G.CFG_FRAMEWORK = "auto"
+    G.CFG_MAC_ARCHS = ""
+    G.CFG_MAC_DWARF2 = "auto"
+    G.CFG_MAC_XARCH = "auto"
+    G.CFG_MAC_CARBON = "yes"
+    G.CFG_MAC_COCOA = "auto"
+    G.COMMANDLINE_MAC_COCOA = "no"
+    G.CFG_SXE = "no"
+    G.CFG_PREFIX_INSTALL = "yes"
+    G.CFG_SDK = ""
+    G.D_FLAGS = ""
+    G.I_FLAGS = ""
+    G.L_FLAGS = ""
+    G.RPATH_FLAGS = ""
+    l_FLAGS = ""
+    G.QCONFIG_FLAGS = ""
+    G.XPLATFORM = "" /* This seems to be the QMAKESPEC, like "linux-g++" */
+    G.PLATFORM = GetEnv("QMAKESPEC")
+    G.QT_CROSS_COMPILE = "no"
+    G.OPT_CONFIRM_LICENSE = "no"
+    G.OPT_SHADOW = "maybe"
+    G.OPT_FAST = "auto"
+    G.OPT_VERBOSE = "no"
+    G.OPT_HELP = ""
+    G.CFG_SILENT = "no"
+    G.CFG_GRAPHICS_SYSTEM = "default"
+
+    /* initalize variables used for installation */
+    G.QT_INSTALL_PREFIX = ""
+    G.QT_INSTALL_DOCS = ""
+    G.QT_INSTALL_HEADERS = ""
+    G.QT_INSTALL_LIBS = ""
+    G.QT_INSTALL_BINS = ""
+    G.QT_INSTALL_PLUGINS = ""
+    G.QT_INSTALL_DATA = ""
+    G.QT_INSTALL_TRANSLATIONS = ""
+    G.QT_INSTALL_SETTINGS = ""
+    G.QT_INSTALL_EXAMPLES = ""
+    G.QT_INSTALL_DEMOS = ""
+    G.QT_HOST_PREFIX = ""
+
+    /* flags for SQL drivers */
+    G.QT_CFLAGS_PSQL = ""
+    G.QT_LFLAGS_PSQL = ""
+    G.QT_CFLAGS_MYSQL = ""
+    G.QT_LFLAGS_MYSQL = ""
+    G.QT_LFLAGS_MYSQL_R = ""
+    G.QT_CFLAGS_SQLITE = ""
+    G.QT_LFLAGS_SQLITE = ""
+
+    /* check SQL drivers, mouse drivers and decorations available in
+     * this package */
+
+    /* opensource version removes some drivers, so force them to be off */
+    G.CFG_SQL_tds = "no"
+    G.CFG_SQL_oci = "no"
+    G.CFG_SQL_db2 = "no"
+
+    G.CFG_SQL_AVAILABLE = ""
+    if (DirExists(G.RelPath"\src\plugins\sqldrivers")) then do
+        call SysFileTree G.RelPath"\src\plugins\sqldrivers\*", "found", "DO"
+        do i = 1 to found.0
+            base = filespec('N', found.i)
+            if (left(base, 1) == '.')  then iterate
+            G.CFG_SQL_AVAILABLE = Join(G.CFG_SQL_AVAILABLE, base)
+            call value "G.CFG_SQL_"base, "auto"
+        end
+    end
+
+    G.CFG_DECORATION_PLUGIN_AVAILABLE = ""
+    if (DirExists(G.RelPath"\src\plugins\decorations")) then do
+        call SysFileTree G.RelPath"\src\plugins\decorations\*", "found", "DO"
+        do i = 1 to found.0
+            base = filespec('N', found.i)
+            if (left(base, 1) == '.')  then iterate
+            G.CFG_DECORATION_PLUGIN_AVAILABLE = Join(G.CFG_DECORATION_PLUGIN_AVAILABLE, base)
+        end
+    end
+
+    G.CFG_KBD_PLUGIN_AVAILABLE = ""
+    if (DirExists(G.RelPath"\src\plugins\kbddrivers")) then do
+        call SysFileTree G.RelPath"\src\plugins\kbddrivers\*", "found", "DO"
+        do i = 1 to found.0
+            base = filespec('N', found.i)
+            if (left(base, 1) == '.')  then iterate
+            G.CFG_KBD_PLUGIN_AVAILABLE = Join(G.CFG_KBD_PLUGIN_AVAILABLE, base)
+        end
+    end
+
+    G.CFG_MOUSE_PLUGIN_AVAILABLE = ""
+    if (DirExists(G.RelPath"\src\plugins\mousedrivers")) then do
+        call SysFileTree G.RelPath"\src\plugins\mousedrivers\*", "found", "DO"
+        do i = 1 to found.0
+            base = filespec('N', found.i)
+            if (left(base, 1) == '.')  then iterate
+            G.CFG_MOUSE_PLUGIN_AVAILABLE = Join(G.CFG_MOUSE_PLUGIN_AVAILABLE, base)
+        end
+    end
+
+    G.CFG_GFX_PLUGIN_AVAILABLE = ""
+    if (DirExists(G.RelPath"\src\plugins\gfxdrivers")) then do
+        call SysFileTree G.RelPath"\src\plugins\gfxdrivers\*", "found", "DO"
+        do i = 1 to found.0
+            base = filespec('N', found.i)
+            if (left(base, 1) == '.')  then iterate
+            G.CFG_GFX_PLUGIN_AVAILABLE = Join(G.CFG_GFX_PLUGIN_AVAILABLE, base)
+        end
+        G.CFG_GFX_OFF = G.CFG_GFX_AVAILABLE /* assume all off */
+    end
+
+    /* parse command line arguments
+    --------------------------------------------------------------------------*/
+
+    /* @todo */
+
+    if (G.CFG_QCONFIG \== "full" & G.CFG_QT3SUPPORT == "yes") then do
+        call SaySay "Warning: '-qconfig "G.CFG_QCONFIG"' will disable the qt3support library."
+        G.CFG_QT3SUPPORT = "no"
+    end
+
+    /* update QT_CONFIG to show our current predefined configuration */
+    w = wordpos(G.CFG_QCONFIG, "minimal small medium large full")
+    if (w > 0) then do
+        /* these are a sequence of increasing functionality */
+        do i = 1 to w
+            G.QT_CONFIG = Join(G.QT_CONFIG, w"-config")
+        end
+    end
+    else do
+        /* not known to be sufficient for anything */
+        fn = G.RelPath"\src\corelib\global\qconfig-"G.CFG_QCONFIG".h"
+        if (\FileExists(fn)) then do
+            call SayErr "Error: configuration file not found:"
+            call SayErr "  "fn
+            G.OPT_HELP = "yes"
+        end
+    end
+
+    /* skip this if the user just needs help... */
+    if (G.OPT_HELP \== "yes") then do
+
+        /* detect build style */
+        if (G.CFG_DEBUG == "auto") then do
+            if (G.CFG_DEV == "yes") then do
+                G.CFG_DEBUG_RELEASE = "no"
+                G.CFG_DEBUG = "yes"
+            end
+            else do
+                G.CFG_DEBUG_RELEASE = "no"
+                G.CFG_DEBUG = "no"
+            end
+        end
+        if (G.CFG_DEBUG_RELEASE == "yes") then
+            G.QMAKE_CONFIG = Join(G.QMAKE_CONFIG, "build_all")
+
+        if (G.CFG_SILENT == "yes") then
+            G.QMAKE_CONFIG = Join(G.QMAKE_CONFIG, "silent")
+
+        if (G.OPT_FAST == "auto") then
+           if (G.CFG_DEV == "yes") then G.OPT_FAST = "yes"
+           else G.OPT_FAST = "no"
+
+        /* find a make command */
+        G.MAKE = GetEnv("MAKE")
+        if (G.MAKE == "") then do
+            G.MAKE = SysSearchPath('PATH', 'make.exe')
+            if (G.MAKE == "") then do
+                call SayErr "You don't seem to have 'make.exe' in your PATH."
+                call SayErr "Cannot proceed."
+                call Done 1
+            end
+        end
+
+    end
+
+    /* # auto-detect all that hasn't been specified in the arguments
+    --------------------------------------------------------------------------*/
+
     signal Nonsense
     return
@@ -113,5 +429,5 @@
         when aMode == "add" then eq = "+="
         when aMode == "del" then eq = "-="
-        otherwise signal Nonsence
+        otherwise signal Nonsense
     end
 
@@ -120,7 +436,7 @@
     return
 
-
-/* utility functions
- ******************************************************************************/
+/*------------------------------------------------------------------------------
+ utility functions
+------------------------------------------------------------------------------*/
 
 CompareFileToVar: procedure expose (Globals)
@@ -171,6 +487,6 @@
     parse arg str, noeol
     noeol = (noeol == 1)
-    if (noeol) then call charout, '    'str
-    else say '    'str
+    if (noeol) then call charout, str
+    else say str
     return
 
@@ -219,4 +535,25 @@
     call SysCurPos row, col
     return
+
+/**
+ * Joins the supplied argulents with one space character. Empty arguments are
+ * skipped.
+ *
+ * @param  ...          String arguments to join.
+ * @return              Resulting string.
+ */
+Join: procedure expose (Globals)
+
+    result = ""
+    do i = 1 to arg()
+        if (length(arg(i)) > 0) then do
+            if (length(result) > 0) then
+                result = result' 'arg(i)
+            else
+                result = arg(i)
+        end
+    end
+
+    return result
 
 /**
@@ -795,4 +1132,52 @@
 
 /**
+ * Gets the OS/2 environment variable.
+ *
+ * @param aName     Variable name.
+ * @return          Variable value.
+ */
+GetEnv: procedure expose (Globals)
+
+    parse arg aName
+
+    extLibPath = (translate(aName) == 'BEGINLIBPATH' | translate(aName) == 'ENDLIBPATH')
+    if (extLibPath) then val = SysQueryExtLibPath(left(aName, 1))
+    else val = value(aName,, 'OS2ENVIRONMENT')
+
+    return val
+
+/**
+ * Sets the OS/2 environment variable.
+ *
+ * @param aName     Variable name.
+ * @param aValue    Variable Value.
+ */
+SetEnv: procedure expose (Globals)
+
+    parse arg aName, aValue
+
+    extLibPath = (translate(aName) == 'BEGINLIBPATH' | translate(aName) == 'ENDLIBPATH')
+    if (extLibPath) then call SysSetExtLibPath aValue, left(aName, 1)
+    else call value aName, aValue, 'OS2ENVIRONMENT'
+
+    return
+
+/**
+ * Unsets the OS/2 environment variable.
+ *
+ * @param aName     Variable name.
+ * @param aValue    Variable Value.
+ */
+UnsetEnv: procedure expose (Globals)
+
+    parse arg aName
+
+    extLibPath = (translate(aName) == 'BEGINLIBPATH' | translate(aName) == 'ENDLIBPATH')
+    if (extLibPath) then call SysSetExtLibPath "", left(aName, 1)
+    else call value aName, "", 'OS2ENVIRONMENT'
+
+    return
+
+/**
  *  Adds the given path to the contents of the given variable
  *  containing a list of paths separated by semicolons.
