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