Index: trunk/qmake/Makefile.os2-g++
===================================================================
--- trunk/qmake/Makefile.os2-g++	(revision 682)
+++ trunk/qmake/Makefile.os2-g++	(revision 769)
@@ -22,4 +22,5 @@
 		-I$(BUILD_PATH)/src/corelib/xml \
 		-I$(SOURCE_PATH)/mkspecs/os2-g++ \
+		-I$(SOURCE_PATH)/tools/shared \
 		-DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \
 	    -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DHAVE_QCONFIG_CPP \
@@ -116,5 +117,7 @@
 		$(SOURCE_PATH)/src/corelib/io/qfsfileengine_os2.cpp \
 		$(SOURCE_PATH)/src/corelib/io/qfsfileengine_iterator_os2.cpp \
-		$(SOURCE_PATH)/src/corelib/io/qsettings_os2.cpp
+		$(SOURCE_PATH)/src/corelib/io/qsettings_os2.cpp \
+        $(SOURCE_PATH)/tools/shared/windows/registry.cpp \
+        $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
 
 define SRC_TO_OBJ
@@ -161,2 +164,3 @@
 
 $(foreach src,$(SOURCES),$(eval $(call SRC_TO_OBJ_RULE,$(src))))
+
Index: trunk/qmake/Makefile.unix
===================================================================
--- trunk/qmake/Makefile.unix	(revision 682)
+++ trunk/qmake/Makefile.unix	(revision 769)
@@ -12,4 +12,6 @@
      borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \
      symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \
+     registry.o \
+     epocroot.o \
      gnumake.o
 
@@ -34,4 +36,6 @@
 	   generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \
 	   generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \
+	   $(SOURCE_PATH)/tools/shared/windows/registry.cpp \
+	   $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp \
 	   generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \
 	   generators/os2/gnumake.cpp \
@@ -65,4 +69,5 @@
 	   -I$(BUILD_PATH)/include -I$(BUILD_PATH)/include/QtCore \
 	   -I$(BUILD_PATH)/src/corelib/global -I$(BUILD_PATH)/src/corelib/xml \
+	   -I$(SOURCE_PATH)/tools/shared \
 	   -DQT_NO_PCRE \
 	   -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED \
@@ -284,4 +289,10 @@
 	$(CXX) -c -o $@ $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp
 
+registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+	$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+
+epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+	$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+
 gnumake.o: generators/os2/gnumake.cpp
 	$(CXX) -c -o $@ $(CXXFLAGS) generators/os2/gnumake.cpp
@@ -295,4 +306,5 @@
 qxmlutils.o: $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp
 	$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp
+
 #default rules
 .cpp.o:
Index: trunk/qmake/Makefile.win32
===================================================================
--- trunk/qmake/Makefile.win32	(revision 682)
+++ trunk/qmake/Makefile.win32	(revision 769)
@@ -35,4 +35,5 @@
               -I$(BUILD_PATH)\src\corelib\xml \
               -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC)  \
+              -I$(SOURCE_PATH)\tools\shared \
               -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \
               -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \
@@ -60,4 +61,5 @@
 	-I$(BUILD_PATH)\src\corelib\global \
         -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC)  \
+    -I$(SOURCE_PATH)\tools\shared \
 	-DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \
 	-DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \
@@ -76,4 +78,6 @@
               borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \
               msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \
+              registry.obj \
+              epocroot.obj \
               symmake_abld.obj symmake_sbsv2.obj gnumake.obj
 
@@ -199,4 +203,6 @@
 	-del symmake_sbsv2.obj
 	-del initprojectdeploy_symbian.obj
+	-del registry.obj
+	-del epocroot.obj
 	-del gnumake.obj
 	-del pbuilder_pbx.obj
