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