Merge remote branch 'origin/4.6' into integration-master-from-4.6
[qt:kenya888s-qt-palm-pre.git] / qmake / generators / symbian / symmake.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the qmake application of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "symmake.h"
43
44 #include <qstring.h>
45 #include <qhash.h>
46 #include <qstringlist.h>
47 #include <qdir.h>
48 #include <qdatetime.h>
49 #include <stdlib.h>
50 #include <qdebug.h>
51
52 #ifdef Q_OS_WIN
53 #define SCRIPT_EXT ".bat"
54 #else
55 #define SCRIPT_EXT ".sh"
56 #endif
57
58 #define RESOURCE_DIRECTORY_MMP "/resource/apps"
59 #define RESOURCE_DIRECTORY_RESOURCE "\\\\resource\\\\apps\\\\"
60 #define REGISTRATION_RESOURCE_DIRECTORY_HW "/private/10003a3f/import/apps"
61 #define PLUGIN_COMMON_DEF_FILE_FOR_MMP "./plugin_common.def"
62 #define PLUGIN_COMMON_DEF_FILE_ACTUAL "plugin_commonu.def"
63 #define BLD_INF_FILENAME_LEN (sizeof(BLD_INF_FILENAME) - 1)
64
65 #define BLD_INF_RULES_BASE "BLD_INF_RULES."
66 #define BLD_INF_TAG_PLATFORMS "prj_platforms"
67 #define BLD_INF_TAG_MMPFILES "prj_mmpfiles"
68 #define BLD_INF_TAG_TESTMMPFILES "prj_testmmpfiles"
69 #define BLD_INF_TAG_EXTENSIONS "prj_extensions"
70 #define BLD_INF_TAG_EXPORTS "prj_exports"
71
72 #define RSS_RULES "RSS_RULES"
73 #define RSS_RULES_BASE "RSS_RULES."
74 #define RSS_TAG_NBROFICONS "number_of_icons"
75 #define RSS_TAG_ICONFILE "icon_file"
76
77 #define MMP_TARGET "TARGET"
78 #define MMP_TARGETTYPE "TARGETTYPE"
79 #define MMP_SECUREID "SECUREID"
80 #define MMP_OPTION_CW "OPTION CW"
81 #define MMP_OPTION_ARMCC "OPTION ARMCC"
82 #define MMP_OPTION_GCCE "OPTION GCCE"
83 #define MMP_LINKEROPTION_CW "LINKEROPTION CW"
84 #define MMP_LINKEROPTION_ARMCC "LINKEROPTION ARMCC"
85 #define MMP_LINKEROPTION_GCCE "LINKEROPTION GCCE"
86 #define MMP_CAPABILITY "CAPABILITY"
87 #define MMP_EPOCALLOWDLLDATA "EPOCALLOWDLLDATA"
88 #define MMP_EPOCHEAPSIZE "EPOCHEAPSIZE"
89 #define MMP_EPOCSTACKSIZE "EPOCSTACKSIZE"
90 #define MMP_UID "UID"
91 #define MMP_VENDORID "VENDORID"
92 #define MMP_VERSION "VERSION"
93 #define MMP_START_RESOURCE "START RESOURCE"
94 #define MMP_END_RESOURCE "END"
95
96 #define SIS_TARGET "sis"
97 #define INSTALLER_SIS_TARGET "installer_sis"
98 #define ROM_STUB_SIS_TARGET "stub_sis"
99 #define OK_SIS_TARGET "ok_sis"
100 #define OK_INSTALLER_SIS_TARGET "ok_installer_sis"
101 #define OK_ROM_STUB_SIS_TARGET "ok_stub_sis"
102 #define FAIL_SIS_NOPKG_TARGET "fail_sis_nopkg"
103 #define FAIL_SIS_NOCACHE_TARGET "fail_sis_nocache"
104
105 #define PRINT_FILE_CREATE_ERROR(filename) fprintf(stderr, "Error: Could not create '%s'\n", qPrintable(filename));
106
107 #define MANUFACTURER_NOTE_FILE "manufacturer_note.txt"
108 #define DEFAULT_MANUFACTURER_NOTE \
109     "The package is not supported for devices from this manufacturer. Please try the selfsigned " \
110     "version of the package instead."
111
112 QString SymbianMakefileGenerator::fixPathForMmp(const QString& origPath, const QDir& parentDir)
113 {
114     static QString epocRootStr;
115     if (epocRootStr.isEmpty()) {
116         QFileInfo efi(epocRoot());
117         epocRootStr = efi.canonicalFilePath();
118         if (epocRootStr.isEmpty()) {
119             fprintf(stderr, "Unable to resolve epocRoot '%s' to real dir on current drive, defaulting to '/' for mmp paths\n", qPrintable(epocRoot()));
120             epocRootStr = "/";
121         }
122         if (!epocRootStr.endsWith("/"))
123             epocRootStr += "/";
124
125         epocRootStr += "epoc32/";
126     }
127
128     QString resultPath = origPath;
129
130     // Make it relative, unless it starts with "%epocroot%/epoc32/"
131     if (resultPath.startsWith(epocRootStr, Qt::CaseInsensitive)) {
132         resultPath.replace(epocRootStr, "/epoc32/", Qt::CaseInsensitive);
133     } else {
134         resultPath = parentDir.relativeFilePath(resultPath);
135     }
136     resultPath = QDir::cleanPath(resultPath);
137
138     if (resultPath.isEmpty())
139         resultPath = ".";
140
141     return resultPath;
142 }
143
144 QString SymbianMakefileGenerator::canonizePath(const QString& origPath)
145 {
146     // Since current path gets appended almost always anyway, use it as default
147     // for nonexisting paths.
148     static QString defaultPath;
149     if (defaultPath.isEmpty()) {
150         QFileInfo fi(".");
151         defaultPath = fi.canonicalFilePath();
152     }
153
154     // Prepend epocroot to any paths beginning with "/epoc32/"
155     QString resultPath = QDir::fromNativeSeparators(origPath);
156     if (resultPath.startsWith("/epoc32/", Qt::CaseInsensitive))
157         resultPath = QDir::fromNativeSeparators(epocRoot()) + resultPath.mid(1);
158
159     QFileInfo fi(fileInfo(resultPath));
160     if (fi.isDir()) {
161         resultPath = fi.canonicalFilePath();
162     } else {
163         resultPath = fi.canonicalPath();
164     }
165
166     resultPath = QDir::cleanPath(resultPath);
167
168     if (resultPath.isEmpty())
169         resultPath = defaultPath;
170
171     return resultPath;
172 }
173
174 SymbianMakefileGenerator::SymbianMakefileGenerator() : MakefileGenerator() { }
175 SymbianMakefileGenerator::~SymbianMakefileGenerator() { }
176
177 void SymbianMakefileGenerator::writeHeader(QTextStream &t)
178 {
179     t << "// ============================================================================" << endl;
180     t << "// * Makefile for building: " << escapeFilePath(var("TARGET")) << endl;
181     t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: ";
182     t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl;
183     t << "// * This file is generated by qmake and should not be modified by the" << endl;
184     t << "// * user." << endl;
185     t << "// * Project:  " << fileFixify(project->projectFile()) << endl;
186     t << "// * Template: " << var("TEMPLATE") << endl;
187     t << "// ============================================================================" << endl;
188     t << endl;
189
190     // Defining define for bld.inf
191
192     QString shortProFilename = project->projectFile();
193     shortProFilename.replace(0, shortProFilename.lastIndexOf("/") + 1, QString(""));
194     shortProFilename.replace(Option::pro_ext, QString(""));
195
196     QString bldinfDefine = shortProFilename;
197     bldinfDefine.append("_");
198     bldinfDefine.append(generate_uid(project->projectFile()));
199
200     bldinfDefine.prepend("BLD_INF_");
201     removeSpecialCharacters(bldinfDefine);
202
203     t << "#define " << bldinfDefine.toUpper() << endl << endl;
204 }
205
206 bool SymbianMakefileGenerator::writeMakefile(QTextStream &t)
207 {
208     writeHeader(t);
209
210     QString numberOfIcons;
211     QString iconFile;
212     QStringList userRssRules;
213     readRssRules(numberOfIcons, iconFile, userRssRules);
214
215     // Get the application translations and convert to symbian OS lang code, i.e. decical number
216     QStringList symbianLangCodes = symbianLangCodesFromTsFiles();
217
218     // Generate pkg files if there are any actual files to deploy
219     bool generatePkg = false;
220     DeploymentList depList;
221
222     if (targetType == TypeExe) {
223         generatePkg = true;
224     } else {
225         foreach(QString item, project->values("DEPLOYMENT")) {
226             if (!project->values(item + ".sources").isEmpty()) {
227                 generatePkg = true;
228                 break;
229             }
230         }
231     }
232
233     if (generatePkg) {
234         generatePkgFile(iconFile, depList);
235     }
236
237     writeBldInfContent(t, generatePkg, iconFile, depList);
238
239     // Generate empty wrapper makefile here, because wrapper makefile must exist before writeMkFile,
240     // but all required data is not yet available.
241     bool isPrimaryMakefile = true;
242     QString wrapperFileName("Makefile");
243     QString outputFileName = fileInfo(Option::output.fileName()).fileName();
244     if (outputFileName != BLD_INF_FILENAME) {
245         wrapperFileName.append(".").append(outputFileName.startsWith(BLD_INF_FILENAME)
246                                            ? outputFileName.mid(sizeof(BLD_INF_FILENAME))
247                                            : outputFileName);
248         isPrimaryMakefile = false;
249     }
250
251     QFile wrapperMakefile(wrapperFileName);
252     if (wrapperMakefile.open(QIODevice::WriteOnly)) {
253         generatedFiles << wrapperFileName;
254     } else {
255         PRINT_FILE_CREATE_ERROR(wrapperFileName);
256         return false;
257     }
258
259     if (targetType == TypeSubdirs) {
260         // If we have something to deploy, generate extension makefile for just that, since
261         // normal extension makefile is not getting generated and we need emulator deployment to be done.
262         if (generatePkg)
263             writeMkFile(wrapperFileName, true);
264         writeWrapperMakefile(wrapperMakefile, isPrimaryMakefile);
265         return true;
266     }
267
268     writeMkFile(wrapperFileName, false);
269
270     QString shortProFilename = project->projectFile();
271     shortProFilename.replace(0, shortProFilename.lastIndexOf("/") + 1, QString(""));
272     shortProFilename.replace(Option::pro_ext, QString(""));
273
274     QString mmpFilename = shortProFilename;
275     mmpFilename.append("_");
276     mmpFilename.append(uid3);
277     mmpFilename.append(Option::mmp_ext);
278     writeMmpFile(mmpFilename, symbianLangCodes);
279
280     if (targetType == TypeExe) {
281         if (!project->isActiveConfig("no_icon")) {
282             writeRegRssFile(userRssRules);
283             writeRssFile(numberOfIcons, iconFile);
284             writeLocFile(symbianLangCodes);
285         }
286     }
287
288     writeCustomDefFile();
289     writeWrapperMakefile(wrapperMakefile, isPrimaryMakefile);
290
291     return true;
292 }
293
294 void SymbianMakefileGenerator::generatePkgFile(const QString &iconFile, DeploymentList &depList)
295 {
296     QString pkgFilename = QString("%1_template.%2")
297                           .arg(fixedTarget)
298                           .arg("pkg");
299     QFile pkgFile(pkgFilename);
300     if (!pkgFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
301         PRINT_FILE_CREATE_ERROR(pkgFilename);
302         return;
303     }
304
305     generatedFiles << pkgFile.fileName();
306     QTextStream t(&pkgFile);
307
308     QString installerSisHeader = project->values("DEPLOYMENT.installer_header").join("\n");
309     if (installerSisHeader.isEmpty())
310         installerSisHeader = "0xA000D7CE"; // Use default self-signable UID if not defined
311
312     QString wrapperStreamBuffer;
313     QTextStream tw(&wrapperStreamBuffer);
314
315     QString dateStr = QDateTime::currentDateTime().toString(Qt::ISODate);
316
317     // Header info
318     QString wrapperPkgFilename = QString("%1_installer.%2")
319                                 .arg(fixedTarget)
320                                 .arg("pkg");
321     QString headerComment = "; %1 generated by qmake at %2\n"
322         "; This file is generated by qmake and should not be modified by the user\n"
323         ";\n\n";
324     t << headerComment.arg(pkgFilename).arg(dateStr);
325     tw << headerComment.arg(wrapperPkgFilename).arg(dateStr);
326
327     // Construct QStringList from pkg_prerules since we need search it before printed to file
328     QStringList rawPkgPreRules;
329     foreach(QString deploymentItem, project->values("DEPLOYMENT")) {
330         foreach(QString pkgrulesItem, project->values(deploymentItem + ".pkg_prerules")) {
331             QStringList pkgrulesValue = project->values(pkgrulesItem);
332             // If there is no stringlist defined for a rule, use rule name directly
333             // This is convenience for defining single line mmp statements
334             if (pkgrulesValue.isEmpty()) {
335                 rawPkgPreRules << pkgrulesItem;
336             } else {
337                 foreach(QString pkgrule, pkgrulesValue) {
338                     rawPkgPreRules << pkgrule;
339                 }
340             }
341         }
342     }
343
344     // Apply some defaults if specific data does not exist in PKG pre-rules
345
346     if (!containsStartWithItem('&', rawPkgPreRules)) {
347         // language, (*** hardcoded to english atm, should be parsed from TRANSLATIONS)
348         QString languageCode = "; Language\n&EN\n\n";
349         t << languageCode;
350         tw << languageCode;
351     } else {
352         // In case user defines langs, he must take care also about SIS header
353         if (!containsStartWithItem('#', rawPkgPreRules))
354             fprintf(stderr, "Warning: If language is defined with DEPLOYMENT pkg_prerules, also the SIS header must be defined\n");
355     }
356
357     // name of application, UID and version
358     QString applicationVersion = project->first("VERSION").isEmpty() ? "1,0,0" : project->first("VERSION").replace('.', ',');
359     QString sisHeader = "; SIS header: name, uid, version\n#{\"%1\"},(%2),%3\n\n";
360     QString visualTarget = escapeFilePath(fileFixify(project->first("TARGET")));
361     visualTarget = removePathSeparators(visualTarget);
362     QString wrapperTarget = visualTarget + " installer";
363
364     if (installerSisHeader.startsWith("0x", Qt::CaseInsensitive)) {
365         tw << sisHeader.arg(wrapperTarget).arg(installerSisHeader).arg(applicationVersion);
366     } else {
367         tw << installerSisHeader << endl;
368     }
369
370     if (!containsStartWithItem('#', rawPkgPreRules)) {
371         t << sisHeader.arg(visualTarget).arg(uid3).arg(applicationVersion);
372     }
373
374     // Localized vendor name
375     QString vendorName;
376     if (!containsStartWithItem('%', rawPkgPreRules)) {
377         vendorName += "; Localised Vendor name\n%{\"Vendor\"}\n\n";
378     }
379
380     // Unique vendor name
381     if (!containsStartWithItem(':', rawPkgPreRules)) {
382         vendorName += "; Unique Vendor name\n:\"Vendor\"\n\n";
383     }
384
385     t << vendorName;
386     tw << vendorName;
387
388     // PKG pre-rules - these are added before actual file installations i.e. SIS package body
389     if (rawPkgPreRules.size()) {
390         QString comment = "\n; Manual PKG pre-rules from PRO files\n";
391         t << comment;
392         tw << comment;
393
394         foreach(QString item, rawPkgPreRules) {
395             // Only regular pkg file should have package dependencies or pkg header if that is
396             // defined using prerules.
397             if (!item.startsWith("(") && !item.startsWith("#")) {
398                 tw << item << endl;
399             }
400             t << item << endl;
401         }
402         t << endl;
403         tw << endl;
404     }
405
406     // Begin Manufacturer block
407     if (!project->values("DEPLOYMENT.manufacturers").isEmpty()) {
408         QString manufacturerStr("IF ");
409         foreach(QString manufacturer, project->values("DEPLOYMENT.manufacturers")) {
410             manufacturerStr.append(QString("(MANUFACTURER)=(%1) OR \n   ").arg(manufacturer));
411         }
412         // Remove the final OR
413         manufacturerStr.chop(8);
414         t << manufacturerStr << endl;
415     }
416
417     // Install paths on the phone *** should be dynamic at some point
418     QString installPathBin = "!:\\sys\\bin";
419     QString installPathResource = "!:\\resource\\apps";
420     QString installPathRegResource = "!:\\private\\10003a3f\\import\\apps";
421
422     // Find location of builds
423     QString epocReleasePath = QString("%1epoc32/release/$(PLATFORM)/$(TARGET)")
424                               .arg(epocRoot());
425
426     if (targetType == TypeExe) {
427         // deploy .exe file
428         t << "; Executable and default resource files" << endl;
429         QString exeFile = fixedTarget + ".exe";
430         t << QString("\"%1/%2\"    - \"%3\\%4\"")
431              .arg(epocReleasePath)
432              .arg(exeFile)
433              .arg(installPathBin)
434              .arg(exeFile) << endl;
435
436         // deploy rsc & reg_rsc file
437         if (!project->isActiveConfig("no_icon")) {
438             t << QString("\"%1epoc32/data/z/resource/apps/%2\"    - \"%3\\%4\"")
439                  .arg(epocRoot())
440                  .arg(fixedTarget + ".rsc")
441                  .arg(installPathResource)
442                  .arg(fixedTarget + ".rsc") << endl;
443
444             t << QString("\"%1epoc32/data/z/private/10003a3f/import/apps/%2\"    - \"%3\\%4\"")
445                  .arg(epocRoot())
446                  .arg(fixedTarget + "_reg.rsc")
447                  .arg(installPathRegResource)
448                  .arg(fixedTarget + "_reg.rsc") << endl;
449
450             if (!iconFile.isEmpty())  {
451                 t << QString("\"%1epoc32/data/z%2\"    - \"!:%3\"")
452                      .arg(epocRoot())
453                      .arg(iconFile)
454                      .arg(QDir::toNativeSeparators(iconFile)) << endl << endl;
455             }
456         }
457     }
458
459     // deploy any additional DEPLOYMENT  files
460     QString remoteTestPath;
461     remoteTestPath = QString("!:\\private\\%1").arg(privateDirUid);
462
463     initProjectDeploySymbian(project, depList, remoteTestPath, true, "$(PLATFORM)", "$(TARGET)", generatedDirs, generatedFiles);
464     if (depList.size())
465         t << "; DEPLOYMENT" << endl;
466     for (int i = 0; i < depList.size(); ++i)  {
467         t << QString("\"%1\"    - \"%2\"")
468              .arg(QString(depList.at(i).from).replace('\\','/'))
469              .arg(QString(depList.at(i).to).replace('/','\\')) << endl;
470     }
471     t << endl;
472
473     // PKG post-rules - these are added after actual file installations i.e. SIS package body
474     t << "; Manual PKG post-rules from PRO files" << endl;
475     foreach(QString deploymentItem, project->values("DEPLOYMENT")) {
476         foreach(QString pkgrulesItem, project->values(deploymentItem + ".pkg_postrules")) {
477             QStringList pkgrulesValue = project->values(pkgrulesItem);
478             // If there is no stringlist defined for a rule, use rule name directly
479             // This is convenience for defining single line statements
480             if (pkgrulesValue.isEmpty()) {
481                 t << pkgrulesItem << endl;
482             } else {
483                 foreach(QString pkgrule, pkgrulesValue) {
484                     t << pkgrule << endl;
485                 }
486             }
487             t << endl;
488         }
489     }
490
491     // Close Manufacturer block
492     if (!project->values("DEPLOYMENT.manufacturers").isEmpty()) {
493         QString manufacturerFailNoteFile;
494         if (project->values("DEPLOYMENT.manufacturers.fail_note").isEmpty()) {
495             manufacturerFailNoteFile = QString("%1_" MANUFACTURER_NOTE_FILE).arg(uid3);
496             QFile ft(manufacturerFailNoteFile);
497             if (ft.open(QIODevice::WriteOnly)) {
498                 generatedFiles << ft.fileName();
499                 QTextStream t2(&ft);
500
501                 t2 << QString(DEFAULT_MANUFACTURER_NOTE) << endl;
502             } else {
503                 PRINT_FILE_CREATE_ERROR(manufacturerFailNoteFile)
504             }
505         } else {
506             manufacturerFailNoteFile = project->values("DEPLOYMENT.manufacturers.fail_note").join("");
507         }
508
509         t << "ELSEIF NOT(0) ; MANUFACTURER" << endl
510           << "\"" << fileInfo(manufacturerFailNoteFile).absoluteFilePath() << "\""
511           << " - \"\", FILETEXT, TEXTEXIT" << endl
512           << "ENDIF ; MANUFACTURER" << endl;
513     }
514
515     // Write wrapper pkg
516     if (!installerSisHeader.isEmpty()) {
517         QFile wrapperPkgFile(wrapperPkgFilename);
518         if (!wrapperPkgFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
519             PRINT_FILE_CREATE_ERROR(wrapperPkgFilename);
520             return;
521         }
522
523         generatedFiles << wrapperPkgFile.fileName();
524         QTextStream twf(&wrapperPkgFile);
525
526         twf << wrapperStreamBuffer << endl;
527
528         // Wrapped files deployment
529         QString currentPath = qmake_getpwd();
530         QString sisName = QString("%1.sis").arg(fixedTarget);
531         twf << "\"" << currentPath << "/" << sisName << "\" - \"c:\\adm\\" << sisName << "\"" << endl;
532
533         QString bootStrapPath = QLibraryInfo::location(QLibraryInfo::PrefixPath);
534         bootStrapPath.append("/smartinstaller.sis");
535         QFileInfo fi(fileInfo(bootStrapPath));
536         twf << "@\"" << fi.absoluteFilePath() << "\",(0x2002CCCD)" << endl;
537     }
538 }
539
540 bool SymbianMakefileGenerator::containsStartWithItem(const QChar &c, const QStringList& src)
541 {
542     bool result = false;
543     foreach(QString str, src) {
544         if (str.startsWith(c)) {
545             result =  true;
546             break;
547         }
548     }
549     return result;
550 }
551
552 void SymbianMakefileGenerator::writeCustomDefFile()
553 {
554     if (targetType == TypePlugin && !project->isActiveConfig("stdbinary")) {
555         // Create custom def file for plugin
556         QFile ft(QLatin1String(PLUGIN_COMMON_DEF_FILE_ACTUAL));
557
558         if (ft.open(QIODevice::WriteOnly)) {
559             generatedFiles << ft.fileName();
560             QTextStream t(&ft);
561
562             t << "; ==============================================================================" << endl;
563             t << "; Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: ";
564             t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl;
565             t << "; This file is generated by qmake and should not be modified by the" << endl;
566             t << "; user." << endl;
567             t << ";  Name        : " PLUGIN_COMMON_DEF_FILE_ACTUAL << endl;
568             t << ";  Part of     : " << project->values("TARGET").join(" ") << endl;
569             t << ";  Description : Fixes common plugin symbols to known ordinals" << endl;
570             t << ";  Version     : " << endl;
571             t << ";" << endl;
572             t << "; ==============================================================================" << "\n" << endl;
573
574             t << endl;
575
576             t << "EXPORTS" << endl;
577             t << "\tqt_plugin_query_verification_data @ 1 NONAME" << endl;
578             t << "\tqt_plugin_instance @ 2 NONAME" << endl;
579             t << endl;
580         } else {
581             PRINT_FILE_CREATE_ERROR(QString(PLUGIN_COMMON_DEF_FILE_ACTUAL))
582         }
583     }
584 }
585
586 void SymbianMakefileGenerator::init()
587 {
588     MakefileGenerator::init();
589     fixedTarget = escapeFilePath(fileFixify(project->first("TARGET")));
590     fixedTarget = removePathSeparators(fixedTarget);
591     removeSpecialCharacters(fixedTarget);
592
593     if (0 != project->values("QMAKE_PLATFORM").size())
594         platform = varGlue("QMAKE_PLATFORM", "", " ", "");
595
596     if (0 == project->values("QMAKESPEC").size())
597         project->values("QMAKESPEC").append(qgetenv("QMAKESPEC"));
598
599     project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
600     project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
601
602     // bld.inf
603     project->values("MAKEFILE") += BLD_INF_FILENAME;
604
605     // .mmp
606     initMmpVariables();
607
608     // Check TARGET.UID3 presence
609     if (0 != project->values("TARGET.UID3").size()) {
610         uid3 = project->first("TARGET.UID3");
611     } else {
612         uid3 = generateUID3();
613     }
614
615     if ((project->values("TEMPLATE")).contains("app"))
616         targetType = TypeExe;
617     else if ((project->values("TEMPLATE")).contains("lib")) {
618         // Check CONFIG to see if we are to build staticlib or dll
619         if (project->isActiveConfig("staticlib") || project->isActiveConfig("static"))
620             targetType = TypeLib;
621         else if (project->isActiveConfig("plugin"))
622             targetType = TypePlugin;
623         else
624             targetType = TypeDll;
625     } else {
626         targetType = TypeSubdirs;
627     }
628
629     if (0 != project->values("TARGET.UID2").size()) {
630         uid2 = project->first("TARGET.UID2");
631     } else if (project->isActiveConfig("stdbinary")) {
632         uid2 = "0x20004C45";
633     } else {
634         if (targetType == TypeExe) {
635             if (project->values("QT").contains("gui", Qt::CaseInsensitive)) {
636                 // exe and gui -> uid2 needed
637                 uid2 = "0x100039CE";
638             } else {
639                 // exe but not gui: uid2 is ignored anyway -> set it to 0
640                 uid2 = "0";
641             }
642         } else if (targetType == TypeDll || targetType == TypeLib || targetType == TypePlugin) {
643             uid2 = "0x1000008d";
644         }
645     }
646
647     uid2 = uid2.trimmed();
648     uid3 = uid3.trimmed();
649
650     // UID is valid as either hex or decimal, so just convert it to number and back to hex
651     // to get proper string for private dir
652     bool conversionOk = false;
653     uint uidNum = uid3.toUInt(&conversionOk, 0);
654
655     if (!conversionOk) {
656         fprintf(stderr, "Error: Invalid UID \"%s\".\n", uid3.toUtf8().constData());
657     } else {
658         privateDirUid.setNum(uidNum, 16);
659         while (privateDirUid.length() < 8)
660             privateDirUid.insert(0, QLatin1Char('0'));
661     }
662 }
663
664 QString SymbianMakefileGenerator::getTargetExtension()
665 {
666     QString ret;
667     if (targetType == TypeExe) {
668         ret.append("exe");
669     } else if (targetType == TypeLib) {
670         ret.append("lib");
671     } else if (targetType == TypeDll || targetType == TypePlugin) {
672         ret.append("dll");
673     } else if (targetType == TypeSubdirs) {
674         // Not actually usable, so return empty
675     } else {
676         // If nothing else set, default to exe
677         ret.append("exe");
678     }
679
680     return ret;
681 }
682
683 QString SymbianMakefileGenerator::generateUID3()
684 {
685     QString target = project->first("TARGET");
686     QString currPath = qmake_getpwd();
687     target.prepend("/").prepend(currPath);
688     return generate_test_uid(target);
689 }
690
691 void SymbianMakefileGenerator::initMmpVariables()
692 {
693     QStringList sysincspaths;
694     QStringList srcincpaths;
695     QStringList srcpaths;
696
697     srcpaths << project->values("SOURCES") << project->values("GENERATED_SOURCES");
698     srcpaths << project->values("UNUSED_SOURCES") << project->values("UI_SOURCES_DIR");
699     srcpaths << project->values("UI_DIR");
700
701     QDir current = QDir::current();
702     QString canonizedCurrent = canonizePath(".");
703
704     for (int j = 0; j < srcpaths.size(); ++j) {
705         QFileInfo fi(fileInfo(srcpaths.at(j)));
706         // Sometimes sources have other than *.c* files (e.g. *.moc); prune them.
707         if (fi.suffix().startsWith("c")) {
708             if (fi.filePath().length() > fi.fileName().length()) {
709                 appendIfnotExist(srcincpaths, fi.path());
710                 sources[canonizePath(fi.path())] += fi.fileName();
711             } else {
712                 sources[canonizedCurrent] += fi.fileName();
713                 appendIfnotExist(srcincpaths, canonizedCurrent);
714             }
715         }
716     }
717
718     QStringList incpaths;
719     incpaths << project->values("INCLUDEPATH");
720     incpaths << QLibraryInfo::location(QLibraryInfo::HeadersPath);
721     incpaths << project->values("HEADERS");
722     incpaths << srcincpaths;
723     incpaths << project->values("UI_HEADERS_DIR");
724     incpaths << project->values("UI_DIR");
725
726     for (int j = 0; j < incpaths.size(); ++j) {
727         QString includepath = canonizePath(incpaths.at(j));
728         appendIfnotExist(sysincspaths, includepath);
729         appendAbldTempDirs(sysincspaths, includepath);
730     }
731
732     // Remove duplicate include path entries
733     QStringList temporary;
734     for (int i = 0; i < sysincspaths.size(); ++i) {
735         QString origPath = sysincspaths.at(i);
736         QFileInfo origPathInfo(fileInfo(origPath));
737         bool bFound = false;
738
739         for (int j = 0; j < temporary.size(); ++j) {
740             QString tmpPath = temporary.at(j);
741             QFileInfo tmpPathInfo(fileInfo(tmpPath));
742
743             if (origPathInfo.absoluteFilePath() == tmpPathInfo.absoluteFilePath()) {
744                 bFound = true;
745                 if (!tmpPathInfo.isRelative() && origPathInfo.isRelative()) {
746                     // We keep the relative notation
747                     temporary.removeOne(tmpPath);
748                     temporary << origPath;
749                 }
750             }
751         }
752
753         if (!bFound)
754             temporary << origPath;
755
756     }
757
758     sysincspaths.clear();
759     sysincspaths << temporary;
760
761     systeminclude.insert("SYSTEMINCLUDE", sysincspaths);
762
763     // Check MMP_RULES for singleton keywords that are overridden
764     QStringList overridableMmpKeywords;
765     QStringList restrictableMmpKeywords;
766     QStringList restrictedMmpKeywords;
767     bool inResourceBlock = false;
768
769     overridableMmpKeywords << QLatin1String(MMP_TARGETTYPE);
770     restrictableMmpKeywords << QLatin1String(MMP_TARGET) << QLatin1String(MMP_SECUREID)
771        << QLatin1String(MMP_OPTION_CW) << QLatin1String(MMP_OPTION_ARMCC)
772        << QLatin1String(MMP_OPTION_GCCE) << QLatin1String(MMP_LINKEROPTION_CW)
773        << QLatin1String(MMP_LINKEROPTION_ARMCC) << QLatin1String(MMP_LINKEROPTION_GCCE)
774        << QLatin1String(MMP_CAPABILITY) << QLatin1String(MMP_EPOCALLOWDLLDATA)
775        << QLatin1String(MMP_EPOCHEAPSIZE) << QLatin1String(MMP_EPOCSTACKSIZE)
776        << QLatin1String(MMP_UID) << QLatin1String(MMP_VENDORID)
777        << QLatin1String(MMP_VERSION);
778
779     foreach (QString item, project->values("MMP_RULES")) {
780         if (project->values(item).isEmpty()) {
781             handleMmpRulesOverrides(item, inResourceBlock, restrictedMmpKeywords,
782                                     restrictableMmpKeywords, overridableMmpKeywords);
783         } else {
784             foreach (QString itemRow, project->values(item)) {
785                 handleMmpRulesOverrides(itemRow, inResourceBlock, restrictedMmpKeywords,
786                                         restrictableMmpKeywords, overridableMmpKeywords);
787             }
788         }
789     }
790
791     if (restrictedMmpKeywords.size()) {
792         fprintf(stderr, "Warning: Restricted statements detected in MMP_RULES:\n"
793                 "         (%s)\n"
794                 "         Use corresponding qmake variable(s) instead.\n",
795                 qPrintable(restrictedMmpKeywords.join(", ")));
796         }
797 }
798
799 void SymbianMakefileGenerator::handleMmpRulesOverrides(QString &checkString,
800                                                        bool &inResourceBlock,
801                                                        QStringList &restrictedMmpKeywords,
802                                                        const QStringList &restrictableMmpKeywords,
803                                                        const QStringList &overridableMmpKeywords)
804 {
805     QString simplifiedString = checkString.simplified();
806
807     if (!inResourceBlock && simplifiedString.startsWith(MMP_START_RESOURCE, Qt::CaseInsensitive))
808         inResourceBlock = true;
809     else if (inResourceBlock && simplifiedString.startsWith(MMP_END_RESOURCE, Qt::CaseInsensitive))
810         inResourceBlock = false;
811
812     // Allow restricted and overridable items in RESOURCE blocks as those do not actually
813     // override anything.
814     if (!inResourceBlock) {
815         appendKeywordIfMatchFound(overriddenMmpKeywords, overridableMmpKeywords, simplifiedString);
816         appendKeywordIfMatchFound(restrictedMmpKeywords, restrictableMmpKeywords, simplifiedString);
817     }
818 }
819
820 void SymbianMakefileGenerator::appendKeywordIfMatchFound(QStringList &list,
821                                                          const QStringList &keywordList,
822                                                          QString &checkString)
823 {
824     // Check if checkString starts with any supplied keyword and
825     // add the found keyword to list if it does.
826     foreach (QString item, keywordList) {
827         if (checkString.startsWith(QString(item).append(" "), Qt::CaseInsensitive)
828             || checkString.compare(item, Qt::CaseInsensitive) == 0) {
829             appendIfnotExist(list, item);
830         }
831     }
832 }
833
834
835 bool SymbianMakefileGenerator::removeDuplicatedStrings(QStringList &stringList)
836 {
837     QStringList tmpStringList;
838
839     for (int i = 0; i < stringList.size(); ++i) {
840         QString string = stringList.at(i);
841         if (tmpStringList.contains(string))
842             continue;
843         else
844             tmpStringList.append(string);
845     }
846
847     stringList.clear();
848     stringList = tmpStringList;
849     return true;
850 }
851
852 void SymbianMakefileGenerator::writeMmpFileHeader(QTextStream &t)
853 {
854     t << "// ==============================================================================" << endl;
855     t << "// Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: ";
856     t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl;
857     t << "// This file is generated by qmake and should not be modified by the" << endl;
858     t << "// user." << endl;
859     t << "//  Name        : " << escapeFilePath(fileFixify(project->projectFile().remove(project->projectFile().length() - 4, 4))) << Option::mmp_ext << endl;
860     t << "// ==============================================================================" << endl << endl;
861 }
862
863 void SymbianMakefileGenerator::writeMmpFile(QString &filename, QStringList &symbianLangCodes)
864 {
865     QFile ft(filename);
866     if (ft.open(QIODevice::WriteOnly)) {
867         generatedFiles << ft.fileName();
868
869         QTextStream t(&ft);
870
871         writeMmpFileHeader(t);
872
873         writeMmpFileTargetPart(t);
874
875         writeMmpFileResourcePart(t, symbianLangCodes);
876
877         writeMmpFileMacrosPart(t);
878
879         writeMmpFileIncludePart(t);
880
881         QDir current = QDir::current();
882
883         for (QMap<QString, QStringList>::iterator it = sources.begin(); it != sources.end(); ++it) {
884             QStringList values = it.value();
885             QString currentSourcePath = it.key();
886
887             if (values.size())
888                 t << "SOURCEPATH \t" <<  fixPathForMmp(currentSourcePath, current) << endl;
889
890             for (int i = 0; i < values.size(); ++i) {
891                 QString sourceFileName = values.at(i);
892                 t << "SOURCE\t\t" << sourceFileName << endl;
893             }
894             t << endl;
895         }
896         t << endl;
897
898         if (!project->isActiveConfig("static") && !project->isActiveConfig("staticlib")) {
899             writeMmpFileLibraryPart(t);
900         }
901
902         writeMmpFileCapabilityPart(t);
903
904         writeMmpFileCompilerOptionPart(t);
905
906         writeMmpFileBinaryVersionPart(t);
907
908         writeMmpFileRulesPart(t);
909     } else {
910         PRINT_FILE_CREATE_ERROR(filename)
911     }
912 }
913
914 void SymbianMakefileGenerator::writeMmpFileMacrosPart(QTextStream& t)
915 {
916     t << endl;
917
918     QStringList &defines = project->values("DEFINES");
919     if (defines.size())
920         t << "// Qt Macros" << endl;
921     for (int i = 0; i < defines.size(); ++i) {
922         QString def = defines.at(i);
923         addMacro(t, def);
924     }
925
926     // These are required in order that all methods will be correctly exported e.g from qtestlib
927     QStringList &exp_defines = project->values("PRL_EXPORT_DEFINES");
928     if (exp_defines.size())
929         t << endl << "// Qt Export Defines" << endl;
930     for (int i = 0; i < exp_defines.size(); ++i) {
931         QString def = exp_defines.at(i);
932         addMacro(t, def);
933     }
934
935     t << endl;
936 }
937
938 void SymbianMakefileGenerator::addMacro(QTextStream& t, const QString& value)
939 {
940     t << "MACRO\t\t" <<  value << endl;
941 }
942
943
944 void SymbianMakefileGenerator::writeMmpFileTargetPart(QTextStream& t)
945 {
946     bool skipTargetType = overriddenMmpKeywords.contains(MMP_TARGETTYPE);
947
948     if (targetType == TypeExe) {
949         t << MMP_TARGET "\t\t" << fixedTarget << ".exe" << endl;
950         if (!skipTargetType) {
951             if (project->isActiveConfig("stdbinary"))
952                 t << MMP_TARGETTYPE "\t\tSTDEXE" << endl;
953             else
954                 t << MMP_TARGETTYPE "\t\tEXE" << endl;
955         }
956     } else if (targetType == TypeDll || targetType == TypePlugin) {
957         t << MMP_TARGET "\t\t" << fixedTarget << ".dll" << endl;
958         if (!skipTargetType) {
959             if (project->isActiveConfig("stdbinary"))
960                 t << MMP_TARGETTYPE "\t\tSTDDLL" << endl;
961             else
962                 t << MMP_TARGETTYPE "\t\tDLL" << endl;
963         }
964     } else if (targetType == TypeLib) {
965         t << MMP_TARGET "\t\t" << fixedTarget << ".lib" << endl;
966         if (!skipTargetType) {
967             if (project->isActiveConfig("stdbinary"))
968                 t << MMP_TARGETTYPE "\t\tSTDLIB" << endl;
969             else
970                 t << MMP_TARGETTYPE "\t\tLIB" << endl;
971         }
972     } else {
973         fprintf(stderr, "Error: Unexpected targettype (%d) in SymbianMakefileGenerator::writeMmpFileTargetPart\n", targetType);
974     }
975
976     t << endl;
977
978     t << MMP_UID "\t\t" << uid2 << " " << uid3 << endl;
979
980     if (0 != project->values("TARGET.SID").size()) {
981         t << MMP_SECUREID "\t\t" << project->values("TARGET.SID").join(" ") << endl;
982     } else {
983         if (0 == uid3.size())
984             t << MMP_SECUREID "\t\t0" << endl;
985         else
986             t << MMP_SECUREID "\t\t" << uid3 << endl;
987     }
988
989     // default value used from mkspecs is 0
990     if (0 != project->values("TARGET.VID").size()) {
991         t << MMP_VENDORID "\t\t" << project->values("TARGET.VID").join(" ") << endl;
992     }
993
994     t << endl;
995
996     if (0 != project->first("TARGET.EPOCSTACKSIZE").size())
997         t << MMP_EPOCSTACKSIZE "\t\t" << project->first("TARGET.EPOCSTACKSIZE") << endl;
998     if (0 != project->values("TARGET.EPOCHEAPSIZE").size())
999         t << MMP_EPOCHEAPSIZE "\t\t" << project->values("TARGET.EPOCHEAPSIZE").join(" ") << endl;
1000     if (0 != project->values("TARGET.EPOCALLOWDLLDATA").size())
1001         t << MMP_EPOCALLOWDLLDATA << endl;
1002
1003     if (targetType == TypePlugin && !project->isActiveConfig("stdbinary")) {
1004         // Use custom def file for Qt plugins
1005         t << "DEFFILE " PLUGIN_COMMON_DEF_FILE_FOR_MMP << endl;
1006     }
1007
1008     t << endl;
1009 }
1010
1011
1012 /*
1013     Application registration resource files should be installed to the
1014     \private\10003a3f\import\apps directory.
1015 */
1016 void SymbianMakefileGenerator::writeMmpFileResourcePart(QTextStream& t, QStringList &symbianLangCodes)
1017 {
1018     if ((targetType == TypeExe) &&
1019             !project->isActiveConfig("no_icon")) {
1020
1021         QString locTarget = fixedTarget;
1022         locTarget.append(".rss");
1023
1024         t << "SOURCEPATH\t\t\t. " << endl;
1025         t << "LANG SC ";    // no endl
1026         foreach(QString lang, symbianLangCodes) {
1027             t << lang << " "; // no endl
1028         }
1029         t << endl;
1030         t << MMP_START_RESOURCE "\t\t" << locTarget << endl;
1031         t << "HEADER" << endl;
1032         t << "TARGETPATH\t\t\t" RESOURCE_DIRECTORY_MMP << endl;
1033         t << MMP_END_RESOURCE << endl << endl;
1034
1035         QString regTarget = fixedTarget;
1036         regTarget.append("_reg.rss");
1037
1038         t << "SOURCEPATH\t\t\t." << endl;
1039         t << MMP_START_RESOURCE "\t\t" << regTarget << endl;
1040         if (isForSymbianSbsv2())
1041             t << "DEPENDS " << fixedTarget << ".rsg" << endl;
1042         t << "TARGETPATH\t\t" REGISTRATION_RESOURCE_DIRECTORY_HW << endl;
1043         t << MMP_END_RESOURCE << endl << endl;
1044     }
1045 }
1046
1047 void SymbianMakefileGenerator::writeMmpFileSystemIncludePart(QTextStream& t)
1048 {
1049     QDir current = QDir::current();
1050
1051     for (QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
1052         QStringList values = it.value();
1053         for (int i = 0; i < values.size(); ++i) {
1054             QString handledPath = values.at(i);
1055             t << "SYSTEMINCLUDE\t\t" << fixPathForMmp(handledPath, current) << endl;
1056         }
1057     }
1058
1059     t << endl;
1060 }
1061
1062 void SymbianMakefileGenerator::writeMmpFileIncludePart(QTextStream& t)
1063 {
1064     writeMmpFileSystemIncludePart(t);
1065 }
1066
1067 void SymbianMakefileGenerator::writeMmpFileLibraryPart(QTextStream& t)
1068 {
1069     QStringList &libs = project->values("LIBS");
1070     libs << project->values("QMAKE_LIBS") << project->values("QMAKE_LIBS_PRIVATE");
1071
1072     removeDuplicatedStrings(libs);
1073
1074     for (int i = 0; i < libs.size(); ++i) {
1075         QString lib = libs.at(i);
1076         // The -L flag is uninteresting, since all symbian libraries exist in the same directory.
1077         if (lib.startsWith("-l")) {
1078             lib.remove(0, 2);
1079             QString mmpStatement;
1080             if (lib.endsWith(".dll")) {
1081                 lib.chop(4);
1082                 mmpStatement = "LIBRARY\t\t";
1083             } else if (lib.endsWith(".lib")) {
1084                 lib.chop(4);
1085                 mmpStatement = "STATICLIBRARY\t";
1086             } else {
1087                 // Hacky way to find out what kind of library it is. Check the
1088                 // ARMV5 build directory for library type. We default to shared
1089                 // library, since that is more common.
1090                 QString udebStaticLibLocation(epocRoot());
1091                 QString urelStaticLibLocation(udebStaticLibLocation);
1092                 udebStaticLibLocation += QString("epoc32/release/armv5/udeb/%1.lib").arg(lib);
1093                 urelStaticLibLocation += QString("epoc32/release/armv5/urel/%1.lib").arg(lib);
1094                 if (QFile::exists(udebStaticLibLocation) || QFile::exists(urelStaticLibLocation)) {
1095                     mmpStatement = "STATICLIBRARY\t";
1096                 } else {
1097                     mmpStatement = "LIBRARY\t\t";
1098                 }
1099             }
1100             t << mmpStatement <<  lib << ".lib" << endl;
1101         }
1102     }
1103
1104     t << endl;
1105 }
1106
1107 void SymbianMakefileGenerator::writeMmpFileCapabilityPart(QTextStream& t)
1108 {
1109     if (0 != project->first("TARGET.CAPABILITY").size()) {
1110         QStringList &capabilities = project->values("TARGET.CAPABILITY");
1111         t << MMP_CAPABILITY "\t\t";
1112
1113         for (int i = 0; i < capabilities.size(); ++i) {
1114             QString cap = capabilities.at(i);
1115             t << cap << " ";
1116         }
1117     } else {
1118         t << MMP_CAPABILITY "\t\tNone";
1119     }
1120     t << endl << endl;
1121 }
1122
1123 void SymbianMakefileGenerator::writeMmpFileCompilerOptionPart(QTextStream& t)
1124 {
1125     QString cw, armcc, gcce;
1126     QString cwlink, armlink, gccelink;
1127
1128     if (0 != project->values("QMAKE_CXXFLAGS.CW").size()) {
1129         cw.append(project->values("QMAKE_CXXFLAGS.CW").join(" "));
1130         cw.append(" ");
1131     }
1132
1133     if (0 != project->values("QMAKE_CXXFLAGS.ARMCC").size()) {
1134         armcc.append(project->values("QMAKE_CXXFLAGS.ARMCC").join(" "));
1135         armcc.append(" ");
1136     }
1137
1138     if (0 != project->values("QMAKE_CXXFLAGS.GCCE").size()) {
1139         gcce.append(project->values("QMAKE_CXXFLAGS.GCCE").join(" "));
1140         gcce.append(" ");
1141     }
1142
1143     if (0 != project->values("QMAKE_CFLAGS.CW").size()) {
1144         cw.append(project->values("QMAKE_CFLAGS.CW").join(" "));
1145         cw.append(" ");
1146     }
1147
1148     if (0 != project->values("QMAKE_CFLAGS.ARMCC").size()) {
1149         armcc.append(project->values("QMAKE_CFLAGS.ARMCC").join(" "));
1150         armcc.append(" ");
1151     }
1152
1153     if (0 != project->values("QMAKE_CFLAGS.GCCE").size()) {
1154         gcce.append(project->values("QMAKE_CXXFLAGS.GCCE").join(" "));
1155         gcce.append(" ");
1156     }
1157
1158     if (0 != project->values("QMAKE_CXXFLAGS").size()) {
1159         cw.append(project->values("QMAKE_CXXFLAGS").join(" "));
1160         cw.append(" ");
1161         armcc.append(project->values("QMAKE_CXXFLAGS").join(" "));
1162         armcc.append(" ");
1163         gcce.append(project->values("QMAKE_CXXFLAGS").join(" "));
1164         gcce.append(" ");
1165     }
1166
1167     if (0 != project->values("QMAKE_CFLAGS").size()) {
1168         cw.append(project->values("QMAKE_CFLAGS").join(" "));
1169         cw.append(" ");
1170         armcc.append(project->values("QMAKE_CFLAGS").join(" "));
1171         armcc.append(" ");
1172         gcce.append(project->values("QMAKE_CFLAGS").join(" "));
1173         gcce.append(" ");
1174     }
1175
1176     if (0 != project->values("QMAKE_LFLAGS.CW").size()) {
1177         cwlink.append(project->values("QMAKE_LFLAGS.CW").join(" "));
1178         cwlink.append(" ");
1179     }
1180
1181     if (0 != project->values("QMAKE_LFLAGS.ARMCC").size()) {
1182         armlink.append(project->values("QMAKE_LFLAGS.ARMCC").join(" "));
1183         armlink.append(" ");
1184     }
1185
1186     if (0 != project->values("QMAKE_LFLAGS.GCCE").size()) {
1187         gccelink.append(project->values("QMAKE_LFLAGS.GCCE").join(" "));
1188         gccelink.append(" ");
1189     }
1190
1191     if (0 != project->values("QMAKE_LFLAGS").size()) {
1192         cwlink.append(project->values("QMAKE_LFLAGS").join(" "));
1193         cwlink.append(" ");
1194         armlink.append(project->values("QMAKE_LFLAGS").join(" "));
1195         armlink.append(" ");
1196         gccelink.append(project->values("QMAKE_LFLAGS").join(" "));
1197         gccelink.append(" ");
1198     }
1199
1200     if (!cw.isEmpty() && cw[cw.size()-1] == ' ')
1201         cw.chop(1);
1202     if (!armcc.isEmpty() && armcc[armcc.size()-1] == ' ')
1203         armcc.chop(1);
1204     if (!gcce.isEmpty() && gcce[gcce.size()-1] == ' ')
1205         gcce.chop(1);
1206     if (!cwlink.isEmpty() && cwlink[cwlink.size()-1] == ' ')
1207         cwlink.chop(1);
1208     if (!armlink.isEmpty() && armlink[armlink.size()-1] == ' ')
1209         armlink.chop(1);
1210     if (!gccelink.isEmpty() && gccelink[gccelink.size()-1] == ' ')
1211         gccelink.chop(1);
1212
1213     if (!cw.isEmpty())
1214         t << MMP_OPTION_CW " " << cw <<  endl;
1215     if (!armcc.isEmpty())
1216         t << MMP_OPTION_ARMCC " " << armcc <<  endl;
1217     if (!gcce.isEmpty())
1218         t << MMP_OPTION_GCCE " " << gcce <<  endl;
1219
1220     if (!cwlink.isEmpty())
1221         t << MMP_LINKEROPTION_CW " " << cwlink <<  endl;
1222     if (!armlink.isEmpty())
1223         t << MMP_LINKEROPTION_ARMCC " " << armlink <<  endl;
1224     if (!gccelink.isEmpty())
1225         t << MMP_LINKEROPTION_GCCE " " << gccelink <<  endl;
1226
1227     t << endl;
1228 }
1229
1230 void SymbianMakefileGenerator::writeMmpFileBinaryVersionPart(QTextStream& t)
1231 {
1232     QString applicationVersion = project->first("VERSION");
1233     QStringList verNumList = applicationVersion.split('.');
1234     uint major = 0;
1235     uint minor = 0;
1236     uint patch = 0;
1237     bool success = false;
1238
1239     if (verNumList.size() > 0) {
1240         major = verNumList[0].toUInt(&success);
1241         if (success && verNumList.size() > 1) {
1242             minor = verNumList[1].toUInt(&success);
1243             if (success && verNumList.size() > 2) {
1244                 patch = verNumList[2].toUInt(&success);
1245             }
1246         }
1247     }
1248
1249     QString mmpVersion;
1250     if (success && major <= 0xFFFF && minor <= 0xFF && patch <= 0xFF) {
1251         // Symbian binary version only has major and minor components, so compress
1252         // Qt's minor and patch values into the minor component. Since Symbian's minor
1253         // component is a 16 bit value, only allow 8 bits for each to avoid overflow.
1254         mmpVersion.append(QString::number(major))
1255             .append('.')
1256             .append(QString::number((minor << 8) + patch));
1257     } else {
1258         if (!applicationVersion.isEmpty())
1259             fprintf(stderr, "Invalid VERSION string: %s\n", qPrintable(applicationVersion));
1260         mmpVersion = "10.0"; // Default binary version for symbian is 10.0
1261     }
1262
1263     t << MMP_VERSION " " << mmpVersion  << endl;
1264 }
1265
1266 void SymbianMakefileGenerator::writeMmpFileRulesPart(QTextStream& t)
1267 {
1268     foreach(QString item, project->values("MMP_RULES")) {
1269         t << endl;
1270         // If there is no stringlist defined for a rule, use rule name directly
1271         // This is convenience for defining single line mmp statements
1272         if (project->values(item).isEmpty()) {
1273             t << item << endl;
1274         } else {
1275             foreach(QString itemRow, project->values(item)) {
1276                 t << itemRow << endl;
1277             }
1278         }
1279     }
1280 }
1281
1282 void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploymentExtension, const QString &iconFile, DeploymentList &depList)
1283 {
1284     // Read user defined bld inf rules
1285
1286     QMap<QString, QStringList> userBldInfRules;
1287     for (QMap<QString, QStringList>::iterator it = project->variables().begin(); it != project->variables().end(); ++it) {
1288         if (it.key().startsWith(BLD_INF_RULES_BASE)) {
1289             QString newKey = it.key().mid(sizeof(BLD_INF_RULES_BASE) - 1);
1290             if (newKey.isEmpty()) {
1291                 fprintf(stderr, "Warning: Empty BLD_INF_RULES key encountered\n");
1292                 continue;
1293             }
1294             QStringList newValues;
1295             QStringList values = it.value();
1296             foreach(QString item, values) {
1297                 // If there is no stringlist defined for a rule, use rule name directly
1298                 // This is convenience for defining single line statements
1299                 if (project->values(item).isEmpty()) {
1300                     newValues << item;
1301                 } else {
1302                     foreach(QString itemRow, project->values(item)) {
1303                         newValues << itemRow;
1304                     }
1305                 }
1306             }
1307             userBldInfRules.insert(newKey, newValues);
1308         }
1309     }
1310
1311     // Add includes of subdirs bld.inf files
1312
1313     QString mmpfilename = escapeFilePath(fileFixify(project->projectFile()));
1314     mmpfilename = mmpfilename.replace(mmpfilename.lastIndexOf("."), 4, Option::mmp_ext);
1315     QString currentPath = qmake_getpwd();
1316     QDir directory(currentPath);
1317
1318     const QStringList &subdirs = project->values("SUBDIRS");
1319     foreach(QString item, subdirs) {
1320         QString fixedItem;
1321         if (!project->isEmpty(item + ".file")) {
1322             fixedItem = project->first(item + ".file");
1323         } else if (!project->isEmpty(item + ".subdir")) {
1324             fixedItem = project->first(item + ".subdir");
1325         } else {
1326             fixedItem = item;
1327         }
1328
1329         QFileInfo subdir(fileInfo(fixedItem));
1330         QString relativePath = directory.relativeFilePath(fixedItem);
1331         QString subdirFileName = subdir.completeBaseName();
1332         QString fullProName = subdir.absoluteFilePath();;
1333         QString bldinfFilename;
1334
1335         if (subdir.isDir()) {
1336             // Subdir is a regular project
1337             bldinfFilename = relativePath + QString("/") + QString(BLD_INF_FILENAME);
1338             fullProName += QString("/") + subdirFileName + Option::pro_ext;
1339         } else {
1340             // Subdir is actually a .pro file
1341             if (relativePath.contains("/")) {
1342                 // .pro not in same directory as parent .pro
1343                 relativePath.remove(relativePath.lastIndexOf("/") + 1, relativePath.length());
1344                 bldinfFilename = relativePath;
1345             } else {
1346                 // .pro and parent .pro in same directory
1347                 bldinfFilename = QString("./");
1348             }
1349             bldinfFilename += QString(BLD_INF_FILENAME ".") + subdirFileName;
1350         }
1351
1352         QString uid = generate_uid(fullProName);
1353         QString bldinfDefine = QString("BLD_INF_") + subdirFileName + QString("_") + uid;
1354         bldinfDefine = bldinfDefine.toUpper();
1355         removeSpecialCharacters(bldinfDefine);
1356
1357         t << "#ifndef " << bldinfDefine << endl;
1358         t << "\t#include \"" << bldinfFilename << "\"" << endl;
1359         t << "#endif // " << bldinfDefine << endl;
1360     }
1361
1362     // Add supported project platforms
1363
1364     t << endl << BLD_INF_TAG_PLATFORMS << endl << endl;
1365     if (0 != project->values("SYMBIAN_PLATFORMS").size())
1366         t << project->values("SYMBIAN_PLATFORMS").join(" ") << endl;
1367
1368     QStringList userItems = userBldInfRules.value(BLD_INF_TAG_PLATFORMS);
1369     foreach(QString item, userItems)
1370         t << item << endl;
1371     userBldInfRules.remove(BLD_INF_TAG_PLATFORMS);
1372     t << endl;
1373
1374     // Add project mmps and old style extension makefiles
1375
1376     QString mmpTag;
1377     if (project->isActiveConfig("symbian_test"))
1378         mmpTag = QLatin1String(BLD_INF_TAG_TESTMMPFILES);
1379     else
1380         mmpTag = QLatin1String(BLD_INF_TAG_MMPFILES);
1381
1382     t << endl << mmpTag << endl << endl;
1383
1384     writeBldInfMkFilePart(t, addDeploymentExtension);
1385     if (targetType != TypeSubdirs) {
1386         QString shortProFilename = project->projectFile();
1387         shortProFilename.replace(0, shortProFilename.lastIndexOf("/") + 1, QString(""));
1388         shortProFilename.replace(Option::pro_ext, QString(""));
1389
1390         QString mmpFilename = shortProFilename + QString("_") + uid3 + Option::mmp_ext;
1391
1392         t << mmpFilename << endl;
1393     }
1394
1395     userItems = userBldInfRules.value(mmpTag);
1396     foreach(QString item, userItems)
1397         t << item << endl;
1398     userBldInfRules.remove(mmpTag);
1399
1400     t << endl << BLD_INF_TAG_EXTENSIONS << endl << endl;
1401
1402     // Generate extension rules
1403
1404     writeBldInfExtensionRulesPart(t, iconFile);
1405
1406     userItems = userBldInfRules.value(BLD_INF_TAG_EXTENSIONS);
1407     foreach(QString item, userItems)
1408         t << item << endl;
1409     userBldInfRules.remove(BLD_INF_TAG_EXTENSIONS);
1410
1411     t << endl << BLD_INF_TAG_EXPORTS << endl << endl;
1412
1413     // Generate export rules
1414
1415     // Export any deployed plugin stubs under /epoc32/data/z to support ROM builds
1416     for (int i = 0; i < depList.size(); ++i)  {
1417         int index = depList.at(i).from.indexOf(PLUGIN_STUB_DIR);
1418         if (index != -1) {
1419             t << QString("%1 /epoc32/data/z%2")
1420                 .arg(QString(depList.at(i).from).mid(index).replace('\\','/'))
1421                 .arg(QString(depList.at(i).to).mid(2).replace('\\','/')) << endl;
1422         }
1423     }
1424
1425     userItems = userBldInfRules.value(BLD_INF_TAG_EXPORTS);
1426     foreach(QString item, userItems)
1427         t << item << endl;
1428     userBldInfRules.remove(BLD_INF_TAG_EXPORTS);
1429
1430     // Add rest of the user defined content
1431
1432     for (QMap<QString, QStringList>::iterator it = userBldInfRules.begin(); it != userBldInfRules.end(); ++it) {
1433         t << endl << endl << it.key() << endl << endl;
1434         userItems = it.value();
1435         foreach(QString item, userItems)
1436             t << item << endl;
1437     }
1438 }
1439
1440 void SymbianMakefileGenerator::writeRegRssFile(QStringList &userItems)
1441 {
1442     QString filename(fixedTarget);
1443     filename.append("_reg.rss");
1444     QFile ft(filename);
1445     if (ft.open(QIODevice::WriteOnly)) {
1446         generatedFiles << ft.fileName();
1447         QTextStream t(&ft);
1448         t << "// ============================================================================" << endl;
1449         t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: ";
1450         t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl;
1451         t << "// * This file is generated by qmake and should not be modified by the" << endl;
1452         t << "// * user." << endl;
1453         t << "// ============================================================================" << endl;
1454         t << endl;
1455         t << "#include <" << fixedTarget << ".rsg>" << endl;
1456         t << "#include <appinfo.rh>" << endl;
1457         t << endl;
1458         t << "UID2 KUidAppRegistrationResourceFile" << endl;
1459         t << "UID3 " << uid3 << endl << endl;
1460         t << "RESOURCE APP_REGISTRATION_INFO" << endl;
1461         t << "\t{" << endl;
1462         t << "\tapp_file=\"" << fixedTarget << "\";" << endl;
1463         t << "\tlocalisable_resource_file=\"" RESOURCE_DIRECTORY_RESOURCE << fixedTarget << "\";" << endl;
1464         t << endl;
1465
1466         foreach(QString item, userItems)
1467             t << "\t" << item << endl;
1468         t << "\t}" << endl;
1469     } else {
1470         PRINT_FILE_CREATE_ERROR(filename)
1471     }
1472 }
1473
1474 void SymbianMakefileGenerator::writeRssFile(QString &numberOfIcons, QString &iconFile)
1475 {
1476     QString filename(fixedTarget);
1477     filename.append(".rss");
1478     QFile ft(filename);
1479     if (ft.open(QIODevice::WriteOnly)) {
1480         generatedFiles << ft.fileName();
1481         QTextStream t(&ft);
1482         t << "// ============================================================================" << endl;
1483         t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: ";
1484         t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl;
1485         t << "// * This file is generated by qmake and should not be modified by the" << endl;
1486         t << "// * user." << endl;
1487         t << "// ============================================================================" << endl;
1488         t << endl;
1489         t << "#include <appinfo.rh>" << endl;
1490         t << "#include \"" << fixedTarget << ".loc\"" << endl;
1491         t << endl;
1492         t << "RESOURCE LOCALISABLE_APP_INFO r_localisable_app_info" << endl;
1493         t << "\t{" << endl;
1494         t << "\tshort_caption = STRING_r_short_caption;" << endl;
1495         t << "\tcaption_and_icon =" << endl;
1496         t << "\tCAPTION_AND_ICON_INFO" << endl;
1497         t << "\t\t{" << endl;
1498         t << "\t\tcaption = STRING_r_caption;" << endl;
1499
1500         QString rssIconFile = iconFile;
1501         rssIconFile = rssIconFile.replace("/", "\\\\");
1502
1503         if (numberOfIcons.isEmpty() || rssIconFile.isEmpty()) {
1504             // There can be maximum one item in this tag, validated when parsed
1505             t << "\t\tnumber_of_icons = 0;" << endl;
1506             t << "\t\ticon_file = \"\";" << endl;
1507         } else {
1508             // There can be maximum one item in this tag, validated when parsed
1509             t << "\t\tnumber_of_icons = " << numberOfIcons << ";" << endl;
1510             t << "\t\ticon_file = \"" << rssIconFile << "\";" << endl;
1511         }
1512         t << "\t\t};" << endl;
1513         t << "\t}" << endl;
1514         t << endl;
1515     } else {
1516         PRINT_FILE_CREATE_ERROR(filename);
1517     }
1518 }
1519
1520 void SymbianMakefileGenerator::writeLocFile(QStringList &symbianLangCodes)
1521 {
1522     QString filename(fixedTarget);
1523     filename.append(".loc");
1524     QFile ft(filename);
1525     if (ft.open(QIODevice::WriteOnly)) {
1526         generatedFiles << ft.fileName();
1527         QTextStream t(&ft);
1528         t << "// ============================================================================" << endl;
1529         t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: ";
1530         t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl;
1531         t << "// * This file is generated by qmake and should not be modified by the" << endl;
1532         t << "// * user." << endl;
1533         t << "// ============================================================================" << endl;
1534         t << endl;
1535         t << "#ifdef LANGUAGE_SC" << endl;
1536         t << "#define STRING_r_short_caption \"" << fixedTarget  << "\"" << endl;
1537         t << "#define STRING_r_caption \"" << fixedTarget  << "\"" << endl;
1538         foreach(QString lang, symbianLangCodes) {
1539             t << "#elif defined LANGUAGE_" << lang << endl;
1540             t << "#define STRING_r_short_caption \"" << fixedTarget  << "\"" << endl;
1541             t << "#define STRING_r_caption \"" << fixedTarget  << "\"" << endl;
1542         }
1543         t << "#else" << endl;
1544         t << "#define STRING_r_short_caption \"" << fixedTarget  << "\"" << endl;
1545         t << "#define STRING_r_caption \"" << fixedTarget  << "\"" << endl;
1546         t << "#endif" << endl;
1547     } else {
1548         PRINT_FILE_CREATE_ERROR(filename);
1549     }
1550 }
1551
1552 void SymbianMakefileGenerator::readRssRules(QString &numberOfIcons, QString &iconFile, QStringList &userRssRules)
1553 {
1554     for (QMap<QString, QStringList>::iterator it = project->variables().begin(); it != project->variables().end(); ++it) {
1555         if (it.key().startsWith(RSS_RULES_BASE)) {
1556             QString newKey = it.key().mid(sizeof(RSS_RULES_BASE) - 1);
1557             if (newKey.isEmpty()) {
1558                 fprintf(stderr, "Warning: Empty RSS_RULES_BASE key encountered\n");
1559                 continue;
1560             }
1561             QStringList newValues;
1562             QStringList values = it.value();
1563             foreach(QString item, values) {
1564                 // If there is no stringlist defined for a rule, use rule name directly
1565                 // This is convenience for defining single line statements
1566                 if (project->values(item).isEmpty()) {
1567                     newValues << item;
1568                 } else {
1569                     foreach(QString itemRow, project->values(item)) {
1570                         newValues << itemRow;
1571                     }
1572                 }
1573             }
1574             // Verify thet there is exactly one value in RSS_TAG_NBROFICONS
1575             if (newKey == RSS_TAG_NBROFICONS) {
1576                 if (newValues.count() == 1) {
1577                     numberOfIcons = newValues[0];
1578                 } else {
1579                     fprintf(stderr, "Warning: There must be exactly one value in '%s%s'\n",
1580                             RSS_RULES_BASE, RSS_TAG_NBROFICONS);
1581                     continue;
1582                 }
1583             // Verify thet there is exactly one value in RSS_TAG_ICONFILE
1584             } else if (newKey == RSS_TAG_ICONFILE) {
1585                 if (newValues.count() == 1) {
1586                     iconFile = newValues[0];
1587                 } else {
1588                     fprintf(stderr, "Warning: There must be exactly one value in '%s%s'\n",
1589                             RSS_RULES_BASE, RSS_TAG_ICONFILE);
1590                     continue;
1591                 }
1592             } else {
1593                 fprintf(stderr, "Warning: Unsupported key:'%s%s'\n",
1594                         RSS_RULES_BASE, newKey.toLatin1().constData());
1595                 continue;
1596             }
1597         }
1598     }
1599
1600     foreach(QString item, project->values(RSS_RULES)) {
1601         // If there is no stringlist defined for a rule, use rule name directly
1602         // This is convenience for defining single line mmp statements
1603         if (project->values(item).isEmpty()) {
1604             userRssRules << item;
1605         } else {
1606             userRssRules << project->values(item);
1607         }
1608     }
1609
1610     // Validate that either both RSS_TAG_NBROFICONS and RSS_TAG_ICONFILE keys exist
1611     // or neither of them exist
1612     if (!((numberOfIcons.isEmpty() && iconFile.isEmpty()) ||
1613             (!numberOfIcons.isEmpty() && !iconFile.isEmpty()))) {
1614         numberOfIcons.clear();
1615         iconFile.clear();
1616         fprintf(stderr, "Warning: Both or neither of '%s%s' and '%s%s' keys must exist.\n",
1617                 RSS_RULES_BASE, RSS_TAG_NBROFICONS, RSS_RULES_BASE, RSS_TAG_ICONFILE);
1618     }
1619
1620     // Validate that RSS_TAG_NBROFICONS contains only numbers
1621     if (!numberOfIcons.isEmpty()) {
1622         bool ok;
1623         numberOfIcons = numberOfIcons.simplified();
1624         numberOfIcons.toInt(&ok);
1625         if (!ok) {
1626             numberOfIcons.clear();
1627             iconFile.clear();
1628             fprintf(stderr, "Warning: '%s%s' must be integer in decimal format.\n",
1629                     RSS_RULES_BASE, RSS_TAG_NBROFICONS);
1630         }
1631     }
1632 }
1633
1634 QStringList SymbianMakefileGenerator::symbianLangCodesFromTsFiles()
1635 {
1636     QStringList tsfiles;
1637     QStringList symbianLangCodes;
1638     tsfiles << project->values("TRANSLATIONS");
1639
1640     fillQt2S60LangMapTable();
1641
1642     foreach(QString file, tsfiles) {
1643         int extIndex = file.lastIndexOf(".");
1644         int langIndex = file.lastIndexOf("_", (extIndex - file.length()));
1645         langIndex += 1;
1646         QString qtlang = file.mid(langIndex, extIndex - langIndex);
1647         QString s60lang = qt2S60LangMapTable.value(qtlang, QString("SC"));
1648
1649         if (!symbianLangCodes.contains(s60lang) && s60lang != "SC")
1650             symbianLangCodes += s60lang;
1651     }
1652
1653     return symbianLangCodes;
1654 }
1655
1656 void SymbianMakefileGenerator::fillQt2S60LangMapTable()
1657 {
1658     qt2S60LangMapTable.reserve(170); // 165 items at time of writing.
1659     qt2S60LangMapTable.insert("ab", "SC");            //Abkhazian                     //
1660     qt2S60LangMapTable.insert("om", "SC");            //Afan                          //
1661     qt2S60LangMapTable.insert("aa", "SC");            //Afar                          //
1662     qt2S60LangMapTable.insert("af", "34");            //Afrikaans                     //Afrikaans
1663     qt2S60LangMapTable.insert("sq", "35");            //Albanian                      //Albanian
1664     qt2S60LangMapTable.insert("am", "36");            //Amharic                       //Amharic
1665     qt2S60LangMapTable.insert("ar", "37");            //Arabic                        //Arabic
1666     qt2S60LangMapTable.insert("hy", "38");            //Armenian                      //Armenian
1667     qt2S60LangMapTable.insert("as", "SC");            //Assamese                      //
1668     qt2S60LangMapTable.insert("ay", "SC");            //Aymara                        //
1669     qt2S60LangMapTable.insert("az", "SC");            //Azerbaijani                   //
1670     qt2S60LangMapTable.insert("ba", "SC");            //Bashkir                       //
1671     qt2S60LangMapTable.insert("eu", "SC");            //Basque                        //
1672     qt2S60LangMapTable.insert("bn", "41");            //Bengali                       //Bengali
1673     qt2S60LangMapTable.insert("dz", "SC");            //Bhutani                       //
1674     qt2S60LangMapTable.insert("bh", "SC");            //Bihari                        //
1675     qt2S60LangMapTable.insert("bi", "SC");            //Bislama                       //
1676     qt2S60LangMapTable.insert("br", "SC");            //Breton                        //
1677     qt2S60LangMapTable.insert("bg", "42");            //Bulgarian                     //Bulgarian
1678     qt2S60LangMapTable.insert("my", "43");            //Burmese                       //Burmese
1679     qt2S60LangMapTable.insert("be", "40");            //Byelorussian                  //Belarussian
1680     qt2S60LangMapTable.insert("km", "SC");            //Cambodian                     //
1681     qt2S60LangMapTable.insert("ca", "44");            //Catalan                       //Catalan
1682     qt2S60LangMapTable.insert("zh", "SC");            //Chinese                       //
1683     qt2S60LangMapTable.insert("co", "SC");            //Corsican                      //
1684     qt2S60LangMapTable.insert("hr", "45");            //Croatian                      //Croatian
1685     qt2S60LangMapTable.insert("cs", "25");            //Czech                         //Czech
1686     qt2S60LangMapTable.insert("da", "07");            //Danish                        //Danish
1687     qt2S60LangMapTable.insert("nl", "18");            //Dutch                         //Dutch
1688     qt2S60LangMapTable.insert("en", "01");            //English                       //English(UK)
1689     qt2S60LangMapTable.insert("eo", "SC");            //Esperanto                     //
1690     qt2S60LangMapTable.insert("et", "49");            //Estonian                      //Estonian
1691     qt2S60LangMapTable.insert("fo", "SC");            //Faroese                       //
1692     qt2S60LangMapTable.insert("fj", "SC");            //Fiji                          //
1693     qt2S60LangMapTable.insert("fi", "09");            //Finnish                       //Finnish
1694     qt2S60LangMapTable.insert("fr", "02");            //French                        //French
1695     qt2S60LangMapTable.insert("fy", "SC");            //Frisian                       //
1696     qt2S60LangMapTable.insert("gd", "52");            //Gaelic                        //Gaelic
1697     qt2S60LangMapTable.insert("gl", "SC");            //Galician                      //
1698     qt2S60LangMapTable.insert("ka", "53");            //Georgian                      //Georgian
1699     qt2S60LangMapTable.insert("de", "03");            //German                        //German
1700     qt2S60LangMapTable.insert("el", "54");            //Greek                         //Greek
1701     qt2S60LangMapTable.insert("kl", "SC");            //Greenlandic                   //
1702     qt2S60LangMapTable.insert("gn", "SC");            //Guarani                       //
1703     qt2S60LangMapTable.insert("gu", "56");            //Gujarati                      //Gujarati
1704     qt2S60LangMapTable.insert("ha", "SC");            //Hausa                         //
1705     qt2S60LangMapTable.insert("he", "57");            //Hebrew                        //Hebrew
1706     qt2S60LangMapTable.insert("hi", "58");            //Hindi                         //Hindi
1707     qt2S60LangMapTable.insert("hu", "17");            //Hungarian                     //Hungarian
1708     qt2S60LangMapTable.insert("is", "15");            //Icelandic                     //Icelandic
1709     qt2S60LangMapTable.insert("id", "59");            //Indonesian                    //Indonesian
1710     qt2S60LangMapTable.insert("ia", "SC");            //Interlingua                   //
1711     qt2S60LangMapTable.insert("ie", "SC");            //Interlingue                   //
1712     qt2S60LangMapTable.insert("iu", "SC");            //Inuktitut                     //
1713     qt2S60LangMapTable.insert("ik", "SC");            //Inupiak                       //
1714     qt2S60LangMapTable.insert("ga", "60");            //Irish                         //Irish
1715     qt2S60LangMapTable.insert("it", "05");            //Italian                       //Italian
1716     qt2S60LangMapTable.insert("ja", "32");            //Japanese                      //Japanese
1717     qt2S60LangMapTable.insert("jv", "SC");            //Javanese                      //
1718     qt2S60LangMapTable.insert("kn", "62");            //Kannada                       //Kannada
1719     qt2S60LangMapTable.insert("ks", "SC");            //Kashmiri                      //
1720     qt2S60LangMapTable.insert("kk", "63");            //Kazakh                        //Kazakh
1721     qt2S60LangMapTable.insert("rw", "SC");            //Kinyarwanda                   //
1722     qt2S60LangMapTable.insert("ky", "SC");            //Kirghiz                       //
1723     qt2S60LangMapTable.insert("ko", "65");            //Korean                        //Korean
1724     qt2S60LangMapTable.insert("ku", "SC");            //Kurdish                       //
1725     qt2S60LangMapTable.insert("rn", "SC");            //Kurundi                       //
1726     qt2S60LangMapTable.insert("lo", "66");            //Laothian                      //Laothian
1727     qt2S60LangMapTable.insert("la", "SC");            //Latin                         //
1728     qt2S60LangMapTable.insert("lv", "67");            //Latvian                       //Latvian
1729     qt2S60LangMapTable.insert("ln", "SC");            //Lingala                       //
1730     qt2S60LangMapTable.insert("lt", "68");            //Lithuanian                    //Lithuanian
1731     qt2S60LangMapTable.insert("mk", "69");            //Macedonian                    //Macedonian
1732     qt2S60LangMapTable.insert("mg", "SC");            //Malagasy                      //
1733     qt2S60LangMapTable.insert("ms", "70");            //Malay                         //Malay
1734     qt2S60LangMapTable.insert("ml", "71");            //Malayalam                     //Malayalam
1735     qt2S60LangMapTable.insert("mt", "SC");            //Maltese                       //
1736     qt2S60LangMapTable.insert("mi", "SC");            //Maori                         //
1737     qt2S60LangMapTable.insert("mr", "72");            //Marathi                       //Marathi
1738     qt2S60LangMapTable.insert("mo", "73");            //Moldavian                     //Moldovian
1739     qt2S60LangMapTable.insert("mn", "74");            //Mongolian                     //Mongolian
1740     qt2S60LangMapTable.insert("na", "SC");            //Nauru                         //
1741     qt2S60LangMapTable.insert("ne", "SC");            //Nepali                        //
1742     qt2S60LangMapTable.insert("nb", "08");            //Norwegian                     //Norwegian
1743     qt2S60LangMapTable.insert("oc", "SC");            //Occitan                       //
1744     qt2S60LangMapTable.insert("or", "SC");            //Oriya                         //
1745     qt2S60LangMapTable.insert("ps", "SC");            //Pashto                        //
1746     qt2S60LangMapTable.insert("fa", "SC");            //Persian                       //
1747     qt2S60LangMapTable.insert("pl", "27");            //Polish                        //Polish
1748     qt2S60LangMapTable.insert("pt", "13");            //Portuguese                    //Portuguese
1749     qt2S60LangMapTable.insert("pa", "77");            //Punjabi                       //Punjabi
1750     qt2S60LangMapTable.insert("qu", "SC");            //Quechua                       //
1751     qt2S60LangMapTable.insert("rm", "SC");            //RhaetoRomance                 //
1752     qt2S60LangMapTable.insert("ro", "78");            //Romanian                      //Romanian
1753     qt2S60LangMapTable.insert("ru", "16");            //Russian                       //Russian
1754     qt2S60LangMapTable.insert("sm", "SC");            //Samoan                        //
1755     qt2S60LangMapTable.insert("sg", "SC");            //Sangho                        //
1756     qt2S60LangMapTable.insert("sa", "SC");            //Sanskrit                      //
1757     qt2S60LangMapTable.insert("sr", "79");            //Serbian                       //Serbian
1758     qt2S60LangMapTable.insert("sh", "SC");            //SerboCroatian                 //
1759     qt2S60LangMapTable.insert("st", "SC");            //Sesotho                       //
1760     qt2S60LangMapTable.insert("tn", "SC");            //Setswana                      //
1761     qt2S60LangMapTable.insert("sn", "SC");            //Shona                         //
1762     qt2S60LangMapTable.insert("sd", "SC");            //Sindhi                        //
1763     qt2S60LangMapTable.insert("si", "80");            //Singhalese                    //Sinhalese
1764     qt2S60LangMapTable.insert("ss", "SC");            //Siswati                       //
1765     qt2S60LangMapTable.insert("sk", "26");            //Slovak                        //Slovak
1766     qt2S60LangMapTable.insert("sl", "28");            //Slovenian                     //Slovenian
1767     qt2S60LangMapTable.insert("so", "81");            //Somali                        //Somali
1768     qt2S60LangMapTable.insert("es", "04");            //Spanish                       //Spanish
1769     qt2S60LangMapTable.insert("su", "SC");            //Sundanese                     //
1770     qt2S60LangMapTable.insert("sw", "84");            //Swahili                       //Swahili
1771     qt2S60LangMapTable.insert("sv", "06");            //Swedish                       //Swedish
1772     qt2S60LangMapTable.insert("tl", "39");            //Tagalog                       //Tagalog
1773     qt2S60LangMapTable.insert("tg", "SC");            //Tajik                         //
1774     qt2S60LangMapTable.insert("ta", "87");            //Tamil                         //Tamil
1775     qt2S60LangMapTable.insert("tt", "SC");            //Tatar                         //
1776     qt2S60LangMapTable.insert("te", "88");            //Telugu                        //Telugu
1777     qt2S60LangMapTable.insert("th", "33");            //Thai                          //Thai
1778     qt2S60LangMapTable.insert("bo", "89");            //Tibetan                       //Tibetan
1779     qt2S60LangMapTable.insert("ti", "90");            //Tigrinya                      //Tigrinya
1780     qt2S60LangMapTable.insert("to", "SC");            //Tonga                         //
1781     qt2S60LangMapTable.insert("ts", "SC");            //Tsonga                        //
1782     qt2S60LangMapTable.insert("tr", "14");            //Turkish                       //Turkish
1783     qt2S60LangMapTable.insert("tk", "92");            //Turkmen                       //Turkmen
1784     qt2S60LangMapTable.insert("tw", "SC");            //Twi                           //
1785     qt2S60LangMapTable.insert("ug", "SC");            //Uigur                         //
1786     qt2S60LangMapTable.insert("uk", "93");            //Ukrainian                     //Ukrainian
1787     qt2S60LangMapTable.insert("ur", "94");            //Urdu                          //Urdu
1788     qt2S60LangMapTable.insert("uz", "SC");            //Uzbek                         //
1789     qt2S60LangMapTable.insert("vi", "96");            //Vietnamese                    //Vietnamese
1790     qt2S60LangMapTable.insert("vo", "SC");            //Volapuk                       //
1791     qt2S60LangMapTable.insert("cy", "97");            //Welsh                         //Welsh
1792     qt2S60LangMapTable.insert("wo", "SC");            //Wolof                         //
1793     qt2S60LangMapTable.insert("xh", "SC");            //Xhosa                         //
1794     qt2S60LangMapTable.insert("yi", "SC");            //Yiddish                       //
1795     qt2S60LangMapTable.insert("yo", "SC");            //Yoruba                        //
1796     qt2S60LangMapTable.insert("za", "SC");            //Zhuang                        //
1797     qt2S60LangMapTable.insert("zu", "98");            //Zulu                          //Zulu
1798     qt2S60LangMapTable.insert("nn", "75");            //Nynorsk                       //NorwegianNynorsk
1799     qt2S60LangMapTable.insert("bs", "SC");            //Bosnian                       //
1800     qt2S60LangMapTable.insert("dv", "SC");            //Divehi                        //
1801     qt2S60LangMapTable.insert("gv", "SC");            //Manx                          //
1802     qt2S60LangMapTable.insert("kw", "SC");            //Cornish                       //
1803     qt2S60LangMapTable.insert("ak", "SC");            //Akan                          //
1804     qt2S60LangMapTable.insert("kok", "SC");           //Konkani                       //
1805     qt2S60LangMapTable.insert("gaa", "SC");           //Ga                            //
1806     qt2S60LangMapTable.insert("ig", "SC");            //Igbo                          //
1807     qt2S60LangMapTable.insert("kam", "SC");           //Kamba                         //
1808     qt2S60LangMapTable.insert("syr", "SC");           //Syriac                        //
1809     qt2S60LangMapTable.insert("byn", "SC");           //Blin                          //
1810     qt2S60LangMapTable.insert("gez", "SC");           //Geez                          //
1811     qt2S60LangMapTable.insert("kfo", "SC");           //Koro                          //
1812     qt2S60LangMapTable.insert("sid", "SC");           //Sidamo                        //
1813     qt2S60LangMapTable.insert("cch", "SC");           //Atsam                         //
1814     qt2S60LangMapTable.insert("tig", "SC");           //Tigre                         //
1815     qt2S60LangMapTable.insert("kaj", "SC");           //Jju                           //
1816     qt2S60LangMapTable.insert("fur", "SC");           //Friulian                      //
1817     qt2S60LangMapTable.insert("ve", "SC");            //Venda                         //
1818     qt2S60LangMapTable.insert("ee", "SC");            //Ewe                           //
1819     qt2S60LangMapTable.insert("wa", "SC");            //Walamo                        //
1820     qt2S60LangMapTable.insert("haw", "SC");           //Hawaiian                      //
1821     qt2S60LangMapTable.insert("kcg", "SC");           //Tyap                          //
1822     qt2S60LangMapTable.insert("ny", "SC");            //Chewa                         //
1823 }
1824
1825 void SymbianMakefileGenerator::appendIfnotExist(QStringList &list, QString value)
1826 {
1827     if (!list.contains(value))
1828         list += value;
1829 }
1830
1831 void SymbianMakefileGenerator::appendIfnotExist(QStringList &list, QStringList values)
1832 {
1833     foreach(QString item, values)
1834         appendIfnotExist(list, item);
1835 }
1836
1837 QString SymbianMakefileGenerator::removePathSeparators(QString &file)
1838 {
1839     QString ret = file;
1840     while (ret.indexOf(QDir::separator()) > 0) {
1841         ret.remove(0, ret.indexOf(QDir::separator()) + 1);
1842     }
1843
1844     return ret;
1845 }
1846
1847
1848 QString SymbianMakefileGenerator::removeTrailingPathSeparators(QString &file)
1849 {
1850     QString ret = file;
1851     if (ret.endsWith(QDir::separator())) {
1852         ret.remove(ret.length() - 1, 1);
1853     }
1854
1855     return ret;
1856 }
1857
1858 void SymbianMakefileGenerator::generateCleanCommands(QTextStream& t,
1859         const QStringList& toClean,
1860         const QString& cmd,
1861         const QString& cmdOptions,
1862         const QString& itemPrefix,
1863         const QString& itemSuffix)
1864 {
1865     for (int i = 0; i < toClean.size(); ++i) {
1866         QString item = toClean.at(i);
1867         item.prepend(itemPrefix).append(itemSuffix);
1868 #if defined(Q_OS_WIN)
1869         t << "\t-@ if EXIST \"" << QDir::toNativeSeparators(item) << "\" ";
1870         t << cmd << " " << cmdOptions << " \"" << QDir::toNativeSeparators(item) << "\"" << endl;
1871 #else
1872         t << "\t-if test -e " << QDir::toNativeSeparators(item) << "; then ";
1873         t << cmd << " " << cmdOptions << " " << QDir::toNativeSeparators(item) << "; fi" << endl;
1874 #endif
1875     }
1876 }
1877
1878 void SymbianMakefileGenerator::removeSpecialCharacters(QString& str)
1879 {
1880     // When modifying this method check also application_icon.prf
1881     str.replace(QString("/"), QString("_"));
1882     str.replace(QString("\\"), QString("_"));
1883     str.replace(QString("-"), QString("_"));
1884     str.replace(QString(":"), QString("_"));
1885     str.replace(QString("."), QString("_"));
1886     str.replace(QString(" "), QString("_"));
1887 }
1888
1889 void SymbianMakefileGenerator::writeSisTargets(QTextStream &t)
1890 {
1891     t << "-include " MAKE_CACHE_NAME << endl;
1892     t << endl;
1893
1894     t << SIS_TARGET ":" << endl;
1895     QString siscommand = QString::fromLatin1("\t$(if $(wildcard %1_template.%2),$(if $(wildcard %3)," \
1896                                   "$(MAKE) -s -f $(MAKEFILE) %4," \
1897                                   "$(if $(QT_SIS_TARGET),$(MAKE) -s -f $(MAKEFILE) %4," \
1898                                   "$(MAKE) -s -f $(MAKEFILE) %5))," \
1899                                   "$(MAKE) -s -f $(MAKEFILE) %6)")
1900                           .arg(fixedTarget)
1901                           .arg("pkg")
1902                           .arg(MAKE_CACHE_NAME)
1903                           .arg(OK_SIS_TARGET)
1904                           .arg(FAIL_SIS_NOCACHE_TARGET)
1905                           .arg(FAIL_SIS_NOPKG_TARGET);
1906     t << siscommand << endl;
1907     t << endl;
1908
1909     t << OK_SIS_TARGET ":" << endl;
1910
1911     QString pkgcommand = QString::fromLatin1("\tcreatepackage" SCRIPT_EXT " $(QT_SIS_OPTIONS) %1_template.%2 $(QT_SIS_TARGET) " \
1912                                  "$(QT_SIS_CERTIFICATE) $(QT_SIS_KEY) $(QT_SIS_PASSPHRASE)")
1913                           .arg(fixedTarget)
1914                           .arg("pkg");
1915     t << pkgcommand << endl;
1916     t << endl;
1917
1918     QString sisName = fixedTarget;
1919     sisName += ".sis";
1920
1921     t << sisName << ":" << endl;
1922     t << "\t$(MAKE) -s -f $(MAKEFILE) " SIS_TARGET << endl << endl;
1923
1924     t << ROM_STUB_SIS_TARGET ":" << endl;
1925     QString stubsiscommand = QString::fromLatin1("\t$(if $(wildcard %1_template.%2),$(if $(wildcard %3)," \
1926                                   "$(MAKE) -s -f $(MAKEFILE) %4," \
1927                                   "$(if $(QT_SIS_TARGET),$(MAKE) -s -f $(MAKEFILE) %4," \
1928                                   "$(MAKE) -s -f $(MAKEFILE) %5))," \
1929                                   "$(MAKE) -s -f $(MAKEFILE) %6)")
1930                           .arg(fixedTarget)
1931                           .arg("pkg")
1932                           .arg(MAKE_CACHE_NAME)
1933                           .arg(OK_ROM_STUB_SIS_TARGET)
1934                           .arg(FAIL_SIS_NOCACHE_TARGET)
1935                           .arg(FAIL_SIS_NOPKG_TARGET);
1936     t << stubsiscommand << endl;
1937     t << endl;
1938
1939     t << OK_ROM_STUB_SIS_TARGET ":" << endl;
1940
1941     QString stubpkgcommand = QString::fromLatin1("\tcreatepackage" SCRIPT_EXT " -s $(QT_SIS_OPTIONS) %1_template.%2 $(QT_SIS_TARGET) " \
1942                                  "$(QT_SIS_CERTIFICATE) $(QT_SIS_KEY) $(QT_SIS_PASSPHRASE)")
1943                           .arg(fixedTarget)
1944                           .arg("pkg");
1945     t << stubpkgcommand << endl;
1946     t << endl;
1947
1948     t << INSTALLER_SIS_TARGET ": " << sisName << endl;
1949     siscommand = QString::fromLatin1("\t$(if $(wildcard %1_installer.%2)," \
1950                                   "$(MAKE) -s -f $(MAKEFILE) %3," \
1951                                   "$(MAKE) -s -f $(MAKEFILE) %4)")
1952                           .arg(fixedTarget)
1953                           .arg("pkg")
1954                           .arg(OK_INSTALLER_SIS_TARGET)
1955                           .arg(FAIL_SIS_NOPKG_TARGET);
1956     t << siscommand << endl;
1957     t << endl;
1958
1959     t << OK_INSTALLER_SIS_TARGET ": " << endl;
1960
1961     pkgcommand = QString::fromLatin1("\tcreatepackage.bat $(QT_SIS_OPTIONS) %1_installer.%2 - " \
1962                          "$(QT_SIS_CERTIFICATE) $(QT_SIS_KEY) $(QT_SIS_PASSPHRASE)")
1963                   .arg(fixedTarget)
1964                   .arg("pkg");
1965     t << pkgcommand << endl;
1966     t << endl;
1967
1968     t << FAIL_SIS_NOPKG_TARGET ":" << endl;
1969     t << "\t$(error PKG file does not exist, '" SIS_TARGET "' and '" INSTALLER_SIS_TARGET "' target are only supported for executables or projects with DEPLOYMENT statement)" << endl;
1970     t << endl;
1971
1972     t << FAIL_SIS_NOCACHE_TARGET ":" << endl;
1973     t << "\t$(error Project has to be built or QT_SIS_TARGET environment variable has to be set before calling 'SIS' target)" << endl;
1974     t << endl;
1975 }
1976
1977 void SymbianMakefileGenerator::generateDistcleanTargets(QTextStream& t)
1978 {
1979     t << "dodistclean:" << endl;
1980     const QStringList &subdirs = project->values("SUBDIRS");
1981     foreach(QString item, subdirs) {
1982         bool fromFile = false;
1983         QString fixedItem;
1984         if (!project->isEmpty(item + ".file")) {
1985             fixedItem = project->first(item + ".file");
1986             fromFile = true;
1987         } else if (!project->isEmpty(item + ".subdir")) {
1988             fixedItem = project->first(item + ".subdir");
1989             fromFile = false;
1990         } else {
1991             fromFile = item.endsWith(Option::pro_ext);
1992             fixedItem = item;
1993         }
1994         QFileInfo fi(fileInfo(fixedItem));
1995         if (!fromFile) {
1996             t << "\t-$(MAKE) -f \"" << Option::fixPathToTargetOS(fi.absoluteFilePath() + "/Makefile") << "\" dodistclean" << endl;
1997         } else {
1998             QString itemName = fi.fileName();
1999             int extIndex = itemName.lastIndexOf(Option::pro_ext);
2000             if (extIndex)
2001                 fixedItem = fi.absolutePath() + "/" + QString("Makefile.") + itemName.mid(0, extIndex);
2002             t << "\t-$(MAKE) -f \"" << Option::fixPathToTargetOS(fixedItem) << "\" dodistclean" << endl;
2003         }
2004
2005     }
2006
2007     generatedFiles << Option::fixPathToTargetOS(fileInfo(Option::output.fileName()).absoluteFilePath()); // bld.inf
2008     generatedFiles << project->values("QMAKE_INTERNAL_PRL_FILE"); // Add generated prl files for cleanup
2009     generatedFiles << project->values("QMAKE_DISTCLEAN"); // Add any additional files marked for distclean
2010     QStringList fixedFiles;
2011     QStringList fixedDirs;
2012     foreach(QString item, generatedFiles) {
2013         QString fixedItem = Option::fixPathToTargetOS(fileInfo(item).absoluteFilePath());
2014         if (!fixedFiles.contains(fixedItem)) {
2015             fixedFiles << fixedItem;
2016         }
2017     }
2018     foreach(QString item, generatedDirs) {
2019         QString fixedItem = Option::fixPathToTargetOS(fileInfo(item).absoluteFilePath());
2020         if (!fixedDirs.contains(fixedItem)) {
2021             fixedDirs << fixedItem;
2022         }
2023     }
2024     generateCleanCommands(t, fixedFiles, "$(DEL_FILE)", "", "", "");
2025     generateCleanCommands(t, fixedDirs, "$(DEL_DIR)", "", "", "");
2026     t << endl;
2027
2028     t << "distclean: clean dodistclean" << endl;
2029     t << endl;
2030 }
2031
2032 void SymbianMakefileGenerator::generateExecutionTargets(QTextStream& t, const QStringList& platforms)
2033 {
2034     // create execution targets
2035     if (targetType == TypeExe) {
2036         if (platforms.contains("winscw")) {
2037             t << "run:" << endl;
2038             t << "\t-call " << epocRoot() << "epoc32/release/winscw/udeb/" << fixedTarget << ".exe " << "$(QT_RUN_OPTIONS)" << endl;
2039         }
2040         t << "runonphone: sis" << endl;
2041         t << "\trunonphone $(QT_RUN_ON_PHONE_OPTIONS) --sis " << fixedTarget << "_$(QT_SIS_TARGET).sis " << fixedTarget << ".exe " << "$(QT_RUN_OPTIONS)" << endl;
2042         t << endl;
2043     }
2044 }