summaryrefslogtreecommitdiffstats
path: root/qmake/generators/symbian/symmake_abld.cpp
blob: aee9745bcd200e76f3f16eb39ded4797eafbb3ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $TROLLTECH_DUAL_LICENSE$
**
****************************************************************************/

#include "symmake_abld.h"
#include "initprojectdeploy_symbian.h"

#include <qstring.h>
#include <qstringlist.h>
#include <qdir.h>
#include <qdatetime.h>
#include <qdebug.h>

#define DO_NOTHING_TARGET "do_nothing"
#define CREATE_TEMPS_TARGET "create_temps"
#define EXTENSION_CLEAN "extension_clean"
#define PRE_TARGETDEPS_TARGET "pre_targetdeps"
#define COMPILER_CLEAN_TARGET "compiler_clean"
#define FINALIZE_TARGET "finalize"
#define GENERATED_SOURCES_TARGET "generated_sources"
#define ALL_SOURCE_DEPS_TARGET "all_source_deps"
#define WINSCW_DEPLOYMENT_TARGET "winscw_deployment"
#define WINSCW_DEPLOYMENT_CLEAN_TARGET "winscw_deployment_clean"

SymbianAbldMakefileGenerator::SymbianAbldMakefileGenerator() : SymbianMakefileGenerator() { }
SymbianAbldMakefileGenerator::~SymbianAbldMakefileGenerator() { }

bool SymbianAbldMakefileGenerator::writeMkFile(const QString& wrapperFileName, bool deploymentOnly)
{

    QString gnuMakefileName = QLatin1String("Makefile_") + uid3;
    removeSpecialCharacters(gnuMakefileName);
    gnuMakefileName.append(".mk");

    QFile ft(gnuMakefileName);
    if(ft.open(QIODevice::WriteOnly)) {
        generatedFiles << ft.fileName();
        QTextStream t(&ft);

        t << "# ==============================================================================" << endl;
        t << "# Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: ";
        t << QDateTime::currentDateTime().toString() << endl;
        t << "# This file is generated by qmake and should not be modified by the" << endl;
        t << "# user." << endl;
        t << "#  Name        : " << gnuMakefileName << endl;
        t << "#  Part of     : " << project->values("TARGET").join(" ") << endl;
        t << "#  Description : This file is used to call necessary targets on wrapper makefile" << endl;
        t << "#                during normal Symbian build process." << endl;
        t << "#  Version     : " << endl;
        t << "#" << endl;
        t << "# ==============================================================================" << "\n" << endl;

        t << endl << endl;

        t << "MAKE = make" << endl;
        t << endl;

        t << DO_NOTHING_TARGET " :" << endl;
        t << "\t" << "@rem " DO_NOTHING_TARGET << endl << endl;

        QString buildDeps;
        QString cleanDeps;
        QString finalDeps;
        QString cleanDepsWinscw;
        QString finalDepsWinscw;
        QStringList wrapperTargets;
        if (deploymentOnly) {
            buildDeps.append(DO_NOTHING_TARGET);
            cleanDeps.append(DO_NOTHING_TARGET);
            cleanDepsWinscw.append( WINSCW_DEPLOYMENT_CLEAN_TARGET);
            finalDeps.append(DO_NOTHING_TARGET);
            finalDepsWinscw.append(WINSCW_DEPLOYMENT_TARGET);
            wrapperTargets << WINSCW_DEPLOYMENT_TARGET << WINSCW_DEPLOYMENT_CLEAN_TARGET;
        } else {
            buildDeps.append(CREATE_TEMPS_TARGET " " PRE_TARGETDEPS_TARGET);
            cleanDeps.append(EXTENSION_CLEAN);
            cleanDepsWinscw.append(EXTENSION_CLEAN " " WINSCW_DEPLOYMENT_CLEAN_TARGET);
            finalDeps.append(FINALIZE_TARGET);
            finalDepsWinscw.append(FINALIZE_TARGET " " WINSCW_DEPLOYMENT_TARGET);
            wrapperTargets << PRE_TARGETDEPS_TARGET
                << CREATE_TEMPS_TARGET
                << EXTENSION_CLEAN
                << FINALIZE_TARGET
                << WINSCW_DEPLOYMENT_CLEAN_TARGET
                << WINSCW_DEPLOYMENT_TARGET;
        }

        t << "MAKMAKE: " << buildDeps << endl << endl;
        t << "LIB: " << buildDeps << endl << endl;
        t << "BLD: " << buildDeps << endl << endl;
        t << "ifeq \"$(PLATFORM)\" \"WINSCW\"" << endl;
        t << "CLEAN: " << cleanDepsWinscw << endl;
        t << "else" << endl;
        t << "CLEAN: " << cleanDeps << endl;
        t << "endif" << endl << endl;
        t << "CLEANLIB: " DO_NOTHING_TARGET << endl << endl;
        t << "RESOURCE: " DO_NOTHING_TARGET << endl << endl;
        t << "FREEZE: " DO_NOTHING_TARGET << endl << endl;
        t << "SAVESPACE: " DO_NOTHING_TARGET << endl << endl;
        t << "RELEASABLES: " DO_NOTHING_TARGET << endl << endl;
        t << "ifeq \"$(PLATFORM)\" \"WINSCW\"" << endl;
        t << "FINAL: " << finalDepsWinscw << endl;
        t << "else" << endl;
        t << "FINAL: " << finalDeps << endl;
        t << "endif" << endl << endl;

        QString makefile(Option::fixPathToTargetOS(fileInfo(wrapperFileName).canonicalFilePath()));
        foreach(QString target, wrapperTargets) {
            t << target << " : " << makefile << endl;
            t << "\t-$(MAKE) -f \"" << makefile << "\" " << target << endl << endl;
        }

        t << endl;
    } // if(ft.open(QIODevice::WriteOnly))

    return true;
}

