summaryrefslogtreecommitdiffstats
path: root/qmake/generators/symbian/symmake_abld.cpp
blob: 42031b939f2f47f5ffd21cec2e0b2fc406889c6b (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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the qmake application of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

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

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

// Included from tools/shared
#include <symbian/epocroot.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 DEPLOYMENT_TARGET "deployment"
#define DEPLOYMENT_CLEAN_TARGET "deployment_clean"
#define WINSCW_DEPLOYMENT_TARGET "winscw_deployment"
#define WINSCW_DEPLOYMENT_CLEAN_TARGET "winscw_deployment_clean"
#define STORE_BUILD_TARGET "store_build"

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

void 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 << "VISUAL_CFG = RELEASE" << endl;
        t << "ifeq \"$(CFG)\" \"UDEB\"" << endl;
        t << "VISUAL_CFG = DEBUG" << endl;
        t << "endif" << 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(STORE_BUILD_TARGET);
            cleanDeps.append(DEPLOYMENT_CLEAN_TARGET);
            cleanDepsWinscw.append(WINSCW_DEPLOYMENT_CLEAN_TARGET " " DEPLOYMENT_CLEAN_TARGET);
            finalDeps.append(DEPLOYMENT_TARGET);
            finalDepsWinscw.append(WINSCW_DEPLOYMENT_TARGET " " DEPLOYMENT_TARGET);
            wrapperTargets << WINSCW_DEPLOYMENT_TARGET
                << WINSCW_DEPLOYMENT_CLEAN_TARGET
                << DEPLOYMENT_TARGET
                << DEPLOYMENT_CLEAN_TARGET
                << STORE_BUILD_TARGET;
        } else {
            buildDeps.append(CREATE_TEMPS_TARGET " " PRE_TARGETDEPS_TARGET " " STORE_BUILD_TARGET);
            cleanDeps.append(EXTENSION_CLEAN " " DEPLOYMENT_CLEAN_TARGET);
            cleanDepsWinscw.append(EXTENSION_CLEAN " " WINSCW_DEPLOYMENT_CLEAN_TARGET " " DEPLOYMENT_CLEAN_TARGET);
            finalDeps.append(FINALIZE_TARGET " " DEPLOYMENT_TARGET);
            finalDepsWinscw.append(FINALIZE_TARGET " " WINSCW_DEPLOYMENT_TARGET " " DEPLOYMENT_TARGET);
            wrapperTargets << PRE_TARGETDEPS_TARGET
                << CREATE_TEMPS_TARGET
                << EXTENSION_CLEAN
                << FINALIZE_TARGET
                << WINSCW_DEPLOYMENT_CLEAN_TARGET
                << WINSCW_DEPLOYMENT_TARGET
                << DEPLOYMENT_CLEAN_TARGET
                << DEPLOYMENT_TARGET
                << STORE_BUILD_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 << " QT_SIS_TARGET=$(VISUAL_CFG)-$(PLATFORM)" << endl << endl;
        }

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

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

    QString testClause;
    if (project->isActiveConfig(SYMBIAN_TEST_CONFIG))
        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 << "MAKEFILE          = " << wrapperFile.fileName() << 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 << "MOVE              = " << var("QMAKE_MOVE") << endl;
#ifdef Q_OS_WIN32
    t << "XCOPY             = xcopy /d /f /h /r /y /i" << endl;
    t << "ABLD              = ABLD.BAT" << endl;
#else
    t << "XCOPY             = cp -u -v" << endl;
    t << "ABLD              = abld" << endl;
#endif
    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)" << QDir::toNativeSeparators("epoc32/release/$(PLATFORM)/$(CFG)/z") << endl;
    t << "else" << endl;
    t << "ZDIR=$(EPOCROOT)" << QDir::toNativeSeparators("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;

    }

    // 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 (targetType != TypeSubdirs) {
        writeExtraTargets(t);
        writeExtraCompilerTargets(t);

        t << CREATE_TEMPS_TARGET ":" << endl;
        // generate command lines like this ...
        // -@ if NOT EXIST  ".\somedir"         mkdir ".\somedir"
        QStringList dirsToClean;
        QString dirExists = var("QMAKE_CHK_DIR_EXISTS");
        QString mkdir = var("QMAKE_MKDIR");
        for (QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
            QStringList values = it.value();
            for (int i = 0; i < values.size(); ++i) {
                if (values.at(i).endsWith("/" QT_EXTRA_INCLUDE_DIR)) {
                    QString fixedValue(QDir::toNativeSeparators(values.at(i)));
                    dirsToClean << fixedValue;
                    t << "\t-@ " << dirExists << " \""  << fixedValue << "\" "
                      << mkdir << " \"" << fixedValue << "\"" << 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;
        generateCleanCommands(t, dirsToClean, var("QMAKE_DEL_TREE"), "", "", "");
        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;
    } else {
        QList<MakefileGenerator::SubTarget*> subtargets = findSubDirsSubTargets();
        writeSubTargets(t, subtargets, SubTargetSkipDefaultVariables | SubTargetSkipDefaultTargets);
        qDeleteAll(subtargets);
    }

    // Deploymend targets for both emulator and rom deployment
    writeDeploymentTargets(t, false);
    writeDeploymentTargets(t, true);

    generateDistcleanTargets(t);

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

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

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

    generateExecutionTargets(t, debugPlatforms);
}

void SymbianAbldMakefileGenerator::writeBldInfExtensionRulesPart(QTextStream& t, const QString &iconTargetFile)
{
    // We don't use extensions for anything in abld
    Q_UNUSED(t);
    Q_UNUSED(iconTargetFile);
}

bool SymbianAbldMakefileGenerator::writeDeploymentTargets(QTextStream &t, bool isRom)
{
    if (isRom)
        t << DEPLOYMENT_TARGET ":" << endl;
    else
        t << WINSCW_DEPLOYMENT_TARGET ":" << endl;

    QString remoteTestPath = epocRoot()
        + QLatin1String(isRom ? "epoc32\\data\\z\\private\\" : "epoc32\\winscw\\c\\private\\")
        + privateDirUid;
    DeploymentList depList;

    initProjectDeploySymbian(project, depList, remoteTestPath, false,
        QLatin1String(isRom ? ROM_DEPLOYMENT_PLATFORM : EMULATOR_DEPLOYMENT_PLATFORM),
        QString(), 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;

    if (isRom)
        t << DEPLOYMENT_CLEAN_TARGET ":" << endl;
    else
        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 (targetType != TypeSubdirs || addDeploymentExtension) {
        QString gnuMakefileName = QLatin1String("Makefile_") + uid3;
        removeSpecialCharacters(gnuMakefileName);
        gnuMakefileName.append(".mk");
        t << "gnumakefile " << gnuMakefileName << endl;
    }
}

void SymbianAbldMakefileGenerator::appendAbldTempDirs(QStringList& sysincspaths, QString includepath)
{
    // As a workaround for Symbian toolchain insistence to treat include
    // statements as relative to source file rather than the file they appear in,
    // we generate extra temporary include directories to make
    // relative include paths used in various headers to work properly.
    // Note that this is not a fix-all solution; it's just a stop-gap measure
    // to make Qt itself build until toolchain can support relative includes in
    // a way that Qt expects.
    QString epocPath("epoc32");
    if (!includepath.contains(epocPath)) // No temp dirs for epoc includes
        appendIfnotExist(sysincspaths, includepath + QString("/" QT_EXTRA_INCLUDE_DIR));
}