@@ -399,4 +405,10 @@
 	$(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp
 
+registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+	$(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+
+epocroot.obj: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+	$(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+
 gnumake.obj: $(SOURCE_PATH)/qmake/generators/os2/gnumake.cpp
 	$(CXX) $(CXXFLAGS) generators/os2/gnumake.cpp
Index: trunk/qmake/Makefile.win32-g++
===================================================================
--- trunk/qmake/Makefile.win32-g++	(revision 682)
+++ trunk/qmake/Makefile.win32-g++	(revision 769)
@@ -22,4 +22,5 @@
 		-I$(BUILD_PATH)/src/corelib/xml \
 		-I$(SOURCE_PATH)/mkspecs/win32-g++  \
+		-I$(SOURCE_PATH)/tools/shared \
 		-DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \
 		-DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \
@@ -39,4 +40,6 @@
               borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \
               msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \
+              registry.o \
+              epocroot.o \
               symmake_abld.o symmake_sbsv2.o gnumake.o
 
@@ -279,4 +282,10 @@
 	$(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp
 
+registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+	$(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+
+epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+	$(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+
 gnumake.o: $(SOURCE_PATH)/qmake/generators/os2/gnumake.cpp
 	$(CXX) $(CXXFLAGS) generators/os2/gnumake.cpp
Index: trunk/qmake/Makefile.win32-g++-sh
===================================================================
--- trunk/qmake/Makefile.win32-g++-sh	(revision 682)
+++ trunk/qmake/Makefile.win32-g++-sh	(revision 769)
@@ -22,4 +22,5 @@
 		-I$(BUILD_PATH)/src/corelib/xml \
 		-I$(SOURCE_PATH)/mkspecs/win32-g++  \
+		-I$(SOURCE_PATH)/tools/shared \
 		-DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \
 		-DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \
@@ -39,4 +40,6 @@
               borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \
               msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \
+              registry.o \
+              epocroot.o \
               symmake_abld.o symmake_sbsv2.o gnumake.o
 
@@ -278,4 +281,10 @@
 	$(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp
 
+registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+	$(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp
+
+epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+	$(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp
+
 gnumake.o: $(SOURCE_PATH)/qmake/generators/os2/gnumake.cpp
 	$(CXX) $(CXXFLAGS) generators/os2/gnumake.cpp
Index: trunk/qmake/generators/makefile.cpp
===================================================================
--- trunk/qmake/generators/makefile.cpp	(revision 682)
+++ trunk/qmake/generators/makefile.cpp	(revision 769)
@@ -1267,5 +1267,5 @@
             do_default = false;
             for(QStringList::Iterator wild_it = tmp.begin(); wild_it != tmp.end(); ++wild_it) {
-                QString wild = Option::fixPathToLocalOS((*wild_it), false, false);
+                QString wild = Option::fixPathToTargetOS((*wild_it), false, false);
                 QString dirstr = qmake_getpwd(), filestr = wild;
                 int slsh = filestr.lastIndexOf(Option::dir_sep);
@@ -1307,11 +1307,24 @@
                 QString local_dirstr = Option::fixPathToLocalOS(dirstr, true);
                 QStringList files = QDir(local_dirstr).entryList(QStringList(filestr));
-                if(project->values((*it) + ".CONFIG").indexOf("no_check_exist") != -1 && files.isEmpty()) {
+                const QStringList &installConfigValues = project->values((*it) + ".CONFIG");
+                if (installConfigValues.contains("no_check_exist") && files.isEmpty()) {
                     if(!target.isEmpty())
                         target += "\t";
                     QString dst_file = filePrefixRoot(root, dst);
                     QFileInfo fi(fileInfo(wild));
-                    QString cmd = inst_prefix + QString(fi.isExecutable() ? "$(INSTALL_PROGRAM)" : "$(INSTALL_FILE)") + " " +
-                                   wild + " " + dst_file + "\n";
+                    QString cmd;
+                    if (installConfigValues.contains("directory")) {
+                        cmd = QLatin1String(inst_prefix + "$(INSTALL_DIR)");
+                        if (!dst_file.endsWith(Option::dir_sep))
+                            dst_file += Option::dir_sep;
+                        dst_file += fi.fileName();
+                    } else if (installConfigValues.contains("executable")) {
+                        cmd = QLatin1String(inst_prefix + "$(INSTALL_PROGRAM)");
+                    } else if (installConfigValues.contains("data")) {
+                        cmd = QLatin1String(inst_prefix + "$(INSTALL_FILE)");
+                    } else {
+                        cmd = inst_prefix + QString(fi.isExecutable() ? "$(INSTALL_PROGRAM)" : "$(INSTALL_FILE)");
+                    }
+                    cmd += " " + wild + " " + dst_file + "\n";
                     target += cmd;
                     if(!uninst.isEmpty())
@@ -1878,6 +1891,7 @@
                     }
                 }
-                if(!cleans.isEmpty())
+                if(!cleans.isEmpty()) {
                     t << valGlue(cleans, "\n\t" + del_statement, del_suffix + "\n\t" + del_statement, del_suffix);
+                }
                 if(!wrote_clean_cmds) {
                     for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) {
@@ -2592,4 +2606,5 @@
             if(!ofile.isEmpty())
                 t << "\t-$(DEL_FILE) " << ofile << del_suffix << endl;
+            t << varGlue("QMAKE_DISTCLEAN","\t-$(DEL_FILE) "," ","\n");
         } else if(project->isActiveConfig("no_empty_targets")) {
             t << "\t" << "@cd ." << endl;
Index: trunk/qmake/generators/makefiledeps.cpp
===================================================================
--- trunk/qmake/generators/makefiledeps.cpp	(revision 682)
+++ trunk/qmake/generators/makefiledeps.cpp	(revision 769)
@@ -398,5 +398,5 @@
         for(int have_read = 0;
             (have_read = QT_READ(fd, buffer + buffer_len, fst.st_size - buffer_len));
-            buffer_len += have_read);
+            buffer_len += have_read) ;
         QT_CLOSE(fd);
     }
@@ -419,20 +419,20 @@
                 if(buffer_len >= x + 12 && !strncmp(buffer + x, "includehint", 11) &&
                    (*(buffer + x + 11) == ' ' || *(buffer + x + 11) == '>')) {
-                    for(x += 11; *(buffer + x) != '>'; ++x);
+                    for(x += 11; *(buffer + x) != '>'; ++x) ;
                     int inc_len = 0;
-                    for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len);
+                    for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len) ;
                     *(buffer + x + inc_len) = '\0';
                     inc = buffer + x;
                 } else if(buffer_len >= x + 13 && !strncmp(buffer + x, "customwidget", 12) &&
                           (*(buffer + x + 12) == ' ' || *(buffer + x + 12) == '>')) {
-                    for(x += 13; *(buffer + x) != '>'; ++x); //skip up to >
+                    for(x += 13; *(buffer + x) != '>'; ++x) ; //skip up to >
                     while(x < buffer_len) {
-                        for(x++; *(buffer + x) != '<'; ++x); //skip up to <
+                        for(x++; *(buffer + x) != '<'; ++x) ; //skip up to <
                         x++;
                         if(buffer_len >= x + 7 && !strncmp(buffer+x, "header", 6) &&
                            (*(buffer + x + 6) == ' ' || *(buffer + x + 6) == '>')) {
-                            for(x += 7; *(buffer + x) != '>'; ++x); //skip up to >
+                            for(x += 7; *(buffer + x) != '>'; ++x) ; //skip up to >
                             int inc_len = 0;
-                            for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len);
+                            for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len) ;
                             *(buffer + x + inc_len) = '\0';
                             inc = buffer + x;
@@ -449,8 +449,8 @@
                         if(buffer_len >= x + 9 && *(buffer + x) == 'i' &&
                            !strncmp(buffer + x, "impldecl", 8)) {
-                            for(x += 8; *(buffer + x) != '='; ++x);
+                            for(x += 8; *(buffer + x) != '='; ++x) ;
                             if(*(buffer + x) != '=')
                                 continue;
-                            for(++x; *(buffer+x) == '\t' || *(buffer+x) == ' '; ++x);
+                            for(++x; *(buffer+x) == '\t' || *(buffer+x) == ' '; ++x) ;
                             char quote = 0;
                             if(*(buffer+x) == '\'' || *(buffer+x) == '"') {
@@ -476,5 +476,5 @@
                     }
                     int inc_len = 0;
-                    for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len);
+                    for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len) ;
                     *(buffer + x + inc_len) = '\0';
                     inc = buffer + x;
@@ -482,5 +482,5 @@
             }
             //read past new line now..
-            for(; x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x);
+            for(; x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x) ;
             ++line_count;
         } else if(file->type == QMakeSourceFileInfo::TYPE_QRC) {
@@ -495,5 +495,5 @@
                         if(buffer_len >= x) {
                             if(*(buffer+x) == '/') { //c++ style comment
-                                for(; x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x);
+                                for(; x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x) ;
                                 beginning = 1;
                             } else if(*(buffer+x) == '*') { //c style comment
@@ -559,5 +559,5 @@
                     for(x+=keyword_len; //skip spaces after keyword
                         x < buffer_len && (*(buffer+x) == ' ' || *(buffer+x) == '\t');
-                        x++);
+                        x++) ;
                     break;
                 } else if(qmake_endOfLine(*(buffer+x+keyword_len))) {
@@ -580,5 +580,5 @@
 
                 int inc_len;
-                for(inc_len = 0; *(buffer + x + inc_len) != term && !qmake_endOfLine(*(buffer + x + inc_len)); ++inc_len);
+                for(inc_len = 0; *(buffer + x + inc_len) != term && !qmake_endOfLine(*(buffer + x + inc_len)); ++inc_len) ;
                 *(buffer + x + inc_len) = '\0';
                 inc = buffer + x;
@@ -595,5 +595,5 @@
                 int msg_len;
                 for(msg_len = 0; (term && *(buffer + x + msg_len) != term) &&
-                              !qmake_endOfLine(*(buffer + x + msg_len)); ++msg_len);
+                              !qmake_endOfLine(*(buffer + x + msg_len)); ++msg_len) ;
                 *(buffer + x + msg_len) = '\0';
                 debug_msg(0, "%s:%d %s -- %s", file->file.local().toLatin1().constData(), line_count, keyword, buffer+x);
@@ -707,5 +707,5 @@
         for(int have_read = buffer_len = 0;
             (have_read = QT_READ(fd, buffer + buffer_len, fst.st_size - buffer_len));
-            buffer_len += have_read);
+            buffer_len += have_read) ;
         QT_CLOSE(fd);
     }
@@ -721,5 +721,5 @@
             if(buffer_len >= x) {
                 if(*(buffer + x) == '/') { //c++ style comment
-                    for(;x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x);
+                    for(;x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x) ;
                 } else if(*(buffer + x) == '*') { //c style comment
                     for(++x; x < buffer_len; ++x) {
Index: trunk/qmake/generators/symbian/epocroot.h
===================================================================
--- trunk/qmake/generators/symbian/epocroot.h	(revision 682)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/****************************************************************************
-**
-** 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$
-** Commercial Usage
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** 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.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef EPOCROOT_H
-#define EPOCROOT_H
-
-#include <qstring.h>
-
-// Implementation of epocRoot method is in initprojectdeploy_symbian.cpp
-// Defined in separate header for inclusion clarity
-extern QString epocRoot();
-
-#endif // EPOCROOT_H
Index: trunk/qmake/generators/symbian/initprojectdeploy_symbian.cpp
===================================================================
--- trunk/qmake/generators/symbian/initprojectdeploy_symbian.cpp	(revision 682)
+++ trunk/qmake/generators/symbian/initprojectdeploy_symbian.cpp	(revision 769)
@@ -47,5 +47,8 @@
 #include <qdebug.h>
 
-#define SYSBIN_DIR "\\sys\\bin"
+// Included from tools/shared
+#include <symbian/epocroot.h>
+
+#define SYSBIN_DIR "/sys/bin"
 
 #define SUFFIX_DLL "dll"
@@ -53,96 +56,9 @@
 #define SUFFIX_QTPLUGIN "qtplugin"
 
-static void fixEpocRootStr(QString& path)
-{
-    path.replace("\\", "/");
-
-    if (path.size() > 1 && path[1] == QChar(':')) {
-        path = path.mid(2);
-    }
-
-    if (!path.size() || path[path.size()-1] != QChar('/')) {
-        path += QChar('/');
-    }
-}
-
-#define SYMBIAN_SDKS_KEY "HKEY_LOCAL_MACHINE\\Software\\Symbian\\EPOC SDKs"
-
-static QString epocRootStr;
-
-QString epocRoot()
-{
-    if (!epocRootStr.isEmpty()) {
-        return epocRootStr;
-    }
-
-    // First, check the env variable
-    epocRootStr = qgetenv("EPOCROOT");
-
-    if (epocRootStr.isEmpty()) {
-        // No EPOCROOT set, check the default device
-        // First check EPOCDEVICE env variable
-        QString defaultDevice = qgetenv("EPOCDEVICE");
-
-        // Check the windows registry via QSettings for devices.xml path
-        QSettings settings(SYMBIAN_SDKS_KEY, QSettings::NativeFormat);
-        QString devicesXmlPath = settings.value("CommonPath").toString();
-
-        if (!devicesXmlPath.isEmpty()) {
-            // Parse xml for correct device
-            devicesXmlPath += "/devices.xml";
-            QFile devicesFile(devicesXmlPath);
-            if (devicesFile.open(QIODevice::ReadOnly)) {
-                QXmlStreamReader xml(&devicesFile);
-                while (!xml.atEnd()) {
-                    xml.readNext();
-                    if (xml.isStartElement() && xml.name() == "devices") {
-                        if (xml.attributes().value("version") == "1.0") {
-                            // Look for correct device
-                            while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) {
-                                xml.readNext();
-                                if (xml.isStartElement() && xml.name() == "device") {
-                                    if ((defaultDevice.isEmpty() && xml.attributes().value("default") == "yes") ||
-                                        (!defaultDevice.isEmpty() && (xml.attributes().value("id").toString() + QString(":") + xml.attributes().value("name").toString()) == defaultDevice)) {
-                                        // Found the correct device
-                                        while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) {
-                                            xml.readNext();
-                                            if (xml.isStartElement() && xml.name() == "epocroot") {
-                                                epocRootStr = xml.readElementText();
-                                                fixEpocRootStr(epocRootStr);
-                                                return epocRootStr;
-                                            }
-                                        }
-                                        xml.raiseError("No epocroot element found");
-                                    }
-                                }
-                            }
-                        } else {
-                            xml.raiseError("Invalid 'devices' element version");
-                        }
-                    }
-                }
-                if (xml.hasError()) {
-                    fprintf(stderr, "ERROR: \"%s\" when parsing devices.xml\n", qPrintable(xml.errorString()));
-                }
-            } else {
-                fprintf(stderr, "Could not open devices.xml (%s)\n", qPrintable(devicesXmlPath));
-            }
-        } else {
-            fprintf(stderr, "Could not retrieve " SYMBIAN_SDKS_KEY " setting\n");
-        }
-
-        fprintf(stderr, "Failed to determine epoc root.\n");
-        if (!defaultDevice.isEmpty())
-            fprintf(stderr, "The device indicated by EPOCDEVICE environment variable (%s) could not be found.\n", qPrintable(defaultDevice));
-        fprintf(stderr, "Either set EPOCROOT or EPOCDEVICE environment variable to a valid value, or provide a default Symbian device.\n");
-
-        // No valid device found; set epocroot to "/"
-        epocRootStr = QLatin1String("/");
-    }
-
-    fixEpocRootStr(epocRootStr);
-    return epocRootStr;
-}
-
+static QString fixPathToEpocOS(const QString &src)
+{
+    QString ret = Option::fixPathToTargetOS(src);
+    return ret.replace('/', '\\');
+}
 
 static bool isPlugin(const QFileInfo& info, const QString& devicePath)
@@ -176,10 +92,10 @@
                              QStringList& generatedFiles)
 {
-    QDir().mkpath(QLatin1String(PLUGIN_STUB_DIR "\\"));
+    QDir().mkpath(QLatin1String(PLUGIN_STUB_DIR));
     if (!generatedDirs.contains(PLUGIN_STUB_DIR))
         generatedDirs << PLUGIN_STUB_DIR;
     // Plugin stubs must have different name from the actual plugins, because
     // the toolchain for creating ROM images cannot handle non-binary .dll files properly.
-    QFile stubFile(QLatin1String(PLUGIN_STUB_DIR "\\") + info.completeBaseName() + "." SUFFIX_QTPLUGIN);
+    QFile stubFile(QLatin1String(PLUGIN_STUB_DIR "/") + info.completeBaseName() + "." SUFFIX_QTPLUGIN);
     if (stubFile.open(QIODevice::WriteOnly)) {
         if (!generatedFiles.contains(stubFile.fileName()))
@@ -195,5 +111,5 @@
     QFileInfo stubInfo(stubFile);
     deploymentList.append(CopyItem(Option::fixPathToLocalOS(stubInfo.absoluteFilePath()),
-                                   Option::fixPathToLocalOS(devicePath + "\\" + stubInfo.fileName())));
+                                   fixPathToEpocOS(devicePath + "/" + stubInfo.fileName())));
 }
 
@@ -208,5 +124,5 @@
     }
 
-    unsigned long hash = 5381;
+    quint32 hash = 5381;
     int c;
 
@@ -259,8 +175,21 @@
     foreach(QString item, project->values("DEPLOYMENT")) {
         QString devicePath = project->first(item + ".path");
+        QString devicePathWithoutDrive = devicePath;
+
+        bool devicePathHasDriveLetter = false;
+        if (devicePath.size() > 1) {
+            devicePathHasDriveLetter = devicePath.at(1) == QLatin1Char(':');
+        }
+
+        // Sometimes devicePath can contain disk but APP_RESOURCE_DIR does not,
+        // so remove the drive letter for comparison purposes.
+        if (devicePathHasDriveLetter)
+        {
+            devicePathWithoutDrive.remove(0,2);
+        }
         if (!deployBinaries
-                && !devicePath.isEmpty()
-                && (0 == devicePath.compare(project->values("APP_RESOURCE_DIR").join(""), Qt::CaseInsensitive)
-                    || 0 == devicePath.compare(project->values("REG_RESOURCE_IMPORT_DIR").join(""), Qt::CaseInsensitive))) {
+                && !devicePathWithoutDrive.isEmpty()
+                && (0 == devicePathWithoutDrive.compare(project->values("APP_RESOURCE_DIR").join(""), Qt::CaseInsensitive)
+                    || 0 == devicePathWithoutDrive.compare(project->values("REG_RESOURCE_IMPORT_DIR").join(""), Qt::CaseInsensitive))) {
             // Do not deploy resources in emulator builds, as that seems to cause conflicts
             // If there is ever a real need to deploy pre-built resources for emulator,
@@ -269,9 +198,4 @@
         }
 
-        bool devicePathHasDriveLetter = false;
-        if (devicePath.size() > 1) {
-            devicePathHasDriveLetter = devicePath.at(1) == QLatin1Char(':');
-        }
-
         if (devicePath.isEmpty() || devicePath == QLatin1String(".")) {
             devicePath = targetPath;
@@ -281,22 +205,33 @@
                    || devicePath.at(0) == QLatin1Char('\\')
                    || devicePathHasDriveLetter)) {
-            // create output path
-            devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath));
+            // Create output path
+            devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('/') + devicePath));
         } else {
-            if (0 == platform.compare(QLatin1String("winscw"), Qt::CaseInsensitive)) {
+            if (!platform.compare(QLatin1String(EMULATOR_DEPLOYMENT_PLATFORM))) {
                 if (devicePathHasDriveLetter) {
-                    devicePath = epocRoot() + "epoc32\\winscw\\" + devicePath.remove(1, 1);
+                    devicePath = epocRoot() + "epoc32/winscw/" + devicePath.remove(1, 1);
                 } else {
-                    devicePath = epocRoot() + "epoc32\\winscw\\c" + devicePath;
+                    devicePath = epocRoot() + "epoc32/winscw/c" + devicePath;
                 }
             } else {
-                // Drive letter needed if targetpath contains one and it is not already in
-                if (targetPathHasDriveLetter && !devicePathHasDriveLetter) {
-                    devicePath = deploymentDrive + devicePath;
+                if (!devicePathHasDriveLetter) {
+                    if (!platform.compare(QLatin1String(ROM_DEPLOYMENT_PLATFORM))) {
+                        //For plugin deployment under ARM no needed drive letter
+                        devicePath = epocRoot() + "epoc32/data/z" + devicePath;
+                    } else if (targetPathHasDriveLetter) {
+                        // Drive letter needed if targetpath contains one and it is not already in
+                        devicePath = deploymentDrive + devicePath;
+                    }
+                } else {
+                    //it is necessary to delete drive letter for ARM deployment
+                    if (!platform.compare(QLatin1String(ROM_DEPLOYMENT_PLATFORM))) {
+                        devicePath.remove(0,2);
+                        devicePath = epocRoot() + "epoc32/data/z" + devicePath;
+                    }
                 }
             }
         }
 
-        devicePath.replace(QLatin1String("/"), QLatin1String("\\"));
+        devicePath.replace(QLatin1String("\\"), QLatin1String("/"));
 
         if (!deployBinaries &&
@@ -322,5 +257,5 @@
             } else {
                 if (info.exists() || source.indexOf('*') != -1) {
-                    nameFilter = source.split('\\').last();
+                    nameFilter = source.split(QDir::separator()).last();
                     searchPath = info.absolutePath();
                 } else {
@@ -330,11 +265,17 @@
                         if (deployBinaries) {
                             // Executables and libraries are deployed to \sys\bin
-                            QFileInfo releasePath(epocRoot() + "epoc32\\release\\" + platform + "\\" + build + "\\");
+                            QFileInfo targetPath(epocRoot() + "epoc32/release/" + platform + "/" + build + "/");
                             if(devicePathHasDriveLetter) {
-                                deploymentList.append(CopyItem(Option::fixPathToLocalOS(releasePath.absolutePath() + "\\" + info.fileName(), false, true),
-                                                               Option::fixPathToLocalOS(devicePath.left(2) + QLatin1String(SYSBIN_DIR "\\") + info.fileName())));
+                                deploymentList.append(CopyItem(
+                                    Option::fixPathToLocalOS(targetPath.absolutePath() + "/" + info.fileName(),
+                                    false, true),
+                                    fixPathToEpocOS(devicePath.left(2) + QLatin1String(SYSBIN_DIR "/")
+                                    + info.fileName())));
                             } else {
-                                deploymentList.append(CopyItem(Option::fixPathToLocalOS(releasePath.absolutePath() + "\\" + info.fileName(), false, true),
-                                                               Option::fixPathToLocalOS(deploymentDrive + QLatin1String(SYSBIN_DIR "\\") + info.fileName())));
+                                deploymentList.append(CopyItem(
+                                    Option::fixPathToLocalOS(targetPath.absolutePath() + "/" + info.fileName(),
+                                    false, true),
+                                    fixPathToEpocOS(deploymentDrive + QLatin1String(SYSBIN_DIR "/")
+                                    + info.fileName())));
                             }
                         }
@@ -347,5 +288,5 @@
                         // when generating .pkg files.
                         deploymentList.append(CopyItem(Option::fixPathToLocalOS(info.absoluteFilePath()),
-                                                       Option::fixPathToLocalOS(devicePath + "\\" + info.fileName())));
+                                                       fixPathToEpocOS(devicePath + "/" + info.fileName())));
                         continue;
                     }
@@ -369,12 +310,24 @@
                         // as they have SYSBIN_DIR target path.
                         if (deployBinaries) {
-                            deploymentList.append(CopyItem(Option::fixPathToLocalOS(absoluteItemPath + "\\" + iterator.fileName()),
-                                                           Option::fixPathToLocalOS(deploymentDrive + QLatin1String(SYSBIN_DIR "\\") + iterator.fileName())));
+                            if (devicePathHasDriveLetter) {
+                                deploymentList.append(CopyItem(
+                                    Option::fixPathToLocalOS(absoluteItemPath + "/" + iterator.fileName()),
+                                    fixPathToEpocOS(devicePath.left(2) + QLatin1String(SYSBIN_DIR "/")
+                                    + iterator.fileName())));
+                            } else {
+                                deploymentList.append(CopyItem(
+                                    Option::fixPathToLocalOS(absoluteItemPath + "/" + iterator.fileName()),
+                                    fixPathToEpocOS(deploymentDrive + QLatin1String(SYSBIN_DIR "/")
+                                    + iterator.fileName())));
+                            }
                         }
-                        createPluginStub(info, devicePath + "\\" + absoluteItemPath.right(diffSize), deploymentList, generatedDirs, generatedFiles);
+                        createPluginStub(info, devicePath + "/" + absoluteItemPath.right(diffSize),
+                            deploymentList, generatedDirs, generatedFiles);
                         continue;
                     } else {
-                        deploymentList.append(CopyItem(Option::fixPathToLocalOS(absoluteItemPath + "\\" + iterator.fileName()),
-                                                       Option::fixPathToLocalOS(devicePath + "\\" + absoluteItemPath.right(diffSize) + "\\" + iterator.fileName())));
+                        deploymentList.append(CopyItem(
+                            Option::fixPathToLocalOS(absoluteItemPath + "/" + iterator.fileName()),
+                            fixPathToEpocOS(devicePath + "/" + absoluteItemPath.right(diffSize)
+                            + "/" + iterator.fileName())));
                     }
                 }
Index: trunk/qmake/generators/symbian/initprojectdeploy_symbian.h
===================================================================
--- trunk/qmake/generators/symbian/initprojectdeploy_symbian.h	(revision 682)
+++ trunk/qmake/generators/symbian/initprojectdeploy_symbian.h	(revision 769)
@@ -51,7 +51,7 @@
 #include <stdlib.h>
 
-#include "epocroot.h"
-
 #define PLUGIN_STUB_DIR "qmakepluginstubs"
+#define ROM_DEPLOYMENT_PLATFORM "rom"
+#define EMULATOR_DEPLOYMENT_PLATFORM "emulator"
 
 struct CopyItem
Index: trunk/qmake/generators/symbian/symmake.cpp
===================================================================
--- trunk/qmake/generators/symbian/symmake.cpp	(revision 682)
+++ trunk/qmake/generators/symbian/symmake.cpp	(revision 769)
@@ -50,4 +50,7 @@
 #include <qdebug.h>
 
+// Included from tools/shared
+#include <symbian/epocroot.h>
+
 #define RESOURCE_DIRECTORY_MMP "/resource/apps"
 #define RESOURCE_DIRECTORY_RESOURCE "\\\\resource\\\\apps\\\\"
@@ -55,5 +58,4 @@
 #define PLUGIN_COMMON_DEF_FILE_FOR_MMP "./plugin_common.def"
 #define PLUGIN_COMMON_DEF_FILE_ACTUAL "plugin_commonU.def"
-#define BLD_INF_FILENAME_LEN (sizeof(BLD_INF_FILENAME) - 1)
 
 #define BLD_INF_RULES_BASE "BLD_INF_RULES."
@@ -62,5 +64,5 @@
 #define BLD_INF_TAG_TESTMMPFILES "prj_testmmpfiles"
 #define BLD_INF_TAG_EXTENSIONS "prj_extensions"
-#define BLD_INF_TAG_EXPORTS "prj_exports"
+#define BLD_INF_TAG_TESTEXTENSIONS "prj_testextensions"
 
 #define RSS_RULES "RSS_RULES"
@@ -68,14 +70,16 @@
 #define RSS_TAG_NBROFICONS "number_of_icons"
 #define RSS_TAG_ICONFILE "icon_file"
+#define RSS_TAG_HEADER "header"
+#define RSS_TAG_SERVICE_LIST "service_list"
+#define RSS_TAG_FILE_OWNERSHIP_LIST "file_ownership_list"
+#define RSS_TAG_DATATYPE_LIST "datatype_list"
+#define RSS_TAG_FOOTER "footer"
+#define RSS_TAG_DEFAULT "default_rules" // Same as just giving rules without tag
 
 #define MMP_TARGET "TARGET"
 #define MMP_TARGETTYPE "TARGETTYPE"
 #define MMP_SECUREID "SECUREID"
-#define MMP_OPTION_CW "OPTION CW"
-#define MMP_OPTION_ARMCC "OPTION ARMCC"
-#define MMP_OPTION_GCCE "OPTION GCCE"
-#define MMP_LINKEROPTION_CW "LINKEROPTION CW"
-#define MMP_LINKEROPTION_ARMCC "LINKEROPTION ARMCC"
-#define MMP_LINKEROPTION_GCCE "LINKEROPTION GCCE"
+#define MMP_OPTION "OPTION"
+#define MMP_LINKEROPTION "LINKEROPTION"
 #define MMP_CAPABILITY "CAPABILITY"
 #define MMP_EPOCALLOWDLLDATA "EPOCALLOWDLLDATA"
@@ -88,8 +92,14 @@
 #define MMP_END_RESOURCE "END"
 
+#define VAR_CXXFLAGS "QMAKE_CXXFLAGS"
+#define VAR_CFLAGS "QMAKE_CFLAGS"
+#define VAR_LFLAGS "QMAKE_LFLAGS"
+
 #define SIS_TARGET "sis"
 #define INSTALLER_SIS_TARGET "installer_sis"
+#define ROM_STUB_SIS_TARGET "stub_sis"
 #define OK_SIS_TARGET "ok_sis"
 #define OK_INSTALLER_SIS_TARGET "ok_installer_sis"
+#define OK_ROM_STUB_SIS_TARGET "ok_stub_sis"
 #define FAIL_SIS_NOPKG_TARGET "fail_sis_nopkg"
 #define FAIL_SIS_NOCACHE_TARGET "fail_sis_nocache"
@@ -106,9 +116,11 @@
     static QString epocRootStr;
     if (epocRootStr.isEmpty()) {
-        QFileInfo efi(epocRoot());
-        epocRootStr = efi.canonicalFilePath();
-        if (epocRootStr.isEmpty()) {
+        epocRootStr = epocRoot();
+        QFileInfo efi(epocRootStr);
+        if (!efi.exists() || epocRootStr.isEmpty()) {
             fprintf(stderr, "Unable to resolve epocRoot '%s' to real dir on current drive, defaulting to '/' for mmp paths\n", qPrintable(epocRoot()));
             epocRootStr = "/";
+        } else {
+            epocRootStr = efi.absoluteFilePath();
         }
         if (!epocRootStr.endsWith("/"))
@@ -134,14 +146,6 @@
 }
 
-QString SymbianMakefileGenerator::canonizePath(const QString& origPath)
-{
-    // Since current path gets appended almost always anyway, use it as default
-    // for nonexisting paths.
-    static QString defaultPath;
-    if (defaultPath.isEmpty()) {
-        QFileInfo fi(".");
-        defaultPath = fi.canonicalFilePath();
-    }
-
+QString SymbianMakefileGenerator::absolutizePath(const QString& origPath)
+{
     // Prepend epocroot to any paths beginning with "/epoc32/"
     QString resultPath = QDir::fromNativeSeparators(origPath);
@@ -150,14 +154,15 @@
 
     QFileInfo fi(fileInfo(resultPath));
-    if (fi.isDir()) {
-        resultPath = fi.canonicalFilePath();
+
+    // Since origPath can be something given in HEADERS, we need to check if we are dealing
+    // with a file or a directory. In case the origPath doesn't yet exist, isFile() returns
+    // false and we default to assuming it is a dir.
+    if (fi.isFile()) {
+        resultPath = fi.absolutePath();
     } else {
-        resultPath = fi.canonicalPath();
+        resultPath = fi.absoluteFilePath();
     }
 
     resultPath = QDir::cleanPath(resultPath);
-
-    if (resultPath.isEmpty())
-        resultPath = defaultPath;
 
     return resultPath;
@@ -202,5 +207,5 @@
     QString numberOfIcons;
     QString iconFile;
-    QStringList userRssRules;
+    QMap<QString, QStringList> userRssRules;
     readRssRules(numberOfIcons, iconFile, userRssRules);
 
@@ -235,5 +240,7 @@
     QString outputFileName = fileInfo(Option::output.fileName()).fileName();
     if (outputFileName != BLD_INF_FILENAME) {
-        wrapperFileName.append(".").append((outputFileName.size() > BLD_INF_FILENAME_LEN && outputFileName.left(BLD_INF_FILENAME_LEN) == BLD_INF_FILENAME) ? outputFileName.mid(8) : outputFileName);
+        wrapperFileName.append(".").append(outputFileName.startsWith(BLD_INF_FILENAME)
+                                           ? outputFileName.mid(sizeof(BLD_INF_FILENAME))
+                                           : outputFileName);
         isPrimaryMakefile = false;
     }
@@ -269,5 +276,5 @@
 
     if (targetType == TypeExe) {
-        if (!project->values("CONFIG").contains("no_icon", Qt::CaseInsensitive)) {
+        if (!project->isActiveConfig("no_icon")) {
             writeRegRssFile(userRssRules);
             writeRssFile(numberOfIcons, iconFile);
@@ -316,5 +323,9 @@
 
     // Construct QStringList from pkg_prerules since we need search it before printed to file
+    // Note: Though there can't be more than one language or header line, use stringlists
+    // in case user wants comments to go with the rules.
     QStringList rawPkgPreRules;
+    QStringList languageRules;
+    QStringList headerRules;
     foreach(QString deploymentItem, project->values("DEPLOYMENT")) {
         foreach(QString pkgrulesItem, project->values(deploymentItem + ".pkg_prerules")) {
@@ -323,8 +334,23 @@
             // This is convenience for defining single line mmp statements
             if (pkgrulesValue.isEmpty()) {
-                rawPkgPreRules << pkgrulesItem;
+                if (pkgrulesItem.startsWith("&"))
+                    languageRules << pkgrulesItem;
+                else if (pkgrulesItem.startsWith("#"))
+                    headerRules << pkgrulesItem;
+                else
+                    rawPkgPreRules << pkgrulesItem;
             } else {
-                foreach(QString pkgrule, pkgrulesValue) {
-                    rawPkgPreRules << pkgrule;
+                if (containsStartWithItem('&', pkgrulesValue)) {
+                    foreach(QString pkgrule, pkgrulesValue) {
+                        languageRules << pkgrule;
+                    }
+                } else if (containsStartWithItem('#', pkgrulesValue)) {
+                    foreach(QString pkgrule, pkgrulesValue) {
+                        headerRules << pkgrule;
+                    }
+                } else {
+                    foreach(QString pkgrule, pkgrulesValue) {
+                        rawPkgPreRules << pkgrule;
+                    }
                 }
             }
@@ -334,14 +360,14 @@
     // Apply some defaults if specific data does not exist in PKG pre-rules
 
-    if (!containsStartWithItem('&', rawPkgPreRules)) {
+    if (languageRules.isEmpty()) {
         // language, (*** hardcoded to english atm, should be parsed from TRANSLATIONS)
-        QString languageCode = "; Language\n&EN\n\n";
-        t << languageCode;
-        tw << languageCode;
-    } else {
+        languageRules << "; Language\n&EN\n\n";
+    } else if (headerRules.isEmpty()) {
         // In case user defines langs, he must take care also about SIS header
-        if (!containsStartWithItem('#', rawPkgPreRules))
-            fprintf(stderr, "Warning: If language is defined with DEPLOYMENT pkg_prerules, also the SIS header must be defined\n");
-    }
+        fprintf(stderr, "Warning: If language is defined with DEPLOYMENT pkg_prerules, also the SIS header must be defined\n");
+    }
+
+    t << languageRules.join("\n") << endl;
+    tw << languageRules.join("\n") << endl;
 
     // name of application, UID and version
@@ -358,7 +384,8 @@
     }
 
-    if (!containsStartWithItem('#', rawPkgPreRules)) {
+    if (headerRules.isEmpty())
         t << sisHeader.arg(visualTarget).arg(uid3).arg(applicationVersion);
-    }
+    else
+        t << headerRules.join("\n") << endl;
 
     // Localized vendor name
@@ -425,5 +452,5 @@
 
         // deploy rsc & reg_rsc file
-        if (!project->values("CONFIG").contains("no_icon", Qt::CaseInsensitive)) {
+        if (!project->isActiveConfig("no_icon")) {
             t << QString("\"%1epoc32/data/z/resource/apps/%2\"    - \"%3\\%4\"")
                  .arg(epocRoot())
@@ -450,4 +477,5 @@
     QString remoteTestPath;
     remoteTestPath = QString("!:\\private\\%1").arg(privateDirUid);
+    QString zDir = epocRoot() + QLatin1String("epoc32/data/z");
 
     initProjectDeploySymbian(project, depList, remoteTestPath, true, "$(PLATFORM)", "$(TARGET)", generatedDirs, generatedFiles);
@@ -455,7 +483,21 @@
         t << "; DEPLOYMENT" << endl;
     for (int i = 0; i < depList.size(); ++i)  {
-        t << QString("\"%1\"    - \"%2\"")
-             .arg(QString(depList.at(i).from).replace('\\','/'))
-             .arg(depList.at(i).to) << endl;
+        QString from = depList.at(i).from;
+        QString to = depList.at(i).to;
+
+        // Deploy anything not already deployed from under epoc32 instead from under
+        // \epoc32\data\z\ to enable using pkg file without rebuilding
+        // the project, which can be useful for some binary only distributions.
+        if (!from.contains(QLatin1String("epoc32"), Qt::CaseInsensitive)) {
+            from = to;
+            if (from.size() > 1 && from.at(1) == QLatin1Char(':'))
+                from = from.mid(2);
+            from.prepend(zDir);
+        } else {
+            if (from.size() > 1 && from.at(1) == QLatin1Char(':'))
+                from = from.mid(2);
+        }
+
+        t << QString("\"%1\"    - \"%2\"").arg(from.replace('\\','/')).arg(to) << endl;
     }
     t << endl;
@@ -542,5 +584,5 @@
 void SymbianMakefileGenerator::writeCustomDefFile()
 {
-    if (targetType == TypePlugin && !project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) {
+    if (targetType == TypePlugin && !project->isActiveConfig("stdbinary")) {
         // Create custom def file for plugin
         QFile ft(QLatin1String(PLUGIN_COMMON_DEF_FILE_ACTUAL));
@@ -607,7 +649,7 @@
     else if ((project->values("TEMPLATE")).contains("lib")) {
         // Check CONFIG to see if we are to build staticlib or dll
-        if (project->values("CONFIG").contains("staticlib") || project->values("CONFIG").contains("static"))
+        if (project->isActiveConfig("staticlib") || project->isActiveConfig("static"))
             targetType = TypeLib;
-        else if (project->values("CONFIG").contains("plugin"))
+        else if (project->isActiveConfig("plugin"))
             targetType = TypePlugin;
         else
@@ -619,5 +661,5 @@
     if (0 != project->values("TARGET.UID2").size()) {
         uid2 = project->first("TARGET.UID2");
-    } else if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) {
+    } else if (project->isActiveConfig("stdbinary")) {
         uid2 = "0x20004C45";
     } else {
@@ -690,5 +732,5 @@
 
     QDir current = QDir::current();
-    QString canonizedCurrent = canonizePath(".");
+    QString absolutizedCurrent = absolutizePath(".");
 
     for (int j = 0; j < srcpaths.size(); ++j) {
@@ -698,8 +740,8 @@
             if (fi.filePath().length() > fi.fileName().length()) {
                 appendIfnotExist(srcincpaths, fi.path());
-                sources[canonizePath(fi.path())] += fi.fileName();
+                sources[absolutizePath(fi.path())] += fi.fileName();
             } else {
-                sources[canonizedCurrent] += fi.fileName();
-                appendIfnotExist(srcincpaths, canonizedCurrent);
+                sources[absolutizedCurrent] += fi.fileName();
+                appendIfnotExist(srcincpaths, absolutizedCurrent);
             }
         }
@@ -715,5 +757,5 @@
 
     for (int j = 0; j < incpaths.size(); ++j) {
-        QString includepath = canonizePath(incpaths.at(j));
+        QString includepath = absolutizePath(incpaths.at(j));
         appendIfnotExist(sysincspaths, includepath);
         appendAbldTempDirs(sysincspaths, includepath);
@@ -757,13 +799,10 @@
     bool inResourceBlock = false;
 
-    overridableMmpKeywords << QLatin1String(MMP_TARGETTYPE);
+    overridableMmpKeywords << QLatin1String(MMP_TARGETTYPE) << QLatin1String(MMP_EPOCHEAPSIZE);
     restrictableMmpKeywords << QLatin1String(MMP_TARGET) << QLatin1String(MMP_SECUREID)
-       << QLatin1String(MMP_OPTION_CW) << QLatin1String(MMP_OPTION_ARMCC)
-       << QLatin1String(MMP_OPTION_GCCE) << QLatin1String(MMP_LINKEROPTION_CW)
-       << QLatin1String(MMP_LINKEROPTION_ARMCC) << QLatin1String(MMP_LINKEROPTION_GCCE)
+       << QLatin1String(MMP_OPTION) << QLatin1String(MMP_LINKEROPTION)
        << QLatin1String(MMP_CAPABILITY) << QLatin1String(MMP_EPOCALLOWDLLDATA)
-       << QLatin1String(MMP_EPOCHEAPSIZE) << QLatin1String(MMP_EPOCSTACKSIZE)
-       << QLatin1String(MMP_UID) << QLatin1String(MMP_VENDORID)
-       << QLatin1String(MMP_VERSION);
+       << QLatin1String(MMP_EPOCSTACKSIZE) << QLatin1String(MMP_UID)
+       << QLatin1String(MMP_VENDORID) << QLatin1String(MMP_VERSION);
 
     foreach (QString item, project->values("MMP_RULES")) {
@@ -886,5 +925,5 @@
         t << endl;
 
-        if (!project->values("CONFIG").contains("static") && !project->values("CONFIG").contains("staticlib")) {
+        if (!project->isActiveConfig("static") && !project->isActiveConfig("staticlib")) {
             writeMmpFileLibraryPart(t);
         }
@@ -935,9 +974,10 @@
 {
     bool skipTargetType = overriddenMmpKeywords.contains(MMP_TARGETTYPE);
+    bool skipEpocHeapSize = overriddenMmpKeywords.contains(MMP_EPOCHEAPSIZE);
 
     if (targetType == TypeExe) {
         t << MMP_TARGET "\t\t" << fixedTarget << ".exe" << endl;
         if (!skipTargetType) {
-            if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive))
+            if (project->isActiveConfig("stdbinary"))
                 t << MMP_TARGETTYPE "\t\tSTDEXE" << endl;
             else
@@ -947,5 +987,5 @@
         t << MMP_TARGET "\t\t" << fixedTarget << ".dll" << endl;
         if (!skipTargetType) {
-            if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive))
+            if (project->isActiveConfig("stdbinary"))
                 t << MMP_TARGETTYPE "\t\tSTDDLL" << endl;
             else
@@ -955,5 +995,5 @@
         t << MMP_TARGET "\t\t" << fixedTarget << ".lib" << endl;
         if (!skipTargetType) {
-            if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive))
+            if (project->isActiveConfig("stdbinary"))
                 t << MMP_TARGETTYPE "\t\tSTDLIB" << endl;
             else
@@ -986,10 +1026,10 @@
     if (0 != project->first("TARGET.EPOCSTACKSIZE").size())
         t << MMP_EPOCSTACKSIZE "\t\t" << project->first("TARGET.EPOCSTACKSIZE") << endl;
-    if (0 != project->values("TARGET.EPOCHEAPSIZE").size())
+    if (!skipEpocHeapSize && 0 != project->values("TARGET.EPOCHEAPSIZE").size())
         t << MMP_EPOCHEAPSIZE "\t\t" << project->values("TARGET.EPOCHEAPSIZE").join(" ") << endl;
     if (0 != project->values("TARGET.EPOCALLOWDLLDATA").size())
         t << MMP_EPOCALLOWDLLDATA << endl;
 
-    if (targetType == TypePlugin && !project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) {
+    if (targetType == TypePlugin && !project->isActiveConfig("stdbinary")) {
         // Use custom def file for Qt plugins
         t << "DEFFILE " PLUGIN_COMMON_DEF_FILE_FOR_MMP << endl;
@@ -1007,5 +1047,5 @@
 {
     if ((targetType == TypeExe) &&
-            !project->values("CONFIG").contains("no_icon", Qt::CaseInsensitive)) {
+            !project->isActiveConfig("no_icon")) {
 
         QString locTarget = fixedTarget;
@@ -1111,107 +1151,62 @@
 }
 
+void SymbianMakefileGenerator::writeMmpFileConditionalOptions(QTextStream& t,
+                                                              const QString &optionType,
+                                                              const QString &optionTag,
+                                                              const QString &variableBase)
+{
+    foreach(QString compilerVersion, project->values("VERSION_FLAGS." + optionTag)) {
+        QStringList currentValues = project->values(variableBase + "." + compilerVersion);
+        if (currentValues.size()) {
+            t << "#if defined(" << compilerVersion << ")" << endl;
+            t << optionType << " " << optionTag << " " << currentValues.join(" ") <<  endl;
+            t << "#endif" << endl;
+        }
+    }
+}
+
+void SymbianMakefileGenerator::writeMmpFileSimpleOption(QTextStream& t,
+                                                        const QString &optionType,
+                                                        const QString &optionTag,
+                                                        const QString &options)
+{
+    QString trimmedOptions = options.trimmed();
+    if (!trimmedOptions.isEmpty())
+        t << optionType << " " << optionTag << " " << trimmedOptions << endl;
+}
+
+void SymbianMakefileGenerator::appendMmpFileOptions(QString &options, const QStringList &list)
+{
+    if (list.size()) {
+        options.append(list.join(" "));
+        options.append(" ");
+    }
+}
+
 void SymbianMakefileGenerator::writeMmpFileCompilerOptionPart(QTextStream& t)
 {
-    QString cw, armcc, gcce;
-    QString cwlink, armlink, gccelink;
-
-    if (0 != project->values("QMAKE_CXXFLAGS.CW").size()) {
-        cw.append(project->values("QMAKE_CXXFLAGS.CW").join(" "));
-        cw.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CXXFLAGS.ARMCC").size()) {
-        armcc.append(project->values("QMAKE_CXXFLAGS.ARMCC").join(" "));
-        armcc.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CXXFLAGS.GCCE").size()) {
-        gcce.append(project->values("QMAKE_CXXFLAGS.GCCE").join(" "));
-        gcce.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CFLAGS.CW").size()) {
-        cw.append(project->values("QMAKE_CFLAGS.CW").join(" "));
-        cw.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CFLAGS.ARMCC").size()) {
-        armcc.append(project->values("QMAKE_CFLAGS.ARMCC").join(" "));
-        armcc.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CFLAGS.GCCE").size()) {
-        gcce.append(project->values("QMAKE_CXXFLAGS.GCCE").join(" "));
-        gcce.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CXXFLAGS").size()) {
-        cw.append(project->values("QMAKE_CXXFLAGS").join(" "));
-        cw.append(" ");
-        armcc.append(project->values("QMAKE_CXXFLAGS").join(" "));
-        armcc.append(" ");
-        gcce.append(project->values("QMAKE_CXXFLAGS").join(" "));
-        gcce.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_CFLAGS").size()) {
-        cw.append(project->values("QMAKE_CFLAGS").join(" "));
-        cw.append(" ");
-        armcc.append(project->values("QMAKE_CFLAGS").join(" "));
-        armcc.append(" ");
-        gcce.append(project->values("QMAKE_CFLAGS").join(" "));
-        gcce.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_LFLAGS.CW").size()) {
-        cwlink.append(project->values("QMAKE_LFLAGS.CW").join(" "));
-        cwlink.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_LFLAGS.ARMCC").size()) {
-        armlink.append(project->values("QMAKE_LFLAGS.ARMCC").join(" "));
-        armlink.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_LFLAGS.GCCE").size()) {
-        gccelink.append(project->values("QMAKE_LFLAGS.GCCE").join(" "));
-        gccelink.append(" ");
-    }
-
-    if (0 != project->values("QMAKE_LFLAGS").size()) {
-        cwlink.append(project->values("QMAKE_LFLAGS").join(" "));
-        cwlink.append(" ");
-        armlink.append(project->values("QMAKE_LFLAGS").join(" "));
-        armlink.append(" ");
-        gccelink.append(project->values("QMAKE_LFLAGS").join(" "));
-        gccelink.append(" ");
-    }
-
-    if (!cw.isEmpty() && cw[cw.size()-1] == ' ')
-        cw.chop(1);
-    if (!armcc.isEmpty() && armcc[armcc.size()-1] == ' ')
-        armcc.chop(1);
-    if (!gcce.isEmpty() && gcce[gcce.size()-1] == ' ')
-        gcce.chop(1);
-    if (!cwlink.isEmpty() && cwlink[cwlink.size()-1] == ' ')
-        cwlink.chop(1);
-    if (!armlink.isEmpty() && armlink[armlink.size()-1] == ' ')
-        armlink.chop(1);
-    if (!gccelink.isEmpty() && gccelink[gccelink.size()-1] == ' ')
-        gccelink.chop(1);
-
-    if (!cw.isEmpty())
-        t << MMP_OPTION_CW " " << cw <<  endl;
-    if (!armcc.isEmpty())
-        t << MMP_OPTION_ARMCC " " << armcc <<  endl;
-    if (!gcce.isEmpty())
-        t << MMP_OPTION_GCCE " " << gcce <<  endl;
-
-    if (!cwlink.isEmpty())
-        t << MMP_LINKEROPTION_CW " " << cwlink <<  endl;
-    if (!armlink.isEmpty())
-        t << MMP_LINKEROPTION_ARMCC " " << armlink <<  endl;
-    if (!gccelink.isEmpty())
-        t << MMP_LINKEROPTION_GCCE " " << gccelink <<  endl;
+    QStringList keywords =  project->values("MMP_OPTION_KEYWORDS");
+    QStringList commonCxxFlags = project->values(VAR_CXXFLAGS);
+    QStringList commonCFlags = project->values(VAR_CFLAGS);
+    QStringList commonLFlags = project->values(VAR_LFLAGS);
+
+    foreach(QString item, keywords) {
+        QString compilerOption;
+        QString linkerOption;
+
+        appendMmpFileOptions(compilerOption, project->values(VAR_CXXFLAGS "." + item));
+        appendMmpFileOptions(compilerOption, project->values(VAR_CFLAGS "." + item));
+        appendMmpFileOptions(compilerOption, commonCxxFlags);
+        appendMmpFileOptions(compilerOption, commonCFlags);
+
+        appendMmpFileOptions(linkerOption, project->values(VAR_LFLAGS "."  + item));
+        appendMmpFileOptions(linkerOption, commonLFlags);
+
+        writeMmpFileSimpleOption(t, MMP_OPTION, item, compilerOption);
+        writeMmpFileSimpleOption(t, MMP_LINKEROPTION, item, linkerOption);
+
+        writeMmpFileConditionalOptions(t, MMP_OPTION, item, VAR_CXXFLAGS);
+        writeMmpFileConditionalOptions(t, MMP_LINKEROPTION, item, VAR_LFLAGS);
+    }
 
     t << endl;
@@ -1317,4 +1312,8 @@
         }
 
+        QString condition;
+        if (!project->isEmpty(item + ".condition"))
+            condition = project->first(item + ".condition");
+
         QFileInfo subdir(fileInfo(fixedItem));
         QString relativePath = directory.relativeFilePath(fixedItem);
@@ -1345,7 +1344,14 @@
         removeSpecialCharacters(bldinfDefine);
 
+        if (!condition.isEmpty())
+            t << "#if defined(" << condition << ")" << endl;
+
         t << "#ifndef " << bldinfDefine << endl;
-        t << "\t#include \"" << QDir::toNativeSeparators(bldinfFilename) << "\"" << endl;
-        t << "#endif // " << bldinfDefine << endl;
+        t << "\t#include \"" << bldinfFilename << "\"" << endl;
+        t << "#endif" << endl;
+
+        if (!condition.isEmpty())
+            t << "#endif" << endl;
+
     }
 
@@ -1365,5 +1371,5 @@
 
     QString mmpTag;
-    if (project->values("CONFIG").contains("symbian_test", Qt::CaseInsensitive))
+    if (project->isActiveConfig(SYMBIAN_TEST_CONFIG))
         mmpTag = QLatin1String(BLD_INF_TAG_TESTMMPFILES);
     else
@@ -1388,5 +1394,11 @@
     userBldInfRules.remove(mmpTag);
 
-    t << endl << BLD_INF_TAG_EXTENSIONS << endl << endl;
+    QString extensionTag;
+    if (project->isActiveConfig(SYMBIAN_TEST_CONFIG))
+        extensionTag = QLatin1String(BLD_INF_TAG_TESTEXTENSIONS);
+    else
+        extensionTag = QLatin1String(BLD_INF_TAG_EXTENSIONS);
+
+    t << endl << extensionTag << endl << endl;
 
     // Generate extension rules
@@ -1394,27 +1406,8 @@
     writeBldInfExtensionRulesPart(t, iconFile);
 
-    userItems = userBldInfRules.value(BLD_INF_TAG_EXTENSIONS);
+    userItems = userBldInfRules.value(extensionTag);
     foreach(QString item, userItems)
         t << item << endl;
-    userBldInfRules.remove(BLD_INF_TAG_EXTENSIONS);
-
-    t << endl << BLD_INF_TAG_EXPORTS << endl << endl;
-
-    // Generate export rules
-
-    // Export any deployed plugin stubs under /epoc32/data/z to support ROM builds
-    for (int i = 0; i < depList.size(); ++i)  {
-        int index = depList.at(i).from.indexOf(PLUGIN_STUB_DIR);
-        if (index != -1) {
-            t << QString("%1 /epoc32/data/z%2")
-                .arg(QString(depList.at(i).from).mid(index).replace('\\','/'))
-                .arg(QString(depList.at(i).to).mid(2).replace('\\','/')) << endl;
-        }
-    }
-
-    userItems = userBldInfRules.value(BLD_INF_TAG_EXPORTS);
-    foreach(QString item, userItems)
-        t << item << endl;
-    userBldInfRules.remove(BLD_INF_TAG_EXPORTS);
+    userBldInfRules.remove(extensionTag);
 
     // Add rest of the user defined content
@@ -1428,5 +1421,5 @@
 }
 
-void SymbianMakefileGenerator::writeRegRssFile(QStringList &userItems)
+void SymbianMakefileGenerator::writeRegRssFile(QMap<QString, QStringList> &userItems)
 {
     QString filename(fixedTarget);
@@ -1445,4 +1438,6 @@
         t << "#include <" << fixedTarget << ".rsg>" << endl;
         t << "#include <appinfo.rh>" << endl;
+        foreach(QString item, userItems[RSS_TAG_HEADER])
+            t << item << endl;
         t << endl;
         t << "UID2 KUidAppRegistrationResourceFile" << endl;
@@ -1452,11 +1447,46 @@
         t << "\tapp_file=\"" << fixedTarget << "\";" << endl;
         t << "\tlocalisable_resource_file=\"" RESOURCE_DIRECTORY_RESOURCE << fixedTarget << "\";" << endl;
+
+        writeRegRssList(t, userItems[RSS_TAG_SERVICE_LIST],
+                        QLatin1String(RSS_TAG_SERVICE_LIST),
+                        QLatin1String("SERVICE_INFO"));
+        writeRegRssList(t, userItems[RSS_TAG_FILE_OWNERSHIP_LIST],
+                        QLatin1String(RSS_TAG_FILE_OWNERSHIP_LIST),
+                        QLatin1String("FILE_OWNERSHIP_INFO"));
+        writeRegRssList(t, userItems[RSS_TAG_DATATYPE_LIST],
+                        QLatin1String(RSS_TAG_DATATYPE_LIST),
+                        QLatin1String("DATATYPE"));
         t << endl;
 
-        foreach(QString item, userItems)
-            t << "\t" << item << endl;
+        foreach(QString item, userItems[RSS_TAG_DEFAULT])
+            t << "\t" << item.replace("\n","\n\t") << endl;
         t << "\t}" << endl;
+
+        foreach(QString item, userItems[RSS_TAG_FOOTER])
+            t << item << endl;
     } else {
         PRINT_FILE_CREATE_ERROR(filename)
+    }
+}
+
+void SymbianMakefileGenerator::writeRegRssList(QTextStream &t,
+                                               QStringList &userList,
+                                               const QString &listTag,
+                                               const QString &listItem)
+{
+    int itemCount = userList.count();
+    if (itemCount) {
+        t << "\t" << listTag << " ="<< endl;
+        t << "\t\t{" << endl;
+        foreach(QString item, userList) {
+            t << "\t\t" << listItem << endl;
+            t << "\t\t\t{" << endl;
+            t << "\t\t\t" << item.replace("\n","\n\t\t\t") << endl;
+            t << "\t\t\t}";
+            if (--itemCount)
+                t << ",";
+            t << endl;
+        }
+        t << "\t\t}; "<< endl;
     }
 }
@@ -1540,5 +1570,7 @@
 }
 
-void SymbianMakefileGenerator::readRssRules(QString &numberOfIcons, QString &iconFile, QStringList &userRssRules)
+void SymbianMakefileGenerator::readRssRules(QString &numberOfIcons,
+                                            QString &iconFile, QMap<QString,
+                                            QStringList> &userRssRules)
 {
     for (QMap<QString, QStringList>::iterator it = project->variables().begin(); it != project->variables().end(); ++it) {
@@ -1552,12 +1584,14 @@
             QStringList values = it.value();
             foreach(QString item, values) {
-                // If there is no stringlist defined for a rule, use rule name directly
+                // If there is no stringlist defined for a rule, use rule value directly
                 // This is convenience for defining single line statements
                 if (project->values(item).isEmpty()) {
                     newValues << item;
                 } else {
+                    QStringList itemList;
                     foreach(QString itemRow, project->values(item)) {
-                        newValues << itemRow;
+                        itemList << itemRow;
                     }
+                    newValues << itemList.join("\n");
                 }
             }
@@ -1580,4 +1614,12 @@
                     continue;
                 }
+            } else if (newKey == RSS_TAG_HEADER
+                       || newKey == RSS_TAG_SERVICE_LIST
+                       || newKey == RSS_TAG_FILE_OWNERSHIP_LIST
+                       || newKey == RSS_TAG_DATATYPE_LIST
+                       || newKey == RSS_TAG_FOOTER
+                       || newKey == RSS_TAG_DEFAULT) {
+                userRssRules[newKey] = newValues;
+                continue;
             } else {
                 fprintf(stderr, "Warning: Unsupported key:'%s%s'\n",
@@ -1588,13 +1630,15 @@
     }
 
+    QStringList newValues;
     foreach(QString item, project->values(RSS_RULES)) {
-        // If there is no stringlist defined for a rule, use rule name directly
-        // This is convenience for defining single line mmp statements
+        // If there is no stringlist defined for a rule, use rule value directly
+        // This is convenience for defining single line statements
         if (project->values(item).isEmpty()) {
-            userRssRules << item;
+            newValues << item;
         } else {
-            userRssRules << project->values(item);
-        }
-    }
+            newValues << project->values(item);
+        }
+    }
+    userRssRules[RSS_TAG_DEFAULT] << newValues;
 
     // Validate that either both RSS_TAG_NBROFICONS and RSS_TAG_ICONFILE keys exist
@@ -1612,5 +1656,5 @@
         bool ok;
         numberOfIcons = numberOfIcons.simplified();
-        int tmp = numberOfIcons.toInt(&ok);
+        numberOfIcons.toInt(&ok);
         if (!ok) {
             numberOfIcons.clear();
@@ -1883,5 +1927,5 @@
 
     t << SIS_TARGET ":" << endl;
-    QString siscommand = QString("\t$(if $(wildcard %1_template.%2),$(if $(wildcard %3)," \
+    QString siscommand = QString::fromLatin1("\t$(if $(wildcard %1_template.%2),$(if $(wildcard %3)," \
                                   "$(MAKE) -s -f $(MAKEFILE) %4," \
                                   "$(if $(QT_SIS_TARGET),$(MAKE) -s -f $(MAKEFILE) %4," \
@@ -1899,5 +1943,5 @@
     t << OK_SIS_TARGET ":" << endl;
 
-    QString pkgcommand = QString("\tcreatepackage.bat $(QT_SIS_OPTIONS) %1_template.%2 $(QT_SIS_TARGET) " \
+    QString pkgcommand = QString::fromLatin1("\tcreatepackage.bat $(QT_SIS_OPTIONS) %1_template.%2 $(QT_SIS_TARGET) " \
                                  "$(QT_SIS_CERTIFICATE) $(QT_SIS_KEY) $(QT_SIS_PASSPHRASE)")
                           .arg(fixedTarget)
@@ -1912,6 +1956,30 @@
     t << "\t$(MAKE) -s -f $(MAKEFILE) " SIS_TARGET << endl << endl;
 
+    t << ROM_STUB_SIS_TARGET ":" << endl;
+    QString stubsiscommand = QString::fromLatin1("\t$(if $(wildcard %1_template.%2),$(if $(wildcard %3)," \
+                                  "$(MAKE) -s -f $(MAKEFILE) %4," \
+                                  "$(if $(QT_SIS_TARGET),$(MAKE) -s -f $(MAKEFILE) %4," \
+                                  "$(MAKE) -s -f $(MAKEFILE) %5))," \
+                                  "$(MAKE) -s -f $(MAKEFILE) %6)")
+                          .arg(fixedTarget)
+                          .arg("pkg")
+                          .arg(MAKE_CACHE_NAME)
+                          .arg(OK_ROM_STUB_SIS_TARGET)
+                          .arg(FAIL_SIS_NOCACHE_TARGET)
+                          .arg(FAIL_SIS_NOPKG_TARGET);
+    t << stubsiscommand << endl;
+    t << endl;
+
+    t << OK_ROM_STUB_SIS_TARGET ":" << endl;
+
+    QString stubpkgcommand = QString::fromLatin1("\tcreatepackage.bat -s $(QT_SIS_OPTIONS) %1_template.%2 $(QT_SIS_TARGET) " \
+                                 "$(QT_SIS_CERTIFICATE) $(QT_SIS_KEY) $(QT_SIS_PASSPHRASE)")
+                          .arg(fixedTarget)
+                          .arg("pkg");
+    t << stubpkgcommand << endl;
+    t << endl;
+
     t << INSTALLER_SIS_TARGET ": " << sisName << endl;
-    siscommand = QString("\t$(if $(wildcard %1_installer.%2)," \
+    siscommand = QString::fromLatin1("\t$(if $(wildcard %1_installer.%2)," \
                                   "$(MAKE) -s -f $(MAKEFILE) %3," \
                                   "$(MAKE) -s -f $(MAKEFILE) %4)")
@@ -1925,5 +1993,5 @@
     t << OK_INSTALLER_SIS_TARGET ": " << endl;
 
-    pkgcommand = QString("\tcreatepackage.bat $(QT_SIS_OPTIONS) %1_installer.%2 - " \
+    pkgcommand = QString::fromLatin1("\tcreatepackage.bat $(QT_SIS_OPTIONS) %1_installer.%2 - " \
                          "$(QT_SIS_CERTIFICATE) $(QT_SIS_KEY) $(QT_SIS_PASSPHRASE)")
                   .arg(fixedTarget)
@@ -2005,5 +2073,5 @@
         }
         t << "runonphone: sis" << endl;
-        t << "\trunonphone $(QT_RUN_ON_PHONE_OPTIONS) --sis " << fixedTarget << "_$(QT_SIS_TARGET).sis " << fixedTarget << ".exe " << "$(QT_RUN_OPTIONS)" << endl;
+        t << "\trunonphone $(QT_RUN_ON_PHONE_OPTIONS) --sis " << fixedTarget << ".sis " << fixedTarget << ".exe " << "$(QT_RUN_OPTIONS)" << endl;
         t << endl;
     }
Index: trunk/qmake/generators/symbian/symmake.h
===================================================================
--- trunk/qmake/generators/symbian/symmake.h	(revision 682)
+++ trunk/qmake/generators/symbian/symmake.h	(revision 769)
@@ -50,7 +50,7 @@
 #define BLD_INF_FILENAME "bld.inf"
 #define MAKEFILE_DEPENDENCY_SEPARATOR " \\\n\t"
-
 #define QT_EXTRA_INCLUDE_DIR "tmp"
 #define MAKE_CACHE_NAME ".make.cache"
+#define SYMBIAN_TEST_CONFIG "symbian_test"
 
 class SymbianMakefileGenerator : public MakefileGenerator
@@ -85,5 +85,5 @@
     void removeSpecialCharacters(QString& str);
     QString fixPathForMmp(const QString& origPath, const QDir& parentDir);
-    QString canonizePath(const QString& origPath);
+    QString absolutizePath(const QString& origPath);
 
     virtual bool writeMakefile(QTextStream &t);
@@ -108,5 +108,8 @@
 
     void writeHeader(QTextStream &t);
-    void writeBldInfContent(QTextStream& t, bool addDeploymentExtension, const QString &iconFile, DeploymentList &depList);
+    void writeBldInfContent(QTextStream& t,
+                            bool addDeploymentExtension,
+                            const QString &iconFile,
+                            DeploymentList &depList);
 
     static bool removeDuplicatedStrings(QStringList& stringList);
@@ -122,4 +125,13 @@
     void writeMmpFileLibraryPart(QTextStream& t);
     void writeMmpFileCapabilityPart(QTextStream& t);
+    void writeMmpFileConditionalOptions(QTextStream& t,
+                                        const QString &optionType,
+                                        const QString &optionTag,
+                                        const QString &variableBase);
+    void writeMmpFileSimpleOption(QTextStream& t,
+                                  const QString &optionType,
+                                  const QString &optionTag,
+                                  const QString &options);
+    void appendMmpFileOptions(QString &options, const QStringList &list);
     void writeMmpFileCompilerOptionPart(QTextStream& t);
     void writeMmpFileBinaryVersionPart(QTextStream& t);
@@ -128,8 +140,13 @@
     void writeCustomDefFile();
 
-    void writeRegRssFile(QStringList &useritems);
+    void writeRegRssFile(QMap<QString, QStringList> &useritems);
+    void writeRegRssList(QTextStream &t, QStringList &userList,
+                         const QString &listTag,
+                         const QString &listItem);
     void writeRssFile(QString &numberOfIcons, QString &iconfile);
     void writeLocFile(QStringList &symbianLangCodes);
-    void readRssRules(QString &numberOfIcons, QString &iconFile, QStringList &userRssRules);
+    void readRssRules(QString &numberOfIcons,
+                      QString &iconFile,
+                      QMap<QString, QStringList> &userRssRules);
 
     QStringList symbianLangCodesFromTsFiles();
Index: trunk/qmake/generators/symbian/symmake_abld.cpp
===================================================================
--- trunk/qmake/generators/symbian/symmake_abld.cpp	(revision 682)
+++ trunk/qmake/generators/symbian/symmake_abld.cpp	(revision 769)
@@ -48,4 +48,7 @@
 #include <qdatetime.h>
 #include <qdebug.h>
+
+// Included from tools/shared
+#include <symbian/epocroot.h>
 
 #define DO_NOTHING_TARGET "do_nothing"
@@ -57,4 +60,6 @@
 #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"
@@ -110,17 +115,19 @@
         if (deploymentOnly) {
             buildDeps.append(STORE_BUILD_TARGET);
-            cleanDeps.append(DO_NOTHING_TARGET);
-            cleanDepsWinscw.append(WINSCW_DEPLOYMENT_CLEAN_TARGET);
-            finalDeps.append(DO_NOTHING_TARGET);
-            finalDepsWinscw.append(WINSCW_DEPLOYMENT_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);
-            cleanDepsWinscw.append(EXTENSION_CLEAN " " WINSCW_DEPLOYMENT_CLEAN_TARGET);
-            finalDeps.append(FINALIZE_TARGET);
-            finalDepsWinscw.append(FINALIZE_TARGET " " WINSCW_DEPLOYMENT_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
@@ -129,4 +136,6 @@
                 << WINSCW_DEPLOYMENT_CLEAN_TARGET
                 << WINSCW_DEPLOYMENT_TARGET
+                << DEPLOYMENT_CLEAN_TARGET
+                << DEPLOYMENT_TARGET
                 << STORE_BUILD_TARGET;
         }
@@ -173,5 +182,5 @@
 
     QString testClause;
-    if (project->values("CONFIG").contains("symbian_test", Qt::CaseInsensitive))
+    if (project->isActiveConfig(SYMBIAN_TEST_CONFIG))
         testClause = QLatin1String(" test");
     else
@@ -196,4 +205,6 @@
     t << "DEL_DIR           = " << var("QMAKE_DEL_DIR") << endl;
     t << "MOVE              = " << var("QMAKE_MOVE") << endl;
+    t << "CHK_DIR_EXISTS    = " << var("QMAKE_CHK_DIR_EXISTS") << endl;
+    t << "MKDIR             = " << var("QMAKE_MKDIR") << endl;
     t << "XCOPY             = xcopy /d /f /h /r /y /i" << endl;
     t << "ABLD              = ABLD.BAT" << endl;
@@ -360,5 +371,7 @@
     }
 
-    writeDeploymentTargets(t);
+    // Deploymend targets for both emulator and rom deployment
+    writeDeploymentTargets(t, false);
+    writeDeploymentTargets(t, true);
 
     writeSisTargets(t);
@@ -405,11 +418,19 @@
 }
 
-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
+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("winscw"), QLatin1String("udeb"), generatedDirs, generatedFiles);
+
+    initProjectDeploySymbian(project, depList, remoteTestPath, false,
+        QLatin1String(isRom ? ROM_DEPLOYMENT_PLATFORM : EMULATOR_DEPLOYMENT_PLATFORM),
+        QString(), generatedDirs, generatedFiles);
 
     if (depList.size())
@@ -420,10 +441,15 @@
         // 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;
+        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) {
Index: trunk/qmake/generators/symbian/symmake_abld.h
===================================================================
--- trunk/qmake/generators/symbian/symmake_abld.h	(revision 682)
+++ trunk/qmake/generators/symbian/symmake_abld.h	(revision 769)
@@ -59,5 +59,5 @@
 
     void writeStoreBuildTarget(QTextStream &t);
-    bool writeDeploymentTargets(QTextStream &t);
+    bool writeDeploymentTargets(QTextStream &t, bool isRom);
 
 public:
Index: trunk/qmake/generators/symbian/symmake_sbsv2.cpp
===================================================================
--- trunk/qmake/generators/symbian/symmake_sbsv2.cpp	(revision 682)
+++ trunk/qmake/generators/symbian/symmake_sbsv2.cpp	(revision 769)
@@ -49,4 +49,7 @@
 #include <qdebug.h>
 
+// Included from tools/shared
+#include <symbian/epocroot.h>
+
 SymbianSbsv2MakefileGenerator::SymbianSbsv2MakefileGenerator() : SymbianMakefileGenerator() { }
 SymbianSbsv2MakefileGenerator::~SymbianSbsv2MakefileGenerator() { }
@@ -73,5 +76,5 @@
         foreach(QFileInfo item, sourceInfos) {
             QFileInfo destInfo = QFileInfo(destDir.absolutePath() + "/" + item.fileName());
-            if (!destInfo.exists() || destInfo.lastModified() < item.lastModified()) {
+            if (!destInfo.exists() || destInfo.lastModified() != item.lastModified()) {
                 if (destInfo.exists())
                     QFile::remove(destInfo.absoluteFilePath());
@@ -88,285 +91,6 @@
 }
 
-void SymbianSbsv2MakefileGenerator::writeMkFile(const QString& wrapperFileName, bool deploymentOnly)
-{
-    // Can't use extension makefile with sbsv2
-    Q_UNUSED(wrapperFileName);
-    Q_UNUSED(deploymentOnly);
-}
-
-void SymbianSbsv2MakefileGenerator::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 << "DEBUG_PLATFORMS   = " << debugPlatforms.join(" ") << endl;
-    t << "RELEASE_PLATFORMS = " << releasePlatforms.join(" ") << endl;
-    t << "MAKE              = make" << endl;
-    t << "SBS               = sbs" << 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-sbsv2 -o \"" << fileInfo(Option::output.fileName()).fileName()
-          << "\" \"" << project->projectFile() << "\"" << endl;
-        t << endl;
-        t << BLD_INF_FILENAME ":" << endl;
-        t << "\t$(QMAKE)" << endl;
-        t << endl;
-
-        QString winscw("winscw");
-        t << "debug: " << BLD_INF_FILENAME << endl;
-        t << "\t$(SBS)";
-        foreach(QString item, debugPlatforms) {
-            if(QString::compare(item, winscw) == 0)
-                t << " -c " << item << "_udeb.mwccinc" << testClause;
-            else
-                t << " -c " << item << "_udeb" << testClause;
-        }
-        t << endl;
-        t << "release: " << BLD_INF_FILENAME << endl;
-        t << "\t$(SBS)";
-        foreach(QString item, releasePlatforms) {
-            if(QString::compare(item, winscw) == 0)
-                t << " -c " << item << "_urel.mwccinc" << testClause;
-            else
-                t << " -c " << item << "_urel" << testClause;
-        }
-        t << endl;
-
-        // For more specific builds, targets are in this form: build-platform, e.g. release-armv5
-        foreach(QString item, debugPlatforms) {
-            t << "debug-" << item << ": " << BLD_INF_FILENAME << endl;
-            if(QString::compare(item, winscw) == 0)
-                t << "\t$(SBS) -c " << item << "_udeb.mwccinc" << testClause << endl;
-            else
-                t << "\t$(SBS) -c " << item << "_udeb" << testClause << endl;
-        }
-
-        foreach(QString item, releasePlatforms) {
-            t << "release-" << item << ": " << BLD_INF_FILENAME << endl;
-            if(QString::compare(item, winscw) == 0)
-                t << "\t$(SBS) -c " << item << "_urel.mwccinc" << testClause << endl;
-            else
-                t << "\t$(SBS) -c " << item << "_urel" << testClause << endl;
-        }
-
-        t << endl;
-        t << "export: " << BLD_INF_FILENAME << endl;
-        t << "\t$(SBS) export" << endl;
-        t << endl;
-
-        t << "cleanexport: " << BLD_INF_FILENAME << endl;
-        t << "\t$(SBS) cleanexport" << endl;
-        t << endl;
-
-    }
-
-    // Add all extra targets including extra compiler targest also to wrapper makefile,
-    // even though many of them may have already been added to bld.inf as FLMs.
-    // This is to enable use of targets like 'mocables', which call targets generated by extra compilers.
-    if (targetType != TypeSubdirs) {
-        t << extraTargetsCache;
-        t << extraCompilersCache;
-    } else {
-        QList<MakefileGenerator::SubTarget*> subtargets = findSubDirsSubTargets();
-        writeSubTargets(t, subtargets, SubTargetSkipDefaultVariables|SubTargetSkipDefaultTargets);
-        qDeleteAll(subtargets);
-    }
-
-    writeSisTargets(t);
-
-    generateDistcleanTargets(t);
-
-    t << "clean: " << BLD_INF_FILENAME << endl;
-    t << "\t-$(SBS) reallyclean" << endl;
-    t << endl;
-
-    t << "clean-debug: " << BLD_INF_FILENAME << endl;
-    t << "\t$(SBS) reallyclean";
-    foreach(QString item, debugPlatforms) {
-        t << " -c " << item << "_udeb" << testClause;
-    }
-    t << endl;
-    t << "clean-release: " << BLD_INF_FILENAME << endl;
-    t << "\t$(SBS) reallyclean";
-    foreach(QString item, releasePlatforms) {
-        t << " -c " << item << "_urel" << testClause;
-    }
-    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 << ": " << BLD_INF_FILENAME << endl;
-        t << "\t$(SBS) reallyclean -c " << item << "_udeb" << testClause << endl;
-    }
-    foreach(QString item, releasePlatforms) {
-        t << "clean-release-" << item << ": " << BLD_INF_FILENAME << endl;
-        t << "\t$(SBS) reallyclean -c " << item << "_urel" << testClause << endl;
-    }
-    t << endl;
-
-    generateExecutionTargets(t, debugPlatforms);
-}
-
-void SymbianSbsv2MakefileGenerator::writeBldInfExtensionRulesPart(QTextStream& t, const QString &iconTargetFile)
-{
-    // Makes sure we have needed FLMs in place.
-    exportFlm();
-
-    // Parse extra compilers data
-    QStringList defines;
-    QStringList incPath;
-
-    defines << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
-            << varGlue("QMAKE_COMPILER_DEFINES", "-D", "-D", " ")
-            << varGlue("DEFINES","-D"," -D","");
-    for (QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
-        QStringList values = it.value();
-        for (int i = 0; i < values.size(); ++i) {
-            incPath << QLatin1String(" -I\"") + values.at(i) + "\"";
-        }
-    }
-
-    // Write extra compilers and targets to initialize QMAKE_ET_* variables
-    // Cache results to avoid duplicate calls when creating wrapper makefile
-    QTextStream extraCompilerStream(&extraCompilersCache);
-    QTextStream extraTargetStream(&extraTargetsCache);
-    writeExtraCompilerTargets(extraCompilerStream);
-    writeExtraTargets(extraTargetStream);
-
-    // Figure out everything the target depends on as we don't want to run extra targets that
-    // are not necessary.
-    QStringList allPreDeps;
-    foreach(QString item, project->values("PRE_TARGETDEPS")) {
-        // Predeps get mangled in windows, so fix them to more sbsv2 friendly format
-#if defined(Q_OS_WIN)
-        if (item.mid(1, 1) == ":")
-            item = item.mid(0, 1).toUpper().append(item.mid(1)); // Fix drive to uppercase
-#endif
-        item.replace("\\", "/");
-        allPreDeps << escapeDependencyPath(item);
-    }
-
-    foreach (QString item, project->values("GENERATED_SOURCES")) {
-        allPreDeps.append(fileInfo(item).absoluteFilePath());
-    }
-
-    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) {
-            QString sourceFile = currentSourcePath + "/" + values.at(i);
-            QStringList deps = findDependencies(QDir::toNativeSeparators(sourceFile));
-            foreach(QString depItem, deps) {
-                appendIfnotExist(allPreDeps, fileInfo(depItem).absoluteFilePath());
-            }
-        }
-    }
-
-    // Write FLM rules for all extra targets and compilers that we depend on to build the target.
-    QStringList extraTargets;
-    extraTargets << project->values("QMAKE_EXTRA_TARGETS") <<  project->values("QMAKE_EXTRA_COMPILERS");
-    foreach(QString item, extraTargets) {
-        foreach(QString targetItem, project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + item)) {
-            // Make sure targetpath is absolute
-            QString absoluteTarget = fileInfo(targetItem).absoluteFilePath();
-            if (allPreDeps.contains(absoluteTarget)) {
-                QStringList deps = project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + item + targetItem);
-                QString commandItem =  project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + item + targetItem).join(" ");
-
-
-                // Make sure all deps paths are absolute
-                QString absoluteDeps;
-                foreach (QString depItem, deps) {
-                    if (!depItem.isEmpty()) {
-                        absoluteDeps.append(fileInfo(depItem).absoluteFilePath());
-                        absoluteDeps.append(" ");
-                    }
-                }
-
-                t << "START EXTENSION qt/qmake_extra_pre_targetdep" << endl;
-                t << "OPTION PREDEP_TARGET " << absoluteTarget << endl;
-                t << "OPTION DEPS " << absoluteDeps << endl;
-
-                if (commandItem.indexOf("$(INCPATH)") != -1)
-                    commandItem.replace("$(INCPATH)", incPath.join(" "));
-                if (commandItem.indexOf("$(DEFINES)") != -1)
-                    commandItem.replace("$(DEFINES)", defines.join(" "));
-
-                // Sbsv2 strips all backslashes (even doubles ones) from option parameters, so just replace them with slashes
-                // Problem: If some command actually needs backslashes for something else than dir separator, we are out of luck...
-                commandItem.replace("\\", "/");
-                t << "OPTION COMMAND " << commandItem << endl;
-                t << "END" << endl;
-            }
-        }
-    }
-
-    t << endl;
-
-    // Write winscw deployment rules
-    QString remoteTestPath = epocRoot() + QLatin1String("epoc32/winscw/c/private/") + privateDirUid;
-    DeploymentList depList;
-    initProjectDeploySymbian(project, depList, remoteTestPath, false, QLatin1String("winscw"), QLatin1String("udeb"), generatedDirs, generatedFiles);
-
-    t << "#if defined(WINSCW)" << endl;
+void SymbianSbsv2MakefileGenerator::writeSbsDeploymentList(const DeploymentList& depList, QTextStream& t)
+{
     for (int i = 0; i < depList.size(); ++i) {
         t << "START EXTENSION qt/qmake_emulator_deployment" << endl;
@@ -382,6 +106,300 @@
         t << "END" << endl;
     }
+}
+
+void SymbianSbsv2MakefileGenerator::writeMkFile(const QString& wrapperFileName, bool deploymentOnly)
+{
+    // Can't use extension makefile with sbsv2
+    Q_UNUSED(wrapperFileName);
+    Q_UNUSED(deploymentOnly);
+}
+
+void SymbianSbsv2MakefileGenerator::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 << "CHK_DIR_EXISTS    = " << var("QMAKE_CHK_DIR_EXISTS") << endl;
+    t << "MKDIR             = " << var("QMAKE_MKDIR") << endl;
+    t << "MOVE              = " << var("QMAKE_MOVE") << endl;
+    t << "DEBUG_PLATFORMS   = " << debugPlatforms.join(" ") << endl;
+    t << "RELEASE_PLATFORMS = " << releasePlatforms.join(" ") << endl;
+    t << "MAKE              = make" << endl;
+    t << "SBS               = sbs" << 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-sbsv2 -o \"" << fileInfo(Option::output.fileName()).fileName()
+          << "\" \"" << project->projectFile() << "\"" << endl;
+        t << endl;
+        t << BLD_INF_FILENAME ":" << endl;
+        t << "\t$(QMAKE)" << endl;
+        t << endl;
+
+        QString winscw("winscw");
+        t << "debug: " << BLD_INF_FILENAME << endl;
+        t << "\t$(SBS)";
+        foreach(QString item, debugPlatforms) {
+            if(QString::compare(item, winscw) == 0)
+                t << " -c " << item << "_udeb.mwccinc" << testClause;
+            else
+                t << " -c " << item << "_udeb" << testClause;
+        }
+        t << endl;
+        t << "release: " << BLD_INF_FILENAME << endl;
+        t << "\t$(SBS)";
+        foreach(QString item, releasePlatforms) {
+            if(QString::compare(item, winscw) == 0)
+                t << " -c " << item << "_urel.mwccinc" << testClause;
+            else
+                t << " -c " << item << "_urel" << testClause;
+        }
+        t << endl;
+
+        // For more specific builds, targets are in this form: build-platform, e.g. release-armv5
+        foreach(QString item, debugPlatforms) {
+            t << "debug-" << item << ": " << BLD_INF_FILENAME << endl;
+            if(QString::compare(item, winscw) == 0)
+                t << "\t$(SBS) -c " << item << "_udeb.mwccinc" << testClause << endl;
+            else
+                t << "\t$(SBS) -c " << item << "_udeb" << testClause << endl;
+        }
+
+        foreach(QString item, releasePlatforms) {
+            t << "release-" << item << ": " << BLD_INF_FILENAME << endl;
+            if(QString::compare(item, winscw) == 0)
+                t << "\t$(SBS) -c " << item << "_urel.mwccinc" << testClause << endl;
+            else
+                t << "\t$(SBS) -c " << item << "_urel" << testClause << endl;
+        }
+
+        t << endl;
+        t << "export: " << BLD_INF_FILENAME << endl;
+        t << "\t$(SBS) export" << endl;
+        t << endl;
+
+        t << "cleanexport: " << BLD_INF_FILENAME << endl;
+        t << "\t$(SBS) cleanexport" << endl;
+        t << endl;
+
+    }
+
+    // Add all extra targets including extra compiler targest also to wrapper makefile,
+    // even though many of them may have already been added to bld.inf as FLMs.
+    // This is to enable use of targets like 'mocables', which call targets generated by extra compilers.
+    if (targetType != TypeSubdirs) {
+        t << extraTargetsCache;
+        t << extraCompilersCache;
+    } else {
+        QList<MakefileGenerator::SubTarget*> subtargets = findSubDirsSubTargets();
+        writeSubTargets(t, subtargets, SubTargetSkipDefaultVariables|SubTargetSkipDefaultTargets);
+        qDeleteAll(subtargets);
+    }
+
+    writeSisTargets(t);
+
+    generateDistcleanTargets(t);
+
+    t << "clean: " << BLD_INF_FILENAME << endl;
+    t << "\t-$(SBS) reallyclean" << endl;
+    t << endl;
+
+    t << "clean-debug: " << BLD_INF_FILENAME << endl;
+    t << "\t$(SBS) reallyclean";
+    foreach(QString item, debugPlatforms) {
+        t << " -c " << item << "_udeb" << testClause;
+    }
+    t << endl;
+    t << "clean-release: " << BLD_INF_FILENAME << endl;
+    t << "\t$(SBS) reallyclean";
+    foreach(QString item, releasePlatforms) {
+        t << " -c " << item << "_urel" << testClause;
+    }
+    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 << ": " << BLD_INF_FILENAME << endl;
+        t << "\t$(SBS) reallyclean -c " << item << "_udeb" << testClause << endl;
+    }
+    foreach(QString item, releasePlatforms) {
+        t << "clean-release-" << item << ": " << BLD_INF_FILENAME << endl;
+        t << "\t$(SBS) reallyclean -c " << item << "_urel" << testClause << endl;
+    }
+    t << endl;
+
+    generateExecutionTargets(t, debugPlatforms);
+}
+
+void SymbianSbsv2MakefileGenerator::writeBldInfExtensionRulesPart(QTextStream& t, const QString &iconTargetFile)
+{
+    // Makes sure we have needed FLMs in place.
+    exportFlm();
+
+    // Parse extra compilers data
+    QStringList defines;
+    QStringList incPath;
+
+    defines << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
+            << varGlue("QMAKE_COMPILER_DEFINES", "-D", "-D", " ")
+            << varGlue("DEFINES","-D"," -D","");
+    for (QMap<QString, QStringList>::iterator it = systeminclude.begin(); it != systeminclude.end(); ++it) {
+        QStringList values = it.value();
+        for (int i = 0; i < values.size(); ++i) {
+            incPath << QLatin1String(" -I\"") + values.at(i) + "\"";
+        }
+    }
+
+    // Write extra compilers and targets to initialize QMAKE_ET_* variables
+    // Cache results to avoid duplicate calls when creating wrapper makefile
+    QTextStream extraCompilerStream(&extraCompilersCache);
+    QTextStream extraTargetStream(&extraTargetsCache);
+    writeExtraCompilerTargets(extraCompilerStream);
+    writeExtraTargets(extraTargetStream);
+
+    // Figure out everything the target depends on as we don't want to run extra targets that
+    // are not necessary.
+    QStringList allPreDeps;
+    foreach(QString item, project->values("PRE_TARGETDEPS")) {
+        // Predeps get mangled in windows, so fix them to more sbsv2 friendly format
+#if defined(Q_OS_WIN)
+        if (item.mid(1, 1) == ":")
+            item = item.mid(0, 1).toUpper().append(item.mid(1)); // Fix drive to uppercase
+#endif
+        item.replace("\\", "/");
+        allPreDeps << escapeDependencyPath(item);
+    }
+
+    foreach (QString item, project->values("GENERATED_SOURCES")) {
+        allPreDeps.append(fileInfo(item).absoluteFilePath());
+    }
+
+    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) {
+            QString sourceFile = currentSourcePath + "/" + values.at(i);
+            QStringList deps = findDependencies(QDir::toNativeSeparators(sourceFile));
+            foreach(QString depItem, deps) {
+                appendIfnotExist(allPreDeps, fileInfo(depItem).absoluteFilePath());
+            }
+        }
+    }
+
+    // Write FLM rules for all extra targets and compilers that we depend on to build the target.
+    QStringList extraTargets;
+    extraTargets << project->values("QMAKE_EXTRA_TARGETS") <<  project->values("QMAKE_EXTRA_COMPILERS");
+    foreach(QString item, extraTargets) {
+        foreach(QString targetItem, project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + item)) {
+            // Make sure targetpath is absolute
+            QString absoluteTarget = fileInfo(targetItem).absoluteFilePath();
+            if (allPreDeps.contains(absoluteTarget)) {
+                QStringList deps = project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + item + targetItem);
+                QString commandItem =  project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + item + targetItem).join(" ");
+
+
+                // Make sure all deps paths are absolute
+                QString absoluteDeps;
+                foreach (QString depItem, deps) {
+                    if (!depItem.isEmpty()) {
+                        absoluteDeps.append(fileInfo(depItem).absoluteFilePath());
+                        absoluteDeps.append(" ");
+                    }
+                }
+
+                t << "START EXTENSION qt/qmake_extra_pre_targetdep.export" << endl;
+                t << "OPTION PREDEP_TARGET " << absoluteTarget << endl;
+                t << "OPTION DEPS " << absoluteDeps << endl;
+
+                if (commandItem.indexOf("$(INCPATH)") != -1)
+                    commandItem.replace("$(INCPATH)", incPath.join(" "));
+                if (commandItem.indexOf("$(DEFINES)") != -1)
+                    commandItem.replace("$(DEFINES)", defines.join(" "));
+
+                // Sbsv2 strips all backslashes (even doubles ones) from option parameters, so just replace them with slashes
+                // Problem: If some command actually needs backslashes for something else than dir separator, we are out of luck...
+                commandItem.replace("\\", "/");
+                t << "OPTION COMMAND " << commandItem << endl;
+                t << "END" << endl;
+            }
+        }
+    }
+
+    t << endl;
+
+    // Write deployment rules
+    QString remoteTestPath = epocRoot() + QLatin1String("epoc32/winscw/c/private/") + privateDirUid;
+    DeploymentList depList;
+
+    //write emulator deployment
+    t << "#if defined(WINSCW)" << endl;
+    initProjectDeploySymbian(project, depList, remoteTestPath, false,
+        QLatin1String(EMULATOR_DEPLOYMENT_PLATFORM), QString(), generatedDirs, generatedFiles);
+    writeSbsDeploymentList(depList, t);
     t << "#endif" << endl;
 
+    //write ROM deployment
+    remoteTestPath = epocRoot() + QLatin1String("epoc32/data/z/private/") + privateDirUid;
+    depList.clear();
+    initProjectDeploySymbian(project, depList, remoteTestPath, false,
+        QLatin1String(ROM_DEPLOYMENT_PLATFORM), QString(), generatedDirs, generatedFiles);
+    writeSbsDeploymentList(depList, t);
     t << endl;
 
Index: trunk/qmake/generators/symbian/symmake_sbsv2.h
===================================================================
--- trunk/qmake/generators/symbian/symmake_sbsv2.h	(revision 682)
+++ trunk/qmake/generators/symbian/symmake_sbsv2.h	(revision 769)
@@ -65,4 +65,5 @@
 private:
     void exportFlm();
+    void writeSbsDeploymentList(const DeploymentList& depList, QTextStream& t);
 
     QString extraTargetsCache;
Index: trunk/qmake/generators/win32/msvc_vcproj.cpp
===================================================================
--- trunk/qmake/generators/win32/msvc_vcproj.cpp	(revision 682)
+++ trunk/qmake/generators/win32/msvc_vcproj.cpp	(revision 769)
@@ -68,4 +68,5 @@
 #ifdef Q_OS_WIN32
 #include <qt_windows.h>
+#include <windows/registry.h>
 
 QT_BEGIN_NAMESPACE
@@ -94,100 +95,4 @@
 };
 
-static QString keyPath(const QString &rKey)
-{
-    int idx = rKey.lastIndexOf(QLatin1Char('\\'));
-    if (idx == -1)
-        return QString();
-    return rKey.left(idx + 1);
-}
-
-static QString keyName(const QString &rKey)
-{
-    int idx = rKey.lastIndexOf(QLatin1Char('\\'));
-    if (idx == -1)
-        return rKey;
-
-    QString res(rKey.mid(idx + 1));
-    if (res == "Default" || res == ".")
-        res = "";
-    return res;
-}
-
-static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey)
-{
-
-    QString rSubkeyName = keyName(rSubkey);
-    QString rSubkeyPath = keyPath(rSubkey);
-
-    HKEY handle = 0;
-    LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle);
-
-    if (res != ERROR_SUCCESS)
-        return QString();
-
-    // get the size and type of the value
-    DWORD dataType;
-    DWORD dataSize;
-    res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize);
-    if (res != ERROR_SUCCESS) {
-        RegCloseKey(handle);
-        return QString();
-    }
-
-    // get the value
-    QByteArray data(dataSize, 0);
-    res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0,
-                          reinterpret_cast<unsigned char*>(data.data()), &dataSize);
-    if (res != ERROR_SUCCESS) {
-        RegCloseKey(handle);
-        return QString();
-    }
-
-    QString result;
-    switch (dataType) {
-        case REG_EXPAND_SZ:
-        case REG_SZ: {
-            result = QString::fromWCharArray(((const wchar_t *)data.constData()));
-            break;
-        }
-
-        case REG_MULTI_SZ: {
-            QStringList l;
-            int i = 0;
-            for (;;) {
-                QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
-                i += s.length() + 1;
-
-                if (s.isEmpty())
-                    break;
-                l.append(s);
-            }
-            result = l.join(", ");
-            break;
-        }
-
-        case REG_NONE:
-        case REG_BINARY: {
-            result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
-            break;
-        }
-
-        case REG_DWORD_BIG_ENDIAN:
-        case REG_DWORD: {
-            Q_ASSERT(data.size() == sizeof(int));
-            int i;
-            memcpy((char*)&i, data.constData(), sizeof(int));
-            result = QString::number(i);
-            break;
-        }
-
-        default:
-            qWarning("QSettings: unknown data %d type in windows registry", dataType);
-            break;
-    }
-
-    RegCloseKey(handle);
-    return result;
-}
 QT_END_NAMESPACE
 #endif
Index: trunk/qmake/generators/win32/winmakefile.cpp
===================================================================
--- trunk/qmake/generators/win32/winmakefile.cpp	(revision 682)
+++ trunk/qmake/generators/win32/winmakefile.cpp	(revision 769)
@@ -151,4 +151,8 @@
                        exists((*it).local() + Option::dir_sep + lib + extension)) {
                         out = (*it).real() + Option::dir_sep + lib + extension;
+                        if (out.contains(QLatin1Char(' '))) {
+                            out.prepend(QLatin1Char('\"'));
+                            out.append(QLatin1Char('\"'));
+                        }
                         break;
                     }
Index: trunk/qmake/meta.cpp
===================================================================
--- trunk/qmake/meta.cpp	(revision 682)
+++ trunk/qmake/meta.cpp	(revision 769)
@@ -120,8 +120,9 @@
         }
     }
-    if(ret.isNull())
+    if(ret.isNull()) {
         debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.toLatin1().constData());
-    else
+    } else {
         debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.toLatin1().constData(), lib.toLatin1().constData());
+    }
     return ret;
 }
Index: trunk/qmake/option.cpp
===================================================================
--- trunk/qmake/option.cpp	(revision 682)
+++ trunk/qmake/option.cpp	(revision 769)
@@ -645,6 +645,6 @@
     }
 
-    if (string.startsWith("\"") && string.endsWith("\"") ||
-        string.startsWith("\'") && string.endsWith("\'"))
+    if ((string.startsWith("\"") && string.endsWith("\"")) ||
+        (string.startsWith("\'") && string.endsWith("\'")))
         string = string.mid(1, string.length()-2);
 
Index: trunk/qmake/project.cpp
===================================================================
--- trunk/qmake/project.cpp	(revision 682)
+++ trunk/qmake/project.cpp	(revision 769)
@@ -45,6 +45,4 @@
 #include "cachekeys.h"
 
-#include "epocroot.h"
-
 #include <qdatetime.h>
 #include <qfile.h>
@@ -66,4 +64,7 @@
 #include <stdio.h>
 #include <stdlib.h>
+
+// Included from tools/shared
+#include <symbian/epocroot.h>
 
 #ifdef Q_OS_WIN32
@@ -3076,5 +3077,5 @@
     } else if(var == QLatin1String("_PRO_FILE_PWD_")) {
         var = ".BUILTIN." + var;
-        place[var] =  QStringList(QFileInfo(pfile).absolutePath());
+        place[var] = QStringList(pfile.isEmpty() ? qmake_getpwd() : QFileInfo(pfile).absolutePath());
     } else if(var == QLatin1String("_QMAKE_CACHE_")) {
         var = ".BUILTIN." + var;
Index: trunk/qmake/qmake.pri
===================================================================
--- trunk/qmake/qmake.pri	(revision 682)
+++ trunk/qmake/qmake.pri	(revision 769)
@@ -14,4 +14,6 @@
            generators/symbian/symmake_sbsv2.cpp \
            generators/symbian/initprojectdeploy_symbian.cpp \
+           windows/registry.cpp \
+           symbian/epocroot.cpp \
            generators/os2/gnumake.cpp
 
@@ -26,6 +28,7 @@
            generators/symbian/symmake_abld.h \
            generators/symbian/symmake_sbsv2.h \
-           generators/symbian/epocroot.h \
            generators/symbian/initprojectdeploy_symbian.h \
+           windows/registry.h \
+           symbian/epocroot.h \
            generators/os2/gnumake.h
 
@@ -129,4 +132,5 @@
         SOURCES += qfsfileengine_win.cpp qfsfileengine_iterator_win.cpp qsettings_win.cpp
         win32-msvc*:LIBS += ole32.lib advapi32.lib
+        win32-g++:LIBS += -lole32 -luuid
     } else:os2 {
         SOURCES += qfsfileengine_os2.cpp qfsfileengine_iterator_os2.cpp qsettings_os2.cpp
Index: trunk/qmake/qmake.pro
===================================================================
--- trunk/qmake/qmake.pro	(revision 682)
+++ trunk/qmake/qmake.pro	(revision 769)
@@ -20,8 +20,19 @@
          $$QT_SOURCE_TREE/src/corelib/codecs \
          $$QT_SOURCE_TREE/src/corelib/plugin \
-	 $$QT_SOURCE_TREE/src/corelib/xml \
-	 $$QT_SOURCE_TREE/src/corelib/io
-INCPATH += generators generators/unix generators/win32 generators/mac generators/symbian generators/os2 \
-           $$QT_SOURCE_TREE/include $$QT_SOURCE_TREE/include/QtCore
+         $$QT_SOURCE_TREE/src/corelib/xml \
+         $$QT_SOURCE_TREE/src/corelib/io
+INCPATH += generators \
+           generators/unix \
+           generators/win32 \
+           generators/mac \
+           generators/symbian \
+           generators/os2 \
+           $$QT_SOURCE_TREE/include \
+           $$QT_SOURCE_TREE/include/QtCore \
+           $$QT_SOURCE_TREE/qmake
+
+VPATH += $$QT_SOURCE_TREE/tools/shared
+INCPATH += $$QT_SOURCE_TREE/tools/shared
+
 include(qmake.pri)
 