void SymbianAbldMakefileGenerator::writeWrapperMakefile(QFile& wrapperFile, bool isPrimaryMakefile)
{
    QStringList allPlatforms;
    foreach(QString platform, project->values("SYMBIAN_PLATFORMS")) {
        allPlatforms << platform.toLower();
    }

    QStringList debugPlatforms = allPlatforms;
    QStringList releasePlatforms = allPlatforms;
    releasePlatforms.removeAll("winscw"); // No release for emulator

    bool isSubdirs = getTargetExtension() == "subdirs";

    QString testClause;
    if (project->values("CONFIG").contains("symbian_test", Qt::CaseInsensitive))
        testClause = QLatin1String(" test");
    else
        testClause = QLatin1String("");

    QTextStream t(&wrapperFile);

    t << "# ==============================================================================" << endl;
    t << "# Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: ";
    t << QDateTime::currentDateTime().toString() << endl;
    t << "# This file is generated by qmake and should not be modified by the" << endl;
    t << "# user." << endl;
    t << "#  Name        : " << wrapperFile.fileName() << endl;
    t << "#  Description : Wrapper Makefile for calling Symbian build tools" << endl;
    t << "#" << endl;
    t << "# ==============================================================================" << "\n" << endl;
    t << endl;
    t << "QMAKE             = " << Option::fixPathToTargetOS(var("QMAKE_QMAKE")) << endl;
    t << "DEL_FILE          = " << var("QMAKE_DEL_FILE") << endl;
    t << "DEL_DIR           = " << var("QMAKE_DEL_DIR") << endl;
    t << "XCOPY             = xcopy /d /f /h /r /y /i" << endl;
    t << "ABLD              = ABLD.BAT" << endl;
    t << "DEBUG_PLATFORMS   = " << debugPlatforms.join(" ") << endl;
    t << "RELEASE_PLATFORMS = " << releasePlatforms.join(" ") << endl;
    t << "MAKE              = make" << endl;
    t << endl;
    t << "ifeq (WINS,$(findstring WINS, $(PLATFORM)))" << endl;
    t << "ZDIR=$(EPOCROOT)epoc32\\release\\$(PLATFORM)\\$(CFG)\\Z" << endl;
    t << "else" << endl;
    t << "ZDIR=$(EPOCROOT)epoc32\\data\\z" << endl;
    t << "endif" << endl;
    t << endl;
    t << "DEFINES" << '\t' << " = "
        << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
        << varGlue("QMAKE_COMPILER_DEFINES", "-D", "-D", " ")
        << varGlue("DEFINES","-D"," -D","") << endl;

    t << "INCPATH" << '\t' << " = ";

    for(QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
        QStringList values = it.value();
        for (int i = 0; i < values.size(); ++i) {
            t << " -I\"" << values.at(i) << "\"";
        }
    }
    t << endl;
    t << "first: default" << endl;
    if (debugPlatforms.contains("winscw"))
        t << "default: debug-winscw";
    else if (debugPlatforms.contains("armv5"))
        t << "default: debug-armv5";
    else if (debugPlatforms.size())
        t << "default: debug-" << debugPlatforms.first();
    else
        t << "default: all";

    t << endl;
    if (!isPrimaryMakefile) {
        t << "all:" << endl;
    } else {
        t << "all: debug release" << endl;
        t << endl;
        t << "qmake:" << endl;
        t << "\t$(QMAKE) -spec symbian-abld -o \"" << fileInfo(Option::output.fileName()).fileName()
          << "\" \"" << project->projectFile() << "\"" << endl;
        t << endl;
        t << BLD_INF_FILENAME ":" << endl;
        t << "\t$(QMAKE)" << endl;
        t << endl;
        t << "$(ABLD): " BLD_INF_FILENAME << endl;
        t << "\tbldmake bldfiles" << endl;
        t << endl;

        t << "debug: $(ABLD)" << endl;
        foreach(QString item, debugPlatforms) {
            t << "\t$(ABLD)" << testClause << " build " << item << " udeb" << endl;
        }
        t << endl;
        t << "release: $(ABLD)" << endl;
        foreach(QString item, releasePlatforms) {
            t << "\t$(ABLD)" << testClause << " build " << item << " urel" << endl;
        }
        t << endl;

        // For more specific builds, targets are in this form: build-platform, e.g. release-armv5
        foreach(QString item, debugPlatforms) {
            t << "debug-" << item << ": $(ABLD)" << endl;
            t << "\t$(ABLD)" << testClause << " build " << item << " udeb" << endl;
        }

        foreach(QString item, releasePlatforms) {
            t << "release-" << item << ": $(ABLD)" << endl;
            t << "\t$(ABLD)" << testClause << " build " << item << " urel" << endl;
        }

        t << endl;
        t << "export: $(ABLD)" << endl;
        t << "\t$(ABLD)" << testClause << " export" << endl;
        t << endl;

        t << "cleanexport: $(ABLD)" << endl;
        t << "\t$(ABLD)" << testClause << " cleanexport" << endl;
        t << endl;

    }

    writeExtraTargets(t);

    // pre_targetdeps target depends on:
    //  - all targets specified in PRE_TARGETDEPS
    //  - the GENERATED_SOURCES sources (so that they get generated)
    //  - all dependencies of sources targeted for compilation
    //    (mainly to ensure that any included UNUSED_SOURCES that need to be generated get generated)
    //
    // Unfortunately, Symbian build chain doesn't support linking generated objects to target,
    // so supporting generating sources is the best we can do. This is enough for mocs.

    if (!isSubdirs) {
        writeExtraCompilerTargets(t);

        t << CREATE_TEMPS_TARGET ":" << endl;
        // generate command lines like this ...
        // -@ if NOT EXIST  ".\somedir"         mkdir ".\somedir"
        for(QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
            QStringList values = it.value();
            for (int i = 0; i < values.size(); ++i) {
                t << "\t-@ if NOT EXIST \""  << QDir::toNativeSeparators(values.at(i)) << "\\tmp\" mkdir \""
                  << QDir::toNativeSeparators(values.at(i)) << "\\tmp\"" << endl;
            }
        }
        t << endl;

        // Note: EXTENSION_CLEAN will get called many times when doing reallyclean
        //       This is why the "2> NUL" gets appended to generated clean targets in makefile.cpp.
        t << EXTENSION_CLEAN ": " COMPILER_CLEAN_TARGET << endl;
        for(QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
            QStringList dirsToClean = it.value();
            generateCleanCommands(t, dirsToClean, var("QMAKE_DEL_DIR"), " /S /Q ", "", "/tmp");
        }
        t << endl;

        t << PRE_TARGETDEPS_TARGET ":"
          << MAKEFILE_DEPENDENCY_SEPARATOR GENERATED_SOURCES_TARGET
          << MAKEFILE_DEPENDENCY_SEPARATOR ALL_SOURCE_DEPS_TARGET;
        if (project->values("PRE_TARGETDEPS").size())
            t << MAKEFILE_DEPENDENCY_SEPARATOR << project->values("PRE_TARGETDEPS").join(MAKEFILE_DEPENDENCY_SEPARATOR);
        t << endl << endl;
        t << GENERATED_SOURCES_TARGET ":";
        if (project->values("GENERATED_SOURCES").size())
            t << MAKEFILE_DEPENDENCY_SEPARATOR << project->values("GENERATED_SOURCES").join(MAKEFILE_DEPENDENCY_SEPARATOR);
        t << endl << endl;
        t << ALL_SOURCE_DEPS_TARGET ":";

        QStringList allDeps;
        for(QMap<QString, QStringList>::iterator it = sources.begin(); it != sources.end(); ++it) {
            QString currentSourcePath = it.key();
            QStringList values = it.value();
            for (int i = 0; i < values.size(); ++i) {
                // we need additional check
                QString sourceFile = currentSourcePath + "/" + values.at(i);
                QStringList deps = findDependencies(QDir::toNativeSeparators(sourceFile));
                appendIfnotExist(allDeps, deps);
            }
        }

        foreach(QString item, allDeps) {
            t << MAKEFILE_DEPENDENCY_SEPARATOR << item;
        }
        t << endl << endl;

        // Post link operations
        t << FINALIZE_TARGET ":" << endl;
        if(!project->isEmpty("QMAKE_POST_LINK")) {
            t << '\t' << var("QMAKE_POST_LINK");
            t << endl;
        }
        t << endl;
    }

    writeDeploymentTargets(t);

    t << "dodistclean:" << endl;
    foreach(QString item, project->values("SUBDIRS")) {
        bool fromFile = false;
        QString fixedItem;
        if(!project->isEmpty(item + ".file")) {
            fixedItem = project->first(item + ".file");
            fromFile = true;
        } else if(!project->isEmpty(item + ".subdir")) {
            fixedItem = project->first(item + ".subdir");
            fromFile = false;
        } else {
            fromFile = item.endsWith(Option::pro_ext);
            fixedItem = item;
        }
        QFileInfo fi(fileInfo(fixedItem));
        if (!fromFile) {
            t << "\t-$(MAKE) -f \"" << Option::fixPathToTargetOS(fi.canonicalFilePath()) << "\\Makefile\" dodistclean" << endl;
        } else {
            QString itemName = fi.fileName();
            int extIndex = itemName.lastIndexOf(Option::pro_ext);
            if (extIndex)
                fixedItem = fi.canonicalPath() + "/" + QString("Makefile.") + itemName.mid(0,extIndex);
            t << "\t-$(MAKE) -f \"" << Option::fixPathToTargetOS(fixedItem) << "\" dodistclean" << endl;
        }

    }

    generatedFiles << Option::fixPathToTargetOS(fileInfo(Option::output.fileName()).canonicalFilePath()); // bld.inf
    generatedFiles << project->values("QMAKE_INTERNAL_PRL_FILE"); // Add generated prl files for cleanup
    generatedFiles << project->values("QMAKE_DISTCLEAN"); // Add any additional files marked for distclean
    QStringList fixedFiles;
    QStringList fixedDirs;
    foreach(QString item, generatedFiles) {
        QString fixedItem = Option::fixPathToTargetOS(fileInfo(item).canonicalFilePath());
        if (!fixedFiles.contains(fixedItem)) {
            fixedFiles << fixedItem;
        }
    }
    foreach(QString item, generatedDirs) {
        QString fixedItem = Option::fixPathToTargetOS(fileInfo(item).canonicalFilePath());
        if (!fixedDirs.contains(fixedItem)) {
            fixedDirs << fixedItem;
        }
    }
    generateCleanCommands(t, fixedFiles, "$(DEL_FILE)", "", "", "");
    generateCleanCommands(t, fixedDirs, "$(DEL_DIR)", "", "", "");
    t << endl;

    t << "distclean: clean dodistclean" << endl;
    t << endl;
    t << "clean: $(ABLD)" << endl;
    t << "\t-$(ABLD)" << testClause << " reallyclean" << endl;
    t << "\t-bldmake clean" << endl;
    t << endl;

    // create execution target
    if (debugPlatforms.contains("winscw") && getTargetExtension() == "exe") {
        t << "run:" << endl;
        t << "\t-call " << epocRoot() << "epoc32\\release\\winscw\\udeb\\" << removePathSeparators(escapeFilePath(fileFixify(project->first("TARGET"))).append(".exe")) << endl << endl;
    }
}

