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