Rename the 'declarative debug support' to 'qml debug support'
[profile/ivi/qtbase.git] / tools / configure / configureapp.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "configureapp.h"
43 #include "environment.h"
44 #ifdef COMMERCIAL_VERSION
45 #  include "tools.h"
46 #endif
47
48 #include <QDate>
49 #include <qdir.h>
50 #include <qtemporaryfile.h>
51 #include <qstack.h>
52 #include <qdebug.h>
53 #include <qfileinfo.h>
54 #include <qtextstream.h>
55 #include <qregexp.h>
56 #include <qhash.h>
57
58 #include <iostream>
59 #include <windows.h>
60 #include <conio.h>
61
62 QT_BEGIN_NAMESPACE
63
64 std::ostream &operator<<(std::ostream &s, const QString &val) {
65     s << val.toLocal8Bit().data();
66     return s;
67 }
68
69
70 using namespace std;
71
72 // Macros to simplify options marking
73 #define MARK_OPTION(x,y) ( dictionary[ #x ] == #y ? "*" : " " )
74
75
76 bool writeToFile(const char* text, const QString &filename)
77 {
78     QByteArray symFile(text);
79     QFile file(filename);
80     QDir dir(QFileInfo(file).absoluteDir());
81     if (!dir.exists())
82         dir.mkpath(dir.absolutePath());
83     if (!file.open(QFile::WriteOnly)) {
84         cout << "Couldn't write to " << qPrintable(filename) << ": " << qPrintable(file.errorString())
85              << endl;
86         return false;
87     }
88     file.write(symFile);
89     return true;
90 }
91
92 Configure::Configure(int& argc, char** argv)
93 {
94     useUnixSeparators = false;
95     // Default values for indentation
96     optionIndent = 4;
97     descIndent   = 25;
98     outputWidth  = 0;
99     // Get console buffer output width
100     CONSOLE_SCREEN_BUFFER_INFO info;
101     HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
102     if (GetConsoleScreenBufferInfo(hStdout, &info))
103         outputWidth = info.dwSize.X - 1;
104     outputWidth = qMin(outputWidth, 79); // Anything wider gets unreadable
105     if (outputWidth < 35) // Insanely small, just use 79
106         outputWidth = 79;
107     int i;
108
109     /*
110     ** Set up the initial state, the default
111     */
112     dictionary[ "CONFIGCMD" ] = argv[ 0 ];
113
114     for (i = 1; i < argc; i++)
115         configCmdLine += argv[ i ];
116
117     if (configCmdLine.size() >= 2 && configCmdLine.at(0) == "-srcdir") {
118         sourcePath = QDir::cleanPath(configCmdLine.at(1));
119         sourceDir = QDir(sourcePath);
120         configCmdLine.erase(configCmdLine.begin(), configCmdLine.begin() + 2);
121     } else {
122         // Get the path to the executable
123         wchar_t module_name[MAX_PATH];
124         GetModuleFileName(0, module_name, sizeof(module_name) / sizeof(wchar_t));
125         QFileInfo sourcePathInfo = QString::fromWCharArray(module_name);
126         sourcePath = sourcePathInfo.absolutePath();
127         sourceDir = sourcePathInfo.dir();
128     }
129     buildPath = QDir::currentPath();
130 #if 0
131     const QString installPath = QString("C:\\Qt\\%1").arg(QT_VERSION_STR);
132 #else
133     const QString installPath = buildPath;
134 #endif
135     if (sourceDir != buildDir) { //shadow builds!
136         if (!findFile("perl") && !findFile("perl.exe")) {
137             cout << "Error: Creating a shadow build of Qt requires" << endl
138                  << "perl to be in the PATH environment";
139             exit(0); // Exit cleanly for Ctrl+C
140         }
141
142         cout << "Preparing build tree..." << endl;
143         QDir(buildPath).mkpath("bin");
144
145         { //make a syncqt script(s) that can be used in the shadow
146             QFile syncqt(buildPath + "/bin/syncqt");
147             if (syncqt.open(QFile::WriteOnly)) {
148                 QTextStream stream(&syncqt);
149                 stream << "#!/usr/bin/perl -w" << endl
150                        << "require \"" << sourcePath + "/bin/syncqt\";" << endl;
151             }
152             QFile syncqt_bat(buildPath + "/bin/syncqt.bat");
153             if (syncqt_bat.open(QFile::WriteOnly)) {
154                 QTextStream stream(&syncqt_bat);
155                 stream << "@echo off" << endl
156                        << "call " << fixSeparators(sourcePath) << fixSeparators("/bin/syncqt.bat -qtdir \"") << fixSeparators(buildPath) << "\" %*" << endl;
157                 syncqt_bat.close();
158             }
159         }
160
161         QFile configtests(buildPath + "/bin/qtmodule-configtests");
162         if (configtests.open(QFile::WriteOnly)) {
163             QTextStream stream(&configtests);
164             stream << "#!/usr/bin/perl -w" << endl
165                    << "require \"" << sourcePath + "/bin/qtmodule-configtests\";" << endl;
166         }
167         // For Windows CE and shadow builds we need to copy these to the
168         // build directory.
169         QFile::copy(sourcePath + "/bin/setcepaths.bat" , buildPath + "/bin/setcepaths.bat");
170         //copy the mkspecs
171         buildDir.mkpath("mkspecs");
172         if (!Environment::cpdir(sourcePath + "/mkspecs", buildPath + "/mkspecs")){
173             cout << "Couldn't copy mkspecs!" << sourcePath << " " << buildPath << endl;
174             dictionary["DONE"] = "error";
175             return;
176         }
177     }
178
179     defaultBuildParts << QStringLiteral("libs") << QStringLiteral("examples");
180     dictionary[ "QT_SOURCE_TREE" ]    = fixSeparators(sourcePath);
181     dictionary[ "QT_BUILD_TREE" ]     = fixSeparators(buildPath);
182     dictionary[ "QT_INSTALL_PREFIX" ] = fixSeparators(installPath);
183
184     dictionary[ "QMAKESPEC" ] = getenv("QMAKESPEC");
185     if (dictionary[ "QMAKESPEC" ].size() == 0) {
186         dictionary[ "QMAKESPEC" ] = Environment::detectQMakeSpec();
187         dictionary[ "QMAKESPEC_FROM" ] = "detected";
188     } else {
189         dictionary[ "QMAKESPEC_FROM" ] = "env";
190     }
191
192     dictionary[ "QCONFIG" ]         = "full";
193     dictionary[ "EMBEDDED" ]        = "no";
194     dictionary[ "BUILD_QMAKE" ]     = "yes";
195     dictionary[ "DSPFILES" ]        = "yes";
196     dictionary[ "VCPROJFILES" ]     = "yes";
197     dictionary[ "QMAKE_INTERNAL" ]  = "no";
198     dictionary[ "FAST" ]            = "no";
199     dictionary[ "NOPROCESS" ]       = "no";
200     dictionary[ "STL" ]             = "yes";
201     dictionary[ "EXCEPTIONS" ]      = "yes";
202     dictionary[ "WIDGETS" ]         = "yes";
203     dictionary[ "RTTI" ]            = "yes";
204     dictionary[ "MMX" ]             = "auto";
205     dictionary[ "3DNOW" ]           = "auto";
206     dictionary[ "SSE" ]             = "auto";
207     dictionary[ "SSE2" ]            = "auto";
208     dictionary[ "IWMMXT" ]          = "auto";
209     dictionary[ "SYNCQT" ]          = "auto";
210     dictionary[ "CE_CRT" ]          = "no";
211     dictionary[ "CETEST" ]          = "auto";
212     dictionary[ "CE_SIGNATURE" ]    = "no";
213     dictionary[ "PHONON_BACKEND" ]  = "yes";
214     dictionary[ "AUDIO_BACKEND" ]   = "auto";
215     dictionary[ "WMSDK" ]           = "auto";
216     dictionary[ "DIRECTSHOW" ]      = "no";
217     dictionary[ "V8SNAPSHOT" ]      = "auto";
218     dictionary[ "QML_DEBUG" ]       = "yes";
219     dictionary[ "PLUGIN_MANIFESTS" ] = "yes";
220     dictionary[ "DIRECTWRITE" ]     = "no";
221
222     QString version;
223     QFile qglobal_h(sourcePath + "/src/corelib/global/qglobal.h");
224     if (qglobal_h.open(QFile::ReadOnly)) {
225         QTextStream read(&qglobal_h);
226         QRegExp version_regexp("^# *define *QT_VERSION_STR *\"([^\"]*)\"");
227         QString line;
228         while (!read.atEnd()) {
229             line = read.readLine();
230             if (version_regexp.exactMatch(line)) {
231                 version = version_regexp.cap(1).trimmed();
232                 if (!version.isEmpty())
233                     break;
234             }
235         }
236         qglobal_h.close();
237     }
238
239     if (version.isEmpty())
240         version = QString("%1.%2.%3").arg(QT_VERSION>>16).arg(((QT_VERSION>>8)&0xff)).arg(QT_VERSION&0xff);
241
242     dictionary[ "VERSION" ]         = version;
243     {
244         QRegExp version_re("([0-9]*)\\.([0-9]*)\\.([0-9]*)(|-.*)");
245         if (version_re.exactMatch(version)) {
246             dictionary[ "VERSION_MAJOR" ] = version_re.cap(1);
247             dictionary[ "VERSION_MINOR" ] = version_re.cap(2);
248             dictionary[ "VERSION_PATCH" ] = version_re.cap(3);
249         }
250     }
251
252     dictionary[ "REDO" ]            = "no";
253     dictionary[ "DEPENDENCIES" ]    = "no";
254
255     dictionary[ "BUILD" ]           = "debug";
256     dictionary[ "BUILDALL" ]        = "auto"; // Means yes, but not explicitly
257
258     dictionary[ "BUILDTYPE" ]      = "none";
259
260     dictionary[ "BUILDDEV" ]        = "no";
261
262     dictionary[ "SHARED" ]          = "yes";
263
264     dictionary[ "ZLIB" ]            = "auto";
265
266     dictionary[ "PCRE" ]            = "auto";
267
268     dictionary[ "ICU" ]             = "auto";
269
270     dictionary[ "GIF" ]             = "auto";
271     dictionary[ "JPEG" ]            = "auto";
272     dictionary[ "PNG" ]             = "auto";
273     dictionary[ "LIBJPEG" ]         = "auto";
274     dictionary[ "LIBPNG" ]          = "auto";
275     dictionary[ "FREETYPE" ]        = "yes";
276
277     dictionary[ "ACCESSIBILITY" ]   = "yes";
278     dictionary[ "OPENGL" ]          = "yes";
279     dictionary[ "OPENVG" ]          = "no";
280     dictionary[ "OPENSSL" ]         = "auto";
281     dictionary[ "DBUS" ]            = "auto";
282
283     dictionary[ "STYLE_WINDOWS" ]   = "yes";
284     dictionary[ "STYLE_WINDOWSXP" ] = "auto";
285     dictionary[ "STYLE_WINDOWSVISTA" ] = "auto";
286     dictionary[ "STYLE_PLASTIQUE" ] = "yes";
287     dictionary[ "STYLE_CLEANLOOKS" ]= "yes";
288     dictionary[ "STYLE_WINDOWSCE" ] = "no";
289     dictionary[ "STYLE_WINDOWSMOBILE" ] = "no";
290     dictionary[ "STYLE_MOTIF" ]     = "yes";
291     dictionary[ "STYLE_CDE" ]       = "yes";
292     dictionary[ "STYLE_GTK" ]       = "no";
293
294     dictionary[ "SQL_MYSQL" ]       = "no";
295     dictionary[ "SQL_ODBC" ]        = "no";
296     dictionary[ "SQL_OCI" ]         = "no";
297     dictionary[ "SQL_PSQL" ]        = "no";
298     dictionary[ "SQL_TDS" ]         = "no";
299     dictionary[ "SQL_DB2" ]         = "no";
300     dictionary[ "SQL_SQLITE" ]      = "auto";
301     dictionary[ "SQL_SQLITE_LIB" ]  = "qt";
302     dictionary[ "SQL_SQLITE2" ]     = "no";
303     dictionary[ "SQL_IBASE" ]       = "no";
304
305     QString tmp = dictionary[ "QMAKESPEC" ];
306     if (tmp.contains("\\")) {
307         tmp = tmp.mid(tmp.lastIndexOf("\\") + 1);
308     } else {
309         tmp = tmp.mid(tmp.lastIndexOf("/") + 1);
310     }
311     dictionary[ "QMAKESPEC" ] = tmp;
312
313     dictionary[ "INCREDIBUILD_XGE" ] = "auto";
314     dictionary[ "LTCG" ]            = "no";
315     dictionary[ "NATIVE_GESTURES" ] = "yes";
316     dictionary[ "MSVC_MP" ] = "no";
317 }
318
319 Configure::~Configure()
320 {
321     for (int i=0; i<3; ++i) {
322         QList<MakeItem*> items = makeList[i];
323         for (int j=0; j<items.size(); ++j)
324             delete items[j];
325     }
326 }
327
328 QString Configure::fixSeparators(const QString &somePath, bool escape)
329 {
330     if (useUnixSeparators)
331         return QDir::fromNativeSeparators(somePath);
332     QString ret = QDir::toNativeSeparators(somePath);
333     return escape ? escapeSeparators(ret) : ret;
334 }
335
336 QString Configure::escapeSeparators(const QString &somePath)
337 {
338     QString out = somePath;
339     out.replace(QLatin1Char('\\'), QLatin1String("\\\\"));
340     return out;
341 }
342
343 // We could use QDir::homePath() + "/.qt-license", but
344 // that will only look in the first of $HOME,$USERPROFILE
345 // or $HOMEDRIVE$HOMEPATH. So, here we try'em all to be
346 // more forgiving for the end user..
347 QString Configure::firstLicensePath()
348 {
349     QStringList allPaths;
350     allPaths << "./.qt-license"
351              << QString::fromLocal8Bit(getenv("HOME")) + "/.qt-license"
352              << QString::fromLocal8Bit(getenv("USERPROFILE")) + "/.qt-license"
353              << QString::fromLocal8Bit(getenv("HOMEDRIVE")) + QString::fromLocal8Bit(getenv("HOMEPATH")) + "/.qt-license";
354     for (int i = 0; i< allPaths.count(); ++i)
355         if (QFile::exists(allPaths.at(i)))
356             return allPaths.at(i);
357     return QString();
358 }
359
360
361 // #### somehow I get a compiler error about vc++ reaching the nesting limit without
362 // undefining the ansi for scoping.
363 #ifdef for
364 #undef for
365 #endif
366
367 void Configure::parseCmdLine()
368 {
369     int argCount = configCmdLine.size();
370     int i = 0;
371     const QStringList imageFormats = QStringList() << "gif" << "png" << "jpeg";
372
373 #if !defined(EVAL)
374     if (argCount < 1) // skip rest if no arguments
375         ;
376     else if (configCmdLine.at(i) == "-redo") {
377         dictionary[ "REDO" ] = "yes";
378         configCmdLine.clear();
379         reloadCmdLine();
380     }
381     else if (configCmdLine.at(i) == "-loadconfig") {
382         ++i;
383         if (i != argCount) {
384             dictionary[ "REDO" ] = "yes";
385             dictionary[ "CUSTOMCONFIG" ] = "_" + configCmdLine.at(i);
386             configCmdLine.clear();
387             reloadCmdLine();
388         } else {
389             dictionary[ "HELP" ] = "yes";
390         }
391         i = 0;
392     }
393     argCount = configCmdLine.size();
394 #endif
395
396     // Look first for XQMAKESPEC
397     for (int j = 0 ; j < argCount; ++j)
398     {
399         if (configCmdLine.at(j) == "-xplatform") {
400             ++j;
401             if (j == argCount)
402                 break;
403             dictionary["XQMAKESPEC"] = configCmdLine.at(j);
404             if (!dictionary[ "XQMAKESPEC" ].isEmpty())
405                 applySpecSpecifics();
406         }
407     }
408
409     for (; i<configCmdLine.size(); ++i) {
410         bool continueElse[] = {false, false};
411         if (configCmdLine.at(i) == "-help"
412             || configCmdLine.at(i) == "-h"
413             || configCmdLine.at(i) == "-?")
414             dictionary[ "HELP" ] = "yes";
415
416 #if !defined(EVAL)
417         else if (configCmdLine.at(i) == "-qconfig") {
418             ++i;
419             if (i == argCount)
420                 break;
421             dictionary[ "QCONFIG" ] = configCmdLine.at(i);
422         }
423
424         else if (configCmdLine.at(i) == "-release") {
425             dictionary[ "BUILD" ] = "release";
426             if (dictionary[ "BUILDALL" ] == "auto")
427                 dictionary[ "BUILDALL" ] = "no";
428         } else if (configCmdLine.at(i) == "-debug") {
429             dictionary[ "BUILD" ] = "debug";
430             if (dictionary[ "BUILDALL" ] == "auto")
431                 dictionary[ "BUILDALL" ] = "no";
432         } else if (configCmdLine.at(i) == "-debug-and-release")
433             dictionary[ "BUILDALL" ] = "yes";
434
435         else if (configCmdLine.at(i) == "-shared")
436             dictionary[ "SHARED" ] = "yes";
437         else if (configCmdLine.at(i) == "-static")
438             dictionary[ "SHARED" ] = "no";
439         else if (configCmdLine.at(i) == "-developer-build")
440             dictionary[ "BUILDDEV" ] = "yes";
441         else if (configCmdLine.at(i) == "-opensource") {
442             dictionary[ "BUILDTYPE" ] = "opensource";
443         }
444         else if (configCmdLine.at(i) == "-commercial") {
445             dictionary[ "BUILDTYPE" ] = "commercial";
446         }
447         else if (configCmdLine.at(i) == "-ltcg") {
448             dictionary[ "LTCG" ] = "yes";
449         }
450         else if (configCmdLine.at(i) == "-no-ltcg") {
451             dictionary[ "LTCG" ] = "no";
452         }
453         else if (configCmdLine.at(i) == "-mp") {
454             dictionary[ "MSVC_MP" ] = "yes";
455         }
456         else if (configCmdLine.at(i) == "-no-mp") {
457             dictionary[ "MSVC_MP" ] = "no";
458         }
459         else if (configCmdLine.at(i) == "-force-asserts") {
460             dictionary[ "FORCE_ASSERTS" ] = "yes";
461         }
462
463
464 #endif
465
466         else if (configCmdLine.at(i) == "-platform") {
467             ++i;
468             if (i == argCount)
469                 break;
470             dictionary[ "QMAKESPEC" ] = configCmdLine.at(i);
471         dictionary[ "QMAKESPEC_FROM" ] = "commandline";
472         } else if (configCmdLine.at(i) == "-arch") {
473             ++i;
474             if (i == argCount)
475                 break;
476             dictionary["OBSOLETE_ARCH_ARG"] = "yes";
477         } else if (configCmdLine.at(i) == "-embedded") {
478             dictionary[ "EMBEDDED" ] = "yes";
479         } else if (configCmdLine.at(i) == "-xplatform") {
480             ++i;
481             // do nothing
482         }
483
484
485 #if !defined(EVAL)
486         else if (configCmdLine.at(i) == "-no-zlib") {
487             // No longer supported since Qt 4.4.0
488             // But save the information for later so that we can print a warning
489             //
490             // If you REALLY really need no zlib support, you can still disable
491             // it by doing the following:
492             //   add "no-zlib" to mkspecs/qconfig.pri
493             //   #define QT_NO_COMPRESS (probably by adding to src/corelib/global/qconfig.h)
494             //
495             // There's no guarantee that Qt will build under those conditions
496
497             dictionary[ "ZLIB_FORCED" ] = "yes";
498         } else if (configCmdLine.at(i) == "-qt-zlib") {
499             dictionary[ "ZLIB" ] = "qt";
500         } else if (configCmdLine.at(i) == "-system-zlib") {
501             dictionary[ "ZLIB" ] = "system";
502         }
503
504         else if (configCmdLine.at(i) == "-qt-pcre") {
505             dictionary[ "PCRE" ] = "qt";
506         } else if (configCmdLine.at(i) == "-system-pcre") {
507             dictionary[ "PCRE" ] = "system";
508         }
509
510         else if (configCmdLine.at(i) == "-icu") {
511             dictionary[ "ICU" ] = "yes";
512         } else if (configCmdLine.at(i) == "-no-icu") {
513             dictionary[ "ICU" ] = "no";
514         }
515
516         // Image formats --------------------------------------------
517         else if (configCmdLine.at(i) == "-no-gif")
518             dictionary[ "GIF" ] = "no";
519
520         else if (configCmdLine.at(i) == "-no-libjpeg") {
521             dictionary[ "JPEG" ] = "no";
522             dictionary[ "LIBJPEG" ] = "no";
523         } else if (configCmdLine.at(i) == "-qt-libjpeg") {
524             dictionary[ "LIBJPEG" ] = "qt";
525         } else if (configCmdLine.at(i) == "-system-libjpeg") {
526             dictionary[ "LIBJPEG" ] = "system";
527         }
528
529         else if (configCmdLine.at(i) == "-no-libpng") {
530             dictionary[ "PNG" ] = "no";
531             dictionary[ "LIBPNG" ] = "no";
532         } else if (configCmdLine.at(i) == "-qt-libpng") {
533             dictionary[ "LIBPNG" ] = "qt";
534         } else if (configCmdLine.at(i) == "-system-libpng") {
535             dictionary[ "LIBPNG" ] = "system";
536         }
537
538         // Text Rendering --------------------------------------------
539         else if (configCmdLine.at(i) == "-no-freetype")
540             dictionary[ "FREETYPE" ] = "no";
541         else if (configCmdLine.at(i) == "-qt-freetype")
542             dictionary[ "FREETYPE" ] = "yes";
543
544         // CE- C runtime --------------------------------------------
545         else if (configCmdLine.at(i) == "-crt") {
546             ++i;
547             if (i == argCount)
548                 break;
549             QDir cDir(configCmdLine.at(i));
550             if (!cDir.exists())
551                 cout << "WARNING: Could not find directory (" << qPrintable(configCmdLine.at(i)) << ")for C runtime deployment" << endl;
552             else
553                 dictionary[ "CE_CRT" ] = QDir::toNativeSeparators(cDir.absolutePath());
554         } else if (configCmdLine.at(i) == "-qt-crt") {
555             dictionary[ "CE_CRT" ] = "yes";
556         } else if (configCmdLine.at(i) == "-no-crt") {
557             dictionary[ "CE_CRT" ] = "no";
558         }
559         // cetest ---------------------------------------------------
560         else if (configCmdLine.at(i) == "-no-cetest") {
561             dictionary[ "CETEST" ] = "no";
562             dictionary[ "CETEST_REQUESTED" ] = "no";
563         } else if (configCmdLine.at(i) == "-cetest") {
564             // although specified to use it, we stay at "auto" state
565             // this is because checkAvailability() adds variables
566             // we need for crosscompilation; but remember if we asked
567             // for it.
568             dictionary[ "CETEST_REQUESTED" ] = "yes";
569         }
570         // Qt/CE - signing tool -------------------------------------
571         else if (configCmdLine.at(i) == "-signature") {
572             ++i;
573             if (i == argCount)
574                 break;
575             QFileInfo info(configCmdLine.at(i));
576             if (!info.exists())
577                 cout << "WARNING: Could not find signature file (" << qPrintable(configCmdLine.at(i)) << ")" << endl;
578             else
579                 dictionary[ "CE_SIGNATURE" ] = QDir::toNativeSeparators(info.absoluteFilePath());
580         }
581         // Styles ---------------------------------------------------
582         else if (configCmdLine.at(i) == "-qt-style-windows")
583             dictionary[ "STYLE_WINDOWS" ] = "yes";
584         else if (configCmdLine.at(i) == "-no-style-windows")
585             dictionary[ "STYLE_WINDOWS" ] = "no";
586
587         else if (configCmdLine.at(i) == "-qt-style-windowsce")
588             dictionary[ "STYLE_WINDOWSCE" ] = "yes";
589         else if (configCmdLine.at(i) == "-no-style-windowsce")
590             dictionary[ "STYLE_WINDOWSCE" ] = "no";
591         else if (configCmdLine.at(i) == "-qt-style-windowsmobile")
592             dictionary[ "STYLE_WINDOWSMOBILE" ] = "yes";
593         else if (configCmdLine.at(i) == "-no-style-windowsmobile")
594             dictionary[ "STYLE_WINDOWSMOBILE" ] = "no";
595
596         else if (configCmdLine.at(i) == "-qt-style-windowsxp")
597             dictionary[ "STYLE_WINDOWSXP" ] = "yes";
598         else if (configCmdLine.at(i) == "-no-style-windowsxp")
599             dictionary[ "STYLE_WINDOWSXP" ] = "no";
600
601         else if (configCmdLine.at(i) == "-qt-style-windowsvista")
602             dictionary[ "STYLE_WINDOWSVISTA" ] = "yes";
603         else if (configCmdLine.at(i) == "-no-style-windowsvista")
604             dictionary[ "STYLE_WINDOWSVISTA" ] = "no";
605
606         else if (configCmdLine.at(i) == "-qt-style-plastique")
607             dictionary[ "STYLE_PLASTIQUE" ] = "yes";
608         else if (configCmdLine.at(i) == "-no-style-plastique")
609             dictionary[ "STYLE_PLASTIQUE" ] = "no";
610
611         else if (configCmdLine.at(i) == "-qt-style-cleanlooks")
612             dictionary[ "STYLE_CLEANLOOKS" ] = "yes";
613         else if (configCmdLine.at(i) == "-no-style-cleanlooks")
614             dictionary[ "STYLE_CLEANLOOKS" ] = "no";
615
616         else if (configCmdLine.at(i) == "-qt-style-motif")
617             dictionary[ "STYLE_MOTIF" ] = "yes";
618         else if (configCmdLine.at(i) == "-no-style-motif")
619             dictionary[ "STYLE_MOTIF" ] = "no";
620
621         else if (configCmdLine.at(i) == "-qt-style-cde")
622             dictionary[ "STYLE_CDE" ] = "yes";
623         else if (configCmdLine.at(i) == "-no-style-cde")
624             dictionary[ "STYLE_CDE" ] = "no";
625
626         // Work around compiler nesting limitation
627         else
628             continueElse[1] = true;
629         if (!continueElse[1]) {
630         }
631
632         // OpenGL Support -------------------------------------------
633         else if (configCmdLine.at(i) == "-no-opengl") {
634             dictionary[ "OPENGL" ]    = "no";
635         } else if (configCmdLine.at(i) == "-opengl-es-cm") {
636             dictionary[ "OPENGL" ]          = "yes";
637             dictionary[ "OPENGL_ES_CM" ]    = "yes";
638         } else if (configCmdLine.at(i) == "-opengl-es-2") {
639             dictionary[ "OPENGL" ]          = "yes";
640             dictionary[ "OPENGL_ES_2" ]     = "yes";
641         } else if (configCmdLine.at(i) == "-opengl") {
642             dictionary[ "OPENGL" ]          = "yes";
643             i++;
644             if (i == argCount)
645                 break;
646
647             if (configCmdLine.at(i) == "es1") {
648                 dictionary[ "OPENGL_ES_CM" ]    = "yes";
649             } else if ( configCmdLine.at(i) == "es2" ) {
650                 dictionary[ "OPENGL_ES_2" ]     = "yes";
651             } else if ( configCmdLine.at(i) == "desktop" ) {
652                 // OPENGL=yes suffices
653             } else {
654                 cout << "Argument passed to -opengl option is not valid." << endl;
655                 dictionary[ "DONE" ] = "error";
656                 break;
657             }
658         }
659
660         // OpenVG Support -------------------------------------------
661         else if (configCmdLine.at(i) == "-openvg") {
662             dictionary[ "OPENVG" ]    = "yes";
663         } else if (configCmdLine.at(i) == "-no-openvg") {
664             dictionary[ "OPENVG" ]    = "no";
665         }
666
667         // Databases ------------------------------------------------
668         else if (configCmdLine.at(i) == "-qt-sql-mysql")
669             dictionary[ "SQL_MYSQL" ] = "yes";
670         else if (configCmdLine.at(i) == "-plugin-sql-mysql")
671             dictionary[ "SQL_MYSQL" ] = "plugin";
672         else if (configCmdLine.at(i) == "-no-sql-mysql")
673             dictionary[ "SQL_MYSQL" ] = "no";
674
675         else if (configCmdLine.at(i) == "-qt-sql-odbc")
676             dictionary[ "SQL_ODBC" ] = "yes";
677         else if (configCmdLine.at(i) == "-plugin-sql-odbc")
678             dictionary[ "SQL_ODBC" ] = "plugin";
679         else if (configCmdLine.at(i) == "-no-sql-odbc")
680             dictionary[ "SQL_ODBC" ] = "no";
681
682         else if (configCmdLine.at(i) == "-qt-sql-oci")
683             dictionary[ "SQL_OCI" ] = "yes";
684         else if (configCmdLine.at(i) == "-plugin-sql-oci")
685             dictionary[ "SQL_OCI" ] = "plugin";
686         else if (configCmdLine.at(i) == "-no-sql-oci")
687             dictionary[ "SQL_OCI" ] = "no";
688
689         else if (configCmdLine.at(i) == "-qt-sql-psql")
690             dictionary[ "SQL_PSQL" ] = "yes";
691         else if (configCmdLine.at(i) == "-plugin-sql-psql")
692             dictionary[ "SQL_PSQL" ] = "plugin";
693         else if (configCmdLine.at(i) == "-no-sql-psql")
694             dictionary[ "SQL_PSQL" ] = "no";
695
696         else if (configCmdLine.at(i) == "-qt-sql-tds")
697             dictionary[ "SQL_TDS" ] = "yes";
698         else if (configCmdLine.at(i) == "-plugin-sql-tds")
699             dictionary[ "SQL_TDS" ] = "plugin";
700         else if (configCmdLine.at(i) == "-no-sql-tds")
701             dictionary[ "SQL_TDS" ] = "no";
702
703         else if (configCmdLine.at(i) == "-qt-sql-db2")
704             dictionary[ "SQL_DB2" ] = "yes";
705         else if (configCmdLine.at(i) == "-plugin-sql-db2")
706             dictionary[ "SQL_DB2" ] = "plugin";
707         else if (configCmdLine.at(i) == "-no-sql-db2")
708             dictionary[ "SQL_DB2" ] = "no";
709
710         else if (configCmdLine.at(i) == "-qt-sql-sqlite")
711             dictionary[ "SQL_SQLITE" ] = "yes";
712         else if (configCmdLine.at(i) == "-plugin-sql-sqlite")
713             dictionary[ "SQL_SQLITE" ] = "plugin";
714         else if (configCmdLine.at(i) == "-no-sql-sqlite")
715             dictionary[ "SQL_SQLITE" ] = "no";
716         else if (configCmdLine.at(i) == "-system-sqlite")
717             dictionary[ "SQL_SQLITE_LIB" ] = "system";
718         else if (configCmdLine.at(i) == "-qt-sql-sqlite2")
719             dictionary[ "SQL_SQLITE2" ] = "yes";
720         else if (configCmdLine.at(i) == "-plugin-sql-sqlite2")
721             dictionary[ "SQL_SQLITE2" ] = "plugin";
722         else if (configCmdLine.at(i) == "-no-sql-sqlite2")
723             dictionary[ "SQL_SQLITE2" ] = "no";
724
725         else if (configCmdLine.at(i) == "-qt-sql-ibase")
726             dictionary[ "SQL_IBASE" ] = "yes";
727         else if (configCmdLine.at(i) == "-plugin-sql-ibase")
728             dictionary[ "SQL_IBASE" ] = "plugin";
729         else if (configCmdLine.at(i) == "-no-sql-ibase")
730             dictionary[ "SQL_IBASE" ] = "no";
731
732         // Image formats --------------------------------------------
733         else if (configCmdLine.at(i).startsWith("-qt-imageformat-") &&
734                  imageFormats.contains(configCmdLine.at(i).section('-', 3)))
735             dictionary[ configCmdLine.at(i).section('-', 3).toUpper() ] = "yes";
736         else if (configCmdLine.at(i).startsWith("-plugin-imageformat-") &&
737                  imageFormats.contains(configCmdLine.at(i).section('-', 3)))
738             dictionary[ configCmdLine.at(i).section('-', 3).toUpper() ] = "plugin";
739         else if (configCmdLine.at(i).startsWith("-no-imageformat-") &&
740                  imageFormats.contains(configCmdLine.at(i).section('-', 3)))
741             dictionary[ configCmdLine.at(i).section('-', 3).toUpper() ] = "no";
742 #endif
743         // IDE project generation -----------------------------------
744         else if (configCmdLine.at(i) == "-no-dsp")
745             dictionary[ "DSPFILES" ] = "no";
746         else if (configCmdLine.at(i) == "-dsp")
747             dictionary[ "DSPFILES" ] = "yes";
748
749         else if (configCmdLine.at(i) == "-no-vcp")
750             dictionary[ "VCPFILES" ] = "no";
751         else if (configCmdLine.at(i) == "-vcp")
752             dictionary[ "VCPFILES" ] = "yes";
753
754         else if (configCmdLine.at(i) == "-no-vcproj")
755             dictionary[ "VCPROJFILES" ] = "no";
756         else if (configCmdLine.at(i) == "-vcproj")
757             dictionary[ "VCPROJFILES" ] = "yes";
758
759         else if (configCmdLine.at(i) == "-no-incredibuild-xge")
760             dictionary[ "INCREDIBUILD_XGE" ] = "no";
761         else if (configCmdLine.at(i) == "-incredibuild-xge")
762             dictionary[ "INCREDIBUILD_XGE" ] = "yes";
763         else if (configCmdLine.at(i) == "-native-gestures")
764             dictionary[ "NATIVE_GESTURES" ] = "yes";
765         else if (configCmdLine.at(i) == "-no-native-gestures")
766             dictionary[ "NATIVE_GESTURES" ] = "no";
767 #if !defined(EVAL)
768         // Others ---------------------------------------------------
769         else if (configCmdLine.at(i) == "-fast")
770             dictionary[ "FAST" ] = "yes";
771         else if (configCmdLine.at(i) == "-no-fast")
772             dictionary[ "FAST" ] = "no";
773
774         else if (configCmdLine.at(i) == "-stl")
775             dictionary[ "STL" ] = "yes";
776         else if (configCmdLine.at(i) == "-no-stl")
777             dictionary[ "STL" ] = "no";
778
779         else if (configCmdLine.at(i) == "-exceptions")
780             dictionary[ "EXCEPTIONS" ] = "yes";
781         else if (configCmdLine.at(i) == "-no-exceptions")
782             dictionary[ "EXCEPTIONS" ] = "no";
783
784         else if (configCmdLine.at(i) == "-widgets")
785             dictionary[ "WIDGETS" ] = "yes";
786         else if (configCmdLine.at(i) == "-no-widgets")
787             dictionary[ "WIDGETS" ] = "no";
788
789         else if (configCmdLine.at(i) == "-rtti")
790             dictionary[ "RTTI" ] = "yes";
791         else if (configCmdLine.at(i) == "-no-rtti")
792             dictionary[ "RTTI" ] = "no";
793
794         else if (configCmdLine.at(i) == "-accessibility")
795             dictionary[ "ACCESSIBILITY" ] = "yes";
796         else if (configCmdLine.at(i) == "-no-accessibility") {
797             dictionary[ "ACCESSIBILITY" ] = "no";
798             cout << "Setting accessibility to NO" << endl;
799         }
800
801         else if (configCmdLine.at(i) == "-no-mmx")
802             dictionary[ "MMX" ] = "no";
803         else if (configCmdLine.at(i) == "-mmx")
804             dictionary[ "MMX" ] = "yes";
805         else if (configCmdLine.at(i) == "-no-3dnow")
806             dictionary[ "3DNOW" ] = "no";
807         else if (configCmdLine.at(i) == "-3dnow")
808             dictionary[ "3DNOW" ] = "yes";
809         else if (configCmdLine.at(i) == "-no-sse")
810             dictionary[ "SSE" ] = "no";
811         else if (configCmdLine.at(i) == "-sse")
812             dictionary[ "SSE" ] = "yes";
813         else if (configCmdLine.at(i) == "-no-sse2")
814             dictionary[ "SSE2" ] = "no";
815         else if (configCmdLine.at(i) == "-sse2")
816             dictionary[ "SSE2" ] = "yes";
817         else if (configCmdLine.at(i) == "-no-iwmmxt")
818             dictionary[ "IWMMXT" ] = "no";
819         else if (configCmdLine.at(i) == "-iwmmxt")
820             dictionary[ "IWMMXT" ] = "yes";
821
822         else if (configCmdLine.at(i) == "-no-openssl") {
823               dictionary[ "OPENSSL"] = "no";
824         } else if (configCmdLine.at(i) == "-openssl") {
825               dictionary[ "OPENSSL" ] = "yes";
826         } else if (configCmdLine.at(i) == "-openssl-linked") {
827               dictionary[ "OPENSSL" ] = "linked";
828         } else if (configCmdLine.at(i) == "-no-qdbus") {
829             dictionary[ "DBUS" ] = "no";
830         } else if (configCmdLine.at(i) == "-qdbus") {
831             dictionary[ "DBUS" ] = "yes";
832         } else if (configCmdLine.at(i) == "-no-dbus") {
833             dictionary[ "DBUS" ] = "no";
834         } else if (configCmdLine.at(i) == "-dbus") {
835             dictionary[ "DBUS" ] = "yes";
836         } else if (configCmdLine.at(i) == "-dbus-linked") {
837             dictionary[ "DBUS" ] = "linked";
838         } else if (configCmdLine.at(i) == "-audio-backend") {
839             dictionary[ "AUDIO_BACKEND" ] = "yes";
840         } else if (configCmdLine.at(i) == "-no-audio-backend") {
841             dictionary[ "AUDIO_BACKEND" ] = "no";
842         } else if (configCmdLine.at(i) == "-no-phonon-backend") {
843             dictionary[ "PHONON_BACKEND" ] = "no";
844         } else if (configCmdLine.at(i) == "-phonon-backend") {
845             dictionary[ "PHONON_BACKEND" ] = "yes";
846         } else if (configCmdLine.at(i) == "-phonon-wince-ds9") {
847             dictionary[ "DIRECTSHOW" ] = "yes";
848         } else if (configCmdLine.at(i) == "-no-qml-debug") {
849             dictionary[ "QML_DEBUG" ] = "no";
850         } else if (configCmdLine.at(i) == "-qml-debug") {
851             dictionary[ "QML_DEBUG" ] = "yes";
852         } else if (configCmdLine.at(i) == "-no-plugin-manifests") {
853             dictionary[ "PLUGIN_MANIFESTS" ] = "no";
854         } else if (configCmdLine.at(i) == "-plugin-manifests") {
855             dictionary[ "PLUGIN_MANIFESTS" ] = "yes";
856         }
857
858         // Work around compiler nesting limitation
859         else
860             continueElse[0] = true;
861         if (!continueElse[0]) {
862         }
863
864         else if (configCmdLine.at(i) == "-internal")
865             dictionary[ "QMAKE_INTERNAL" ] = "yes";
866
867         else if (configCmdLine.at(i) == "-no-syncqt")
868             dictionary[ "SYNCQT" ] = "no";
869
870         else if (configCmdLine.at(i) == "-no-qmake")
871             dictionary[ "BUILD_QMAKE" ] = "no";
872         else if (configCmdLine.at(i) == "-qmake")
873             dictionary[ "BUILD_QMAKE" ] = "yes";
874
875         else if (configCmdLine.at(i) == "-dont-process")
876             dictionary[ "NOPROCESS" ] = "yes";
877         else if (configCmdLine.at(i) == "-process")
878             dictionary[ "NOPROCESS" ] = "no";
879
880         else if (configCmdLine.at(i) == "-no-qmake-deps")
881             dictionary[ "DEPENDENCIES" ] = "no";
882         else if (configCmdLine.at(i) == "-qmake-deps")
883             dictionary[ "DEPENDENCIES" ] = "yes";
884
885
886         else if (configCmdLine.at(i) == "-qtnamespace") {
887             ++i;
888             if (i == argCount)
889                 break;
890             dictionary[ "QT_NAMESPACE" ] = configCmdLine.at(i);
891         } else if (configCmdLine.at(i) == "-qtlibinfix") {
892             ++i;
893             if (i == argCount)
894                 break;
895             dictionary[ "QT_LIBINFIX" ] = configCmdLine.at(i);
896         } else if (configCmdLine.at(i) == "-D") {
897             ++i;
898             if (i == argCount)
899                 break;
900             qmakeDefines += configCmdLine.at(i);
901         } else if (configCmdLine.at(i) == "-I") {
902             ++i;
903             if (i == argCount)
904                 break;
905             qmakeIncludes += configCmdLine.at(i);
906         } else if (configCmdLine.at(i) == "-L") {
907             ++i;
908             if (i == argCount)
909                 break;
910             QFileInfo checkDirectory(configCmdLine.at(i));
911             if (!checkDirectory.isDir()) {
912                 cout << "Argument passed to -L option is not a directory path. Did you mean the -l option?" << endl;
913                 dictionary[ "DONE" ] = "error";
914                 break;
915             }
916             qmakeLibs += QString("-L" + configCmdLine.at(i));
917         } else if (configCmdLine.at(i) == "-l") {
918             ++i;
919             if (i == argCount)
920                 break;
921             qmakeLibs += QString("-l" + configCmdLine.at(i));
922         } else if (configCmdLine.at(i).startsWith("OPENSSL_LIBS=")) {
923             opensslLibs = configCmdLine.at(i);
924         } else if (configCmdLine.at(i).startsWith("PSQL_LIBS=")) {
925             psqlLibs = configCmdLine.at(i);
926         } else if (configCmdLine.at(i).startsWith("SYBASE=")) {
927             sybase = configCmdLine.at(i);
928         } else if (configCmdLine.at(i).startsWith("SYBASE_LIBS=")) {
929             sybaseLibs = configCmdLine.at(i);
930         }
931
932         else if ((configCmdLine.at(i) == "-override-version") || (configCmdLine.at(i) == "-version-override")){
933             ++i;
934             if (i == argCount)
935                 break;
936             dictionary[ "VERSION" ] = configCmdLine.at(i);
937         }
938
939         else if (configCmdLine.at(i) == "-saveconfig") {
940             ++i;
941             if (i == argCount)
942                 break;
943             dictionary[ "CUSTOMCONFIG" ] = "_" + configCmdLine.at(i);
944         }
945
946         else if (configCmdLine.at(i) == "-confirm-license") {
947             dictionary["LICENSE_CONFIRMED"] = "yes";
948         }
949
950         else if (configCmdLine.at(i) == "-make") {
951             ++i;
952             if (i == argCount)
953                 break;
954             buildParts += configCmdLine.at(i);
955         } else if (configCmdLine.at(i) == "-nomake") {
956             ++i;
957             if (i == argCount)
958                 break;
959             nobuildParts.append(configCmdLine.at(i));
960         }
961
962         // Directories ----------------------------------------------
963         else if (configCmdLine.at(i) == "-prefix") {
964             ++i;
965             if (i == argCount)
966                 break;
967             dictionary[ "QT_INSTALL_PREFIX" ] = configCmdLine.at(i);
968         }
969
970         else if (configCmdLine.at(i) == "-bindir") {
971             ++i;
972             if (i == argCount)
973                 break;
974             dictionary[ "QT_INSTALL_BINS" ] = configCmdLine.at(i);
975         }
976
977         else if (configCmdLine.at(i) == "-libdir") {
978             ++i;
979             if (i == argCount)
980                 break;
981             dictionary[ "QT_INSTALL_LIBS" ] = configCmdLine.at(i);
982         }
983
984         else if (configCmdLine.at(i) == "-docdir") {
985             ++i;
986             if (i == argCount)
987                 break;
988             dictionary[ "QT_INSTALL_DOCS" ] = configCmdLine.at(i);
989         }
990
991         else if (configCmdLine.at(i) == "-headerdir") {
992             ++i;
993             if (i == argCount)
994                 break;
995             dictionary[ "QT_INSTALL_HEADERS" ] = configCmdLine.at(i);
996         }
997
998         else if (configCmdLine.at(i) == "-plugindir") {
999             ++i;
1000             if (i == argCount)
1001                 break;
1002             dictionary[ "QT_INSTALL_PLUGINS" ] = configCmdLine.at(i);
1003         }
1004
1005         else if (configCmdLine.at(i) == "-importdir") {
1006             ++i;
1007             if (i == argCount)
1008                 break;
1009             dictionary[ "QT_INSTALL_IMPORTS" ] = configCmdLine.at(i);
1010         }
1011         else if (configCmdLine.at(i) == "-datadir") {
1012             ++i;
1013             if (i == argCount)
1014                 break;
1015             dictionary[ "QT_INSTALL_DATA" ] = configCmdLine.at(i);
1016         }
1017
1018         else if (configCmdLine.at(i) == "-translationdir") {
1019             ++i;
1020             if (i == argCount)
1021                 break;
1022             dictionary[ "QT_INSTALL_TRANSLATIONS" ] = configCmdLine.at(i);
1023         }
1024
1025         else if (configCmdLine.at(i) == "-examplesdir") {
1026             ++i;
1027             if (i == argCount)
1028                 break;
1029             dictionary[ "QT_INSTALL_EXAMPLES" ] = configCmdLine.at(i);
1030         }
1031
1032         else if (configCmdLine.at(i) == "-testsdir") {
1033             ++i;
1034             if (i == argCount)
1035                 break;
1036             dictionary[ "QT_INSTALL_TESTS" ] = configCmdLine.at(i);
1037         }
1038
1039         else if (configCmdLine.at(i) == "-sysroot") {
1040             ++i;
1041             if (i == argCount)
1042                 break;
1043             dictionary[ "CFG_SYSROOT" ] = configCmdLine.at(i);
1044         }
1045
1046         else if (configCmdLine.at(i) == "-hostprefix") {
1047             ++i;
1048             if (i == argCount || configCmdLine.at(i).startsWith('-'))
1049                 dictionary[ "QT_HOST_PREFIX" ] = dictionary[ "QT_BUILD_TREE" ];
1050             else
1051                 dictionary[ "QT_HOST_PREFIX" ] = configCmdLine.at(i);
1052         }
1053
1054         else if (configCmdLine.at(i) == "-hostbindir") {
1055             ++i;
1056             if (i == argCount)
1057                 break;
1058             dictionary[ "QT_HOST_BINS" ] = configCmdLine.at(i);
1059         }
1060
1061         else if (configCmdLine.at(i) == "-hostdatadir") {
1062             ++i;
1063             if (i == argCount)
1064                 break;
1065             dictionary[ "QT_HOST_DATA" ] = configCmdLine.at(i);
1066         }
1067
1068         else if (configCmdLine.at(i) == "-make-tool") {
1069             ++i;
1070             if (i == argCount)
1071                 break;
1072             dictionary[ "MAKE" ] = configCmdLine.at(i);
1073         }
1074
1075         else if (configCmdLine.at(i).indexOf(QRegExp("^-(en|dis)able-")) != -1) {
1076             // Scan to see if any specific modules and drivers are enabled or disabled
1077             for (QStringList::Iterator module = modules.begin(); module != modules.end(); ++module) {
1078                 if (configCmdLine.at(i) == QString("-enable-") + (*module)) {
1079                     enabledModules += (*module);
1080                     break;
1081                 }
1082                 else if (configCmdLine.at(i) == QString("-disable-") + (*module)) {
1083                     disabledModules += (*module);
1084                     break;
1085                 }
1086             }
1087         }
1088
1089         else if (configCmdLine.at(i) == "-directwrite") {
1090             dictionary["DIRECTWRITE"] = "yes";
1091         } else if (configCmdLine.at(i) == "-no-directwrite") {
1092             dictionary["DIRECTWRITE"] = "no";
1093         }
1094
1095         else {
1096             dictionary[ "HELP" ] = "yes";
1097             cout << "Unknown option " << configCmdLine.at(i) << endl;
1098             break;
1099         }
1100
1101 #endif
1102     }
1103
1104     // Ensure that QMAKESPEC exists in the mkspecs folder
1105     QDir mkspec_dir = fixSeparators(sourcePath + "/mkspecs");
1106     QStringList mkspecs = mkspec_dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
1107
1108     if (dictionary["QMAKESPEC"].toLower() == "features"
1109         || !mkspecs.contains(dictionary["QMAKESPEC"], Qt::CaseInsensitive)) {
1110         dictionary[ "HELP" ] = "yes";
1111         if (dictionary ["QMAKESPEC_FROM"] == "commandline") {
1112             cout << "Invalid option \"" << dictionary["QMAKESPEC"] << "\" for -platform." << endl;
1113         } else if (dictionary ["QMAKESPEC_FROM"] == "env") {
1114             cout << "QMAKESPEC environment variable is set to \"" << dictionary["QMAKESPEC"]
1115                  << "\" which is not a supported platform" << endl;
1116         } else { // was autodetected from environment
1117             cout << "Unable to detect the platform from environment. Use -platform command line"
1118                     "argument or set the QMAKESPEC environment variable and run configure again" << endl;
1119         }
1120         cout << "See the README file for a list of supported operating systems and compilers." << endl;
1121     } else {
1122         if (dictionary[ "QMAKESPEC" ].endsWith("-icc") ||
1123             dictionary[ "QMAKESPEC" ].endsWith("-msvc") ||
1124             dictionary[ "QMAKESPEC" ].endsWith("-msvc.net") ||
1125             dictionary[ "QMAKESPEC" ].endsWith("-msvc2002") ||
1126             dictionary[ "QMAKESPEC" ].endsWith("-msvc2003") ||
1127             dictionary[ "QMAKESPEC" ].endsWith("-msvc2005") ||
1128             dictionary[ "QMAKESPEC" ].endsWith("-msvc2008") ||
1129             dictionary[ "QMAKESPEC" ].endsWith("-msvc2010")) {
1130             if (dictionary[ "MAKE" ].isEmpty()) dictionary[ "MAKE" ] = "nmake";
1131             dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32";
1132         } else if (dictionary[ "QMAKESPEC" ] == QString("win32-g++")) {
1133             if (dictionary[ "MAKE" ].isEmpty()) dictionary[ "MAKE" ] = "mingw32-make";
1134             dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32-g++";
1135         } else {
1136             if (dictionary[ "MAKE" ].isEmpty()) dictionary[ "MAKE" ] = "make";
1137             dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32";
1138         }
1139     }
1140
1141     // Tell the user how to proceed building Qt after configure finished its job
1142     dictionary["QTBUILDINSTRUCTION"] = dictionary["MAKE"];
1143     if (dictionary.contains("XQMAKESPEC")) {
1144         if (dictionary["XQMAKESPEC"].startsWith("wince")) {
1145             dictionary["QTBUILDINSTRUCTION"] =
1146                 QString("setcepaths.bat ") + dictionary["XQMAKESPEC"] + QString(" && ") + dictionary["MAKE"];
1147         }
1148     }
1149
1150     // Tell the user how to confclean before the next configure
1151     dictionary["CONFCLEANINSTRUCTION"] = dictionary["MAKE"] + QString(" confclean");
1152
1153     // Ensure that -spec (XQMAKESPEC) exists in the mkspecs folder as well
1154     if (dictionary.contains("XQMAKESPEC") &&
1155         !mkspecs.contains(dictionary["XQMAKESPEC"], Qt::CaseInsensitive)) {
1156             dictionary["HELP"] = "yes";
1157             cout << "Invalid option \"" << dictionary["XQMAKESPEC"] << "\" for -xplatform." << endl;
1158     }
1159
1160     // Ensure that the crt to be deployed can be found
1161     if (dictionary["CE_CRT"] != QLatin1String("yes") && dictionary["CE_CRT"] != QLatin1String("no")) {
1162         QDir cDir(dictionary["CE_CRT"]);
1163         QStringList entries = cDir.entryList();
1164         bool hasDebug = entries.contains("msvcr80.dll");
1165         bool hasRelease = entries.contains("msvcr80d.dll");
1166         if ((dictionary["BUILDALL"] == "auto") && (!hasDebug || !hasRelease)) {
1167             cout << "Could not find debug and release c-runtime." << endl;
1168             cout << "You need to have msvcr80.dll and msvcr80d.dll in" << endl;
1169             cout << "the path specified. Setting to -no-crt";
1170             dictionary[ "CE_CRT" ] = "no";
1171         } else if ((dictionary["BUILD"] == "debug") && !hasDebug) {
1172             cout << "Could not find debug c-runtime (msvcr80d.dll) in the directory specified." << endl;
1173             cout << "Setting c-runtime automatic deployment to -no-crt" << endl;
1174             dictionary[ "CE_CRT" ] = "no";
1175         } else if ((dictionary["BUILD"] == "release") && !hasRelease) {
1176             cout << "Could not find release c-runtime (msvcr80.dll) in the directory specified." << endl;
1177             cout << "Setting c-runtime automatic deployment to -no-crt" << endl;
1178             dictionary[ "CE_CRT" ] = "no";
1179         }
1180     }
1181
1182     useUnixSeparators = (dictionary["QMAKESPEC"] == "win32-g++");
1183
1184     // Allow tests for private classes to be compiled against internal builds
1185     if (dictionary["BUILDDEV"] == "yes")
1186         qtConfig += "private_tests";
1187
1188     if (dictionary["FORCE_ASSERTS"] == "yes")
1189         qtConfig += "force_asserts";
1190
1191 #if !defined(EVAL)
1192     for (QStringList::Iterator dis = disabledModules.begin(); dis != disabledModules.end(); ++dis) {
1193         modules.removeAll((*dis));
1194     }
1195     for (QStringList::Iterator ena = enabledModules.begin(); ena != enabledModules.end(); ++ena) {
1196         if (modules.indexOf((*ena)) == -1)
1197             modules += (*ena);
1198     }
1199     qtConfig += modules;
1200
1201     for (QStringList::Iterator it = disabledModules.begin(); it != disabledModules.end(); ++it)
1202         qtConfig.removeAll(*it);
1203
1204     if ((dictionary[ "REDO" ] != "yes") && (dictionary[ "HELP" ] != "yes"))
1205         saveCmdLine();
1206 #endif
1207 }
1208
1209 #if !defined(EVAL)
1210 void Configure::validateArgs()
1211 {
1212     // Validate the specified config
1213
1214     // Get all possible configurations from the file system.
1215     QDir dir;
1216     QStringList filters;
1217     filters << "qconfig-*.h";
1218     dir.setNameFilters(filters);
1219     dir.setPath(sourcePath + "/src/corelib/global/");
1220
1221     QStringList stringList =  dir.entryList();
1222
1223     QStringList::Iterator it;
1224     for (it = stringList.begin(); it != stringList.end(); ++it)
1225         allConfigs << it->remove("qconfig-").remove(".h");
1226     allConfigs << "full";
1227
1228     // Try internal configurations first.
1229     QStringList possible_configs = QStringList()
1230         << "minimal"
1231         << "small"
1232         << "medium"
1233         << "large"
1234         << "full";
1235     int index = possible_configs.indexOf(dictionary["QCONFIG"]);
1236     if (index >= 0) {
1237         for (int c = 0; c <= index; c++) {
1238             qmakeConfig += possible_configs[c] + "-config";
1239         }
1240         return;
1241     }
1242
1243     // If the internal configurations failed, try others.
1244     QStringList::Iterator config;
1245     for (config = allConfigs.begin(); config != allConfigs.end(); ++config) {
1246         if ((*config) == dictionary[ "QCONFIG" ])
1247             break;
1248     }
1249     if (config == allConfigs.end()) {
1250         dictionary[ "HELP" ] = "yes";
1251         cout << "No such configuration \"" << qPrintable(dictionary[ "QCONFIG" ]) << "\"" << endl ;
1252     }
1253     else
1254         qmakeConfig += (*config) + "-config";
1255 }
1256 #endif
1257
1258
1259 // Output helper functions --------------------------------[ Start ]-
1260 /*!
1261     Determines the length of a string token.
1262 */
1263 static int tokenLength(const char *str)
1264 {
1265     if (*str == 0)
1266         return 0;
1267
1268     const char *nextToken = strpbrk(str, " _/\n\r");
1269     if (nextToken == str || !nextToken)
1270         return 1;
1271
1272     return int(nextToken - str);
1273 }
1274
1275 /*!
1276     Prints out a string which starts at position \a startingAt, and
1277     indents each wrapped line with \a wrapIndent characters.
1278     The wrap point is set to the console width, unless that width
1279     cannot be determined, or is too small.
1280 */
1281 void Configure::desc(const char *description, int startingAt, int wrapIndent)
1282 {
1283     int linePos = startingAt;
1284
1285     bool firstLine = true;
1286     const char *nextToken = description;
1287     while (*nextToken) {
1288         int nextTokenLen = tokenLength(nextToken);
1289         if (*nextToken == '\n'                         // Wrap on newline, duh
1290             || (linePos + nextTokenLen > outputWidth)) // Wrap at outputWidth
1291         {
1292             printf("\n");
1293             linePos = 0;
1294             firstLine = false;
1295             if (*nextToken == '\n')
1296                 ++nextToken;
1297             continue;
1298         }
1299         if (!firstLine && linePos < wrapIndent) {  // Indent to wrapIndent
1300             printf("%*s", wrapIndent , "");
1301             linePos = wrapIndent;
1302             if (*nextToken == ' ') {
1303                 ++nextToken;
1304                 continue;
1305             }
1306         }
1307         printf("%.*s", nextTokenLen, nextToken);
1308         linePos += nextTokenLen;
1309         nextToken += nextTokenLen;
1310     }
1311 }
1312
1313 /*!
1314     Prints out an option with its description wrapped at the
1315     description starting point. If \a skipIndent is true, the
1316     indentation to the option is not outputted (used by marked option
1317     version of desc()). Extra spaces between option and its
1318     description is filled with\a fillChar, if there's available
1319     space.
1320 */
1321 void Configure::desc(const char *option, const char *description, bool skipIndent, char fillChar)
1322 {
1323     if (!skipIndent)
1324         printf("%*s", optionIndent, "");
1325
1326     int remaining  = descIndent - optionIndent - strlen(option);
1327     int wrapIndent = descIndent + qMax(0, 1 - remaining);
1328     printf("%s", option);
1329
1330     if (remaining > 2) {
1331         printf(" "); // Space in front
1332         for (int i = remaining; i > 2; --i)
1333             printf("%c", fillChar); // Fill, if available space
1334     }
1335     printf(" "); // Space between option and description
1336
1337     desc(description, wrapIndent, wrapIndent);
1338     printf("\n");
1339 }
1340
1341 /*!
1342     Same as above, except it also marks an option with an '*', if
1343     the option is default action.
1344 */
1345 void Configure::desc(const char *mark_option, const char *mark, const char *option, const char *description, char fillChar)
1346 {
1347     const QString markedAs = dictionary.value(mark_option);
1348     if (markedAs == "auto" && markedAs == mark) // both "auto", always => +
1349         printf(" +  ");
1350     else if (markedAs == "auto")                // setting marked as "auto" and option is default => +
1351         printf(" %c  " , (defaultTo(mark_option) == QLatin1String(mark))? '+' : ' ');
1352     else if (QLatin1String(mark) == "auto" && markedAs != "no")     // description marked as "auto" and option is available => +
1353         printf(" %c  " , checkAvailability(mark_option) ? '+' : ' ');
1354     else                                        // None are "auto", (markedAs == mark) => *
1355         printf(" %c  " , markedAs == QLatin1String(mark) ? '*' : ' ');
1356
1357     desc(option, description, true, fillChar);
1358 }
1359
1360 /*!
1361     Modifies the default configuration based on given -platform option.
1362     Eg. switches to different default styles for Windows CE.
1363 */
1364 void Configure::applySpecSpecifics()
1365 {
1366     if (dictionary[ "XQMAKESPEC" ].startsWith("wince")) {
1367         dictionary[ "STYLE_WINDOWSXP" ]     = "no";
1368         dictionary[ "STYLE_WINDOWSVISTA" ]  = "no";
1369         dictionary[ "STYLE_PLASTIQUE" ]     = "no";
1370         dictionary[ "STYLE_CLEANLOOKS" ]    = "no";
1371         dictionary[ "STYLE_WINDOWSCE" ]     = "yes";
1372         dictionary[ "STYLE_WINDOWSMOBILE" ] = "yes";
1373         dictionary[ "STYLE_MOTIF" ]         = "no";
1374         dictionary[ "STYLE_CDE" ]           = "no";
1375         dictionary[ "FREETYPE" ]            = "no";
1376         dictionary[ "OPENGL" ]              = "no";
1377         dictionary[ "OPENSSL" ]             = "no";
1378         dictionary[ "STL" ]                 = "no";
1379         dictionary[ "EXCEPTIONS" ]          = "no";
1380         dictionary[ "RTTI" ]                = "no";
1381         dictionary[ "3DNOW" ]               = "no";
1382         dictionary[ "SSE" ]                 = "no";
1383         dictionary[ "SSE2" ]                = "no";
1384         dictionary[ "MMX" ]                 = "no";
1385         dictionary[ "IWMMXT" ]              = "no";
1386         dictionary[ "CE_CRT" ]              = "yes";
1387         dictionary[ "DIRECTSHOW" ]          = "no";
1388         // We only apply MMX/IWMMXT for mkspecs we know they work
1389         if (dictionary[ "XQMAKESPEC" ].startsWith("wincewm")) {
1390             dictionary[ "MMX" ]    = "yes";
1391             dictionary[ "IWMMXT" ] = "yes";
1392             dictionary[ "DIRECTSHOW" ] = "yes";
1393         }
1394         dictionary[ "QT_HOST_PREFIX" ]      = dictionary[ "QT_INSTALL_PREFIX" ];
1395         dictionary[ "QT_INSTALL_PREFIX" ]   = "";
1396
1397     } else if (dictionary[ "XQMAKESPEC" ].startsWith("linux")) { //TODO actually wrong.
1398       //TODO
1399         dictionary[ "STYLE_WINDOWSXP" ]     = "no";
1400         dictionary[ "STYLE_WINDOWSVISTA" ]  = "no";
1401         dictionary[ "KBD_DRIVERS" ]         = "tty";
1402         dictionary[ "GFX_DRIVERS" ]         = "linuxfb";
1403         dictionary[ "MOUSE_DRIVERS" ]       = "pc linuxtp";
1404         dictionary[ "OPENGL" ]              = "no";
1405         dictionary[ "EXCEPTIONS" ]          = "no";
1406         dictionary[ "DBUS"]                 = "no";
1407         dictionary[ "QT_QWS_DEPTH" ]        = "4 8 16 24 32";
1408         dictionary[ "QT_SXE" ]              = "no";
1409         dictionary[ "QT_INOTIFY" ]          = "no";
1410         dictionary[ "QT_LPR" ]              = "no";
1411         dictionary[ "QT_CUPS" ]             = "no";
1412         dictionary[ "QT_GLIB" ]             = "no";
1413         dictionary[ "QT_ICONV" ]            = "no";
1414
1415         dictionary["DECORATIONS"]           = "default windows styled";
1416     }
1417 }
1418
1419 QString Configure::locateFileInPaths(const QString &fileName, const QStringList &paths)
1420 {
1421     QDir d;
1422     for (QStringList::ConstIterator it = paths.begin(); it != paths.end(); ++it) {
1423         // Remove any leading or trailing ", this is commonly used in the environment
1424         // variables
1425         QString path = (*it);
1426         if (path.startsWith("\""))
1427             path = path.right(path.length() - 1);
1428         if (path.endsWith("\""))
1429             path = path.left(path.length() - 1);
1430         if (d.exists(path + QDir::separator() + fileName)) {
1431             return (path);
1432         }
1433     }
1434     return QString();
1435 }
1436
1437 QString Configure::locateFile(const QString &fileName)
1438 {
1439     QString file = fileName.toLower();
1440     QStringList paths;
1441 #if defined(Q_OS_WIN32)
1442     QRegExp splitReg("[;,]");
1443 #else
1444     QRegExp splitReg("[:]");
1445 #endif
1446     if (file.endsWith(".h"))
1447         paths = QString::fromLocal8Bit(getenv("INCLUDE")).split(splitReg, QString::SkipEmptyParts);
1448     else if (file.endsWith(".lib"))
1449         paths = QString::fromLocal8Bit(getenv("LIB")).split(splitReg, QString::SkipEmptyParts);
1450     else
1451         paths = QString::fromLocal8Bit(getenv("PATH")).split(splitReg, QString::SkipEmptyParts);
1452     return locateFileInPaths(file, paths);
1453 }
1454
1455 // Output helper functions ---------------------------------[ Stop ]-
1456
1457
1458 bool Configure::displayHelp()
1459 {
1460     if (dictionary[ "HELP" ] == "yes") {
1461         desc("Usage: configure\n"
1462                     "[-release] [-debug] [-debug-and-release] [-shared] [-static]\n"
1463                     "[-no-fast] [-fast] [-no-exceptions] [-exceptions]\n"
1464                     "[-no-accessibility] [-accessibility] [-no-rtti] [-rtti]\n"
1465                     "[-no-stl] [-stl] [-no-sql-<driver>] [-qt-sql-<driver>]\n"
1466                     "[-plugin-sql-<driver>] [-system-sqlite]\n"
1467                     "[-D <define>] [-I <includepath>] [-L <librarypath>]\n"
1468                     "[-help] [-no-dsp] [-dsp] [-no-vcproj] [-vcproj]\n"
1469                     "[-no-qmake] [-qmake] [-dont-process] [-process]\n"
1470                     "[-no-style-<style>] [-qt-style-<style>] [-redo]\n"
1471                     "[-saveconfig <config>] [-loadconfig <config>]\n"
1472                     "[-qt-zlib] [-system-zlib] [-qt-pcre] [-system-pcre] [-no-gif]\n"
1473                     "[-no-libpng] [-qt-libpng] [-system-libpng]\n"
1474                     "[-no-libjpeg] [-qt-libjpeg] [-system-libjpeg]\n"
1475                     "[-mmx] [-no-mmx] [-3dnow] [-no-3dnow] [-sse] [-no-sse] [-sse2] [-no-sse2]\n"
1476                     "[-no-iwmmxt] [-iwmmxt] [-openssl] [-openssl-linked]\n"
1477                     "[-no-openssl] [-no-dbus] [-dbus] [-dbus-linked] [-platform <spec>]\n"
1478                     "[-qtnamespace <namespace>] [-qtlibinfix <infix>] [-no-phonon]\n"
1479                     "[-phonon] [-no-phonon-backend] [-phonon-backend]\n"
1480                     "[-no-multimedia] [-multimedia] [-no-audio-backend] [-audio-backend]\n"
1481                     "[-no-script] [-script] [-no-scripttools] [-scripttools]\n"
1482                     "[-no-webkit] [-webkit] [-webkit-debug]\n"
1483                     "[-no-directwrite] [-directwrite] [-no-widgets] [-icu]\n\n", 0, 7);
1484
1485         desc("Installation options:\n\n");
1486
1487 #if !defined(EVAL)
1488         desc("Configure options:\n\n");
1489
1490         desc(" The defaults (*) are usually acceptable. A plus (+) denotes a default value"
1491              " that needs to be evaluated. If the evaluation succeeds, the feature is"
1492              " included. Here is a short explanation of each option:\n\n", 0, 1);
1493
1494         desc("BUILD", "release","-release",             "Compile and link Qt with debugging turned off.");
1495         desc("BUILD", "debug",  "-debug",               "Compile and link Qt with debugging turned on.");
1496         desc("BUILDALL", "yes", "-debug-and-release",   "Compile and link two Qt libraries, with and without debugging turned on.\n");
1497
1498         desc("OPENSOURCE", "opensource", "-opensource",   "Compile and link the Open-Source Edition of Qt.");
1499         desc("COMMERCIAL", "commercial", "-commercial",   "Compile and link the Commercial Edition of Qt.\n");
1500
1501         desc("BUILDDEV", "yes", "-developer-build",      "Compile and link Qt with Qt developer options (including auto-tests exporting)\n");
1502
1503         desc("SHARED", "yes",   "-shared",              "Create and use shared Qt libraries.");
1504         desc("SHARED", "no",    "-static",              "Create and use static Qt libraries.\n");
1505
1506         desc("LTCG", "yes",   "-ltcg",                  "Use Link Time Code Generation. (Release builds only)");
1507         desc("LTCG", "no",    "-no-ltcg",               "Do not use Link Time Code Generation.\n");
1508
1509         desc("FAST", "no",      "-no-fast",             "Configure Qt normally by generating Makefiles for all project files.");
1510         desc("FAST", "yes",     "-fast",                "Configure Qt quickly by generating Makefiles only for library and "
1511                                                         "subdirectory targets.  All other Makefiles are created as wrappers "
1512                                                         "which will in turn run qmake\n");
1513
1514         desc(                   "-make <part>",         "Add part to the list of parts to be built at make time.");
1515         for (int i=0; i<defaultBuildParts.size(); ++i)
1516             desc(               "",                     qPrintable(QString("  %1").arg(defaultBuildParts.at(i))), false, ' ');
1517         desc(                   "-nomake <part>",       "Exclude part from the list of parts to be built.\n");
1518
1519         desc("EXCEPTIONS", "no", "-no-exceptions",      "Disable exceptions on platforms that support it.");
1520         desc("EXCEPTIONS", "yes","-exceptions",         "Enable exceptions on platforms that support it.\n");
1521
1522         desc("WIDGETS", "no", "-no-widgets",            "Disable QtWidgets module\n");
1523
1524         desc("ACCESSIBILITY", "no",  "-no-accessibility", "Do not compile Windows Active Accessibility support.");
1525         desc("ACCESSIBILITY", "yes", "-accessibility",    "Compile Windows Active Accessibility support.\n");
1526
1527         desc("STL", "no",       "-no-stl",              "Do not compile STL support.");
1528         desc("STL", "yes",      "-stl",                 "Compile STL support.\n");
1529
1530         desc(                   "-no-sql-<driver>",     "Disable SQL <driver> entirely, by default none are turned on.");
1531         desc(                   "-qt-sql-<driver>",     "Enable a SQL <driver> in the Qt Library.");
1532         desc(                   "-plugin-sql-<driver>", "Enable SQL <driver> as a plugin to be linked to at run time.\n"
1533                                                         "Available values for <driver>:");
1534         desc("SQL_MYSQL", "auto", "",                   "  mysql", ' ');
1535         desc("SQL_PSQL", "auto", "",                    "  psql", ' ');
1536         desc("SQL_OCI", "auto", "",                     "  oci", ' ');
1537         desc("SQL_ODBC", "auto", "",                    "  odbc", ' ');
1538         desc("SQL_TDS", "auto", "",                     "  tds", ' ');
1539         desc("SQL_DB2", "auto", "",                     "  db2", ' ');
1540         desc("SQL_SQLITE", "auto", "",                  "  sqlite", ' ');
1541         desc("SQL_SQLITE2", "auto", "",                 "  sqlite2", ' ');
1542         desc("SQL_IBASE", "auto", "",                   "  ibase", ' ');
1543         desc(                   "",                     "(drivers marked with a '+' have been detected as available on this system)\n", false, ' ');
1544
1545         desc(                   "-system-sqlite",       "Use sqlite from the operating system.\n");
1546
1547         desc("OPENGL", "no","-no-opengl",               "Disables OpenGL functionality\n");
1548         desc("OPENGL", "no","-opengl <api>",            "Enable OpenGL support with specified API version.\n"
1549                                                         "Available values for <api>:");
1550         desc("", "", "",                                "  desktop - Enable support for Desktop OpenGL", ' ');
1551         desc("OPENGL_ES_CM", "no", "",                  "  es1 - Enable support for OpenGL ES Common Profile", ' ');
1552         desc("OPENGL_ES_2",  "no", "",                  "  es2 - Enable support for OpenGL ES 2.0", ' ');
1553
1554         desc("OPENVG", "no","-no-openvg",               "Disables OpenVG functionality\n");
1555         desc("OPENVG", "yes","-openvg",                 "Enables OpenVG functionality");
1556         desc(                   "-force-asserts",       "Activate asserts in release mode.\n");
1557 #endif
1558         desc(                   "-platform <spec>",     "The operating system and compiler you are building on.\n(default %QMAKESPEC%)\n");
1559         desc(                   "-xplatform <spec>",    "The operating system and compiler you are cross compiling to.\n");
1560         desc(                   "",                     "See the README file for a list of supported operating systems and compilers.\n", false, ' ');
1561
1562 #if !defined(EVAL)
1563         desc(                   "-qtnamespace <namespace>", "Wraps all Qt library code in 'namespace name {...}");
1564         desc(                   "-qtlibinfix <infix>",  "Renames all Qt* libs to Qt*<infix>\n");
1565         desc(                   "-D <define>",          "Add an explicit define to the preprocessor.");
1566         desc(                   "-I <includepath>",     "Add an explicit include path.");
1567         desc(                   "-L <librarypath>",     "Add an explicit library path.");
1568         desc(                   "-l <libraryname>",     "Add an explicit library name, residing in a librarypath.\n");
1569 #endif
1570
1571         desc(                   "-help, -h, -?",        "Display this information.\n");
1572
1573 #if !defined(EVAL)
1574         // 3rd party stuff options go below here --------------------------------------------------------------------------------
1575         desc("Third Party Libraries:\n\n");
1576
1577         desc("ZLIB", "qt",      "-qt-zlib",             "Use the zlib bundled with Qt.");
1578         desc("ZLIB", "system",  "-system-zlib",         "Use zlib from the operating system.\nSee http://www.gzip.org/zlib\n");
1579
1580         desc("PCRE", "qt",       "-qt-pcre",            "Use the PCRE library bundled with Qt.");
1581         desc("PCRE", "qt",       "-system-pcre",        "Use the PCRE library from the operating system.\nSee http://pcre.org/\n");
1582
1583         desc("ICU", "yes",       "-icu",                "Use the ICU library.");
1584         desc("ICU", "no",        "-no-icu",             "Do not use the ICU library.\nSee http://site.icu-project.org/\n");
1585
1586         desc("GIF", "no",       "-no-gif",              "Do not compile GIF reading support.");
1587
1588         desc("LIBPNG", "no",    "-no-libpng",           "Do not compile PNG support.");
1589         desc("LIBPNG", "qt",    "-qt-libpng",           "Use the libpng bundled with Qt.");
1590         desc("LIBPNG", "system","-system-libpng",       "Use libpng from the operating system.\nSee http://www.libpng.org/pub/png\n");
1591
1592         desc("LIBJPEG", "no",    "-no-libjpeg",         "Do not compile JPEG support.");
1593         desc("LIBJPEG", "qt",    "-qt-libjpeg",         "Use the libjpeg bundled with Qt.");
1594         desc("LIBJPEG", "system","-system-libjpeg",     "Use libjpeg from the operating system.\nSee http://www.ijg.org\n");
1595
1596         desc("FREETYPE", "no",   "-no-freetype",        "Do not compile in Freetype2 support.");
1597         desc("FREETYPE", "yes",  "-qt-freetype",        "Use the libfreetype bundled with Qt.");
1598 #endif
1599         // Qt\Windows only options go below here --------------------------------------------------------------------------------
1600         desc("Qt for Windows only:\n\n");
1601
1602         desc("DSPFILES", "no",  "-no-dsp",              "Do not generate VC++ .dsp files.");
1603         desc("DSPFILES", "yes", "-dsp",                 "Generate VC++ .dsp files, only if spec \"win32-msvc\".\n");
1604
1605         desc("VCPROJFILES", "no", "-no-vcproj",         "Do not generate VC++ .vcproj files.");
1606         desc("VCPROJFILES", "yes", "-vcproj",           "Generate VC++ .vcproj files, only if platform \"win32-msvc.net\".\n");
1607
1608         desc("INCREDIBUILD_XGE", "no", "-no-incredibuild-xge", "Do not add IncrediBuild XGE distribution commands to custom build steps.");
1609         desc("INCREDIBUILD_XGE", "yes", "-incredibuild-xge",   "Add IncrediBuild XGE distribution commands to custom build steps. This will distribute MOC and UIC steps, and other custom buildsteps which are added to the INCREDIBUILD_XGE variable.\n(The IncrediBuild distribution commands are only added to Visual Studio projects)\n");
1610
1611         desc("PLUGIN_MANIFESTS", "no", "-no-plugin-manifests", "Do not embed manifests in plugins.");
1612         desc("PLUGIN_MANIFESTS", "yes", "-plugin-manifests",   "Embed manifests in plugins.\n");
1613
1614 #if !defined(EVAL)
1615         desc("BUILD_QMAKE", "no", "-no-qmake",          "Do not compile qmake.");
1616         desc("BUILD_QMAKE", "yes", "-qmake",            "Compile qmake.\n");
1617
1618         desc("NOPROCESS", "yes", "-dont-process",       "Do not generate Makefiles/Project files. This will override -no-fast if specified.");
1619         desc("NOPROCESS", "no",  "-process",            "Generate Makefiles/Project files.\n");
1620
1621         desc("RTTI", "no",      "-no-rtti",             "Do not compile runtime type information.");
1622         desc("RTTI", "yes",     "-rtti",                "Compile runtime type information.\n");
1623         desc("MMX", "no",       "-no-mmx",              "Do not compile with use of MMX instructions");
1624         desc("MMX", "yes",      "-mmx",                 "Compile with use of MMX instructions");
1625         desc("3DNOW", "no",     "-no-3dnow",            "Do not compile with use of 3DNOW instructions");
1626         desc("3DNOW", "yes",    "-3dnow",               "Compile with use of 3DNOW instructions");
1627         desc("SSE", "no",       "-no-sse",              "Do not compile with use of SSE instructions");
1628         desc("SSE", "yes",      "-sse",                 "Compile with use of SSE instructions");
1629         desc("SSE2", "no",      "-no-sse2",             "Do not compile with use of SSE2 instructions");
1630         desc("SSE2", "yes",      "-sse2",               "Compile with use of SSE2 instructions");
1631         desc("OPENSSL", "no",    "-no-openssl",         "Do not compile in OpenSSL support");
1632         desc("OPENSSL", "yes",   "-openssl",            "Compile in run-time OpenSSL support");
1633         desc("OPENSSL", "linked","-openssl-linked",     "Compile in linked OpenSSL support");
1634         desc("DBUS", "no",       "-no-dbus",            "Do not compile in D-Bus support");
1635         desc("DBUS", "yes",      "-dbus",               "Compile in D-Bus support and load libdbus-1 dynamically");
1636         desc("DBUS", "linked",   "-dbus-linked",        "Compile in D-Bus support and link to libdbus-1");
1637         desc("PHONON_BACKEND","no", "-no-phonon-backend","Do not compile the platform-specific Phonon backend-plugin");
1638         desc("PHONON_BACKEND","yes","-phonon-backend",  "Compile in the platform-specific Phonon backend-plugin");
1639         desc("AUDIO_BACKEND", "no","-no-audio-backend", "Do not compile in the platform audio backend into QtMultimedia");
1640         desc("AUDIO_BACKEND", "yes","-audio-backend",   "Compile in the platform audio backend into QtMultimedia");
1641         desc("QML_DEBUG", "no",    "-no-qml-debug",     "Do not build the QML debugging support");
1642         desc("QML_DEBUG", "yes",   "-qml-debug",        "Build the QML debugging support");
1643         desc("DIRECTWRITE", "no", "-no-directwrite", "Do not build support for DirectWrite font rendering");
1644         desc("DIRECTWRITE", "yes", "-directwrite", "Build support for DirectWrite font rendering (experimental, requires DirectWrite availability on target systems, e.g. Windows Vista with Platform Update, Windows 7, etc.)");
1645
1646         desc(                   "-no-style-<style>",    "Disable <style> entirely.");
1647         desc(                   "-qt-style-<style>",    "Enable <style> in the Qt Library.\nAvailable styles: ");
1648
1649         desc("STYLE_WINDOWS", "yes", "",                "  windows", ' ');
1650         desc("STYLE_WINDOWSXP", "auto", "",             "  windowsxp", ' ');
1651         desc("STYLE_WINDOWSVISTA", "auto", "",          "  windowsvista", ' ');
1652         desc("STYLE_PLASTIQUE", "yes", "",              "  plastique", ' ');
1653         desc("STYLE_CLEANLOOKS", "yes", "",             "  cleanlooks", ' ');
1654         desc("STYLE_MOTIF", "yes", "",                  "  motif", ' ');
1655         desc("STYLE_CDE", "yes", "",                    "  cde", ' ');
1656         desc("STYLE_WINDOWSCE", "yes", "",              "  windowsce", ' ');
1657         desc("STYLE_WINDOWSMOBILE" , "yes", "",         "  windowsmobile", ' ');
1658         desc("NATIVE_GESTURES", "no", "-no-native-gestures", "Do not use native gestures on Windows 7.");
1659         desc("NATIVE_GESTURES", "yes", "-native-gestures", "Use native gestures on Windows 7.");
1660         desc("MSVC_MP", "no", "-no-mp",                 "Do not use multiple processors for compiling with MSVC");
1661         desc("MSVC_MP", "yes", "-mp",                   "Use multiple processors for compiling with MSVC (-MP)");
1662
1663 /*      We do not support -qconfig on Windows yet
1664
1665         desc(                   "-qconfig <local>",     "Use src/tools/qconfig-local.h rather than the default.\nPossible values for local:");
1666         for (int i=0; i<allConfigs.size(); ++i)
1667             desc(               "",                     qPrintable(QString("  %1").arg(allConfigs.at(i))), false, ' ');
1668         printf("\n");
1669 */
1670 #endif
1671         desc(                   "-loadconfig <config>", "Run configure with the parameters from file configure_<config>.cache.");
1672         desc(                   "-saveconfig <config>", "Run configure and save the parameters in file configure_<config>.cache.");
1673         desc(                   "-redo",                "Run configure with the same parameters as last time.\n");
1674
1675         // Qt\Windows CE only options go below here -----------------------------------------------------------------------------
1676         desc("Qt for Windows CE only:\n\n");
1677         desc("IWMMXT", "no",       "-no-iwmmxt",           "Do not compile with use of IWMMXT instructions");
1678         desc("IWMMXT", "yes",      "-iwmmxt",              "Do compile with use of IWMMXT instructions (Qt for Windows CE on Arm only)");
1679         desc("CE_CRT", "no",       "-no-crt" ,             "Do not add the C runtime to default deployment rules");
1680         desc("CE_CRT", "yes",      "-qt-crt",              "Qt identifies C runtime during project generation");
1681         desc(                      "-crt <path>",          "Specify path to C runtime used for project generation.");
1682         desc("CETEST", "no",       "-no-cetest",           "Do not compile Windows CE remote test application");
1683         desc("CETEST", "yes",      "-cetest",              "Compile Windows CE remote test application");
1684         desc(                      "-signature <file>",    "Use file for signing the target project");
1685
1686         desc("DIRECTSHOW", "no",   "-phonon-wince-ds9",    "Enable Phonon Direct Show 9 backend for Windows CE");
1687         return true;
1688     }
1689     return false;
1690 }
1691
1692 QString Configure::findFileInPaths(const QString &fileName, const QString &paths)
1693 {
1694 #if defined(Q_OS_WIN32)
1695     QRegExp splitReg("[;,]");
1696 #else
1697     QRegExp splitReg("[:]");
1698 #endif
1699     QStringList pathList = paths.split(splitReg, QString::SkipEmptyParts);
1700     QDir d;
1701     for (QStringList::ConstIterator it = pathList.begin(); it != pathList.end(); ++it) {
1702         // Remove any leading or trailing ", this is commonly used in the environment
1703         // variables
1704         QString path = (*it);
1705         if (path.startsWith('\"'))
1706             path = path.right(path.length() - 1);
1707         if (path.endsWith('\"'))
1708             path = path.left(path.length() - 1);
1709         if (d.exists(path + QDir::separator() + fileName))
1710             return path;
1711     }
1712     return QString();
1713 }
1714
1715 static QString mingwPaths(const QString &mingwPath, const QString &pathName)
1716 {
1717     QString ret;
1718     QDir mingwDir = QFileInfo(mingwPath).dir();
1719     const QFileInfoList subdirs = mingwDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
1720     for (int i = 0 ;i < subdirs.length(); ++i) {
1721         const QFileInfo &fi = subdirs.at(i);
1722         const QString name = fi.fileName();
1723         if (name == pathName)
1724             ret += fi.absoluteFilePath() + ';';
1725         else if (name.contains("mingw"))
1726             ret += fi.absoluteFilePath() + QDir::separator() + pathName + ';';
1727     }
1728     return ret;
1729 }
1730
1731 bool Configure::findFile(const QString &fileName)
1732 {
1733     const QString file = fileName.toLower();
1734     const QString pathEnvVar = QString::fromLocal8Bit(getenv("PATH"));
1735     const QString mingwPath = dictionary["QMAKESPEC"].endsWith("-g++") ?
1736         findFileInPaths("g++.exe", pathEnvVar) : QString();
1737
1738     QString paths;
1739     if (file.endsWith(".h")) {
1740         if (!mingwPath.isNull()) {
1741             if (!findFileInPaths(file, mingwPaths(mingwPath, "include")).isNull())
1742                 return true;
1743             //now let's try the additional compiler path
1744
1745             const QFileInfoList mingwConfigs = QDir(mingwPath + QLatin1String("/../lib/gcc")).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
1746             for (int i = 0; i < mingwConfigs.length(); ++i) {
1747                 const QDir mingwLibDir = mingwConfigs.at(i).absoluteFilePath();
1748                 foreach(const QFileInfo &version, mingwLibDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
1749                     if (!findFileInPaths(file, version.absoluteFilePath() + QLatin1String("/include")).isNull())
1750                         return true;
1751                 }
1752             }
1753         }
1754         paths = QString::fromLocal8Bit(getenv("INCLUDE"));
1755     } else if (file.endsWith(".lib") ||  file.endsWith(".a")) {
1756         if (!mingwPath.isNull() && !findFileInPaths(file, mingwPaths(mingwPath, "lib")).isNull())
1757             return true;
1758         paths = QString::fromLocal8Bit(getenv("LIB"));
1759     } else {
1760         paths = pathEnvVar;
1761     }
1762     return !findFileInPaths(file, paths).isNull();
1763 }
1764
1765 /*!
1766     Default value for options marked as "auto" if the test passes.
1767     (Used both by the autoDetection() below, and the desc() function
1768     to mark (+) the default option of autodetecting options.
1769 */
1770 QString Configure::defaultTo(const QString &option)
1771 {
1772     // We prefer using the system version of the 3rd party libs
1773     if (option == "ZLIB"
1774         || option == "PCRE"
1775         || option == "LIBJPEG"
1776         || option == "LIBPNG")
1777         return "system";
1778
1779     // PNG is always built-in, never a plugin
1780     if (option == "PNG")
1781         return "yes";
1782
1783     // These database drivers and image formats can be built-in or plugins.
1784     // Prefer plugins when Qt is shared.
1785     if (dictionary[ "SHARED" ] == "yes") {
1786         if (option == "SQL_MYSQL"
1787             || option == "SQL_MYSQL"
1788             || option == "SQL_ODBC"
1789             || option == "SQL_OCI"
1790             || option == "SQL_PSQL"
1791             || option == "SQL_TDS"
1792             || option == "SQL_DB2"
1793             || option == "SQL_SQLITE"
1794             || option == "SQL_SQLITE2"
1795             || option == "SQL_IBASE"
1796             || option == "JPEG"
1797             || option == "GIF")
1798             return "plugin";
1799     }
1800
1801     // By default we do not want to compile OCI driver when compiling with
1802     // MinGW, due to lack of such support from Oracle. It prob. wont work.
1803     // (Customer may force the use though)
1804     if (dictionary["QMAKESPEC"].endsWith("-g++")
1805         && option == "SQL_OCI")
1806         return "no";
1807
1808     if (option == "SYNCQT"
1809         && (!QFile::exists(sourcePath + "/bin/syncqt") ||
1810             !QFile::exists(sourcePath + "/bin/syncqt.bat")))
1811         return "no";
1812
1813     return "yes";
1814 }
1815
1816 /*!
1817     Checks the system for the availability of a feature.
1818     Returns true if the feature is available, else false.
1819 */
1820 bool Configure::checkAvailability(const QString &part)
1821 {
1822     bool available = false;
1823     if (part == "STYLE_WINDOWSXP")
1824         available = findFile("uxtheme.h");
1825
1826     else if (part == "ZLIB")
1827         available = findFile("zlib.h");
1828
1829     else if (part == "PCRE")
1830         available = findFile("pcre.h");
1831
1832     else if (part == "ICU")
1833         available = findFile("unicode/utypes.h") && findFile("unicode/ucol.h") && findFile("unicode/ustring.h") && findFile("icuin.lib");
1834
1835     else if (part == "LIBJPEG")
1836         available = findFile("jpeglib.h");
1837     else if (part == "LIBPNG")
1838         available = findFile("png.h");
1839     else if (part == "SQL_MYSQL")
1840         available = findFile("mysql.h") && findFile("libmySQL.lib");
1841     else if (part == "SQL_ODBC")
1842         available = findFile("sql.h") && findFile("sqlext.h") && findFile("odbc32.lib");
1843     else if (part == "SQL_OCI")
1844         available = findFile("oci.h") && findFile("oci.lib");
1845     else if (part == "SQL_PSQL")
1846         available = findFile("libpq-fe.h") && findFile("libpq.lib") && findFile("ws2_32.lib") && findFile("advapi32.lib");
1847     else if (part == "SQL_TDS")
1848         available = findFile("sybfront.h") && findFile("sybdb.h") && findFile("ntwdblib.lib");
1849     else if (part == "SQL_DB2")
1850         available = findFile("sqlcli.h") && findFile("sqlcli1.h") && findFile("db2cli.lib");
1851     else if (part == "SQL_SQLITE")
1852         available = true; // Built in, we have a fork
1853     else if (part == "SQL_SQLITE_LIB") {
1854         if (dictionary[ "SQL_SQLITE_LIB" ] == "system") {
1855             available = findFile("sqlite3.h") && findFile("sqlite3.lib");
1856             if (available)
1857                 dictionary[ "QT_LFLAGS_SQLITE" ] += "sqlite3.lib";
1858         } else
1859             available = true;
1860     } else if (part == "SQL_SQLITE2")
1861         available = findFile("sqlite.h") && findFile("sqlite.lib");
1862     else if (part == "SQL_IBASE")
1863         available = findFile("ibase.h") && (findFile("gds32_ms.lib") || findFile("gds32.lib"));
1864     else if (part == "IWMMXT")
1865         available = (dictionary.value("XQMAKESPEC").startsWith("wince"));
1866     else if (part == "OPENGL_ES_CM")
1867         available = (dictionary.value("XQMAKESPEC").startsWith("wince"));
1868     else if (part == "OPENGL_ES_2")
1869         available = (dictionary.value("XQMAKESPEC").startsWith("wince"));
1870     else if (part == "DIRECTSHOW")
1871         available = (dictionary.value("XQMAKESPEC").startsWith("wince"));
1872     else if (part == "SSE2")
1873         available = (dictionary.value("QMAKESPEC") != "win32-msvc");
1874     else if (part == "3DNOW")
1875         available = (dictionary.value("QMAKESPEC") != "win32-msvc") && (dictionary.value("QMAKESPEC") != "win32-icc") && findFile("mm3dnow.h");
1876     else if (part == "MMX" || part == "SSE")
1877         available = (dictionary.value("QMAKESPEC") != "win32-msvc");
1878     else if (part == "OPENSSL")
1879         available = findFile("openssl\\ssl.h");
1880     else if (part == "DBUS")
1881         available = findFile("dbus\\dbus.h");
1882     else if (part == "CETEST") {
1883         QString rapiHeader = locateFile("rapi.h");
1884         QString rapiLib = locateFile("rapi.lib");
1885         available = (dictionary.value("XQMAKESPEC").startsWith("wince")) && !rapiHeader.isEmpty() && !rapiLib.isEmpty();
1886         if (available) {
1887             dictionary[ "QT_CE_RAPI_INC" ] += QLatin1String("\"") + rapiHeader + QLatin1String("\"");
1888             dictionary[ "QT_CE_RAPI_LIB" ] += QLatin1String("\"") + rapiLib + QLatin1String("\"");
1889         }
1890         else if (dictionary[ "CETEST_REQUESTED" ] == "yes") {
1891             cout << "cetest could not be enabled: rapi.h and rapi.lib could not be found." << endl;
1892             cout << "Make sure the environment is set up for compiling with ActiveSync." << endl;
1893             dictionary[ "DONE" ] = "error";
1894         }
1895     }
1896     else if (part == "INCREDIBUILD_XGE")
1897         available = findFile("BuildConsole.exe") && findFile("xgConsole.exe");
1898     else if (part == "PHONON") {
1899         available = findFile("vmr9.h") && findFile("dshow.h") && findFile("dmo.h") && findFile("dmodshow.h")
1900             && (findFile("strmiids.lib") || findFile("libstrmiids.a"))
1901             && (findFile("dmoguids.lib") || findFile("libdmoguids.a"))
1902             && (findFile("msdmo.lib") || findFile("libmsdmo.a"))
1903             && findFile("d3d9.h");
1904
1905         if (!available) {
1906             cout << "All the required DirectShow/Direct3D files couldn't be found." << endl
1907                  << "Make sure you have either the platform SDK AND the DirectShow SDK or the Windows SDK installed." << endl
1908                  << "If you have the DirectShow SDK installed, please make sure that you have run the <path to SDK>\\SetEnv.Cmd script." << endl;
1909             if (!findFile("vmr9.h"))  cout << "vmr9.h not found" << endl;
1910             if (!findFile("dshow.h")) cout << "dshow.h not found" << endl;
1911             if (!findFile("strmiids.lib")) cout << "strmiids.lib not found" << endl;
1912             if (!findFile("dmoguids.lib")) cout << "dmoguids.lib not found" << endl;
1913             if (!findFile("msdmo.lib")) cout << "msdmo.lib not found" << endl;
1914             if (!findFile("d3d9.h")) cout << "d3d9.h not found" << endl;
1915         }
1916     } else if (part == "WMSDK") {
1917         available = findFile("wmsdk.h");
1918     } else if (part == "V8SNAPSHOT") {
1919         available = true;
1920     } else if (part == "AUDIO_BACKEND") {
1921         available = true;
1922     } else if (part == "DIRECTWRITE") {
1923         available = findFile("dwrite.h") && findFile("d2d1.h") && findFile("dwrite.lib");
1924     }
1925
1926     return available;
1927 }
1928
1929 /*
1930     Autodetect options marked as "auto".
1931 */
1932 void Configure::autoDetection()
1933 {
1934     // Style detection
1935     if (dictionary["STYLE_WINDOWSXP"] == "auto")
1936         dictionary["STYLE_WINDOWSXP"] = checkAvailability("STYLE_WINDOWSXP") ? defaultTo("STYLE_WINDOWSXP") : "no";
1937     if (dictionary["STYLE_WINDOWSVISTA"] == "auto") // Vista style has the same requirements as XP style
1938         dictionary["STYLE_WINDOWSVISTA"] = checkAvailability("STYLE_WINDOWSXP") ? defaultTo("STYLE_WINDOWSVISTA") : "no";
1939
1940     // Compression detection
1941     if (dictionary["ZLIB"] == "auto")
1942         dictionary["ZLIB"] =  checkAvailability("ZLIB") ? defaultTo("ZLIB") : "qt";
1943
1944     // PCRE detection
1945     if (dictionary["PCRE"] == "auto")
1946         dictionary["PCRE"] = checkAvailability("PCRE") ? defaultTo("PCRE") : "qt";
1947
1948     // ICU detection
1949     if (dictionary["ICU"] == "auto")
1950         dictionary["ICU"] = checkAvailability("ICU") ? "yes" : "no";
1951
1952     // Image format detection
1953     if (dictionary["GIF"] == "auto")
1954         dictionary["GIF"] = defaultTo("GIF");
1955     if (dictionary["JPEG"] == "auto")
1956         dictionary["JPEG"] = defaultTo("JPEG");
1957     if (dictionary["PNG"] == "auto")
1958         dictionary["PNG"] = defaultTo("PNG");
1959     if (dictionary["LIBJPEG"] == "auto")
1960         dictionary["LIBJPEG"] = checkAvailability("LIBJPEG") ? defaultTo("LIBJPEG") : "qt";
1961     if (dictionary["LIBPNG"] == "auto")
1962         dictionary["LIBPNG"] = checkAvailability("LIBPNG") ? defaultTo("LIBPNG") : "qt";
1963
1964     // SQL detection (not on by default)
1965     if (dictionary["SQL_MYSQL"] == "auto")
1966         dictionary["SQL_MYSQL"] = checkAvailability("SQL_MYSQL") ? defaultTo("SQL_MYSQL") : "no";
1967     if (dictionary["SQL_ODBC"] == "auto")
1968         dictionary["SQL_ODBC"] = checkAvailability("SQL_ODBC") ? defaultTo("SQL_ODBC") : "no";
1969     if (dictionary["SQL_OCI"] == "auto")
1970         dictionary["SQL_OCI"] = checkAvailability("SQL_OCI") ? defaultTo("SQL_OCI") : "no";
1971     if (dictionary["SQL_PSQL"] == "auto")
1972         dictionary["SQL_PSQL"] = checkAvailability("SQL_PSQL") ? defaultTo("SQL_PSQL") : "no";
1973     if (dictionary["SQL_TDS"] == "auto")
1974         dictionary["SQL_TDS"] = checkAvailability("SQL_TDS") ? defaultTo("SQL_TDS") : "no";
1975     if (dictionary["SQL_DB2"] == "auto")
1976         dictionary["SQL_DB2"] = checkAvailability("SQL_DB2") ? defaultTo("SQL_DB2") : "no";
1977     if (dictionary["SQL_SQLITE"] == "auto")
1978         dictionary["SQL_SQLITE"] = checkAvailability("SQL_SQLITE") ? defaultTo("SQL_SQLITE") : "no";
1979     if (dictionary["SQL_SQLITE_LIB"] == "system")
1980         if (!checkAvailability("SQL_SQLITE_LIB"))
1981             dictionary["SQL_SQLITE_LIB"] = "no";
1982     if (dictionary["SQL_SQLITE2"] == "auto")
1983         dictionary["SQL_SQLITE2"] = checkAvailability("SQL_SQLITE2") ? defaultTo("SQL_SQLITE2") : "no";
1984     if (dictionary["SQL_IBASE"] == "auto")
1985         dictionary["SQL_IBASE"] = checkAvailability("SQL_IBASE") ? defaultTo("SQL_IBASE") : "no";
1986     if (dictionary["MMX"] == "auto")
1987         dictionary["MMX"] = checkAvailability("MMX") ? "yes" : "no";
1988     if (dictionary["3DNOW"] == "auto")
1989         dictionary["3DNOW"] = checkAvailability("3DNOW") ? "yes" : "no";
1990     if (dictionary["SSE"] == "auto")
1991         dictionary["SSE"] = checkAvailability("SSE") ? "yes" : "no";
1992     if (dictionary["SSE2"] == "auto")
1993         dictionary["SSE2"] = checkAvailability("SSE2") ? "yes" : "no";
1994     if (dictionary["IWMMXT"] == "auto")
1995         dictionary["IWMMXT"] = checkAvailability("IWMMXT") ? "yes" : "no";
1996     if (dictionary["OPENSSL"] == "auto")
1997         dictionary["OPENSSL"] = checkAvailability("OPENSSL") ? "yes" : "no";
1998     if (dictionary["DBUS"] == "auto")
1999         dictionary["DBUS"] = checkAvailability("DBUS") ? "yes" : "no";
2000     if (dictionary["V8SNAPSHOT"] == "auto")
2001         dictionary["V8SNAPSHOT"] = (dictionary["V8"] == "yes") && checkAvailability("V8SNAPSHOT") ? "yes" : "no";
2002     if (dictionary["QML_DEBUG"] == "auto")
2003         dictionary["QML_DEBUG"] = dictionary["QML"] == "yes" ? "yes" : "no";
2004     if (dictionary["AUDIO_BACKEND"] == "auto")
2005         dictionary["AUDIO_BACKEND"] = checkAvailability("AUDIO_BACKEND") ? "yes" : "no";
2006     if (dictionary["WMSDK"] == "auto")
2007         dictionary["WMSDK"] = checkAvailability("WMSDK") ? "yes" : "no";
2008
2009     // Qt/WinCE remote test application
2010     if (dictionary["CETEST"] == "auto")
2011         dictionary["CETEST"] = checkAvailability("CETEST") ? "yes" : "no";
2012
2013     // Detection of IncrediBuild buildconsole
2014     if (dictionary["INCREDIBUILD_XGE"] == "auto")
2015         dictionary["INCREDIBUILD_XGE"] = checkAvailability("INCREDIBUILD_XGE") ? "yes" : "no";
2016
2017     // Mark all unknown "auto" to the default value..
2018     for (QMap<QString,QString>::iterator i = dictionary.begin(); i != dictionary.end(); ++i) {
2019         if (i.value() == "auto")
2020             i.value() = defaultTo(i.key());
2021     }
2022 }
2023
2024 bool Configure::verifyConfiguration()
2025 {
2026     if (dictionary["SQL_SQLITE_LIB"] == "no" && dictionary["SQL_SQLITE"] != "no") {
2027         cout << "WARNING: Configure could not detect the presence of a system SQLite3 lib." << endl
2028              << "Configure will therefore continue with the SQLite3 lib bundled with Qt." << endl
2029              << "(Press any key to continue..)";
2030         if (_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
2031             exit(0);      // Exit cleanly for Ctrl+C
2032
2033         dictionary["SQL_SQLITE_LIB"] = "qt"; // Set to Qt's bundled lib an continue
2034     }
2035     if (dictionary["QMAKESPEC"].endsWith("-g++")
2036         && dictionary["SQL_OCI"] != "no") {
2037         cout << "WARNING: Qt does not support compiling the Oracle database driver with" << endl
2038              << "MinGW, due to lack of such support from Oracle. Consider disabling the" << endl
2039              << "Oracle driver, as the current build will most likely fail." << endl;
2040         cout << "(Press any key to continue..)";
2041         if (_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
2042             exit(0);      // Exit cleanly for Ctrl+C
2043     }
2044     if (dictionary["QMAKESPEC"].endsWith("win32-msvc.net")) {
2045         cout << "WARNING: The makespec win32-msvc.net is deprecated. Consider using" << endl
2046              << "win32-msvc2002 or win32-msvc2003 instead." << endl;
2047         cout << "(Press any key to continue..)";
2048         if (_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
2049             exit(0);      // Exit cleanly for Ctrl+C
2050     }
2051     if (0 != dictionary["ARM_FPU_TYPE"].size()) {
2052             QStringList l= QStringList()
2053                     << "softvfp"
2054                     << "softvfp+vfpv2"
2055                     << "vfpv2";
2056             if (!(l.contains(dictionary["ARM_FPU_TYPE"])))
2057                     cout << QString("WARNING: Using unsupported fpu flag: %1").arg(dictionary["ARM_FPU_TYPE"]) << endl;
2058     }
2059     if (dictionary["DIRECTWRITE"] == "yes" && !checkAvailability("DIRECTWRITE")) {
2060         cout << "WARNING: To be able to compile the DirectWrite font engine you will" << endl
2061              << "need the Microsoft DirectWrite and Microsoft Direct2D development" << endl
2062              << "files such as headers and libraries." << endl
2063              << "(Press any key to continue..)";
2064         if (_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
2065             exit(0);      // Exit cleanly for Ctrl+C
2066     }
2067
2068     return true;
2069 }
2070
2071 /*
2072  Things that affect the Qt API/ABI:
2073    Options:
2074      minimal-config small-config medium-config large-config full-config
2075
2076    Options:
2077      debug release
2078      stl
2079
2080  Things that do not affect the Qt API/ABI:
2081      system-jpeg no-jpeg jpeg
2082      system-png no-png png
2083      system-zlib no-zlib zlib
2084      no-gif gif
2085      dll staticlib
2086
2087      nocrosscompiler
2088      GNUmake
2089      largefile
2090      nis
2091      nas
2092      tablet
2093
2094      X11     : x11sm xinerama xcursor xfixes xrandr xrender fontconfig xkb
2095      Embedded: embedded freetype
2096 */
2097 void Configure::generateBuildKey()
2098 {
2099     QString spec = dictionary["QMAKESPEC"];
2100
2101     QString compiler = "msvc"; // ICC is compatible
2102     if (spec.endsWith("-g++"))
2103         compiler = "mingw";
2104     else if (spec.endsWith("-borland"))
2105         compiler = "borland";
2106
2107     // Build options which changes the Qt API/ABI
2108     QStringList build_options;
2109     if (!dictionary["QCONFIG"].isEmpty())
2110         build_options += dictionary["QCONFIG"] + "-config ";
2111     build_options.sort();
2112
2113     // Sorted defines that start with QT_NO_
2114     QStringList build_defines = qmakeDefines.filter(QRegExp("^QT_NO_"));
2115     build_defines.sort();
2116 }
2117
2118 void Configure::generateOutputVars()
2119 {
2120     // Generate variables for output
2121     QString build = dictionary[ "BUILD" ];
2122     bool buildAll = (dictionary[ "BUILDALL" ] == "yes");
2123     if (build == "debug") {
2124         if (buildAll)
2125             qtConfig += "release";
2126         qtConfig += "debug";
2127     } else if (build == "release") {
2128         if (buildAll)
2129             qtConfig += "debug";
2130         qtConfig += "release";
2131     }
2132
2133     if (dictionary[ "WIDGETS" ] == "no")
2134         qtConfig += "no-widgets";
2135
2136     // Compression --------------------------------------------------
2137     if (dictionary[ "ZLIB" ] == "qt")
2138         qtConfig += "zlib";
2139     else if (dictionary[ "ZLIB" ] == "system")
2140         qtConfig += "system-zlib";
2141
2142     // PCRE ---------------------------------------------------------
2143     if (dictionary[ "PCRE" ] == "qt")
2144         qmakeConfig += "pcre";
2145
2146     // ICU ---------------------------------------------------------
2147     if (dictionary[ "ICU" ] == "yes")
2148         qtConfig  += "icu";
2149
2150     // Image formates -----------------------------------------------
2151     if (dictionary[ "GIF" ] == "no")
2152         qtConfig += "no-gif";
2153     else if (dictionary[ "GIF" ] == "yes")
2154         qtConfig += "gif";
2155
2156     if (dictionary[ "JPEG" ] == "no")
2157         qtConfig += "no-jpeg";
2158     else if (dictionary[ "JPEG" ] == "yes")
2159         qtConfig += "jpeg";
2160     if (dictionary[ "LIBJPEG" ] == "system")
2161         qtConfig += "system-jpeg";
2162
2163     if (dictionary[ "PNG" ] == "no")
2164         qtConfig += "no-png";
2165     else if (dictionary[ "PNG" ] == "yes")
2166         qtConfig += "png";
2167     if (dictionary[ "LIBPNG" ] == "system")
2168         qtConfig += "system-png";
2169
2170     // Text rendering --------------------------------------------------
2171     if (dictionary[ "FREETYPE" ] == "yes")
2172         qtConfig += "freetype";
2173
2174     // Styles -------------------------------------------------------
2175     if (dictionary[ "STYLE_WINDOWS" ] == "yes")
2176         qmakeStyles += "windows";
2177
2178     if (dictionary[ "STYLE_PLASTIQUE" ] == "yes")
2179         qmakeStyles += "plastique";
2180
2181     if (dictionary[ "STYLE_CLEANLOOKS" ] == "yes")
2182         qmakeStyles += "cleanlooks";
2183
2184     if (dictionary[ "STYLE_WINDOWSXP" ] == "yes")
2185         qmakeStyles += "windowsxp";
2186
2187     if (dictionary[ "STYLE_WINDOWSVISTA" ] == "yes")
2188         qmakeStyles += "windowsvista";
2189
2190     if (dictionary[ "STYLE_MOTIF" ] == "yes")
2191         qmakeStyles += "motif";
2192
2193     if (dictionary[ "STYLE_SGI" ] == "yes")
2194         qmakeStyles += "sgi";
2195
2196     if (dictionary[ "STYLE_WINDOWSCE" ] == "yes")
2197     qmakeStyles += "windowsce";
2198
2199     if (dictionary[ "STYLE_WINDOWSMOBILE" ] == "yes")
2200     qmakeStyles += "windowsmobile";
2201
2202     if (dictionary[ "STYLE_CDE" ] == "yes")
2203         qmakeStyles += "cde";
2204
2205     // Databases ----------------------------------------------------
2206     if (dictionary[ "SQL_MYSQL" ] == "yes")
2207         qmakeSql += "mysql";
2208     else if (dictionary[ "SQL_MYSQL" ] == "plugin")
2209         qmakeSqlPlugins += "mysql";
2210
2211     if (dictionary[ "SQL_ODBC" ] == "yes")
2212         qmakeSql += "odbc";
2213     else if (dictionary[ "SQL_ODBC" ] == "plugin")
2214         qmakeSqlPlugins += "odbc";
2215
2216     if (dictionary[ "SQL_OCI" ] == "yes")
2217         qmakeSql += "oci";
2218     else if (dictionary[ "SQL_OCI" ] == "plugin")
2219         qmakeSqlPlugins += "oci";
2220
2221     if (dictionary[ "SQL_PSQL" ] == "yes")
2222         qmakeSql += "psql";
2223     else if (dictionary[ "SQL_PSQL" ] == "plugin")
2224         qmakeSqlPlugins += "psql";
2225
2226     if (dictionary[ "SQL_TDS" ] == "yes")
2227         qmakeSql += "tds";
2228     else if (dictionary[ "SQL_TDS" ] == "plugin")
2229         qmakeSqlPlugins += "tds";
2230
2231     if (dictionary[ "SQL_DB2" ] == "yes")
2232         qmakeSql += "db2";
2233     else if (dictionary[ "SQL_DB2" ] == "plugin")
2234         qmakeSqlPlugins += "db2";
2235
2236     if (dictionary[ "SQL_SQLITE" ] == "yes")
2237         qmakeSql += "sqlite";
2238     else if (dictionary[ "SQL_SQLITE" ] == "plugin")
2239         qmakeSqlPlugins += "sqlite";
2240
2241     if (dictionary[ "SQL_SQLITE_LIB" ] == "system")
2242         qmakeConfig += "system-sqlite";
2243
2244     if (dictionary[ "SQL_SQLITE2" ] == "yes")
2245         qmakeSql += "sqlite2";
2246     else if (dictionary[ "SQL_SQLITE2" ] == "plugin")
2247         qmakeSqlPlugins += "sqlite2";
2248
2249     if (dictionary[ "SQL_IBASE" ] == "yes")
2250         qmakeSql += "ibase";
2251     else if (dictionary[ "SQL_IBASE" ] == "plugin")
2252         qmakeSqlPlugins += "ibase";
2253
2254     // Other options ------------------------------------------------
2255     if (dictionary[ "BUILDALL" ] == "yes") {
2256         qtConfig += "build_all";
2257     }
2258     qmakeConfig += dictionary[ "BUILD" ];
2259     dictionary[ "QMAKE_OUTDIR" ] = dictionary[ "BUILD" ];
2260
2261     if (buildParts.isEmpty()) {
2262         buildParts = defaultBuildParts;
2263
2264         if (dictionary["BUILDDEV"] == "yes")
2265             buildParts += "tests";
2266     }
2267     while (!nobuildParts.isEmpty())
2268         buildParts.removeAll(nobuildParts.takeFirst());
2269     if (!buildParts.contains("libs"))
2270         buildParts += "libs";
2271     buildParts.removeDuplicates();
2272
2273     if (dictionary["MSVC_MP"] == "yes")
2274         qmakeConfig += "msvc_mp";
2275
2276     if (dictionary[ "SHARED" ] == "yes") {
2277         QString version = dictionary[ "VERSION" ];
2278         if (!version.isEmpty()) {
2279             qmakeVars += "QMAKE_QT_VERSION_OVERRIDE = " + version.left(version.indexOf("."));
2280             version.remove(QLatin1Char('.'));
2281         }
2282         dictionary[ "QMAKE_OUTDIR" ] += "_shared";
2283     } else {
2284         dictionary[ "QMAKE_OUTDIR" ] += "_static";
2285     }
2286
2287     if (dictionary[ "ACCESSIBILITY" ] == "yes")
2288         qtConfig += "accessibility";
2289
2290     if (!qmakeLibs.isEmpty())
2291         qmakeVars += "LIBS           += " + escapeSeparators(qmakeLibs.join(" "));
2292
2293     if (!dictionary["QT_LFLAGS_SQLITE"].isEmpty())
2294         qmakeVars += "QT_LFLAGS_SQLITE += " + escapeSeparators(dictionary["QT_LFLAGS_SQLITE"]);
2295
2296     if (dictionary[ "OPENGL" ] == "yes")
2297         qtConfig += "opengl";
2298
2299     if (dictionary["OPENGL_ES_CM"] == "yes") {
2300         qtConfig += "opengles1";
2301         qtConfig += "egl";
2302     }
2303
2304     if (dictionary["OPENGL_ES_2"] == "yes") {
2305         qtConfig += "opengles2";
2306         qtConfig += "egl";
2307     }
2308
2309     if (dictionary["OPENVG"] == "yes") {
2310         qtConfig += "openvg";
2311         qtConfig += "egl";
2312     }
2313
2314     // ### Vestige
2315      if (dictionary["DIRECTSHOW"] == "yes")
2316         qtConfig += "directshow";
2317
2318     if (dictionary[ "OPENSSL" ] == "yes")
2319         qtConfig += "openssl";
2320     else if (dictionary[ "OPENSSL" ] == "linked")
2321         qtConfig += "openssl-linked";
2322
2323     if (dictionary[ "DBUS" ] == "yes")
2324         qtConfig += "dbus";
2325     else if (dictionary[ "DBUS" ] == "linked")
2326         qtConfig += "dbus dbus-linked";
2327
2328     if (dictionary[ "CETEST" ] == "yes")
2329         qtConfig += "cetest";
2330
2331     // ### Vestige
2332     if (dictionary["PHONON_BACKEND"] == "yes")
2333         qtConfig += "phonon-backend";
2334
2335     // ### Vestige
2336     if (dictionary["AUDIO_BACKEND"] == "yes")
2337         qtConfig += "audio-backend";
2338
2339     if (dictionary["DIRECTWRITE"] == "yes")
2340         qtConfig += "directwrite";
2341
2342     if (dictionary[ "NATIVE_GESTURES" ] == "yes")
2343         qtConfig += "native-gestures";
2344
2345     // We currently have no switch for QtConcurrent, so add it unconditionally.
2346     qtConfig += "concurrent";
2347
2348     // ### Vestige
2349     if (dictionary[ "V8SNAPSHOT" ] == "yes")
2350         qtConfig += "v8snapshot";
2351
2352     // Add config levels --------------------------------------------
2353     QStringList possible_configs = QStringList()
2354         << "minimal"
2355         << "small"
2356         << "medium"
2357         << "large"
2358         << "full";
2359
2360     QString set_config = dictionary["QCONFIG"];
2361     if (possible_configs.contains(set_config)) {
2362         foreach (const QString &cfg, possible_configs) {
2363             qtConfig += (cfg + "-config");
2364             if (cfg == set_config)
2365                 break;
2366         }
2367     }
2368
2369     if (dictionary.contains("XQMAKESPEC") && (dictionary["QMAKESPEC"] != dictionary["XQMAKESPEC"])) {
2370             qmakeConfig += "cross_compile";
2371             dictionary["CROSS_COMPILE"] = "yes";
2372     }
2373
2374     // Directories and settings for .qmake.cache --------------------
2375
2376     // if QT_INSTALL_* have not been specified on commandline, define them now from QT_INSTALL_PREFIX
2377     // if prefix is empty (WINCE), make all of them empty, if they aren't set
2378     bool qipempty = false;
2379     if (dictionary[ "QT_INSTALL_PREFIX" ].isEmpty())
2380         qipempty = true;
2381
2382     if (!dictionary[ "QT_INSTALL_DOCS" ].size())
2383         dictionary[ "QT_INSTALL_DOCS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/doc");
2384     if (!dictionary[ "QT_INSTALL_HEADERS" ].size())
2385         dictionary[ "QT_INSTALL_HEADERS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/include");
2386     if (!dictionary[ "QT_INSTALL_LIBS" ].size())
2387         dictionary[ "QT_INSTALL_LIBS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/lib");
2388     if (!dictionary[ "QT_INSTALL_BINS" ].size())
2389         dictionary[ "QT_INSTALL_BINS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/bin");
2390     if (!dictionary[ "QT_INSTALL_PLUGINS" ].size())
2391         dictionary[ "QT_INSTALL_PLUGINS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/plugins");
2392     if (!dictionary[ "QT_INSTALL_IMPORTS" ].size())
2393         dictionary[ "QT_INSTALL_IMPORTS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/imports");
2394     if (!dictionary[ "QT_INSTALL_DATA" ].size())
2395         dictionary[ "QT_INSTALL_DATA" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ]);
2396     if (!dictionary[ "QT_INSTALL_TRANSLATIONS" ].size())
2397         dictionary[ "QT_INSTALL_TRANSLATIONS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/translations");
2398     if (!dictionary[ "QT_INSTALL_EXAMPLES" ].size())
2399         dictionary[ "QT_INSTALL_EXAMPLES" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/examples");
2400     if (!dictionary[ "QT_INSTALL_TESTS" ].size())
2401         dictionary[ "QT_INSTALL_TESTS" ] = qipempty ? "" : fixSeparators(dictionary[ "QT_INSTALL_PREFIX" ] + "/tests");
2402
2403     bool haveHpx = false;
2404     if (dictionary[ "QT_HOST_PREFIX" ].isEmpty())
2405         dictionary[ "QT_HOST_PREFIX" ] = dictionary[ "QT_INSTALL_PREFIX" ];
2406     else
2407         haveHpx = true;
2408     if (dictionary[ "QT_HOST_BINS" ].isEmpty())
2409         dictionary[ "QT_HOST_BINS" ] = haveHpx ? fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/bin") : dictionary[ "QT_INSTALL_BINS" ];
2410     if (dictionary[ "QT_HOST_DATA" ].isEmpty())
2411         dictionary[ "QT_HOST_DATA" ] = haveHpx ? dictionary[ "QT_HOST_PREFIX" ] : dictionary[ "QT_INSTALL_DATA" ];
2412
2413     if (dictionary.contains("XQMAKESPEC") && dictionary[ "XQMAKESPEC" ].startsWith("linux"))
2414         dictionary[ "QMAKE_RPATHDIR" ] = dictionary[ "QT_INSTALL_LIBS" ];
2415
2416     qmakeVars += QString("OBJECTS_DIR     = ") + fixSeparators("tmp/obj/" + dictionary[ "QMAKE_OUTDIR" ], true);
2417     qmakeVars += QString("MOC_DIR         = ") + fixSeparators("tmp/moc/" + dictionary[ "QMAKE_OUTDIR" ], true);
2418     qmakeVars += QString("RCC_DIR         = ") + fixSeparators("tmp/rcc/" + dictionary["QMAKE_OUTDIR"], true);
2419
2420     if (!qmakeDefines.isEmpty())
2421         qmakeVars += QString("DEFINES        += ") + qmakeDefines.join(" ");
2422     if (!qmakeIncludes.isEmpty())
2423         qmakeVars += QString("INCLUDEPATH    += ") + escapeSeparators(qmakeIncludes.join(" "));
2424     if (!opensslLibs.isEmpty())
2425         qmakeVars += opensslLibs;
2426     else if (dictionary[ "OPENSSL" ] == "linked")
2427         qmakeVars += QString("OPENSSL_LIBS    = -lssleay32 -llibeay32");
2428     if (!psqlLibs.isEmpty())
2429         qmakeVars += QString("QT_LFLAGS_PSQL=") + psqlLibs.section("=", 1);
2430
2431     {
2432         QStringList lflagsTDS;
2433         if (!sybase.isEmpty())
2434             lflagsTDS += QString("-L") + fixSeparators(sybase.section("=", 1) + "/lib");
2435         if (!sybaseLibs.isEmpty())
2436             lflagsTDS += sybaseLibs.section("=", 1);
2437         if (!lflagsTDS.isEmpty())
2438             qmakeVars += QString("QT_LFLAGS_TDS=") + lflagsTDS.join(" ");
2439     }
2440
2441     if (!qmakeSql.isEmpty())
2442         qmakeVars += QString("sql-drivers    += ") + qmakeSql.join(" ");
2443     if (!qmakeSqlPlugins.isEmpty())
2444         qmakeVars += QString("sql-plugins    += ") + qmakeSqlPlugins.join(" ");
2445     if (!qmakeStyles.isEmpty())
2446         qmakeVars += QString("styles         += ") + qmakeStyles.join(" ");
2447     if (!qmakeStylePlugins.isEmpty())
2448         qmakeVars += QString("style-plugins  += ") + qmakeStylePlugins.join(" ");
2449
2450     if (dictionary["QMAKESPEC"].endsWith("-g++")) {
2451         QString includepath = qgetenv("INCLUDE");
2452         bool hasSh = Environment::detectExecutable("sh.exe");
2453         QChar separator = (!includepath.contains(":\\") && hasSh ? QChar(':') : QChar(';'));
2454         qmakeVars += QString("TMPPATH            = $$quote($$(INCLUDE))");
2455         qmakeVars += QString("QMAKE_INCDIR_POST += $$split(TMPPATH,\"%1\")").arg(separator);
2456         qmakeVars += QString("TMPPATH            = $$quote($$(LIB))");
2457         qmakeVars += QString("QMAKE_LIBDIR_POST += $$split(TMPPATH,\"%1\")").arg(separator);
2458     }
2459
2460     if (!dictionary[ "QMAKESPEC" ].length()) {
2461         cout << "Configure could not detect your compiler. QMAKESPEC must either" << endl
2462              << "be defined as an environment variable, or specified as an" << endl
2463              << "argument with -platform" << endl;
2464         dictionary[ "HELP" ] = "yes";
2465
2466         QStringList winPlatforms;
2467         QDir mkspecsDir(sourcePath + "/mkspecs");
2468         const QFileInfoList &specsList = mkspecsDir.entryInfoList();
2469         for (int i = 0; i < specsList.size(); ++i) {
2470             const QFileInfo &fi = specsList.at(i);
2471             if (fi.fileName().left(5) == "win32") {
2472                 winPlatforms += fi.fileName();
2473             }
2474         }
2475         cout << "Available platforms are: " << qPrintable(winPlatforms.join(", ")) << endl;
2476         dictionary[ "DONE" ] = "error";
2477     }
2478 }
2479
2480 #if !defined(EVAL)
2481 void Configure::generateCachefile()
2482 {
2483     // Generate .qmake.cache
2484     QFile cacheFile(buildPath + "/.qmake.cache");
2485     if (cacheFile.open(QFile::WriteOnly | QFile::Text)) { // Truncates any existing file.
2486         QTextStream cacheStream(&cacheFile);
2487
2488         cacheStream << "include($$PWD/mkspecs/qmodule.pri)" << endl;
2489
2490         for (QStringList::Iterator var = qmakeVars.begin(); var != qmakeVars.end(); ++var) {
2491             cacheStream << (*var) << endl;
2492         }
2493         cacheStream << "CONFIG         += " << qmakeConfig.join(" ") << "depend_includepath no_private_qt_headers_warning QTDIR_build" << endl;
2494
2495         cacheStream.flush();
2496         cacheFile.close();
2497     }
2498
2499     // Generate qmodule.pri
2500     QFile moduleFile(dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qmodule.pri");
2501     if (moduleFile.open(QFile::WriteOnly | QFile::Text)) { // Truncates any existing file.
2502         QTextStream moduleStream(&moduleFile);
2503
2504         moduleStream << "#paths" << endl;
2505         moduleStream << "QT_BUILD_TREE   = " << fixSeparators(dictionary[ "QT_BUILD_TREE" ], true) << endl;
2506         moduleStream << "QT_SOURCE_TREE  = " << fixSeparators(dictionary[ "QT_SOURCE_TREE" ], true) << endl;
2507         moduleStream << "QT_BUILD_PARTS  = " << buildParts.join(" ") << endl << endl;
2508
2509         //so that we can build without an install first (which would be impossible)
2510         moduleStream << "#local paths that cannot be queried from the QT_INSTALL_* properties while building QTDIR" << endl;
2511         moduleStream << "QMAKE_INCDIR_QT = $$QT_BUILD_TREE" << fixSeparators("/include", true) << endl;
2512         moduleStream << "QMAKE_LIBDIR_QT = $$QT_BUILD_TREE" << fixSeparators("/lib", true) << endl;
2513
2514
2515         QString targetSpec = dictionary.contains("XQMAKESPEC") ? dictionary[ "XQMAKESPEC" ] : dictionary[ "QMAKESPEC" ];
2516         QString mkspec_path = fixSeparators(sourcePath + "/mkspecs/" + targetSpec);
2517         if (QFile::exists(mkspec_path))
2518             moduleStream << "QMAKESPEC       = " << escapeSeparators(mkspec_path) << endl;
2519         else
2520             moduleStream << "QMAKESPEC       = " << fixSeparators(targetSpec, true) << endl;
2521
2522         if (dictionary["QT_EDITION"] != "QT_EDITION_OPENSOURCE")
2523             moduleStream << "DEFINES        *= QT_EDITION=QT_EDITION_DESKTOP" << endl;
2524
2525         if (dictionary["CETEST"] == "yes") {
2526             moduleStream << "QT_CE_RAPI_INC  = " << fixSeparators(dictionary[ "QT_CE_RAPI_INC" ], true) << endl;
2527             moduleStream << "QT_CE_RAPI_LIB  = " << fixSeparators(dictionary[ "QT_CE_RAPI_LIB" ], true) << endl;
2528         }
2529
2530         moduleStream << "#Qt for Windows CE c-runtime deployment" << endl
2531                      << "QT_CE_C_RUNTIME = " << fixSeparators(dictionary[ "CE_CRT" ], true) << endl;
2532
2533         if (dictionary["CE_SIGNATURE"] != QLatin1String("no"))
2534             moduleStream << "DEFAULT_SIGNATURE=" << dictionary["CE_SIGNATURE"] << endl;
2535
2536         if (!dictionary["QMAKE_RPATHDIR"].isEmpty())
2537             moduleStream << "QMAKE_RPATHDIR += " << dictionary["QMAKE_RPATHDIR"] << endl;
2538
2539         if (!dictionary["QT_LIBINFIX"].isEmpty())
2540             moduleStream << "QT_LIBINFIX = " << dictionary["QT_LIBINFIX"] << endl;
2541
2542         if (!dictionary["QT_NAMESPACE"].isEmpty()) {
2543             moduleStream << "#namespaces" << endl << "QT_NAMESPACE = " << dictionary["QT_NAMESPACE"] << endl;
2544         }
2545
2546         // embedded
2547         if (!dictionary["KBD_DRIVERS"].isEmpty())
2548             moduleStream << "kbd-drivers += "<< dictionary["KBD_DRIVERS"]<<endl;
2549         if (!dictionary["GFX_DRIVERS"].isEmpty())
2550             moduleStream << "gfx-drivers += "<< dictionary["GFX_DRIVERS"]<<endl;
2551         if (!dictionary["MOUSE_DRIVERS"].isEmpty())
2552             moduleStream << "mouse-drivers += "<< dictionary["MOUSE_DRIVERS"]<<endl;
2553         if (!dictionary["DECORATIONS"].isEmpty())
2554             moduleStream << "decorations += "<<dictionary["DECORATIONS"]<<endl;
2555
2556         if (!dictionary["QMAKE_RPATHDIR"].isEmpty())
2557             moduleStream << "QMAKE_RPATHDIR += "<<dictionary["QMAKE_RPATHDIR"]<<endl;
2558
2559         moduleStream << "CONFIG += create_prl link_prl" << endl;
2560
2561         moduleStream.flush();
2562         moduleFile.close();
2563     }
2564 }
2565
2566 /*
2567     Runs qmake on config.tests/arch/arch.pro, which will detect the target arch
2568     for the compiler we are using
2569 */
2570 void Configure::detectArch()
2571 {
2572     QString oldpwd = QDir::currentPath();
2573
2574     QString newpwd = fixSeparators(QString("%1/config.tests/arch").arg(buildPath));
2575     if (!QDir().exists(newpwd) && !QDir().mkpath(newpwd)) {
2576         cout << "Failed to create directory " << qPrintable(newpwd) << endl;
2577         dictionary["DONE"] = "error";
2578         return;
2579     }
2580     if (!QDir::setCurrent(newpwd)) {
2581         cout << "Failed to change working directory to " << qPrintable(newpwd) << endl;
2582         dictionary["DONE"] = "error";
2583         return;
2584     }
2585
2586     QList<QPair<QString, QString> > qmakespecs;
2587     if (dictionary.contains("XQMAKESPEC"))
2588         qmakespecs << qMakePair(QString("XQMAKESPEC"), QString("QT_ARCH"));
2589     qmakespecs << qMakePair(QString("QMAKESPEC"), QString("QT_HOST_ARCH"));
2590
2591     for (int i = 0; i < qmakespecs.count(); ++i) {
2592         const QPair<QString, QString> &pair = qmakespecs.at(i);
2593         QString qmakespec = dictionary.value(pair.first);
2594         QString key = pair.second;
2595
2596         QString command =
2597                 fixSeparators(QString("%1/bin/qmake.exe -spec %2 %3/config.tests/arch/arch.pro -o %4/Makefile.unused 2>&1")
2598                               .arg(buildPath, qmakespec, sourcePath, newpwd));
2599         QString output = Environment::execute(command);
2600         if (output.isEmpty())
2601             continue;
2602
2603         QRegExp re("Project MESSAGE:.*Architecture: ([a-zA-Z0-9_]*)");
2604         if (re.indexIn(output) != -1)
2605             dictionary[key] = re.cap(1);
2606     }
2607
2608     if (!dictionary.contains("QT_HOST_ARCH"))
2609         dictionary["QT_HOST_ARCH"] = "unknown";
2610     if (!dictionary.contains("QT_ARCH"))
2611         dictionary["QT_ARCH"] = dictionary["QT_HOST_ARCH"];
2612
2613     QDir::setCurrent(oldpwd);
2614 }
2615
2616 void Configure::generateQConfigPri()
2617 {
2618     // Generate qconfig.pri
2619     QFile configFile(dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qconfig.pri");
2620     if (configFile.open(QFile::WriteOnly | QFile::Text)) { // Truncates any existing file.
2621         QTextStream configStream(&configFile);
2622
2623         configStream << "CONFIG+= ";
2624         configStream << dictionary[ "BUILD" ];
2625         if (dictionary[ "SHARED" ] == "yes")
2626             configStream << " shared";
2627         else
2628             configStream << " static";
2629
2630         if (dictionary[ "LTCG" ] == "yes")
2631             configStream << " ltcg";
2632         if (dictionary[ "STL" ] == "yes")
2633             configStream << " stl";
2634         if (dictionary[ "EXCEPTIONS" ] == "yes")
2635             configStream << " exceptions";
2636         if (dictionary[ "EXCEPTIONS" ] == "no")
2637             configStream << " exceptions_off";
2638         if (dictionary[ "RTTI" ] == "yes")
2639             configStream << " rtti";
2640         if (dictionary[ "MMX" ] == "yes")
2641             configStream << " mmx";
2642         if (dictionary[ "3DNOW" ] == "yes")
2643             configStream << " 3dnow";
2644         if (dictionary[ "SSE" ] == "yes")
2645             configStream << " sse";
2646         if (dictionary[ "SSE2" ] == "yes")
2647             configStream << " sse2";
2648         if (dictionary[ "IWMMXT" ] == "yes")
2649             configStream << " iwmmxt";
2650         if (dictionary["INCREDIBUILD_XGE"] == "yes")
2651             configStream << " incredibuild_xge";
2652         if (dictionary["PLUGIN_MANIFESTS"] == "no")
2653             configStream << " no_plugin_manifest";
2654         if (dictionary["CROSS_COMPILE"] == "yes")
2655             configStream << " cross_compile";
2656
2657         if (dictionary["DIRECTWRITE"] == "yes")
2658             configStream << "directwrite";
2659
2660         // ### For compatibility only, should be removed later.
2661         configStream << " qpa";
2662
2663         configStream << endl;
2664         configStream << "QT_ARCH = " << dictionary["QT_ARCH"] << endl;
2665         configStream << "QT_HOST_ARCH = " << dictionary["QT_HOST_ARCH"] << endl;
2666         if (dictionary["QT_EDITION"].contains("OPENSOURCE"))
2667             configStream << "QT_EDITION = " << QLatin1String("OpenSource") << endl;
2668         else
2669             configStream << "QT_EDITION = " << dictionary["EDITION"] << endl;
2670         configStream << "QT_CONFIG += " << qtConfig.join(" ") << endl;
2671
2672         configStream << "#versioning " << endl
2673                      << "QT_VERSION = " << dictionary["VERSION"] << endl
2674                      << "QT_MAJOR_VERSION = " << dictionary["VERSION_MAJOR"] << endl
2675                      << "QT_MINOR_VERSION = " << dictionary["VERSION_MINOR"] << endl
2676                      << "QT_PATCH_VERSION = " << dictionary["VERSION_PATCH"] << endl;
2677
2678         if (!dictionary["CFG_SYSROOT"].isEmpty()) {
2679             QString targetSpec = dictionary.contains("XQMAKESPEC") ? dictionary[ "XQMAKESPEC" ] : dictionary[ "QMAKESPEC" ];
2680             configStream << endl
2681                          << "# sysroot" << endl
2682                          << targetSpec << " {" << endl
2683                          << "    QMAKE_CFLAGS    += --sysroot=$$[QT_SYSROOT]" << endl
2684                          << "    QMAKE_CXXFLAGS  += --sysroot=$$[QT_SYSROOT]" << endl
2685                          << "    QMAKE_LFLAGS    += --sysroot=$$[QT_SYSROOT]" << endl
2686                          << "}" << endl;
2687         }
2688
2689         configStream.flush();
2690         configFile.close();
2691     }
2692 }
2693 #endif
2694
2695 QString Configure::addDefine(QString def)
2696 {
2697     QString result, defNeg, defD = def;
2698
2699     defD.replace(QRegExp("=.*"), "");
2700     def.replace(QRegExp("="), " ");
2701
2702     if (def.startsWith("QT_NO_")) {
2703         defNeg = defD;
2704         defNeg.replace("QT_NO_", "QT_");
2705     } else if (def.startsWith("QT_")) {
2706         defNeg = defD;
2707         defNeg.replace("QT_", "QT_NO_");
2708     }
2709
2710     if (defNeg.isEmpty()) {
2711         result = "#ifndef $DEFD\n"
2712                  "# define $DEF\n"
2713                  "#endif\n\n";
2714     } else {
2715         result = "#if defined($DEFD) && defined($DEFNEG)\n"
2716                  "# undef $DEFD\n"
2717                  "#elif !defined($DEFD)\n"
2718                  "# define $DEF\n"
2719                  "#endif\n\n";
2720     }
2721     result.replace("$DEFNEG", defNeg);
2722     result.replace("$DEFD", defD);
2723     result.replace("$DEF", def);
2724     return result;
2725 }
2726
2727 #if !defined(EVAL)
2728 bool Configure::copySpec(const char *name, const char *pfx, const QString &spec)
2729 {
2730     // Copy configured mkspec to default directory, but remove the old one first, if there is any
2731     QString defSpec = buildPath + "/mkspecs/" + name;
2732     QFileInfo defSpecInfo(defSpec);
2733     if (defSpecInfo.exists()) {
2734         if (!Environment::rmdir(defSpec)) {
2735             cout << "Couldn't update default " << pfx << "mkspec! Are files in " << qPrintable(defSpec) << " read-only?" << endl;
2736             dictionary["DONE"] = "error";
2737             return false;
2738         }
2739     }
2740
2741     QString pltSpec = sourcePath + "/mkspecs/" + spec;
2742     QString includeSpec = buildPath + "/mkspecs/" + spec;
2743     if (!Environment::cpdir(pltSpec, defSpec, includeSpec)) {
2744         cout << "Couldn't update default " << pfx << "mkspec! Does " << qPrintable(pltSpec) << " exist?" << endl;
2745         dictionary["DONE"] = "error";
2746         return false;
2747     }
2748     return true;
2749 }
2750
2751 void Configure::generateConfigfiles()
2752 {
2753     QDir(buildPath).mkpath("src/corelib/global");
2754     QString outName(buildPath + "/src/corelib/global/qconfig.h");
2755     QTemporaryFile tmpFile;
2756     QTextStream tmpStream;
2757
2758     if (tmpFile.open()) {
2759         tmpStream.setDevice(&tmpFile);
2760
2761         if (dictionary[ "QCONFIG" ] == "full") {
2762             tmpStream << "/* Everything */" << endl;
2763         } else {
2764             QString configName("qconfig-" + dictionary[ "QCONFIG" ] + ".h");
2765             tmpStream << "/* Copied from " << configName << "*/" << endl;
2766             tmpStream << "#ifndef QT_BOOTSTRAPPED" << endl;
2767             QFile inFile(sourcePath + "/src/corelib/global/" + configName);
2768             if (inFile.open(QFile::ReadOnly)) {
2769                 QByteArray buffer = inFile.readAll();
2770                 tmpFile.write(buffer.constData(), buffer.size());
2771                 inFile.close();
2772             }
2773             tmpStream << "#endif // QT_BOOTSTRAPPED" << endl;
2774         }
2775         tmpStream << endl;
2776
2777         if (dictionary[ "SHARED" ] == "yes") {
2778             tmpStream << "#ifndef QT_DLL" << endl;
2779             tmpStream << "#define QT_DLL" << endl;
2780             tmpStream << "#endif" << endl;
2781         }
2782         tmpStream << endl;
2783         tmpStream << "/* License information */" << endl;
2784         tmpStream << "#define QT_PRODUCT_LICENSEE \"" << licenseInfo[ "LICENSEE" ] << "\"" << endl;
2785         tmpStream << "#define QT_PRODUCT_LICENSE \"" << dictionary[ "EDITION" ] << "\"" << endl;
2786         tmpStream << endl;
2787         tmpStream << "// Qt Edition" << endl;
2788         tmpStream << "#ifndef QT_EDITION" << endl;
2789         tmpStream << "#  define QT_EDITION " << dictionary["QT_EDITION"] << endl;
2790         tmpStream << "#endif" << endl;
2791         tmpStream << endl;
2792         if (dictionary["BUILDDEV"] == "yes") {
2793             dictionary["QMAKE_INTERNAL"] = "yes";
2794             tmpStream << "/* Used for example to export symbols for the certain autotests*/" << endl;
2795             tmpStream << "#define QT_BUILD_INTERNAL" << endl;
2796             tmpStream << endl;
2797         }
2798
2799         // ### For compatibility only, should be removed later.
2800         tmpStream << endl << "#define Q_WS_QPA" << endl;
2801
2802         tmpStream << endl << "// Compile time features" << endl;
2803
2804         QStringList qconfigList;
2805         if (dictionary["STL"] == "no")                qconfigList += "QT_NO_STL";
2806         if (dictionary["STYLE_WINDOWS"] != "yes")     qconfigList += "QT_NO_STYLE_WINDOWS";
2807         if (dictionary["STYLE_PLASTIQUE"] != "yes")   qconfigList += "QT_NO_STYLE_PLASTIQUE";
2808         if (dictionary["STYLE_CLEANLOOKS"] != "yes")   qconfigList += "QT_NO_STYLE_CLEANLOOKS";
2809         if (dictionary["STYLE_WINDOWSXP"] != "yes" && dictionary["STYLE_WINDOWSVISTA"] != "yes")
2810             qconfigList += "QT_NO_STYLE_WINDOWSXP";
2811         if (dictionary["STYLE_WINDOWSVISTA"] != "yes")   qconfigList += "QT_NO_STYLE_WINDOWSVISTA";
2812         if (dictionary["STYLE_MOTIF"] != "yes")       qconfigList += "QT_NO_STYLE_MOTIF";
2813         if (dictionary["STYLE_CDE"] != "yes")         qconfigList += "QT_NO_STYLE_CDE";
2814
2815         // ### We still need the QT_NO_STYLE_S60 define for compiling Qt. Remove later!
2816         qconfigList += "QT_NO_STYLE_S60";
2817
2818         if (dictionary["STYLE_WINDOWSCE"] != "yes")   qconfigList += "QT_NO_STYLE_WINDOWSCE";
2819         if (dictionary["STYLE_WINDOWSMOBILE"] != "yes")   qconfigList += "QT_NO_STYLE_WINDOWSMOBILE";
2820         if (dictionary["STYLE_GTK"] != "yes")         qconfigList += "QT_NO_STYLE_GTK";
2821
2822         if (dictionary["GIF"] == "yes")              qconfigList += "QT_BUILTIN_GIF_READER=1";
2823         if (dictionary["PNG"] != "yes")              qconfigList += "QT_NO_IMAGEFORMAT_PNG";
2824         if (dictionary["JPEG"] != "yes")             qconfigList += "QT_NO_IMAGEFORMAT_JPEG";
2825         if (dictionary["ZLIB"] == "no") {
2826             qconfigList += "QT_NO_ZLIB";
2827             qconfigList += "QT_NO_COMPRESS";
2828         }
2829
2830         if (dictionary["ACCESSIBILITY"] == "no")     qconfigList += "QT_NO_ACCESSIBILITY";
2831         if (dictionary["EXCEPTIONS"] == "no")        qconfigList += "QT_NO_EXCEPTIONS";
2832         if (dictionary["WIDGETS"] == "no")           qconfigList += "QT_NO_WIDGETS";
2833         if (dictionary["OPENGL"] == "no")            qconfigList += "QT_NO_OPENGL";
2834         if (dictionary["OPENVG"] == "no")            qconfigList += "QT_NO_OPENVG";
2835         if (dictionary["OPENSSL"] == "no") {
2836             qconfigList += "QT_NO_OPENSSL";
2837             qconfigList += "QT_NO_SSL";
2838         }
2839         if (dictionary["OPENSSL"] == "linked")       qconfigList += "QT_LINKED_OPENSSL";
2840         if (dictionary["DBUS"] == "no")              qconfigList += "QT_NO_DBUS";
2841         if (dictionary["QML_DEBUG"] == "no")         qconfigList += "QT_QML_NO_DEBUGGER";
2842         if (dictionary["FREETYPE"] == "no")          qconfigList += "QT_NO_FREETYPE";
2843         if (dictionary["NATIVE_GESTURES"] == "no")   qconfigList += "QT_NO_NATIVE_GESTURES";
2844
2845         if (dictionary["OPENGL_ES_CM"] == "yes" ||
2846            dictionary["OPENGL_ES_2"]  == "yes")     qconfigList += "QT_OPENGL_ES";
2847
2848         if (dictionary["OPENGL_ES_CM"] == "yes")     qconfigList += "QT_OPENGL_ES_1";
2849         if (dictionary["OPENGL_ES_2"]  == "yes")     qconfigList += "QT_OPENGL_ES_2";
2850         if (dictionary["SQL_MYSQL"] == "yes")        qconfigList += "QT_SQL_MYSQL";
2851         if (dictionary["SQL_ODBC"] == "yes")         qconfigList += "QT_SQL_ODBC";
2852         if (dictionary["SQL_OCI"] == "yes")          qconfigList += "QT_SQL_OCI";
2853         if (dictionary["SQL_PSQL"] == "yes")         qconfigList += "QT_SQL_PSQL";
2854         if (dictionary["SQL_TDS"] == "yes")          qconfigList += "QT_SQL_TDS";
2855         if (dictionary["SQL_DB2"] == "yes")          qconfigList += "QT_SQL_DB2";
2856         if (dictionary["SQL_SQLITE"] == "yes")       qconfigList += "QT_SQL_SQLITE";
2857         if (dictionary["SQL_SQLITE2"] == "yes")      qconfigList += "QT_SQL_SQLITE2";
2858         if (dictionary["SQL_IBASE"] == "yes")        qconfigList += "QT_SQL_IBASE";
2859
2860         qconfigList.sort();
2861         for (int i = 0; i < qconfigList.count(); ++i)
2862             tmpStream << addDefine(qconfigList.at(i));
2863
2864         if (dictionary["EMBEDDED"] == "yes")
2865         {
2866             // Check for keyboard, mouse, gfx.
2867             QStringList kbdDrivers = dictionary["KBD_DRIVERS"].split(" ");;
2868             QStringList allKbdDrivers;
2869             allKbdDrivers<<"tty"<<"usb"<<"sl5000"<<"yopy"<<"vr41xx"<<"qvfb"<<"um";
2870             foreach (const QString &kbd, allKbdDrivers) {
2871                 if (!kbdDrivers.contains(kbd))
2872                     tmpStream<<"#define QT_NO_QWS_KBD_"<<kbd.toUpper()<<endl;
2873             }
2874
2875             QStringList mouseDrivers = dictionary["MOUSE_DRIVERS"].split(" ");
2876             QStringList allMouseDrivers;
2877             allMouseDrivers << "pc"<<"bus"<<"linuxtp"<<"yopy"<<"vr41xx"<<"tslib"<<"qvfb";
2878             foreach (const QString &mouse, allMouseDrivers) {
2879                 if (!mouseDrivers.contains(mouse))
2880                     tmpStream<<"#define QT_NO_QWS_MOUSE_"<<mouse.toUpper()<<endl;
2881             }
2882
2883             QStringList gfxDrivers = dictionary["GFX_DRIVERS"].split(" ");
2884             QStringList allGfxDrivers;
2885             allGfxDrivers<<"linuxfb"<<"transformed"<<"qvfb"<<"multiscreen"<<"ahi";
2886             foreach (const QString &gfx, allGfxDrivers) {
2887                 if (!gfxDrivers.contains(gfx))
2888                     tmpStream<<"#define QT_NO_QWS_"<<gfx.toUpper()<<endl;
2889             }
2890
2891             tmpStream<<"#define Q_WS_QWS"<<endl;
2892
2893             QStringList depths = dictionary[ "QT_QWS_DEPTH" ].split(" ");
2894             foreach (const QString &depth, depths)
2895               tmpStream<<"#define QT_QWS_DEPTH_"+depth<<endl;
2896         }
2897
2898         if (dictionary[ "QT_CUPS" ] == "no")
2899           tmpStream<<"#define QT_NO_CUPS"<<endl;
2900
2901         if (dictionary[ "QT_ICONV" ]  == "no")
2902           tmpStream<<"#define QT_NO_ICONV"<<endl;
2903
2904         if (dictionary[ "QT_GLIB" ] == "no")
2905           tmpStream<<"#define QT_NO_GLIB"<<endl;
2906
2907         if (dictionary[ "QT_LPR" ] == "no")
2908           tmpStream<<"#define QT_NO_LPR"<<endl;
2909
2910         if (dictionary[ "QT_INOTIFY" ] == "no")
2911           tmpStream<<"#define QT_NO_INOTIFY"<<endl;
2912
2913         if (dictionary[ "QT_SXE" ] == "no")
2914           tmpStream<<"#define QT_NO_SXE"<<endl;
2915
2916         tmpStream.flush();
2917         tmpFile.flush();
2918
2919         // Replace old qconfig.h with new one
2920         ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL);
2921         QFile::remove(outName);
2922         tmpFile.copy(outName);
2923         tmpFile.close();
2924     }
2925
2926     QString spec = dictionary.contains("XQMAKESPEC") ? dictionary["XQMAKESPEC"] : dictionary["QMAKESPEC"];
2927     if (!copySpec("default", "", spec))
2928         return;
2929
2930     // Generate the new qconfig.cpp file
2931     QDir(buildPath).mkpath("src/corelib/global");
2932     outName = buildPath + "/src/corelib/global/qconfig.cpp";
2933
2934     QTemporaryFile tmpFile2;
2935     if (tmpFile2.open()) {
2936         tmpStream.setDevice(&tmpFile2);
2937         tmpStream << "/* Licensed */" << endl
2938                   << "static const char qt_configure_licensee_str          [512 + 12] = \"qt_lcnsuser=" << licenseInfo["LICENSEE"] << "\";" << endl
2939                   << "static const char qt_configure_licensed_products_str [512 + 12] = \"qt_lcnsprod=" << dictionary["EDITION"] << "\";" << endl
2940                   << endl
2941                   << "/* Build date */" << endl
2942                   << "static const char qt_configure_installation          [11  + 12] = \"qt_instdate=" << QDate::currentDate().toString(Qt::ISODate) << "\";" << endl
2943                   << endl
2944                   << "static const char qt_configure_prefix_path_strs[][12 + 512] = {" << endl
2945                   << "    \"qt_prfxpath=" << escapeSeparators(dictionary["QT_INSTALL_PREFIX"]) << "\"," << endl
2946                   << "    \"qt_docspath=" << escapeSeparators(dictionary["QT_INSTALL_DOCS"]) << "\","  << endl
2947                   << "    \"qt_hdrspath=" << escapeSeparators(dictionary["QT_INSTALL_HEADERS"]) << "\","  << endl
2948                   << "    \"qt_libspath=" << escapeSeparators(dictionary["QT_INSTALL_LIBS"]) << "\","  << endl
2949                   << "    \"qt_binspath=" << escapeSeparators(dictionary["QT_INSTALL_BINS"]) << "\","  << endl
2950                   << "    \"qt_plugpath=" << escapeSeparators(dictionary["QT_INSTALL_PLUGINS"]) << "\","  << endl
2951                   << "    \"qt_impspath=" << escapeSeparators(dictionary["QT_INSTALL_IMPORTS"]) << "\","  << endl
2952                   << "    \"qt_datapath=" << escapeSeparators(dictionary["QT_INSTALL_DATA"]) << "\","  << endl
2953                   << "    \"qt_trnspath=" << escapeSeparators(dictionary["QT_INSTALL_TRANSLATIONS"]) << "\"," << endl
2954                   << "    \"qt_xmplpath=" << escapeSeparators(dictionary["QT_INSTALL_EXAMPLES"]) << "\","  << endl
2955                   << "    \"qt_tstspath=" << escapeSeparators(dictionary["QT_INSTALL_TESTS"]) << "\","  << endl
2956                   << "#ifdef QT_BUILD_QMAKE" << endl
2957                   << "    \"qt_ssrtpath=" << escapeSeparators(dictionary["CFG_SYSROOT"]) << "\"," << endl
2958                   << "    \"qt_hpfxpath=" << escapeSeparators(dictionary["QT_HOST_PREFIX"]) << "\"," << endl
2959                   << "    \"qt_hbinpath=" << escapeSeparators(dictionary["QT_HOST_BINS"]) << "\"," << endl
2960                   << "    \"qt_hdatpath=" << escapeSeparators(dictionary["QT_HOST_DATA"]) << "\"," << endl
2961                   << "#endif" << endl
2962                   << "};" << endl
2963                   //<< "static const char qt_configure_settings_path_str [256] = \"qt_stngpath=" << escapeSeparators(dictionary["QT_INSTALL_SETTINGS"]) << "\";" << endl
2964                   << endl
2965                   << "/* strlen( \"qt_lcnsxxxx\") == 12 */" << endl
2966                   << "#define QT_CONFIGURE_LICENSEE qt_configure_licensee_str + 12;" << endl
2967                   << "#define QT_CONFIGURE_LICENSED_PRODUCTS qt_configure_licensed_products_str + 12;" << endl
2968                   //<< "#define QT_CONFIGURE_SETTINGS_PATH qt_configure_settings_path_str + 12;" << endl
2969                   << endl;
2970
2971         tmpStream.flush();
2972         tmpFile2.flush();
2973
2974         // Replace old qconfig.cpp with new one
2975         ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL);
2976         QFile::remove(outName);
2977         tmpFile2.copy(outName);
2978         tmpFile2.close();
2979     }
2980
2981     QTemporaryFile tmpFile3;
2982     if (tmpFile3.open()) {
2983         tmpStream.setDevice(&tmpFile3);
2984         tmpStream << "/* Evaluation license key */" << endl
2985                   << "static const volatile char qt_eval_key_data              [512 + 12] = \"qt_qevalkey=" << licenseInfo["LICENSEKEYEXT"] << "\";" << endl;
2986
2987         tmpStream.flush();
2988         tmpFile3.flush();
2989
2990         outName = buildPath + "/src/corelib/global/qconfig_eval.cpp";
2991         ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL);
2992         QFile::remove(outName);
2993
2994         if (dictionary["EDITION"] == "Evaluation" || qmakeDefines.contains("QT_EVAL"))
2995             tmpFile3.copy(outName);
2996         tmpFile3.close();
2997     }
2998 }
2999 #endif
3000
3001 #if !defined(EVAL)
3002 void Configure::displayConfig()
3003 {
3004     // Give some feedback
3005     cout << "Environment:" << endl;
3006     QString env = QString::fromLocal8Bit(getenv("INCLUDE")).replace(QRegExp("[;,]"), "\r\n      ");
3007     if (env.isEmpty())
3008         env = "Unset";
3009     cout << "    INCLUDE=\r\n      " << env << endl;
3010     env = QString::fromLocal8Bit(getenv("LIB")).replace(QRegExp("[;,]"), "\r\n      ");
3011     if (env.isEmpty())
3012         env = "Unset";
3013     cout << "    LIB=\r\n      " << env << endl;
3014     env = QString::fromLocal8Bit(getenv("PATH")).replace(QRegExp("[;,]"), "\r\n      ");
3015     if (env.isEmpty())
3016         env = "Unset";
3017     cout << "    PATH=\r\n      " << env << endl;
3018
3019     if (dictionary["EDITION"] == "OpenSource") {
3020         cout << "You are licensed to use this software under the terms of the GNU GPL version 3.";
3021         cout << "You are licensed to use this software under the terms of the Lesser GNU LGPL version 2.1." << endl;
3022         cout << "See " << dictionary["LICENSE FILE"] << "3" << endl << endl
3023              << " or " << dictionary["LICENSE FILE"] << "L" << endl << endl;
3024     } else {
3025         QString l1 = licenseInfo[ "LICENSEE" ];
3026         QString l2 = licenseInfo[ "LICENSEID" ];
3027         QString l3 = dictionary["EDITION"] + ' ' + "Edition";
3028         QString l4 = licenseInfo[ "EXPIRYDATE" ];
3029         cout << "Licensee...................." << (l1.isNull() ? "" : l1) << endl;
3030         cout << "License ID.................." << (l2.isNull() ? "" : l2) << endl;
3031         cout << "Product license............." << (l3.isNull() ? "" : l3) << endl;
3032         cout << "Expiry Date................." << (l4.isNull() ? "" : l4) << endl << endl;
3033     }
3034
3035     cout << "Configuration:" << endl;
3036     cout << "    " << qmakeConfig.join("\r\n    ") << endl;
3037     cout << "Qt Configuration:" << endl;
3038     cout << "    " << qtConfig.join("\r\n    ") << endl;
3039     cout << endl;
3040
3041     if (dictionary.contains("XQMAKESPEC"))
3042         cout << "QMAKESPEC..................." << dictionary[ "XQMAKESPEC" ] << " (" << dictionary["QMAKESPEC_FROM"] << ")" << endl;
3043     else
3044         cout << "QMAKESPEC..................." << dictionary[ "QMAKESPEC" ] << " (" << dictionary["QMAKESPEC_FROM"] << ")" << endl;
3045     cout << "Architecture................" << dictionary["QT_ARCH"] << endl;
3046     cout << "Host Architecture..........." << dictionary["QT_HOST_ARCH"] << endl;
3047     cout << "Maketool...................." << dictionary[ "MAKE" ] << endl;
3048     cout << "Debug symbols..............." << (dictionary[ "BUILD" ] == "debug" ? "yes" : "no") << endl;
3049     cout << "Link Time Code Generation..." << dictionary[ "LTCG" ] << endl;
3050     cout << "Accessibility support......." << dictionary[ "ACCESSIBILITY" ] << endl;
3051     cout << "STL support................." << dictionary[ "STL" ] << endl;
3052     cout << "Exception support..........." << dictionary[ "EXCEPTIONS" ] << endl;
3053     cout << "RTTI support................" << dictionary[ "RTTI" ] << endl;
3054     cout << "MMX support................." << dictionary[ "MMX" ] << endl;
3055     cout << "3DNOW support..............." << dictionary[ "3DNOW" ] << endl;
3056     cout << "SSE support................." << dictionary[ "SSE" ] << endl;
3057     cout << "SSE2 support................" << dictionary[ "SSE2" ] << endl;
3058     cout << "IWMMXT support.............." << dictionary[ "IWMMXT" ] << endl;
3059     cout << "OpenGL support.............." << dictionary[ "OPENGL" ] << endl;
3060     cout << "OpenVG support.............." << dictionary[ "OPENVG" ] << endl;
3061     cout << "OpenSSL support............." << dictionary[ "OPENSSL" ] << endl;
3062     cout << "QtDBus support.............." << dictionary[ "DBUS" ] << endl;
3063     cout << "QtWidgets module support...." << dictionary[ "WIDGETS" ] << endl;
3064     cout << "QML debugging..............." << dictionary[ "QML_DEBUG" ] << endl;
3065     cout << "DirectWrite support........." << dictionary[ "DIRECTWRITE" ] << endl << endl;
3066
3067     cout << "Third Party Libraries:" << endl;
3068     cout << "    ZLIB support............" << dictionary[ "ZLIB" ] << endl;
3069     cout << "    GIF support............." << dictionary[ "GIF" ] << endl;
3070     cout << "    JPEG support............" << dictionary[ "JPEG" ] << endl;
3071     cout << "    PNG support............." << dictionary[ "PNG" ] << endl;
3072     cout << "    FreeType support........" << dictionary[ "FREETYPE" ] << endl << endl;
3073     cout << "    PCRE support............" << dictionary[ "PCRE" ] << endl;
3074     cout << "    ICU support............." << dictionary[ "ICU" ] << endl;
3075
3076     cout << "Styles:" << endl;
3077     cout << "    Windows................." << dictionary[ "STYLE_WINDOWS" ] << endl;
3078     cout << "    Windows XP.............." << dictionary[ "STYLE_WINDOWSXP" ] << endl;
3079     cout << "    Windows Vista..........." << dictionary[ "STYLE_WINDOWSVISTA" ] << endl;
3080     cout << "    Plastique..............." << dictionary[ "STYLE_PLASTIQUE" ] << endl;
3081     cout << "    Cleanlooks.............." << dictionary[ "STYLE_CLEANLOOKS" ] << endl;
3082     cout << "    Motif..................." << dictionary[ "STYLE_MOTIF" ] << endl;
3083     cout << "    CDE....................." << dictionary[ "STYLE_CDE" ] << endl;
3084     cout << "    Windows CE.............." << dictionary[ "STYLE_WINDOWSCE" ] << endl;
3085     cout << "    Windows Mobile.........." << dictionary[ "STYLE_WINDOWSMOBILE" ] << endl << endl;
3086
3087     cout << "Sql Drivers:" << endl;
3088     cout << "    ODBC...................." << dictionary[ "SQL_ODBC" ] << endl;
3089     cout << "    MySQL..................." << dictionary[ "SQL_MYSQL" ] << endl;
3090     cout << "    OCI....................." << dictionary[ "SQL_OCI" ] << endl;
3091     cout << "    PostgreSQL.............." << dictionary[ "SQL_PSQL" ] << endl;
3092     cout << "    TDS....................." << dictionary[ "SQL_TDS" ] << endl;
3093     cout << "    DB2....................." << dictionary[ "SQL_DB2" ] << endl;
3094     cout << "    SQLite.................." << dictionary[ "SQL_SQLITE" ] << " (" << dictionary[ "SQL_SQLITE_LIB" ] << ")" << endl;
3095     cout << "    SQLite2................." << dictionary[ "SQL_SQLITE2" ] << endl;
3096     cout << "    InterBase..............." << dictionary[ "SQL_IBASE" ] << endl << endl;
3097
3098     cout << "Sources are in.............." << dictionary[ "QT_SOURCE_TREE" ] << endl;
3099     cout << "Build is done in............" << dictionary[ "QT_BUILD_TREE" ] << endl;
3100     cout << "Install prefix.............." << dictionary[ "QT_INSTALL_PREFIX" ] << endl;
3101     cout << "Headers installed to........" << dictionary[ "QT_INSTALL_HEADERS" ] << endl;
3102     cout << "Libraries installed to......" << dictionary[ "QT_INSTALL_LIBS" ] << endl;
3103     cout << "Plugins installed to........" << dictionary[ "QT_INSTALL_PLUGINS" ] << endl;
3104     cout << "Imports installed to........" << dictionary[ "QT_INSTALL_IMPORTS" ] << endl;
3105     cout << "Binaries installed to......." << dictionary[ "QT_INSTALL_BINS" ] << endl;
3106     cout << "Docs installed to..........." << dictionary[ "QT_INSTALL_DOCS" ] << endl;
3107     cout << "Data installed to..........." << dictionary[ "QT_INSTALL_DATA" ] << endl;
3108     cout << "Translations installed to..." << dictionary[ "QT_INSTALL_TRANSLATIONS" ] << endl;
3109     cout << "Examples installed to......." << dictionary[ "QT_INSTALL_EXAMPLES" ] << endl;
3110     cout << "Tests installed to.........." << dictionary[ "QT_INSTALL_TESTS" ] << endl;
3111
3112     if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith(QLatin1String("wince"))) {
3113         cout << "Using c runtime detection..." << dictionary[ "CE_CRT" ] << endl;
3114         cout << "Cetest support.............." << dictionary[ "CETEST" ] << endl;
3115         cout << "Signature..................." << dictionary[ "CE_SIGNATURE"] << endl << endl;
3116     }
3117
3118     if (checkAvailability("INCREDIBUILD_XGE"))
3119         cout << "Using IncrediBuild XGE......" << dictionary["INCREDIBUILD_XGE"] << endl;
3120     if (!qmakeDefines.isEmpty()) {
3121         cout << "Defines.....................";
3122         for (QStringList::Iterator defs = qmakeDefines.begin(); defs != qmakeDefines.end(); ++defs)
3123             cout << (*defs) << " ";
3124         cout << endl;
3125     }
3126     if (!qmakeIncludes.isEmpty()) {
3127         cout << "Include paths...............";
3128         for (QStringList::Iterator incs = qmakeIncludes.begin(); incs != qmakeIncludes.end(); ++incs)
3129             cout << (*incs) << " ";
3130         cout << endl;
3131     }
3132     if (!qmakeLibs.isEmpty()) {
3133         cout << "Additional libraries........";
3134         for (QStringList::Iterator libs = qmakeLibs.begin(); libs != qmakeLibs.end(); ++libs)
3135             cout << (*libs) << " ";
3136         cout << endl;
3137     }
3138     if (dictionary[ "QMAKE_INTERNAL" ] == "yes") {
3139         cout << "Using internal configuration." << endl;
3140     }
3141     if (dictionary[ "SHARED" ] == "no") {
3142         cout << "WARNING: Using static linking will disable the use of plugins." << endl;
3143         cout << "         Make sure you compile ALL needed modules into the library." << endl;
3144     }
3145     if (dictionary[ "OPENSSL" ] == "linked" && opensslLibs.isEmpty()) {
3146         cout << "NOTE: When linking against OpenSSL, you can override the default" << endl;
3147         cout << "library names through OPENSSL_LIBS." << endl;
3148         cout << "For example:" << endl;
3149         cout << "    configure -openssl-linked OPENSSL_LIBS=\"-lssleay32 -llibeay32\"" << endl;
3150     }
3151     if (dictionary[ "ZLIB_FORCED" ] == "yes") {
3152         QString which_zlib = "supplied";
3153         if (dictionary[ "ZLIB" ] == "system")
3154             which_zlib = "system";
3155
3156         cout << "NOTE: The -no-zlib option was supplied but is no longer supported." << endl
3157              << endl
3158              << "Qt now requires zlib support in all builds, so the -no-zlib" << endl
3159              << "option was ignored. Qt will be built using the " << which_zlib
3160              << "zlib" << endl;
3161     }
3162     if (dictionary["OBSOLETE_ARCH_ARG"] == "yes") {
3163         cout << endl
3164              << "NOTE: The -arch option is obsolete." << endl
3165              << endl
3166              << "Qt now detects the target and host architectures based on compiler" << endl
3167              << "output. Qt will be built using " << dictionary["QT_ARCH"] << " for the target architecture" << endl
3168              << "and " << dictionary["QT_HOST_ARCH"] << " for the host architecture (note that these two" << endl
3169              << "will be the same unless you are cross-compiling)." << endl
3170              << endl;
3171     }
3172 }
3173 #endif
3174
3175 #if !defined(EVAL)
3176 void Configure::generateHeaders()
3177 {
3178     if (dictionary["SYNCQT"] == "yes") {
3179         if (findFile("perl.exe")) {
3180             cout << "Running syncqt..." << endl;
3181             QStringList args;
3182             args += buildPath + "/bin/syncqt.bat";
3183             args += sourcePath;
3184             QStringList env;
3185             env += QString("QTDIR=" + sourcePath);
3186             env += QString("PATH=" + buildPath + "/bin/;" + qgetenv("PATH"));
3187             int retc = Environment::execute(args, env, QStringList());
3188             if (retc) {
3189                 cout << "syncqt failed, return code " << retc << endl << endl;
3190                 dictionary["DONE"] = "error";
3191             }
3192         } else {
3193             cout << "Perl not found in environment - cannot run syncqt." << endl;
3194             dictionary["DONE"] = "error";
3195         }
3196     }
3197 }
3198
3199 void Configure::buildQmake()
3200 {
3201     if (dictionary[ "BUILD_QMAKE" ] == "yes") {
3202         QStringList args;
3203
3204         // Build qmake
3205         QString pwd = QDir::currentPath();
3206         if (!QDir(buildPath).mkpath("qmake")) {
3207             cout << "Cannot create qmake build dir." << endl;
3208             dictionary[ "DONE" ] = "error";
3209             return;
3210         }
3211         if (!QDir::setCurrent(buildPath + "/qmake")) {
3212             cout << "Cannot enter qmake build dir." << endl;
3213             dictionary[ "DONE" ] = "error";
3214             return;
3215         }
3216
3217         QString makefile = "Makefile";
3218         {
3219             QFile out(makefile);
3220             if (out.open(QFile::WriteOnly | QFile::Text)) {
3221                 QTextStream stream(&out);
3222                 stream << "#AutoGenerated by configure.exe" << endl
3223                     << "BUILD_PATH = " << QDir::toNativeSeparators(buildPath) << endl
3224                     << "SOURCE_PATH = " << QDir::toNativeSeparators(sourcePath) << endl;
3225                 stream << "QMAKESPEC = " << dictionary["QMAKESPEC"] << endl
3226                        << "QT_VERSION = " << dictionary["VERSION"] << endl;
3227
3228                 if (dictionary["EDITION"] == "OpenSource" ||
3229                     dictionary["QT_EDITION"].contains("OPENSOURCE"))
3230                     stream << "QMAKE_OPENSOURCE_EDITION = yes" << endl;
3231                 stream << "\n\n";
3232
3233                 QFile in(sourcePath + "/qmake/" + dictionary["QMAKEMAKEFILE"]);
3234                 if (in.open(QFile::ReadOnly | QFile::Text)) {
3235                     QString d = in.readAll();
3236                     //### need replaces (like configure.sh)? --Sam
3237                     stream << d << endl;
3238                 }
3239                 stream.flush();
3240                 out.close();
3241             }
3242         }
3243
3244         args += dictionary[ "MAKE" ];
3245         args += "-f";
3246         args += makefile;
3247
3248         cout << "Creating qmake..." << endl;
3249         int exitCode = Environment::execute(args, QStringList(), QStringList());
3250         if (exitCode) {
3251             args.clear();
3252             args += dictionary[ "MAKE" ];
3253             args += "-f";
3254             args += makefile;
3255             args += "clean";
3256             exitCode = Environment::execute(args, QStringList(), QStringList());
3257             if (exitCode) {
3258                 cout << "Cleaning qmake failed, return code " << exitCode << endl << endl;
3259                 dictionary[ "DONE" ] = "error";
3260             } else {
3261                 args.clear();
3262                 args += dictionary[ "MAKE" ];
3263                 args += "-f";
3264                 args += makefile;
3265                 exitCode = Environment::execute(args, QStringList(), QStringList());
3266                 if (exitCode) {
3267                     cout << "Building qmake failed, return code " << exitCode << endl << endl;
3268                     dictionary[ "DONE" ] = "error";
3269                 }
3270             }
3271         }
3272         QDir::setCurrent(pwd);
3273     }
3274 }
3275 #endif
3276
3277 void Configure::buildHostTools()
3278 {
3279     if (dictionary[ "NOPROCESS" ] == "yes")
3280         dictionary[ "DONE" ] = "yes";
3281
3282     if (!dictionary.contains("XQMAKESPEC"))
3283         return;
3284
3285     QString pwd = QDir::currentPath();
3286     QStringList hostToolsDirs;
3287     hostToolsDirs
3288         << "src/tools";
3289
3290     for (int i = 0; i < hostToolsDirs.count(); ++i) {
3291         cout << "Creating " << hostToolsDirs.at(i) << " ..." << endl;
3292         QString toolBuildPath = buildPath + "/" + hostToolsDirs.at(i);
3293         QString toolSourcePath = sourcePath + "/" + hostToolsDirs.at(i);
3294
3295         // generate Makefile
3296         QStringList args;
3297         args << QDir::toNativeSeparators(buildPath + "/bin/qmake");
3298         // override .qmake.cache because we are not cross-building these.
3299         // we need a full path so that a build with -prefix will still find it.
3300         args << "-spec" << QDir::toNativeSeparators(buildPath + "/mkspecs/" + dictionary["QMAKESPEC"]);
3301         args << "-r";
3302         args << "-o" << QDir::toNativeSeparators(toolBuildPath + "/Makefile");
3303
3304         QDir().mkpath(toolBuildPath);
3305         QDir::setCurrent(toolSourcePath);
3306         int exitCode = Environment::execute(args, QStringList(), QStringList());
3307         if (exitCode) {
3308             cout << "qmake failed, return code " << exitCode << endl << endl;
3309             dictionary["DONE"] = "error";
3310             break;
3311         }
3312
3313         // build app
3314         args.clear();
3315         args += dictionary["MAKE"];
3316         QDir::setCurrent(toolBuildPath);
3317         exitCode = Environment::execute(args, QStringList(), QStringList());
3318         if (exitCode) {
3319             args.clear();
3320             args += dictionary["MAKE"];
3321             args += "clean";
3322             exitCode = Environment::execute(args, QStringList(), QStringList());
3323             if (exitCode) {
3324                 cout << "Cleaning " << hostToolsDirs.at(i) << " failed, return code " << exitCode << endl << endl;
3325                 dictionary["DONE"] = "error";
3326                 break;
3327             } else {
3328                 args.clear();
3329                 args += dictionary["MAKE"];
3330                 exitCode = Environment::execute(args, QStringList(), QStringList());
3331                 if (exitCode) {
3332                     cout << "Building " << hostToolsDirs.at(i) << " failed, return code " << exitCode << endl << endl;
3333                     dictionary["DONE"] = "error";
3334                     break;
3335                 }
3336             }
3337         }
3338     }
3339     QDir::setCurrent(pwd);
3340 }
3341
3342 void Configure::findProjects(const QString& dirName)
3343 {
3344     if (dictionary[ "NOPROCESS" ] == "no") {
3345         QDir dir(dirName);
3346         QString entryName;
3347         int makeListNumber;
3348         ProjectType qmakeTemplate;
3349         const QFileInfoList &list = dir.entryInfoList(QStringList(QLatin1String("*.pro")),
3350                                                       QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
3351         for (int i = 0; i < list.size(); ++i) {
3352             const QFileInfo &fi = list.at(i);
3353             if (fi.fileName() != "qmake.pro") {
3354                 entryName = dirName + "/" + fi.fileName();
3355                 if (fi.isDir()) {
3356                     findProjects(entryName);
3357                 } else {
3358                     qmakeTemplate = projectType(fi.absoluteFilePath());
3359                     switch (qmakeTemplate) {
3360                     case Lib:
3361                     case Subdirs:
3362                         makeListNumber = 1;
3363                         break;
3364                     default:
3365                         makeListNumber = 2;
3366                         break;
3367                     }
3368                     makeList[makeListNumber].append(new MakeItem(sourceDir.relativeFilePath(fi.absolutePath()),
3369                                                     fi.fileName(),
3370                                                     "Makefile",
3371                                                     qmakeTemplate));
3372                 }
3373             }
3374
3375         }
3376     }
3377 }
3378
3379 void Configure::appendMakeItem(int inList, const QString &item)
3380 {
3381     QString dir;
3382     if (item != "src")
3383         dir = "/" + item;
3384     dir.prepend("/src");
3385     makeList[inList].append(new MakeItem(sourcePath + dir,
3386         item + ".pro", buildPath + dir + "/Makefile", Lib));
3387     if (dictionary[ "DSPFILES" ] == "yes") {
3388         makeList[inList].append(new MakeItem(sourcePath + dir,
3389             item + ".pro", buildPath + dir + "/" + item + ".dsp", Lib));
3390     }
3391     if (dictionary[ "VCPFILES" ] == "yes") {
3392         makeList[inList].append(new MakeItem(sourcePath + dir,
3393             item + ".pro", buildPath + dir + "/" + item + ".vcp", Lib));
3394     }
3395     if (dictionary[ "VCPROJFILES" ] == "yes") {
3396         makeList[inList].append(new MakeItem(sourcePath + dir,
3397             item + ".pro", buildPath + dir + "/" + item + ".vcproj", Lib));
3398     }
3399 }
3400
3401 void Configure::generateMakefiles()
3402 {
3403     if (dictionary[ "NOPROCESS" ] == "no") {
3404 #if !defined(EVAL)
3405         cout << "Creating makefiles in src..." << endl;
3406 #endif
3407
3408         QString spec = dictionary.contains("XQMAKESPEC") ? dictionary[ "XQMAKESPEC" ] : dictionary[ "QMAKESPEC" ];
3409         if (spec != "win32-msvc")
3410             dictionary[ "DSPFILES" ] = "no";
3411
3412         if (spec != "win32-msvc.net" && !spec.startsWith("win32-msvc2") && !spec.startsWith(QLatin1String("wince")))
3413             dictionary[ "VCPROJFILES" ] = "no";
3414
3415         int i = 0;
3416         QString pwd = QDir::currentPath();
3417         if (dictionary["FAST"] != "yes") {
3418             QString dirName;
3419             bool generate = true;
3420             bool doDsp = (dictionary["DSPFILES"] == "yes" || dictionary["VCPFILES"] == "yes"
3421                           || dictionary["VCPROJFILES"] == "yes");
3422             while (generate) {
3423                 QString pwd = QDir::currentPath();
3424                 QString dirPath = fixSeparators(buildPath + dirName);
3425                 QStringList args;
3426
3427                 args << fixSeparators(buildPath + "/bin/qmake");
3428
3429                 if (doDsp) {
3430                     if (dictionary[ "DEPENDENCIES" ] == "no")
3431                         args << "-nodepend";
3432                     args << "-tp" <<  "vc";
3433                     doDsp = false; // DSP files will be done
3434                     printf("Generating Visual Studio project files...\n");
3435                 } else {
3436                     printf("Generating Makefiles...\n");
3437                     generate = false; // Now Makefiles will be done
3438                 }
3439                 // don't pass -spec - .qmake.cache has it already
3440                 args << "-r";
3441                 args << (sourcePath + "/qtbase.pro");
3442                 args << "-o";
3443                 args << buildPath;
3444                 if (!dictionary[ "QMAKEADDITIONALARGS" ].isEmpty())
3445                     args << dictionary[ "QMAKEADDITIONALARGS" ];
3446
3447                 QDir::setCurrent(fixSeparators(dirPath));
3448                 if (int exitCode = Environment::execute(args, QStringList(), QStringList())) {
3449                     cout << "Qmake failed, return code " << exitCode  << endl << endl;
3450                     dictionary[ "DONE" ] = "error";
3451                 }
3452             }
3453         } else {
3454             findProjects(sourcePath);
3455             for (i=0; i<3; i++) {
3456                 for (int j=0; j<makeList[i].size(); ++j) {
3457                     MakeItem *it=makeList[i][j];
3458                     QString dirPath = fixSeparators(it->directory + "/");
3459                     QString projectName = it->proFile;
3460                     QString makefileName = buildPath + "/" + dirPath + it->target;
3461
3462                     // For shadowbuilds, we need to create the path first
3463                     QDir buildPathDir(buildPath);
3464                     if (sourcePath != buildPath && !buildPathDir.exists(dirPath))
3465                         buildPathDir.mkpath(dirPath);
3466
3467                     QStringList args;
3468
3469                     args << fixSeparators(buildPath + "/bin/qmake");
3470                     args << sourcePath + "/" + dirPath + projectName;
3471                     args << dictionary[ "QMAKE_ALL_ARGS" ];
3472
3473                     cout << "For " << qPrintable(dirPath + projectName) << endl;
3474                     args << "-o";
3475                     args << it->target;
3476                     args << "-spec";
3477                     args << spec;
3478                     if (!dictionary[ "QMAKEADDITIONALARGS" ].isEmpty())
3479                         args << dictionary[ "QMAKEADDITIONALARGS" ];
3480
3481                     QDir::setCurrent(fixSeparators(dirPath));
3482
3483                     QFile file(makefileName);
3484                     if (!file.open(QFile::WriteOnly)) {
3485                         printf("failed on dirPath=%s, makefile=%s\n",
3486                             qPrintable(dirPath), qPrintable(makefileName));
3487                         continue;
3488                     }
3489                     QTextStream txt(&file);
3490                     txt << "all:\n";
3491                     txt << "\t" << args.join(" ") << "\n";
3492                     txt << "\t\"$(MAKE)\" -$(MAKEFLAGS) -f " << it->target << "\n";
3493                     txt << "first: all\n";
3494                     txt << "qmake:\n";
3495                     txt << "\t" << args.join(" ") << "\n";
3496                 }
3497             }
3498         }
3499         QDir::setCurrent(pwd);
3500     } else {
3501         cout << "Processing of project files have been disabled." << endl;
3502         cout << "Only use this option if you really know what you're doing." << endl << endl;
3503         return;
3504     }
3505 }
3506
3507 void Configure::showSummary()
3508 {
3509     QString make = dictionary[ "MAKE" ];
3510     if (!dictionary.contains("XQMAKESPEC")) {
3511         cout << endl << endl << "Qt is now configured for building. Just run " << qPrintable(make) << "." << endl;
3512         cout << "To reconfigure, run " << qPrintable(make) << " confclean and configure." << endl << endl;
3513     } else if (dictionary.value("QMAKESPEC").startsWith("wince")) {
3514         // we are cross compiling for Windows CE
3515         cout << endl << endl << "Qt is now configured for building. To start the build run:" << endl
3516              << "\tsetcepaths " << dictionary.value("XQMAKESPEC") << endl
3517              << "\t" << qPrintable(make) << endl
3518              << "To reconfigure, run " << qPrintable(make) << " confclean and configure." << endl << endl;
3519     }
3520 }
3521
3522 Configure::ProjectType Configure::projectType(const QString& proFileName)
3523 {
3524     QFile proFile(proFileName);
3525     if (proFile.open(QFile::ReadOnly)) {
3526         QString buffer = proFile.readLine(1024);
3527         while (!buffer.isEmpty()) {
3528             QStringList segments = buffer.split(QRegExp("\\s"));
3529             QStringList::Iterator it = segments.begin();
3530
3531             if (segments.size() >= 3) {
3532                 QString keyword = (*it++);
3533                 QString operation = (*it++);
3534                 QString value = (*it++);
3535
3536                 if (keyword == "TEMPLATE") {
3537                     if (value == "lib")
3538                         return Lib;
3539                     else if (value == "subdirs")
3540                         return Subdirs;
3541                 }
3542             }
3543             // read next line
3544             buffer = proFile.readLine(1024);
3545         }
3546         proFile.close();
3547     }
3548     // Default to app handling
3549     return App;
3550 }
3551
3552 #if !defined(EVAL)
3553
3554 bool Configure::showLicense(QString orgLicenseFile)
3555 {
3556     if (dictionary["LICENSE_CONFIRMED"] == "yes") {
3557         cout << "You have already accepted the terms of the license." << endl << endl;
3558         return true;
3559     }
3560
3561     bool haveGpl3 = false;
3562     QString licenseFile = orgLicenseFile;
3563     QString theLicense;
3564     if (dictionary["EDITION"] == "OpenSource" || dictionary["EDITION"] == "Snapshot") {
3565         haveGpl3 = QFile::exists(orgLicenseFile + "/LICENSE.GPL3");
3566         theLicense = "GNU Lesser General Public License (LGPL) version 2.1";
3567         if (haveGpl3)
3568             theLicense += "\nor the GNU General Public License (GPL) version 3";
3569     } else {
3570         // the first line of the license file tells us which license it is
3571         QFile file(licenseFile);
3572         if (!file.open(QFile::ReadOnly)) {
3573             cout << "Failed to load LICENSE file" << endl;
3574             return false;
3575         }
3576         theLicense = file.readLine().trimmed();
3577     }
3578
3579     forever {
3580         char accept = '?';
3581         cout << "You are licensed to use this software under the terms of" << endl
3582              << "the " << theLicense << "." << endl
3583              << endl;
3584         if (dictionary["EDITION"] == "OpenSource" || dictionary["EDITION"] == "Snapshot") {
3585             if (haveGpl3)
3586                 cout << "Type '3' to view the GNU General Public License version 3 (GPLv3)." << endl;
3587             cout << "Type 'L' to view the Lesser GNU General Public License version 2.1 (LGPLv2.1)." << endl;
3588         } else {
3589             cout << "Type '?' to view the " << theLicense << "." << endl;
3590         }
3591         cout << "Type 'y' to accept this license offer." << endl
3592              << "Type 'n' to decline this license offer." << endl
3593              << endl
3594              << "Do you accept the terms of the license?" << endl;
3595         cin >> accept;
3596         accept = tolower(accept);
3597
3598         if (accept == 'y') {
3599             return true;
3600         } else if (accept == 'n') {
3601             return false;
3602         } else {
3603             if (dictionary["EDITION"] == "OpenSource" || dictionary["EDITION"] == "Snapshot") {
3604                 if (accept == '3')
3605                     licenseFile = orgLicenseFile + "/LICENSE.GPL3";
3606                 else
3607                     licenseFile = orgLicenseFile + "/LICENSE.LGPL";
3608             }
3609             // Get console line height, to fill the screen properly
3610             int i = 0, screenHeight = 25; // default
3611             CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
3612             HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
3613             if (GetConsoleScreenBufferInfo(stdOut, &consoleInfo))
3614                 screenHeight = consoleInfo.srWindow.Bottom
3615                              - consoleInfo.srWindow.Top
3616                              - 1; // Some overlap for context
3617
3618             // Prompt the license content to the user
3619             QFile file(licenseFile);
3620             if (!file.open(QFile::ReadOnly)) {
3621                 cout << "Failed to load LICENSE file" << licenseFile << endl;
3622                 return false;
3623             }
3624             QStringList licenseContent = QString(file.readAll()).split('\n');
3625             while (i < licenseContent.size()) {
3626                 cout << licenseContent.at(i) << endl;
3627                 if (++i % screenHeight == 0) {
3628                     cout << "(Press any key for more..)";
3629                     if (_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
3630                         exit(0);      // Exit cleanly for Ctrl+C
3631                     cout << "\r";     // Overwrite text above
3632                 }
3633             }
3634         }
3635     }
3636 }
3637
3638 void Configure::readLicense()
3639 {
3640    if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/src/corelib/kernel/qfunctions_wince.h") &&
3641        (dictionary.value("QMAKESPEC").startsWith("wince") || dictionary.value("XQMAKESPEC").startsWith("wince")))
3642         dictionary["PLATFORM NAME"] = "Qt for Windows CE";
3643     else
3644         dictionary["PLATFORM NAME"] = "Qt for Windows";
3645     dictionary["LICENSE FILE"] = sourcePath;
3646
3647     bool openSource = false;
3648     bool hasOpenSource = QFile::exists(dictionary["LICENSE FILE"] + "/LICENSE.GPL3") || QFile::exists(dictionary["LICENSE FILE"] + "/LICENSE.LGPL");
3649     if (dictionary["BUILDTYPE"] == "commercial") {
3650         openSource = false;
3651     } else if (dictionary["BUILDTYPE"] == "opensource") {
3652         openSource = true;
3653     } else if (hasOpenSource) { // No Open Source? Just display the commercial license right away
3654         forever {
3655             char accept = '?';
3656             cout << "Which edition of Qt do you want to use ?" << endl;
3657             cout << "Type 'c' if you want to use the Commercial Edition." << endl;
3658             cout << "Type 'o' if you want to use the Open Source Edition." << endl;
3659             cin >> accept;
3660             accept = tolower(accept);
3661
3662             if (accept == 'c') {
3663                 openSource = false;
3664                 break;
3665             } else if (accept == 'o') {
3666                 openSource = true;
3667                 break;
3668             }
3669         }
3670     }
3671     if (hasOpenSource && openSource) {
3672         cout << endl << "This is the " << dictionary["PLATFORM NAME"] << " Open Source Edition." << endl;
3673         licenseInfo["LICENSEE"] = "Open Source";
3674         dictionary["EDITION"] = "OpenSource";
3675         dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
3676         cout << endl;
3677         if (!showLicense(dictionary["LICENSE FILE"])) {
3678             cout << "Configuration aborted since license was not accepted";
3679             dictionary["DONE"] = "error";
3680             return;
3681         }
3682     } else if (openSource) {
3683         cout << endl << "Cannot find the GPL license files! Please download the Open Source version of the library." << endl;
3684         dictionary["DONE"] = "error";
3685     }
3686 #ifdef COMMERCIAL_VERSION
3687     else {
3688         Tools::checkLicense(dictionary, licenseInfo, firstLicensePath());
3689         if (dictionary["DONE"] != "error") {
3690             // give the user some feedback, and prompt for license acceptance
3691             cout << endl << "This is the " << dictionary["PLATFORM NAME"] << " " << dictionary["EDITION"] << " Edition."<< endl << endl;
3692             if (!showLicense(dictionary["LICENSE FILE"])) {
3693                 cout << "Configuration aborted since license was not accepted";
3694                 dictionary["DONE"] = "error";
3695                 return;
3696             }
3697         }
3698     }
3699 #else // !COMMERCIAL_VERSION
3700     else {
3701         cout << endl << "Cannot build commercial edition from the open source version of the library." << endl;
3702         dictionary["DONE"] = "error";
3703     }
3704 #endif
3705 }
3706
3707 void Configure::reloadCmdLine()
3708 {
3709     if (dictionary[ "REDO" ] == "yes") {
3710         QFile inFile(buildPath + "/configure" + dictionary[ "CUSTOMCONFIG" ] + ".cache");
3711         if (inFile.open(QFile::ReadOnly)) {
3712             QTextStream inStream(&inFile);
3713             QString buffer;
3714             inStream >> buffer;
3715             while (buffer.length()) {
3716                 configCmdLine += buffer;
3717                 inStream >> buffer;
3718             }
3719             inFile.close();
3720         }
3721     }
3722 }
3723
3724 void Configure::saveCmdLine()
3725 {
3726     if (dictionary[ "REDO" ] != "yes") {
3727         QFile outFile(buildPath + "/configure" + dictionary[ "CUSTOMCONFIG" ] + ".cache");
3728         if (outFile.open(QFile::WriteOnly | QFile::Text)) {
3729             QTextStream outStream(&outFile);
3730             for (QStringList::Iterator it = configCmdLine.begin(); it != configCmdLine.end(); ++it) {
3731                 outStream << (*it) << " " << endl;
3732             }
3733             outStream.flush();
3734             outFile.close();
3735         }
3736     }
3737 }
3738 #endif // !EVAL
3739
3740 bool Configure::isDone()
3741 {
3742     return !dictionary["DONE"].isEmpty();
3743 }
3744
3745 bool Configure::isOk()
3746 {
3747     return (dictionary[ "DONE" ] != "error");
3748 }
3749
3750 bool
3751 Configure::filesDiffer(const QString &fn1, const QString &fn2)
3752 {
3753     QFile file1(fn1), file2(fn2);
3754     if (!file1.open(QFile::ReadOnly) || !file2.open(QFile::ReadOnly))
3755         return true;
3756     const int chunk = 2048;
3757     int used1 = 0, used2 = 0;
3758     char b1[chunk], b2[chunk];
3759     while (!file1.atEnd() && !file2.atEnd()) {
3760         if (!used1)
3761             used1 = file1.read(b1, chunk);
3762         if (!used2)
3763             used2 = file2.read(b2, chunk);
3764         if (used1 > 0 && used2 > 0) {
3765             const int cmp = qMin(used1, used2);
3766             if (memcmp(b1, b2, cmp))
3767                 return true;
3768             if ((used1 -= cmp))
3769                 memcpy(b1, b1+cmp, used1);
3770             if ((used2 -= cmp))
3771                 memcpy(b2, b2+cmp, used2);
3772         }
3773     }
3774     return !file1.atEnd() || !file2.atEnd();
3775 }
3776
3777 QT_END_NAMESPACE