bool SymbianAbldMakefileGenerator::writeBldInfExtensionRulesPart(QTextStream& t)
{
    // We don't use extensions for anything in abld
    Q_UNUSED(t);
    return true;
}

bool SymbianAbldMakefileGenerator::writeDeploymentTargets(QTextStream &t)
{
    t << WINSCW_DEPLOYMENT_TARGET ":" << endl;

    QString remoteTestPath = epocRoot() + QLatin1String("epoc32\\winscw\\c\\private\\") + privateDirUid;   // default 4 OpenC; 4 all Symbian too
    DeploymentList depList;
    initProjectDeploySymbian( project, depList, remoteTestPath, false, QLatin1String("winscw"), QLatin1String("udeb"), generatedDirs, generatedFiles );

    if (depList.size())
        t << "\t-echo Deploying changed files..." << endl;

    for (int i=0; i<depList.size(); ++i) {
        // xcopy prompts for selecting file or directory if target doesn't exist,
        // and doesn't provide switch to force file selection. It does provide dir forcing, though,
        // so strip the last part of the destination.
        t << "\t-$(XCOPY) \"" << depList.at(i).from << "\" \"" << depList.at(i).to.left(depList.at(i).to.lastIndexOf("\\")+1) << "\"" << endl;
    }

    t << endl;

    t << WINSCW_DEPLOYMENT_CLEAN_TARGET ":" << endl;
    QStringList cleanList;
    for (int i=0; i<depList.size(); ++i) {
        cleanList.append(depList.at(i).to);
    }
    generateCleanCommands(t, cleanList, "$(DEL_FILE)", "", "", "");

    // Note: If deployment creates any directories, they will not get deleted after cleanup.
    // To do this in robust fashion could be quite complex.

    t << endl;

    return true;
}

void SymbianAbldMakefileGenerator::writeBldInfMkFilePart(QTextStream& t, bool addDeploymentExtension)
{
    // Normally emulator deployment gets done via regular makefile, but since subdirs
    // do not get that, special deployment only makefile is generated for them if needed.
    if(getTargetExtension() != "subdirs" || addDeploymentExtension) {
        QString gnuMakefileName = QLatin1String("Makefile_") + uid3;
        removeSpecialCharacters(gnuMakefileName);
        gnuMakefileName.append(".mk");
        t << "gnumakefile " << gnuMakefileName << endl;
    }
}