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