Remove toolcheck from generic clean targets for symbian-sbsv2
[qt:qt.git] / qmake / generators / symbian / symmake_sbsv2.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the 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_sbsv2.h"
43 #include "initprojectdeploy_symbian.h"
44
45 #include <qstring.h>
46 #include <qstringlist.h>
47 #include <qdir.h>
48 #include <qdatetime.h>
49 #include <qdebug.h>
50
51 // Included from tools/shared
52 #include <symbian/epocroot_p.h>
53
54 SymbianSbsv2MakefileGenerator::SymbianSbsv2MakefileGenerator() : SymbianMakefileGenerator() { }
55 SymbianSbsv2MakefileGenerator::~SymbianSbsv2MakefileGenerator() { }
56
57 #define FLM_DEST_DIR "epoc32/tools/makefile_templates/qt"
58 #define FLM_SOURCE_DIR "/mkspecs/symbian-sbsv2/flm/qt"
59 #define PLATFORM_GCCE "gcce"
60 #define PLATFORM_WINSCW "winscw"
61 #define PLATFORM_ARM_PREFIX "arm"
62 #define BUILD_DEBUG "udeb"
63 #define BUILD_RELEASE "urel"
64 #define SBS_RVCT_PREFIX "rvct"
65
66 static QString winscwPlatform;
67 static QString armPlatformPrefix;
68 static QString gccePlatform;
69 static QString sbsRvctPrefix;
70
71 #if defined(Q_OS_UNIX)
72     extern char **environ;
73 #endif
74
75 // Copies Qt FLMs to correct location under epocroot.
76 // This is not done by configure as it is possible to change epocroot after configure.
77 void SymbianSbsv2MakefileGenerator::exportFlm()
78 {
79     static bool flmExportDone = false;
80
81     if (!flmExportDone) {
82         QDir sourceDir = QDir(QLibraryInfo::location(QLibraryInfo::PrefixPath) + FLM_SOURCE_DIR);
83         QFileInfoList sourceInfos = sourceDir.entryInfoList(QDir::Files);
84
85         QDir destDir(qt_epocRoot() + FLM_DEST_DIR);
86         if (!destDir.exists()) {
87             if (destDir.mkpath(destDir.absolutePath()))
88                 generatedDirs << destDir.absolutePath();
89         }
90
91         foreach(QFileInfo item, sourceInfos) {
92             QFileInfo destInfo = QFileInfo(destDir.absolutePath() + "/" + item.fileName());
93             if (!destInfo.exists() || destInfo.lastModified() != item.lastModified()) {
94                 if (destInfo.exists())
95                     QFile::remove(destInfo.absoluteFilePath());
96                 if (QFile::copy(item.absoluteFilePath(), destInfo.absoluteFilePath()))
97                     generatedFiles << destInfo.absoluteFilePath();
98                 else
99                     fprintf(stderr, "Error: Could not copy '%s' -> '%s'\n",
100                             qPrintable(item.absoluteFilePath()),
101                             qPrintable(destInfo.absoluteFilePath()));
102             }
103         }
104         flmExportDone = true;
105     }
106 }
107
108 void SymbianSbsv2MakefileGenerator::findInstalledCompilerVersions(const QString &matchExpression,
109                                                                   const QString &versionPrefix,
110                                                                   QStringList *versionList)
111 {
112     // No need to be able to find env variables on other operating systems,
113     // as only linux and windows have support for symbian-sbsv2 toolchain
114 #if defined(Q_OS_UNIX) || defined(Q_OS_WIN)
115     char *entry = 0;
116     int count = 0;
117     QRegExp matcher(matchExpression);
118     while ((entry = environ[count++])) {
119         if (matcher.exactMatch(QString::fromLocal8Bit(entry))
120             && fileInfo(matcher.cap(matcher.captureCount())).exists()) {
121             // First capture (index 0) is the whole match, which is skipped.
122             // Next n captures are version numbers, which are interesting.
123             // Final capture is the env var value, which we already used, so that is skipped, too.
124             int capture = 1;
125             int finalCapture = matcher.captureCount() - 1;
126             QString version = versionPrefix;
127             while (capture <= finalCapture) {
128                 version.append(matcher.cap(capture));
129                 if (capture != finalCapture)
130                     version.append(QLatin1Char('.'));
131                 capture++;
132             }
133             *versionList << version;
134         }
135     }
136 #endif
137 }
138
139 void SymbianSbsv2MakefileGenerator::findGcceVersions(QStringList *gcceVersionList,
140                                                      QString *defaultVersion)
141 {
142     QString matchStr = QLatin1String("SBS_GCCE(\\d)(\\d)(\\d)BIN=(.*)");
143     findInstalledCompilerVersions(matchStr, gccePlatform, gcceVersionList);
144
145     QString qtGcceVersion = QString::fromLocal8Bit(qgetenv("QT_GCCE_VERSION"));
146
147     if (!qtGcceVersion.isEmpty()) {
148         if (QRegExp("\\d+\\.\\d+\\.\\d+").exactMatch(qtGcceVersion)) {
149             *defaultVersion = gccePlatform + qtGcceVersion;
150         } else {
151             fprintf(stderr, "Warning: Variable QT_GCCE_VERSION ('%s') is in incorrect "
152                     "format, expected format is: 'x.y.z'. Attempting to autodetect GCCE version.\n",
153                     qPrintable(qtGcceVersion));
154         }
155     }
156
157     if (defaultVersion->isEmpty() && gcceVersionList->size()) {
158         gcceVersionList->sort();
159         *defaultVersion = gcceVersionList->last();
160     }
161 }
162
163 void SymbianSbsv2MakefileGenerator::findRvctVersions(QStringList *rvctVersionList,
164                                                      QString *defaultVersion)
165 {
166     QString matchStr = QLatin1String("RVCT(\\d)(\\d)BIN=(.*)");
167     findInstalledCompilerVersions(matchStr, sbsRvctPrefix, rvctVersionList);
168
169     QString qtRvctVersion = QString::fromLocal8Bit(qgetenv("QT_RVCT_VERSION"));
170
171     if (!qtRvctVersion.isEmpty()) {
172         if (QRegExp("\\d+\\.\\d+").exactMatch(qtRvctVersion)) {
173             *defaultVersion = sbsRvctPrefix + qtRvctVersion;
174         } else {
175             fprintf(stderr, "Warning: Variable QT_RVCT_VERSION ('%s') is in incorrect "
176                     "format, expected format is: 'x.y'.\n",
177                     qPrintable(qtRvctVersion));
178         }
179     }
180 }
181
182 QString SymbianSbsv2MakefileGenerator::configClause(const QString &platform,
183                                                     const QString &build,
184                                                     const QString &compilerVersion,
185                                                     const QString &clauseTemplate)
186 {
187     QString retval;
188     if (QString::compare(platform, winscwPlatform) == 0) {
189         retval = clauseTemplate.arg(build);
190     } else if (platform.startsWith(armPlatformPrefix)) {
191         QString fixedCompilerVersion = compilerVersion;
192         fixedCompilerVersion.replace(".","_");
193         retval = clauseTemplate.arg(platform.mid(sizeof(PLATFORM_ARM_PREFIX)-1))
194                                   .arg(build)
195                                   .arg(fixedCompilerVersion);
196     } // else - Unsupported platform for makefile target, return empty clause
197     return retval;
198 }
199
200 void SymbianSbsv2MakefileGenerator::writeSbsDeploymentList(const DeploymentList& depList, QTextStream& t)
201 {
202     for (int i = 0; i < depList.size(); ++i) {
203         t << "START EXTENSION qt/qmake_emulator_deployment" << endl;
204         QString fromItem = depList.at(i).from;
205         QString toItem = depList.at(i).to;
206         fromItem.replace("\\", "/");
207         toItem.replace("\\", "/");
208 #if defined(Q_OS_WIN)
209         // add drive if it doesn't have one yet
210         if (toItem.size() > 1 && toItem[1] != QLatin1Char(':'))
211             toItem.prepend(QDir::current().absolutePath().left(2));
212 #endif
213         t << "OPTION DEPLOY_SOURCE " << fromItem << endl;
214         t << "OPTION DEPLOY_TARGET " << toItem << endl;
215         t << "END" << endl;
216     }
217 }
218
219 void SymbianSbsv2MakefileGenerator::writeMkFile(const QString& wrapperFileName, bool deploymentOnly)
220 {
221     // Can't use extension makefile with sbsv2
222     Q_UNUSED(wrapperFileName);
223     Q_UNUSED(deploymentOnly);
224 }
225
226 void SymbianSbsv2MakefileGenerator::writeWrapperMakefile(QFile& wrapperFile, bool isPrimaryMakefile)
227 {
228     static QString debugBuild;
229     static QString releaseBuild;
230     static QString defaultGcceCompilerVersion;
231     static QString defaultRvctCompilerVersion;
232     static QStringList rvctVersions;
233     static QStringList gcceVersions;
234     static QStringList allArmCompilerVersions;
235
236     // Initialize static variables used in makefile creation
237     if (debugBuild.isEmpty()) {
238         debugBuild.append(QLatin1String(BUILD_DEBUG));
239         releaseBuild.append(QLatin1String(BUILD_RELEASE));
240         winscwPlatform.append(QLatin1String(PLATFORM_WINSCW));
241         gccePlatform.append(QLatin1String(PLATFORM_GCCE));
242         armPlatformPrefix.append(QLatin1String(PLATFORM_ARM_PREFIX));
243         sbsRvctPrefix.append(QLatin1String(SBS_RVCT_PREFIX));
244
245         findGcceVersions(&gcceVersions, &defaultGcceCompilerVersion);
246         findRvctVersions(&rvctVersions, &defaultRvctCompilerVersion);
247
248         allArmCompilerVersions << rvctVersions << gcceVersions;
249
250         if (!allArmCompilerVersions.size()) {
251             fprintf(stderr, "Warning: No HW compilers detected. "
252                     "Please install either GCCE or RVCT compiler to enable release builds.\n");
253         }
254     }
255
256     QStringList allPlatforms;
257     foreach(QString platform, project->values("SYMBIAN_PLATFORMS")) {
258         allPlatforms << platform.toLower();
259     }
260
261     if (!gcceVersions.size())
262         allPlatforms.removeAll(gccePlatform);
263
264     QString testClause;
265     if (project->isActiveConfig(SYMBIAN_TEST_CONFIG))
266         testClause = QLatin1String(".test");
267     else
268         testClause = QLatin1String("");
269
270     // Note: armClause is used for gcce, too, which has a side effect
271     //       of requiring armv* platform(s) in SYMBIAN_PLATFORMS in order
272     //       to get any compiler version specific targets.
273     QString armClause = " -c " PLATFORM_ARM_PREFIX ".%1.%2.%3" + testClause;
274     QString genericArmClause;
275     if (defaultRvctCompilerVersion.isEmpty()) {
276         // Note: Argument %3 needs to be empty string in this version of clause
277         genericArmClause = " -c " PLATFORM_ARM_PREFIX "%1_%2%3" + testClause;
278     } else {
279         // If defaultRvctCompilerVersion is defined, use specific sbs clause for "generic" clause
280         genericArmClause = armClause;
281     }
282     QString winscwClause = " -c " PLATFORM_WINSCW "_%1.mwccinc" + testClause;;
283
284     QStringList armPlatforms = allPlatforms.filter(QRegExp("^" PLATFORM_ARM_PREFIX));
285
286     if (!allArmCompilerVersions.size()) {
287         foreach (QString item, armPlatforms) {
288             allPlatforms.removeAll(item);
289         }
290         armPlatforms.clear();
291     }
292
293     QStringList allClauses;
294     QStringList debugClauses;
295     QStringList releaseClauses;
296
297     // Only winscw and arm platforms are supported
298     QStringList debugPlatforms = allPlatforms;
299     QStringList releasePlatforms = allPlatforms;
300     releasePlatforms.removeAll(winscwPlatform); // No release for emulator
301
302     if (!releasePlatforms.size()) {
303         fprintf(stderr, "Warning: No valid release platforms in SYMBIAN_PLATFORMS (%s)\n"
304                 "Most likely required compiler(s) are not properly installed.\n",
305                 qPrintable(project->values("SYMBIAN_PLATFORMS").join(" ")));
306     }
307
308     if (debugPlatforms.contains(winscwPlatform))
309         debugClauses << configClause(winscwPlatform, debugBuild, QString(), winscwClause);
310
311     foreach(QString item, armPlatforms) {
312         // Only use single clause per arm platform even if multiple compiler versions were found,
313         // otherwise we get makefile target collisions from sbsv2 toolchain.
314         if (rvctVersions.size()) {
315             debugClauses << configClause(item, debugBuild, defaultRvctCompilerVersion, genericArmClause);
316             releaseClauses << configClause(item, releaseBuild, defaultRvctCompilerVersion, genericArmClause);
317         } else {
318             debugClauses << configClause(item, debugBuild, defaultGcceCompilerVersion, armClause);
319             releaseClauses << configClause(item, releaseBuild, defaultGcceCompilerVersion, armClause);
320         }
321     }
322
323     allClauses << debugClauses << releaseClauses;
324
325     QTextStream t(&wrapperFile);
326
327     MakefileGenerator::writeHeader(t);
328
329     t << "MAKEFILE          = " << fileInfo(wrapperFile.fileName()).fileName() << endl;
330     t << "QMAKE             = " << var("QMAKE_QMAKE") << endl;
331     t << "DEL_FILE          = " << var("QMAKE_DEL_FILE") << endl;
332     t << "DEL_DIR           = " << var("QMAKE_DEL_DIR") << endl;
333     t << "CHK_DIR_EXISTS    = " << var("QMAKE_CHK_DIR_EXISTS") << endl;
334     t << "MKDIR             = " << var("QMAKE_MKDIR") << endl;
335     t << "MOVE              = " << var("QMAKE_MOVE") << endl;
336     t << "DEBUG_PLATFORMS   = " << debugPlatforms.join(" ") << endl;
337     t << "RELEASE_PLATFORMS = " << releasePlatforms.join(" ") << endl;
338     t << "MAKE              = make" << endl;
339     t << "SBS               = sbs" << endl;
340     t << endl;
341     t << "DEFINES" << '\t' << " = "
342         << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
343         << varGlue("QMAKE_COMPILER_DEFINES", "-D", "-D", " ")
344         << varGlue("DEFINES","-D"," -D","") << endl;
345
346     t << "INCPATH" << '\t' << " = ";
347
348     for (QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
349         QStringList values = it.value();
350         for (int i = 0; i < values.size(); ++i) {
351             t << " -I\"" << values.at(i) << "\" ";
352         }
353     }
354
355     t << endl;
356     t << "first: default" << endl << endl;
357     if (!isPrimaryMakefile) {
358         t << "all:" << endl << endl;
359         t << "default: all" << endl << endl;
360     } else {
361         t << "all: debug release" << endl << endl;
362         if (debugPlatforms.contains(winscwPlatform))
363             t << "default: debug-winscw";
364         else if (debugPlatforms.size())
365             t << "default: debug-" << debugPlatforms.first();
366         else
367             t << "default: all";
368         t << endl;
369
370         QString qmakeCmd = "\t$(QMAKE) \"" + project->projectFile() + "\" " + buildArgs();
371
372         t << "qmake:" << endl;
373         t << qmakeCmd << endl;
374         t << endl;
375
376         t << BLD_INF_FILENAME ": " << project->projectFile() << endl;
377         t << qmakeCmd << endl;
378         t << endl;
379
380         QString locFileDep = generateLocFileTarget(t, qmakeCmd);
381
382         t << "debug: " << locFileDep << BLD_INF_FILENAME << endl;
383         t << "\t$(SBS)";
384         foreach(QString clause, debugClauses) {
385             t << clause;
386         }
387         t << endl;
388         t << "clean-debug: " << BLD_INF_FILENAME << endl;
389         t << "\t$(SBS) reallyclean --toolcheck=off";
390         foreach(QString clause, debugClauses) {
391             t << clause;
392         }
393         t << endl;
394
395         t << "freeze-debug: " << BLD_INF_FILENAME << endl;
396         t << "\t$(SBS) freeze";
397         foreach(QString clause, debugClauses) {
398             t << clause;
399         }
400         t << endl;
401
402         t << "release: " << locFileDep << BLD_INF_FILENAME << endl;
403         t << "\t$(SBS)";
404         foreach(QString clause, releaseClauses) {
405             t << clause;
406         }
407         t << endl;
408         t << "clean-release: " << BLD_INF_FILENAME << endl;
409         t << "\t$(SBS) reallyclean --toolcheck=off";
410         foreach(QString clause, releaseClauses) {
411             t << clause;
412         }
413         t << endl;
414
415         t << "freeze-release: " << BLD_INF_FILENAME << endl;
416         t << "\t$(SBS) freeze";
417         foreach(QString clause, releaseClauses) {
418             t << clause;
419         }
420         t << endl << endl;
421
422         QString defaultGcceArmVersion;
423         if (armPlatforms.size()) {
424             defaultGcceArmVersion = armPlatforms.first();
425         } else {
426             defaultGcceArmVersion = QLatin1String("armv5");
427         }
428
429         // For more specific builds, targets are in this form:
430         // release-armv5 - generic target, compiler version determined by toolchain or autodetection
431         // release-armv5-rvct4.0 - compiler version specific target
432         foreach(QString item, debugPlatforms) {
433             QString clause;
434             if (item.compare(winscwPlatform) == 0)
435                 clause = configClause(item, debugBuild, QString(), winscwClause);
436             else if (item.compare(gccePlatform) == 0 )
437                 clause = configClause(defaultGcceArmVersion, debugBuild, defaultGcceCompilerVersion, armClause);
438             else // use generic arm clause
439                 clause = configClause(item, debugBuild, defaultRvctCompilerVersion, genericArmClause);
440
441             t << "debug-" << item << ": " << locFileDep << BLD_INF_FILENAME << endl;
442             t << "\t$(SBS)" << clause << endl;
443             t << "clean-debug-" << item << ": " << BLD_INF_FILENAME << endl;
444             t << "\t$(SBS) reallyclean" << clause << endl;
445             t << "freeze-debug-" << item << ": " << BLD_INF_FILENAME << endl;
446             t << "\t$(SBS) freeze" << clause << endl;
447         }
448
449         foreach(QString item, releasePlatforms) {
450             QString clause;
451             if (item.compare(gccePlatform) == 0 )
452                 clause = configClause(defaultGcceArmVersion, releaseBuild, defaultGcceCompilerVersion, armClause);
453             else // use generic arm clause
454                 clause = configClause(item, releaseBuild, defaultRvctCompilerVersion, genericArmClause);
455
456             t << "release-" << item << ": " << locFileDep << BLD_INF_FILENAME << endl;
457             t << "\t$(SBS)" << clause << endl;
458             t << "clean-release-" << item << ": " << BLD_INF_FILENAME << endl;
459             t << "\t$(SBS) reallyclean" << clause << endl;
460             t << "freeze-release-" << item << ": " << BLD_INF_FILENAME << endl;
461             t << "\t$(SBS) freeze" << clause << endl;
462         }
463
464         foreach(QString item, armPlatforms) {
465             foreach(QString compilerVersion, allArmCompilerVersions) {
466                 QString debugClause = configClause(item, debugBuild, compilerVersion, armClause);
467                 QString releaseClause = configClause(item, releaseBuild, compilerVersion, armClause);
468                 t << "debug-" << item << "-" << compilerVersion << ": " << locFileDep << BLD_INF_FILENAME << endl;
469                 t << "\t$(SBS)" << debugClause << endl;
470                 t << "clean-debug-" << item << "-" << compilerVersion << ": " << BLD_INF_FILENAME << endl;
471                 t << "\t$(SBS) reallyclean" << debugClause << endl;
472                 t << "freeze-debug-" << item << "-" << compilerVersion << ": " << BLD_INF_FILENAME << endl;
473                 t << "\t$(SBS) freeze" << debugClause << endl;
474                 t << "release-" << item << "-" << compilerVersion << ": " << locFileDep << BLD_INF_FILENAME << endl;
475                 t << "\t$(SBS)" << releaseClause << endl;
476                 t << "clean-release-" << item << "-" << compilerVersion << ": " << BLD_INF_FILENAME << endl;
477                 t << "\t$(SBS) reallyclean" << releaseClause << endl;
478                 t << "freeze-release-" << item << "-" << compilerVersion << ": " << BLD_INF_FILENAME << endl;
479                 t << "\t$(SBS) freeze" << releaseClause << endl;
480             }
481         }
482
483         t << endl;
484         t << "export: " << BLD_INF_FILENAME << endl;
485         t << "\t$(SBS) export";
486         foreach(QString clause, allClauses) {
487             t << clause;
488         }
489         t << endl << endl;
490
491         t << "cleanexport: " << BLD_INF_FILENAME << endl;
492         t << "\t$(SBS) cleanexport";
493         foreach(QString clause, allClauses) {
494             t << clause;
495         }
496         t << endl << endl;
497
498         // Typically one wants to freeze release binaries, so make plain freeze target equal to
499         // freeze-release. If freezing of debug binaries is needed for some reason, then
500         // freeze-debug target should be used. There is no point to try freezing both with one
501         // target as both produce the same def file.
502         t << "freeze: freeze-release" << endl << endl;
503     }
504
505     // Add all extra targets including extra compiler targets also to wrapper makefile,
506     // even though many of them may have already been added to bld.inf as FLMs.
507     // This is to enable use of targets like 'mocables', which call targets generated by extra compilers.
508     if (targetType != TypeSubdirs) {
509         t << extraTargetsCache;
510         t << extraCompilersCache;
511     } else {
512         QList<MakefileGenerator::SubTarget*> subtargets = findSubDirsSubTargets();
513         writeSubTargets(t, subtargets, SubTargetSkipDefaultVariables|SubTargetSkipDefaultTargets);
514         qDeleteAll(subtargets);
515     }
516
517     generateDistcleanTargets(t);
518
519     // Do not check for tools when doing generic clean, as most tools are not actually needed for
520     // cleaning. Mainly this is relevant for environments that do not have winscw compiler.
521     t << "clean: " << BLD_INF_FILENAME << endl;
522     t << "\t-$(SBS) reallyclean --toolcheck=off";
523     foreach(QString clause, allClauses) {
524         t << clause;
525     }
526     t << endl << endl;
527
528     t << endl;
529 }
530
531 void SymbianSbsv2MakefileGenerator::writeBldInfExtensionRulesPart(QTextStream& t, const QString &iconTargetFile)
532 {
533     // Makes sure we have needed FLMs in place.
534     exportFlm();
535
536     // Parse extra compilers data
537     QStringList defines;
538     QStringList incPath;
539
540     defines << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
541             << varGlue("QMAKE_COMPILER_DEFINES", "-D", "-D", " ")
542             << varGlue("DEFINES","-D"," -D","");
543     for (QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
544         QStringList values = it.value();
545         for (int i = 0; i < values.size(); ++i) {
546             incPath << QLatin1String(" -I\"") + values.at(i) + "\"";
547         }
548     }
549
550     QMap<QString, QString> commandsToReplace;
551     commandsToReplace.insert(project->values("QMAKE_COPY").join(" "),
552                              project->values("QMAKE_SBSV2_COPY").join(" "));
553     commandsToReplace.insert(project->values("QMAKE_COPY_DIR").join(" "),
554                              project->values("QMAKE_SBSV2_COPY_DIR").join(" "));
555     commandsToReplace.insert(project->values("QMAKE_MOVE").join(" "),
556                              project->values("QMAKE_SBSV2_MOVE").join(" "));
557     commandsToReplace.insert(project->values("QMAKE_DEL_FILE").join(" "),
558                              project->values("QMAKE_SBSV2_DEL_FILE").join(" "));
559     commandsToReplace.insert(project->values("QMAKE_MKDIR").join(" "),
560                              project->values("QMAKE_SBSV2_MKDIR").join(" "));
561     commandsToReplace.insert(project->values("QMAKE_DEL_DIR").join(" "),
562                              project->values("QMAKE_SBSV2_DEL_DIR").join(" "));
563     commandsToReplace.insert(project->values("QMAKE_DEL_TREE").join(" "),
564                              project->values("QMAKE_SBSV2_DEL_TREE").join(" "));
565
566     // If commandItem starts with any $$QMAKE_* commands, do a replace for SBS equivalent
567     // Command replacement is done only for the start of the command or right after
568     // concatenation operators (&& and ||), as otherwise unwanted replacements might occur.
569     static QString cmdFind("(^|&&\\s*|\\|\\|\\s*)%1");
570     static QString cmdReplace("\\1%1");
571
572     // Write extra compilers and targets to initialize QMAKE_ET_* variables
573     // Cache results to avoid duplicate calls when creating wrapper makefile
574     QTextStream extraCompilerStream(&extraCompilersCache);
575     QTextStream extraTargetStream(&extraTargetsCache);
576     writeExtraCompilerTargets(extraCompilerStream);
577     writeExtraTargets(extraTargetStream);
578
579     // Figure out everything the target depends on as we don't want to run extra targets that
580     // are not necessary.
581     QStringList allPreDeps;
582     foreach(QString item, project->values("PRE_TARGETDEPS")) {
583         allPreDeps.append(fileInfo(item).absoluteFilePath());
584     }
585
586     foreach (QString item, project->values("GENERATED_SOURCES")) {
587         allPreDeps.append(fileInfo(item).absoluteFilePath());
588     }
589
590     for (QMap<QString, QStringList>::iterator it = sources.begin(); it != sources.end(); ++it) {
591         QString currentSourcePath = it.key();
592         QStringList values = it.value();
593         for (int i = 0; i < values.size(); ++i) {
594             QString sourceFile = currentSourcePath + "/" + values.at(i);
595             QStringList deps = findDependencies(QDir::toNativeSeparators(sourceFile));
596             foreach(QString depItem, deps) {
597                 appendIfnotExist(allPreDeps, fileInfo(depItem).absoluteFilePath());
598             }
599         }
600     }
601
602     // Write FLM rules for all extra targets and compilers that we depend on to build the target.
603     QStringList extraTargets;
604     extraTargets << project->values("QMAKE_EXTRA_TARGETS") <<  project->values("QMAKE_EXTRA_COMPILERS");
605     foreach(QString item, extraTargets) {
606         foreach(QString targetItem, project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + item)) {
607             // Make sure targetpath is absolute
608             QString absoluteTarget = fileInfo(targetItem).absoluteFilePath();
609             if (allPreDeps.contains(absoluteTarget)) {
610                 QStringList deps = project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + item + targetItem);
611                 QString commandItem =  project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + item + targetItem).join(" ");
612
613                 // Make sure all deps paths are absolute
614                 QString absoluteDeps;
615                 foreach (QString depItem, deps) {
616                     if (!depItem.isEmpty()) {
617                         absoluteDeps.append(fileInfo(depItem).absoluteFilePath());
618                         absoluteDeps.append(" ");
619                     }
620                 }
621
622                 t << "START EXTENSION qt/qmake_extra_pre_targetdep.export" << endl;
623                 t << "OPTION PREDEP_TARGET " << absoluteTarget << endl;
624                 t << "OPTION DEPS " << absoluteDeps << endl;
625
626                 // Iterate command replacements in reverse alphabetical order of keys so
627                 // that keys which are starts of other longer keys are iterated after longer keys.
628                 QMapIterator<QString, QString> cmdIter(commandsToReplace);
629                 cmdIter.toBack();
630                 while (cmdIter.hasPrevious()) {
631                     cmdIter.previous();
632                     if (commandItem.contains(cmdIter.key())) {
633                         commandItem.replace(QRegExp(cmdFind.arg(cmdIter.key())),
634                                             cmdReplace.arg(cmdIter.value()));
635                     }
636                 }
637
638                 if (commandItem.indexOf("$(INCPATH)") != -1)
639                     commandItem.replace("$(INCPATH)", incPath.join(" "));
640                 if (commandItem.indexOf("$(DEFINES)") != -1)
641                     commandItem.replace("$(DEFINES)", defines.join(" "));
642
643                 // Sbsv2 strips all backslashes (even doubles ones) from option parameters, so just replace them with slashes
644                 // Problem: If some command actually needs backslashes for something else than dir separator, we are out of luck...
645                 commandItem.replace("\\", "/");
646                 t << "OPTION COMMAND " << commandItem << endl;
647                 t << "END" << endl;
648             }
649         }
650     }
651
652     t << endl;
653
654     // Write deployment rules
655     QString remoteTestPath = qt_epocRoot() + QLatin1String("epoc32/winscw/c/private/") + privateDirUid;
656     DeploymentList depList;
657
658     //write emulator deployment
659     t << "#if defined(WINSCW)" << endl;
660     initProjectDeploySymbian(project, depList, remoteTestPath, false, true,
661         QLatin1String(EMULATOR_DEPLOYMENT_PLATFORM), QString(), generatedDirs, generatedFiles);
662     writeSbsDeploymentList(depList, t);
663     t << "#endif" << endl;
664
665     //write ROM deployment
666     remoteTestPath = qt_epocRoot() + QLatin1String("epoc32/data/z/private/") + privateDirUid;
667     depList.clear();
668     initProjectDeploySymbian(project, depList, remoteTestPath, false, true,
669         QLatin1String(ROM_DEPLOYMENT_PLATFORM), QString(), generatedDirs, generatedFiles);
670     writeSbsDeploymentList(depList, t);
671     t << endl;
672
673     // Write post link rules
674     if (!project->isEmpty("QMAKE_POST_LINK")) {
675         t << "START EXTENSION qt/qmake_post_link" << endl;
676         t << "OPTION POST_LINK_CMD " << var("QMAKE_POST_LINK") << endl;
677         t << "OPTION LINK_TARGET " << removePathSeparators(escapeFilePath(fileFixify(project->first("TARGET"))).append(".").append(getTargetExtension())) << endl;
678         t << "END" << endl;
679         t << endl;
680     }
681
682     // Application icon generation
683     QStringList icons = project->values("ICON");
684     if (icons.size()) {
685         QString icon = icons.first();
686         if (icons.size() > 1)
687             fprintf(stderr, "Warning: Only first icon specified in ICON variable is used: '%s'.", qPrintable(icon));
688
689         t << "START EXTENSION s60/mifconv" << endl;
690
691         QFileInfo iconInfo = fileInfo(icon);
692
693         QFileInfo bldinf(project->values("MAKEFILE").first());
694         QString iconPath = bldinf.dir().relativeFilePath(iconInfo.path());
695
696         QString iconFile = iconInfo.baseName();
697
698         QFileInfo iconTargetInfo = fileInfo(iconTargetFile);
699         QString iconTarget = iconTargetInfo.fileName();
700
701         t << "OPTION SOURCES -c32 " << iconFile << endl;
702         t << "OPTION SOURCEDIR " << iconPath << endl;
703         t << "OPTION TARGETFILE " << iconTarget << endl;
704         t << "OPTION SVGENCODINGVERSION 3" << endl; // Compatibility with S60 3.1 devices and up
705         t << "END" << endl;
706     }
707
708     t << "START EXTENSION qt/qmake_store_build" << endl;
709     t << "END" << endl;
710     t << endl;
711
712     t << endl;
713 }
714
715 void SymbianSbsv2MakefileGenerator::writeBldInfMkFilePart(QTextStream& t, bool addDeploymentExtension)
716 {
717     // We don't generate extension makefile in sbsb2
718     Q_UNUSED(t);
719     Q_UNUSED(addDeploymentExtension);
720 }
721
722 void SymbianSbsv2MakefileGenerator::appendAbldTempDirs(QStringList& sysincspaths, QString includepath)
723 {
724     //Do nothing
725     Q_UNUSED(sysincspaths);
726     Q_UNUSED(includepath);
727 }