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