qmake/generators/symbian/symmake_abld.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qmake/generators/symbian/symmake_abld.cpp	Mon Jan 11 14:00:40 2010 +0000
@@ -0,0 +1,481 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 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>
+
+#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"
+//:QTP:QTPROD-92 Deployment of plugins requires WINSCW build before ARM build
+#define DEPLOYMENT_TARGET "deployment"
+#define DEPLOYMENT_CLEAN_TARGET "deployment_clean"
+#define WINSCW_DEPLOYMENT_TARGET "winscw_deployment"
+#define WINSCW_DEPLOYMENT_CLEAN_TARGET "winscw_deployment_clean"
+/* :QTP:QTPROD-155: Don't write .make.cache during the compilation, it causes dependency problems in
+ * the parallel build clusters
+ */
+#define STORE_BUILD_TARGET ""
+
+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)) {
+        if (Option::mkfile::listgen) {
+            generatePrint(fileInfo(ft.fileName()).absoluteFilePath());
+        }
+        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;
+        //:QTP:QTPROD-92 Deployment of plugins requires WINSCW build before ARM build
+        if (deploymentOnly) {
+            buildDeps.append(STORE_BUILD_TARGET);
+            cleanDeps.append(DEPLOYMENT_CLEAN_TARGET);
+            cleanDepsWinscw.append(WINSCW_DEPLOYMENT_CLEAN_TARGET);
+            finalDeps.append(DEPLOYMENT_TARGET);
+            finalDepsWinscw.append(WINSCW_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);
+            finalDeps.append(FINALIZE_TARGET " " DEPLOYMENT_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
+                << 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->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 << "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;
+    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;
+
+    }
+
+    // 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;
+        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-@ if NOT EXIST \""  << 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_DIR"), " /S /Q ", "", "");
+        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);
+    }
+
+    writeDeploymentTargets(t);
+    //:QTP:QTPROD-92 Deployment of plugins requires WINSCW build before ARM build
+	writeDeploymentTargets(t, true);
+
+    writeSisTargets(t);
+
+    /* :QTP:QTPROD-155: Don't write .make.cache during the compilation, it causes dependency problems in
+     * the parallel build clusters
+    writeStoreBuildTarget(t);
+    */
+
+    generateDistcleanTargets(t);
+
+    t << "clean: $(ABLD)" << endl;
+    t << "\t-$(ABLD)" << testClause << " reallyclean" << endl;
+    t << "\t-bldmake clean" << endl;
+    t << endl;
+
+    // Create execution target
+    if (debugPlatforms.contains("winscw") && targetType == TypeExe) {
+        t << "run:" << endl;
+        t << "\t-call " << epocRoot() << "epoc32\\release\\winscw\\udeb\\" << removePathSeparators(escapeFilePath(fileFixify(project->first("TARGET"))).append(".exe")) << endl << endl;
+    }
+}
+
+void SymbianAbldMakefileGenerator::writeBldInfExtensionRulesPart(QTextStream& t)
+{
+    // We don't use extensions for anything in abld
+    Q_UNUSED(t);
+}
+
+//:QTP:QTPROD-92 Deployment of plugins requires WINSCW build before ARM build
+bool SymbianAbldMakefileGenerator::writeDeploymentTargets(QTextStream &t, bool isRelease /*= false*/)
+{
+    if (isRelease)
+        t << DEPLOYMENT_TARGET ":" << endl;
+    else
+        t << WINSCW_DEPLOYMENT_TARGET ":" << endl;
+
+    QString remoteTestPath = epocRoot() + QLatin1String( isRelease?"epoc32\\data\\z\\private\\":"epoc32\\winscw\\c\\private\\") 
+        + privateDirUid;   // default 4 OpenC; 4 all Symbian too
+    DeploymentList depList;
+
+    initProjectDeploySymbian(project, depList, remoteTestPath, false, QLatin1String(isRelease?"armv5":"winscw"), QLatin1String(isRelease?"urel":"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;
+
+    if (isRelease)
+        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::writeStoreBuildTarget(QTextStream &t)
+{
+    t << STORE_BUILD_TARGET ":" << endl;
+    t << "\t@echo # ============================================================================== > " MAKE_CACHE_NAME << endl;
+    t << "\t@echo # This file is generated by make and should not be modified by the user >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo #  Name        : " << MAKE_CACHE_NAME << " >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo #  Part of     : " << project->values("TARGET").join(" ") << " >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo #  Description : This file is used to cache last build target for >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo #                make sis target. >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo #  Version     :  >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo # >> " MAKE_CACHE_NAME << endl;
+    t << "\t@echo # ============================================================================== >> " MAKE_CACHE_NAME <<  endl;
+    t << "\t@echo. >> " MAKE_CACHE_NAME <<  endl;
+    t << "\t@echo QT_SIS_TARGET ?= $(QT_SIS_TARGET) >> " MAKE_CACHE_NAME << endl;
+    t << endl;
+
+    generatedFiles << MAKE_CACHE_NAME;
+}
+
+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;
+    }
+}