diff --git a/src/plugins/qt4projectmanager/cesdkhandler.cpp b/src/plugins/projectexplorer/cesdkhandler.cpp
similarity index 95%
rename from src/plugins/qt4projectmanager/cesdkhandler.cpp
rename to src/plugins/projectexplorer/cesdkhandler.cpp
index a6e4dfe4925445855a6f67b331ae3d3e2e6f3bce..2317a603e97549b716ecb3c71d78edcce7311ee1 100644
--- a/src/plugins/qt4projectmanager/cesdkhandler.cpp
+++ b/src/plugins/projectexplorer/cesdkhandler.cpp
@@ -37,7 +37,7 @@
 #include <QtCore/QDebug>
 #include <QtCore/QXmlStreamReader>
 
-using namespace Qt4ProjectManager::Internal;
+using namespace ProjectExplorer::Internal;
 using ProjectExplorer::Environment;
 
 CeSdkInfo::CeSdkInfo()
@@ -45,15 +45,13 @@ CeSdkInfo::CeSdkInfo()
 {
 }
 
-Environment CeSdkInfo::addToEnvironment(const Environment &env)
+void CeSdkInfo::addToEnvironment(Environment &env)
 {
     qDebug() << "adding " << name() << "to Environment";
-    Environment e(env);
-    e.set("INCLUDE", m_include);
-    e.set("LIB", m_lib);
-    e.prependOrSetPath(m_bin);
+    env.set("INCLUDE", m_include);
+    env.set("LIB", m_lib);
+    env.prependOrSetPath(m_bin);
     qDebug()<<e.toStringList();
-    return e;
 }
 
 CeSdkHandler::CeSdkHandler()
diff --git a/src/plugins/qt4projectmanager/cesdkhandler.h b/src/plugins/projectexplorer/cesdkhandler.h
similarity index 95%
rename from src/plugins/qt4projectmanager/cesdkhandler.h
rename to src/plugins/projectexplorer/cesdkhandler.h
index d46a65c2ab97433d24fcd8596365da5435963524..3fdb1382c99146d0e0439a7bc6127ad188a16372 100644
--- a/src/plugins/qt4projectmanager/cesdkhandler.h
+++ b/src/plugins/projectexplorer/cesdkhandler.h
@@ -42,8 +42,7 @@
 #define VCINSTALL_MACRO "$(VCInstallDir)"
 #define VSINSTALL_MACRO "$(VSInstallDir)"
 
-namespace Qt4ProjectManager {
-namespace Internal {
+namespace ProjectExplorer {
 
 class CeSdkInfo
 {
@@ -53,7 +52,7 @@ public:
     inline QString                  binPath();
     inline QString                  includePath();
     inline QString                  libPath();
-    ProjectExplorer::Environment    addToEnvironment(const ProjectExplorer::Environment &env);
+    void                            addToEnvironment(ProjectExplorer::Environment &env);
     inline bool                     isValid();
     inline int                      majorVersion();
     inline int                      minorVersion();
@@ -102,7 +101,6 @@ inline QString CeSdkHandler::fixPaths(QString path) const
     return QDir::toNativeSeparators(QDir::cleanPath(path.replace(VCINSTALL_MACRO, VCInstallDir).replace(VSINSTALL_MACRO, VSInstallDir).replace(QLatin1String(";$(PATH)"), QLatin1String(""))));
 }
 
-} // namespace Internal
 } // namespace Qt4ProjectManager
 
 #endif // CE_SDK_HANDLER_H
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index c62362c6ebe77d43c57e754efd78ac5ec93bb874..313d05916451e4a598cc92fd211198b9c7021e85 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -52,7 +52,8 @@ HEADERS += projectexplorer.h \
     removefiledialog.h \
     nodesvisitor.h \
     projectmodels.h \
-    currentprojectfind.h
+    currentprojectfind.h \
+    toolchain.h
 SOURCES += projectexplorer.cpp \
     projectwindow.cpp \
     buildmanager.cpp \
@@ -93,7 +94,8 @@ SOURCES += projectexplorer.cpp \
     removefiledialog.cpp \
     nodesvisitor.cpp \
     projectmodels.cpp \
-    currentprojectfind.cpp
+    currentprojectfind.cpp \
+    toolchain.cpp
 FORMS += dependenciespanel.ui \
     buildsettingspropertiespage.ui \
     processstep.ui \
diff --git a/src/plugins/projectexplorer/toolchain.cpp b/src/plugins/projectexplorer/toolchain.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..17280fb0855293c3a79a0ec67312ef166b1ca81b
--- /dev/null
+++ b/src/plugins/projectexplorer/toolchain.cpp
@@ -0,0 +1,326 @@
+#include "toolchain.h"
+#include "cesdkhandler.h"
+#include <QtCore/QFileInfo>
+#include <QtCore/QProcess>
+#include <QtCore/QDebug>
+#include <QtCore/QSettings>
+#include <QtCore/QDir>
+#include <QtCore/QTemporaryFile>
+#include <QtCore/QString>
+
+using namespace ProjectExplorer;
+using namespace ProjectExplorer::Internal;
+
+bool ToolChain::equals(ToolChain *a, ToolChain *b)
+{
+    if (a == b)
+        return true;
+    if (a == 0 || b == 0)
+        return false;
+    if (a->type() == b->type())
+        a->equals(b);
+}
+
+ToolChain::ToolChain()
+{
+}
+
+ToolChain::~ToolChain()
+{
+
+}
+
+ToolChain *ToolChain::createGccToolChain(const QString &gcc)
+{
+    return new GccToolChain(gcc);
+}
+
+ToolChain *ToolChain::createMinGWToolChain(const QString &gcc, const QString &mingwPath)
+{
+    return new MinGWToolChain(gcc, mingwPath);
+}
+
+ToolChain *ToolChain::createMSVCToolChain(const QString &name)
+{
+    return new MSVCToolChain(name);
+}
+
+ToolChain *ToolChain::createWinCEToolChain(const QString &name, const QString &platform)
+{
+    return new WinCEToolChain(name, platform);
+}
+
+QStringList ToolChain::availableMSVCVersions()
+{
+    QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
+                       QSettings::NativeFormat);
+    QStringList versions = registry.allKeys();
+    return versions;
+}
+
+GccToolChain::GccToolChain(const QString &gcc)
+    : m_gcc(gcc)
+{
+
+}
+
+ToolChain::ToolChainType GccToolChain::type() const
+{
+    return ToolChain::GCC;
+}
+
+QByteArray GccToolChain::predefinedMacros()
+{
+    if (m_predefinedMacros.isEmpty()) {
+        QStringList arguments;
+        arguments << QLatin1String("-xc++")
+                  << QLatin1String("-E")
+                  << QLatin1String("-dM")
+                  << QLatin1String("-");
+
+        QProcess cpp;
+        cpp.start(m_gcc, arguments);
+        cpp.closeWriteChannel();
+        cpp.waitForFinished();
+        m_predefinedMacros = cpp.readAllStandardOutput();
+    }
+    return m_predefinedMacros;
+}
+
+QList<HeaderPath> GccToolChain::systemHeaderPaths()
+{
+    if (m_systemHeaderPaths.isEmpty()) {
+        QStringList arguments;
+        arguments << QLatin1String("-xc++")
+                  << QLatin1String("-E")
+                  << QLatin1String("-v")
+                  << QLatin1String("-");
+
+        QProcess cpp;
+        cpp.setReadChannelMode(QProcess::MergedChannels);
+        cpp.start(m_gcc, arguments);
+        cpp.closeWriteChannel();
+        cpp.waitForFinished();
+
+        QByteArray line;
+        while (cpp.canReadLine()) {
+            line = cpp.readLine();
+            if (line.startsWith("#include"))
+                break;
+        }
+
+        if (! line.isEmpty() && line.startsWith("#include")) {
+            HeaderPath::Kind kind = HeaderPath::UserHeaderPath;
+            while (cpp.canReadLine()) {
+                line = cpp.readLine();
+                if (line.startsWith("#include")) {
+                    kind = HeaderPath::GlobalHeaderPath;
+                } else if (! line.isEmpty() && QChar(line.at(0)).isSpace()) {
+                    HeaderPath::Kind thisHeaderKind = kind;
+
+                    line = line.trimmed();
+                    if (line.endsWith('\n'))
+                        line.chop(1);
+
+                    int index = line.indexOf(" (framework directory)");
+                    if (index != -1) {
+                        line = line.left(index);
+                        thisHeaderKind = HeaderPath::FrameworkHeaderPath;
+                    }
+
+                    m_systemHeaderPaths.append(HeaderPath(QFile::decodeName(line), thisHeaderKind));
+                } else if (line.startsWith("End of search list.")) {
+                    break;
+                } else {
+                    qWarning() << "ignore line:" << line;
+                }
+            }
+        }
+    }
+    return m_systemHeaderPaths;
+}
+
+void GccToolChain::addToEnvironment(ProjectExplorer::Environment &env)
+{
+    Q_UNUSED(env)
+}
+
+bool GccToolChain::equals(ToolChain *other) const
+{
+    return (m_gcc == static_cast<GccToolChain *>(other)->m_gcc);
+}
+
+MinGWToolChain::MinGWToolChain(const QString &gcc, const QString &mingwPath)
+    : GccToolChain(gcc), m_mingwPath(mingwPath)
+{
+
+}
+
+ToolChain::ToolChainType MinGWToolChain::type() const
+{
+    return ToolChain::MinGW;
+}
+
+bool MinGWToolChain::equals(ToolChain *other) const
+{
+    MinGWToolChain *o = static_cast<MinGWToolChain *>(other);
+    return (m_mingwPath == o->m_mingwPath && this->GccToolChain::equals(other));
+}
+
+void MinGWToolChain::addToEnvironment(ProjectExplorer::Environment &env)
+{
+    QString binDir = m_mingwPath + "/bin";
+    if (QFileInfo(binDir).exists())
+        env.prependOrSetPath(binDir);
+}
+
+
+MSVCToolChain::MSVCToolChain(const QString &name)
+    : m_name(name), m_valuesSet(false)
+{
+
+}
+
+ToolChain::ToolChainType MSVCToolChain::type() const
+{
+    return ToolChain::MSVC;
+}
+
+bool MSVCToolChain::equals(ToolChain *other) const
+{
+    MSVCToolChain *o = static_cast<MSVCToolChain *>(other);
+    return (m_name == o->m_name);
+}
+
+QByteArray MSVCToolChain::predefinedMacros()
+{
+    return  "#define __WIN32__\n"
+            "#define __WIN32\n"
+            "#define _WIN32\n"
+            "#define WIN32\n"
+            "#define __WINNT__\n"
+            "#define __WINNT\n"
+            "#define WINNT\n"
+            "#define _X86_\n"
+            "#define __MSVCRT__\n";
+}
+
+QList<HeaderPath> MSVCToolChain::systemHeaderPaths()
+{
+    //TODO fix this code
+    ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
+    addToEnvironment(env);
+#ifdef QTCREATOR_WITH_MSVC_INCLUDES
+    return env.value("INCLUDE").split(QLatin1Char(';'));
+#endif
+    return QList<HeaderPath>();
+}
+
+void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
+{
+    if (!m_valuesSet) {
+        QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
+                       QSettings::NativeFormat);
+        QString path = registry.value(m_name).toString();
+        ProjectExplorer::Environment oldEnv(env);
+        QString desc;
+        QString varsbat = path + "Common7\\Tools\\vsvars32.bat";
+        if (QFileInfo(varsbat).exists()) {
+            QTemporaryFile tf(QDir::tempPath() + "\\XXXXXX.bat");
+            if (!tf.open())
+                return;
+            QString filename = tf.fileName();
+            tf.write("call \"" + varsbat.toLocal8Bit()+"\"\r\n");
+            tf.write(("set > \"" + QDir::tempPath() + "\\qtcreator-msvc-environment.txt\"\r\n").toLocal8Bit());
+            tf.flush();
+            tf.waitForBytesWritten(30000);
+
+            QProcess run;
+            QString cmdPath = env.searchInPath("cmd");
+            run.start(cmdPath, QStringList()<<"/c"<<filename);
+            run.waitForFinished();
+            tf.close();
+
+            QFile vars(QDir::tempPath() + "\\qtcreator-msvc-environment.txt");
+            if (vars.exists() && vars.open(QIODevice::ReadOnly)) {
+                while (!vars.atEnd()) {
+                    QByteArray line = vars.readLine();
+                    QString line2 = QString::fromLocal8Bit(line);
+                    line2 = line2.trimmed();
+                    QRegExp regexp("(\\w*)=(.*)");
+                    if (regexp.exactMatch(line2)) {
+                        QString variable = regexp.cap(1);
+                        QString value = regexp.cap(2);
+                        value.replace('%' + variable + '%', oldEnv.value(variable));
+                        m_values.append(QPair<QString, QString>(variable, value));
+
+                    }
+                }
+                vars.close();
+                vars.remove();
+            }
+        }
+        m_valuesSet = true;
+    }
+
+    QList< QPair<QString, QString> >::const_iterator it, end;
+    end = m_values.constEnd();
+    for (it = m_values.constBegin(); it != end; ++it) {
+        env.set((*it).first, (*it).second);
+        qDebug()<<"variable:"<<(*it).first<<"value:"<<(*it).second;
+    }
+
+}
+
+WinCEToolChain::WinCEToolChain(const QString &name, const QString &platform)
+    : MSVCToolChain(name), m_platform(platform)
+{
+
+}
+
+ToolChain::ToolChainType WinCEToolChain::type() const
+{
+    return ToolChain::WINCE;
+}
+
+bool WinCEToolChain::equals(ToolChain *other) const
+{
+    WinCEToolChain *o = static_cast<WinCEToolChain *>(other);
+    return (m_platform == o->m_platform && this->MSVCToolChain::equals(other));
+}
+
+QByteArray WinCEToolChain::predefinedMacros()
+{
+    //TODO
+    return MSVCToolChain::predefinedMacros();
+}
+
+QList<HeaderPath> WinCEToolChain::systemHeaderPaths()
+{
+    //TODO fix this code
+    ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
+    addToEnvironment(env);
+#ifdef QTCREATOR_WITH_MSVC_INCLUDES
+    return env.value("INCLUDE").split(QLatin1Char(';'));
+#endif
+}
+
+void WinCEToolChain::addToEnvironment(ProjectExplorer::Environment &env)
+{
+    MSVCToolChain::addToEnvironment(env);
+    QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
+                       QSettings::NativeFormat);
+    QString path = registry.value(m_name).toString();
+    // Find MSVC path
+
+    path += "/";
+
+//        qDebug()<<"MSVC path"<<msvcPath;
+//        qDebug()<<"looking for platform name in"<< path() + "/mkspecs/" + mkspec() +"/qmake.conf";
+    // Find Platform name
+//        qDebug()<<"Platform Name"<<platformName;
+
+    CeSdkHandler cesdkhandler;
+    cesdkhandler.parse(path);
+    cesdkhandler.find(m_platform).addToEnvironment(env);
+}
diff --git a/src/plugins/projectexplorer/toolchain.h b/src/plugins/projectexplorer/toolchain.h
new file mode 100644
index 0000000000000000000000000000000000000000..455d480b8606ddba7615d66048d0df059e4b5fd4
--- /dev/null
+++ b/src/plugins/projectexplorer/toolchain.h
@@ -0,0 +1,135 @@
+#ifndef TOOLCHAIN_H
+#define TOOLCHAIN_H
+
+#include "environment.h"
+#include <QtCore/QString>
+#include <QtCore/QPair>
+
+namespace ProjectExplorer {
+
+class PROJECTEXPLORER_EXPORT HeaderPath
+{
+public:
+    enum Kind {
+        GlobalHeaderPath,
+        UserHeaderPath,
+        FrameworkHeaderPath
+    };
+
+    HeaderPath()
+        : _kind(GlobalHeaderPath)
+    { }
+
+    HeaderPath(const QString &path, Kind kind)
+        : _path(path), _kind(kind)
+    { }
+
+    QString path() const { return _path; }
+    Kind    kind() const { return _kind; }
+
+private:
+    QString _path;
+    Kind _kind;
+};
+
+
+
+class PROJECTEXPLORER_EXPORT ToolChain
+{
+public:
+    enum ToolChainType
+    {
+        GCC,
+        MinGW,
+        MSVC,
+        WINCE,
+        OTHER,
+        INVALID
+    };
+
+    virtual QByteArray predefinedMacros() = 0;
+    virtual QList<HeaderPath> systemHeaderPaths() = 0;
+    virtual void addToEnvironment(ProjectExplorer::Environment &env) = 0;
+    virtual ToolChainType type() const = 0;
+
+    ToolChain();
+    virtual ~ToolChain();
+    
+    static bool equals(ToolChain *, ToolChain *);
+    static ToolChain *createGccToolChain(const QString &gcc);
+    static ToolChain *createMinGWToolChain(const QString &gcc, const QString &mingwPath);
+    static ToolChain *createMSVCToolChain(const QString &name);
+    static ToolChain *createWinCEToolChain(const QString &name, const QString &platform);
+    static QStringList availableMSVCVersions();
+
+protected:
+    virtual bool equals(ToolChain *other) const = 0;
+};
+
+namespace Internal {
+class GccToolChain : public ToolChain
+{
+public:
+    GccToolChain(const QString &gcc);
+    virtual QByteArray predefinedMacros();
+    virtual QList<HeaderPath> systemHeaderPaths();
+    virtual void addToEnvironment(ProjectExplorer::Environment &env);
+    virtual ToolChainType type() const;
+
+protected:
+    virtual bool equals(ToolChain *other) const;
+private:
+    QString m_gcc;
+    QByteArray m_predefinedMacros;
+    QList<HeaderPath> m_systemHeaderPaths;
+};
+
+// TODO this class needs to fleshed out more
+class MinGWToolChain : public GccToolChain
+{
+public:
+    MinGWToolChain(const QString &gcc, const QString &mingwPath);
+    virtual void addToEnvironment(ProjectExplorer::Environment &env);
+    virtual ToolChainType type() const;
+protected:
+    virtual bool equals(ToolChain *other) const;
+private:
+    QString m_mingwPath;
+};
+
+// TODO some stuff needs to be moved into this
+class MSVCToolChain : public ToolChain
+{
+public:
+    MSVCToolChain(const QString &name);
+    virtual QByteArray predefinedMacros();
+    virtual QList<HeaderPath> systemHeaderPaths();
+    virtual void addToEnvironment(ProjectExplorer::Environment &env);
+    virtual ToolChainType type() const;
+protected:
+    virtual bool equals(ToolChain *other) const;
+    QString m_name;
+private:
+    mutable QList<QPair<QString, QString> > m_values;
+    mutable bool m_valuesSet;
+};
+
+// TODO some stuff needs to be moved into here
+class WinCEToolChain : public MSVCToolChain
+{
+public:
+    WinCEToolChain(const QString &name, const QString &platform);
+    virtual QByteArray predefinedMacros();
+    virtual QList<HeaderPath> systemHeaderPaths();
+    virtual void addToEnvironment(ProjectExplorer::Environment &env);
+    virtual ToolChainType type() const;
+protected:
+    virtual bool equals(ToolChain *other) const;
+private:
+    QString m_platform;
+};
+
+}
+}
+
+#endif // TOOLCHAIN_H
diff --git a/src/plugins/qt4projectmanager/gccpreprocessor.cpp b/src/plugins/qt4projectmanager/gccpreprocessor.cpp
deleted file mode 100644
index 4ceef15c0531d84188b18f51cc932981fcb9e303..0000000000000000000000000000000000000000
--- a/src/plugins/qt4projectmanager/gccpreprocessor.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/***************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact:  Qt Software Information (qt-info@nokia.com)
-**
-**
-** Non-Open Source Usage
-**
-** Licensees may use this file in accordance with the Qt Beta Version
-** License Agreement, Agreement version 2.2 provided with the Software or,
-** alternatively, in accordance with the terms contained in a written
-** agreement between you and Nokia.
-**
-** GNU General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License versions 2.0 or 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 GNU
-** General Public Licensing requirements will be met:
-**
-** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt GPL Exception
-** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
-**
-***************************************************************************/
-
-#include "gccpreprocessor.h"
-
-#include <QProcess>
-#include <QString>
-#include <QFile>
-#include <QtDebug>
-
-using namespace Qt4ProjectManager::Internal;
-
-GCCPreprocessor::GCCPreprocessor(const QString &gcc)
-    : m_gcc(gcc)
-{ }
-
-GCCPreprocessor::~GCCPreprocessor()
-{ }
-
-void GCCPreprocessor::setGcc(const QString &gcc)
-{
-    if (m_gcc == gcc)
-        return;
-    m_gcc = gcc;
-    m_predefinedMacros.clear();;
-    m_systemHeaderPaths.clear();;
-}
-
-QByteArray GCCPreprocessor::predefinedMacros()
-{
-    if (m_predefinedMacros.isEmpty()) {
-        QStringList arguments;
-        arguments << QLatin1String("-xc++")
-                  << QLatin1String("-E")
-                  << QLatin1String("-dM")
-                  << QLatin1String("-");
-
-        QProcess cpp;
-        cpp.start(m_gcc, arguments);
-        cpp.closeWriteChannel();
-        cpp.waitForFinished();
-        m_predefinedMacros = cpp.readAllStandardOutput();
-    }
-    return m_predefinedMacros;
-}
-
-QList<HeaderPath> GCCPreprocessor::systemHeaderPaths()
-{
-    if (m_systemHeaderPaths.isEmpty()) {
-        QStringList arguments;
-        arguments << QLatin1String("-xc++")
-                  << QLatin1String("-E")
-                  << QLatin1String("-v")
-                  << QLatin1String("-");
-
-        QProcess cpp;
-        cpp.setReadChannelMode(QProcess::MergedChannels);
-        cpp.start(m_gcc, arguments);
-        cpp.closeWriteChannel();
-        cpp.waitForFinished();
-
-        QByteArray line;
-        while (cpp.canReadLine()) {
-            line = cpp.readLine();
-            if (line.startsWith("#include"))
-                break;
-        }
-
-        if (! line.isEmpty() && line.startsWith("#include")) {
-            HeaderPath::Kind kind = HeaderPath::UserHeaderPath;
-            while (cpp.canReadLine()) {
-                line = cpp.readLine();
-                if (line.startsWith("#include")) {
-                    kind = HeaderPath::GlobalHeaderPath;
-                } else if (! line.isEmpty() && QChar(line.at(0)).isSpace()) {
-                    HeaderPath::Kind thisHeaderKind = kind;
-
-                    line = line.trimmed();
-                    if (line.endsWith('\n'))
-                        line.chop(1);
-
-                    int index = line.indexOf(" (framework directory)");
-                    if (index != -1) {
-                        line = line.left(index);
-                        thisHeaderKind = HeaderPath::FrameworkHeaderPath;
-                    }
-
-                    m_systemHeaderPaths.append(HeaderPath(QFile::decodeName(line), thisHeaderKind));
-                } else if (line.startsWith("End of search list.")) {
-                    break;
-                } else {
-                    qWarning() << "ignore line:" << line;
-                }
-            }
-        }
-    }
-    return m_systemHeaderPaths;
-}
diff --git a/src/plugins/qt4projectmanager/gccpreprocessor.h b/src/plugins/qt4projectmanager/gccpreprocessor.h
deleted file mode 100644
index 5ca59856e039f7889fa036d78105b233c7858eeb..0000000000000000000000000000000000000000
--- a/src/plugins/qt4projectmanager/gccpreprocessor.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/***************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact:  Qt Software Information (qt-info@nokia.com)
-**
-**
-** Non-Open Source Usage
-**
-** Licensees may use this file in accordance with the Qt Beta Version
-** License Agreement, Agreement version 2.2 provided with the Software or,
-** alternatively, in accordance with the terms contained in a written
-** agreement between you and Nokia.
-**
-** GNU General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License versions 2.0 or 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 GNU
-** General Public Licensing requirements will be met:
-**
-** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt GPL Exception
-** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
-**
-***************************************************************************/
-
-#ifndef GCCPREPROCESSOR_H
-#define GCCPREPROCESSOR_H
-
-#include "headerpath.h"
-#include <QByteArray>
-#include <QList>
-
-namespace Qt4ProjectManager {
-namespace Internal {
-
-class GCCPreprocessor
-{
-public:
-    GCCPreprocessor(const QString &gcc = QLatin1String("g++"));
-    ~GCCPreprocessor();
-
-    void setGcc(const QString &gcc);
-    QByteArray predefinedMacros();
-    QList<HeaderPath> systemHeaderPaths();
-
-private:
-    QString m_gcc;
-    QByteArray m_predefinedMacros;
-    QList<HeaderPath> m_systemHeaderPaths;
-};
-
-} // namespace Internal
-} // namespace Qt4ProjectManager
-
-#endif // GCCPREPROCESSOR_H
diff --git a/src/plugins/qt4projectmanager/headerpath.h b/src/plugins/qt4projectmanager/headerpath.h
deleted file mode 100644
index 46ea6095df8e886281bcaa6fbb2967a6e22f5f46..0000000000000000000000000000000000000000
--- a/src/plugins/qt4projectmanager/headerpath.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/***************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact:  Qt Software Information (qt-info@nokia.com)
-**
-**
-** Non-Open Source Usage
-**
-** Licensees may use this file in accordance with the Qt Beta Version
-** License Agreement, Agreement version 2.2 provided with the Software or,
-** alternatively, in accordance with the terms contained in a written
-** agreement between you and Nokia.
-**
-** GNU General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License versions 2.0 or 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 GNU
-** General Public Licensing requirements will be met:
-**
-** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt GPL Exception
-** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
-**
-***************************************************************************/
-
-#ifndef HEADERPATH_H
-#define HEADERPATH_H
-
-#include <QString>
-
-namespace Qt4ProjectManager {
-namespace Internal {
-
-class HeaderPath
-{
-public:
-    enum Kind {
-        GlobalHeaderPath,
-        UserHeaderPath,
-        FrameworkHeaderPath
-    };
-
-    HeaderPath()
-        : _kind(GlobalHeaderPath)
-    { }
-
-    HeaderPath(const QString &path, Kind kind)
-        : _path(path), _kind(kind)
-    { }
-
-    QString path() const { return _path; }
-    Kind    kind() const { return _kind; }
-
-private:
-    QString _path;
-    Kind _kind;
-};
-
-} // namespace Internal
-} // namespace Qt4ProjectManager
-
-
-#endif // HEADERPATH_H
diff --git a/src/plugins/qt4projectmanager/makestep.cpp b/src/plugins/qt4projectmanager/makestep.cpp
index 34d4a7e881fa9302855cc9802209c4294f2981e5..8e6eb1542d62a6420d2c59e6fa73ef8651508f9b 100644
--- a/src/plugins/qt4projectmanager/makestep.cpp
+++ b/src/plugins/qt4projectmanager/makestep.cpp
@@ -69,8 +69,8 @@ MakeStep::~MakeStep()
 ProjectExplorer::BuildParserInterface *MakeStep::buildParser(const QtVersion * const version)
 {
     QString buildParser;
-    QtVersion::ToolchainType type = version->toolchainType();
-    if ( type == QtVersion::MSVC || type == QtVersion::WINCE)
+    ProjectExplorer::ToolChain::ToolChainType type = version->toolchainType();
+    if ( type == ProjectExplorer::ToolChain::MSVC || type == ProjectExplorer::ToolChain::WINCE)
         buildParser = Constants::BUILD_PARSER_MSVC;
     else
         buildParser = Constants::BUILD_PARSER_GCC;
@@ -129,8 +129,8 @@ bool MakeStep::init(const QString &name)
     // FIXME doing this without the user having a way to override this is rather bad
     // so we only do it for unix and if the user didn't override the make command
     // but for now this is the least invasive change
-    QtVersion::ToolchainType t =  qobject_cast<Qt4Project *>(project())->qtVersion(name)->toolchainType();
-    if (t != QtVersion::MSVC && t != QtVersion::WINCE) {
+    ProjectExplorer::ToolChain::ToolChainType t =  qobject_cast<Qt4Project *>(project())->qtVersion(name)->toolchainType();
+    if (t != ProjectExplorer::ToolChain::MSVC && t != ProjectExplorer::ToolChain::WINCE) {
         if (value(name, "makeCmd").toString().isEmpty())
             args << "-w";
     }
diff --git a/src/plugins/qt4projectmanager/msvcenvironment.cpp b/src/plugins/qt4projectmanager/msvcenvironment.cpp
deleted file mode 100644
index ebe54104f8d9071c017824100ef8413c5a21a165..0000000000000000000000000000000000000000
--- a/src/plugins/qt4projectmanager/msvcenvironment.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/***************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact:  Qt Software Information (qt-info@nokia.com)
-**
-**
-** Non-Open Source Usage
-**
-** Licensees may use this file in accordance with the Qt Beta Version
-** License Agreement, Agreement version 2.2 provided with the Software or,
-** alternatively, in accordance with the terms contained in a written
-** agreement between you and Nokia.
-**
-** GNU General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License versions 2.0 or 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 GNU
-** General Public Licensing requirements will be met:
-**
-** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt GPL Exception
-** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
-**
-***************************************************************************/
-
-#include "msvcenvironment.h"
-
-#include <QtCore/QDebug>
-#include <QtCore/QFile>
-#include <QtCore/QProcess>
-#include <QtCore/QRegExp>
-#include <QtCore/QSettings>
-#include <QtCore/QStringList>
-#include <QtCore/QTemporaryFile>
-
-using namespace Qt4ProjectManager::Internal;
-using ProjectExplorer::Environment;
-
-MSVCEnvironment::MSVCEnvironment(const QString &name, const QString &path)
-    : m_name(name), m_path(path), m_valuesSet(false)
-{
-
-}
-
-QString MSVCEnvironment::name() const
-{
-    return m_name;
-}
-
-QString MSVCEnvironment::path() const
-{
-    return m_path;
-}
-
-QList<MSVCEnvironment> MSVCEnvironment::availableVersions()
-{
-    QList<MSVCEnvironment> result;
-
-    QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7", 
-                       QSettings::NativeFormat);
-    QStringList versions = registry.allKeys();
-    foreach (const QString &version, versions) {
-        QString dir = registry.value(version).toString();
-        result << MSVCEnvironment(version, dir);
-    }
-    return result;
-}
-
-QString MSVCEnvironment::description() const
-{
-    QString desc;
-    desc = "Microsoft Visual Studio " + m_name + " from " + m_path;
-    return desc;
-}
-
-// This method is ugly as hell, but that is to be expected
-// It crates a temporary batch file which first runs vsvars32.bat from MSVC
-// and then runs *set* to get the environment
-// We cache that information.
-Environment MSVCEnvironment::addToEnvironment(const Environment &env) const
-{
-    Environment e(env);
-    if (!m_valuesSet) {
-        QString desc;
-        QString varsbat = m_path + "Common7\\Tools\\vsvars32.bat";
-        if (QFileInfo(varsbat).exists()) {
-            QTemporaryFile tf(QDir::tempPath() + "\\XXXXXX.bat");
-            if (!tf.open())
-                return e;
-            QString filename = tf.fileName();
-            tf.write("call \"" + varsbat.toLocal8Bit()+"\"\r\n");
-            tf.write(("set > \"" + QDir::tempPath() + "\\qtcreator-msvc-environment.txt\"\r\n").toLocal8Bit());
-            tf.flush();
-            tf.waitForBytesWritten(30000);
-
-            QProcess run;
-            QString cmdPath = e.searchInPath("cmd");
-            run.start(cmdPath, QStringList()<<"/c"<<filename);
-            run.waitForFinished();
-            tf.close();
-
-            QFile vars(QDir::tempPath() + "\\qtcreator-msvc-environment.txt");
-            if (vars.exists() && vars.open(QIODevice::ReadOnly)) {
-                while (!vars.atEnd()) {
-                    QByteArray line = vars.readLine();
-                    QString line2 = QString::fromLocal8Bit(line);
-                    line2 = line2.trimmed();
-                    QRegExp regexp("(\\w*)=(.*)");
-                    if (regexp.exactMatch(line2)) {
-                        QString variable = regexp.cap(1);
-                        QString value = regexp.cap(2);
-                        value.replace('%' + variable + '%', e.value(variable));
-                        m_values.append(QPair<QString, QString>(variable, value));
-
-                    }
-                }
-                vars.close();
-                vars.remove();
-            }
-        }
-        m_valuesSet = true;
-    }
-
-    QList< QPair<QString, QString> >::const_iterator it, end;
-    end = m_values.constEnd();
-    for (it = m_values.constBegin(); it != end; ++it) {
-        e.set((*it).first, (*it).second);
-        qDebug()<<"variable:"<<(*it).first<<"value:"<<(*it).second;
-    }
-
-
-//    QFile varsbat(m_path + "Common7\\Tools\\vsvars32.bat");
-//    if (varsbat.exists() && varsbat.open(QIODevice::ReadOnly)) {
-//        while (!varsbat.atEnd()) {
-//            QByteArray line = varsbat.readLine();
-//            QString line2 = QString::fromLocal8Bit(line);
-//            line2 = line2.trimmed();
-//            QRegExp regexp("\\s*@?(S|s)(E|e)(T|t)\\s*(\\w*)=(.*)");
-//            if (regexp.exactMatch(line2)) {
-//                QString variable = regexp.cap(4);
-//                QString value = regexp.cap(5);
-//                value.replace('%' + variable + '%', e.value(variable));
-//                e.set(variable, value);
-//            }
-//        }
-//        varsbat.close();
-//    }
-
-    return e;
-}
diff --git a/src/plugins/qt4projectmanager/msvcenvironment.h b/src/plugins/qt4projectmanager/msvcenvironment.h
deleted file mode 100644
index c7d7729a99c11868988bbade940a14b6ea577558..0000000000000000000000000000000000000000
--- a/src/plugins/qt4projectmanager/msvcenvironment.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/***************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact:  Qt Software Information (qt-info@nokia.com)
-**
-**
-** Non-Open Source Usage
-**
-** Licensees may use this file in accordance with the Qt Beta Version
-** License Agreement, Agreement version 2.2 provided with the Software or,
-** alternatively, in accordance with the terms contained in a written
-** agreement between you and Nokia.
-**
-** GNU General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License versions 2.0 or 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 GNU
-** General Public Licensing requirements will be met:
-**
-** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt GPL Exception
-** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
-**
-***************************************************************************/
-
-#ifndef MSVCENVIRONMENT_H
-#define MSVCENVIRONMENT_H
-
-#include <QtCore/QString>
-#include <QtCore/QList>
-
-#include <projectexplorer/projectexplorer.h>
-
-namespace Qt4ProjectManager {
-namespace Internal {
-
-class MSVCEnvironment
-{    
-public:
-    QString name() const;
-    QString path() const;
-    ProjectExplorer::Environment addToEnvironment(const ProjectExplorer::Environment &env) const;
-    QString description() const;
-
-    static QList<MSVCEnvironment> availableVersions();
-private:
-
-    MSVCEnvironment(const QString &name, const QString &path);
-    QString m_name;
-    QString m_path;
-    mutable QList<QPair<QString, QString> > m_values;
-    mutable bool m_valuesSet;
-};
-
-} // namespace Internal
-} // namespace Qt4ProjectManager
-
-#endif // MSVCENVIRONMENT_H
diff --git a/src/plugins/qt4projectmanager/qmakestep.ui b/src/plugins/qt4projectmanager/qmakestep.ui
index df5fb98e39342e87c48a6720f8df3e87be0de0b6..5d2871a90cc9aa922f3d4d073bba5fb91a765e3d 100644
--- a/src/plugins/qt4projectmanager/qmakestep.ui
+++ b/src/plugins/qt4projectmanager/qmakestep.ui
@@ -75,7 +75,7 @@
        <item>
         <widget class="QLabel" name="label">
          <property name="text">
-          <string>Arguments:</string>
+          <string>Effective qmake call:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@@ -84,6 +84,9 @@
        </item>
        <item>
         <widget class="QPlainTextEdit" name="qmakeArgumentsEdit">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
          <property name="maximumSize">
           <size>
            <width>16777215</width>
diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp
index 9885221c0c4e2fdc45519d7d12bf72a424caa9e2..6a27c484b808dc19d8c066fe8fdaeb15daf2d765 100644
--- a/src/plugins/qt4projectmanager/qt4project.cpp
+++ b/src/plugins/qt4projectmanager/qt4project.cpp
@@ -231,6 +231,7 @@ void Qt4ProjectFile::modified(Core::IFile::ReloadBehavior *)
   */
 
 Qt4Project::Qt4Project(Qt4Manager *manager, const QString& fileName) :
+    m_toolChain(0),
     m_manager(manager),
     m_rootProjectNode(new Qt4ProFileNode(this, fileName, this)),
     m_nodesWatcher(new Internal::Qt4NodesWatcher(this)),
@@ -265,6 +266,7 @@ Qt4Project::~Qt4Project()
 {
     m_manager->unregisterProject(this);
     delete m_projectFiles;
+    delete m_toolChain;
 }
 
 void Qt4Project::defaultQtVersionChanged()
@@ -400,6 +402,41 @@ void Qt4Project::scheduleUpdateCodeModel()
     m_updateCodeModelTimer.start();
 }
 
+ProjectExplorer::ToolChain *Qt4Project::toolChain(const QString &buildConfiguration) const
+{
+    Q_UNUSED(buildConfiguration);
+    ToolChain *m_test;
+    QtVersion *version = qtVersion(activeBuildConfiguration());
+    ToolChain::ToolChainType t = version->toolchainType();
+    if (t == ToolChain::MinGW) {
+        QStringList list = rootProjectNode()->variableValue(Internal::CxxCompilerVar);
+        QString qmake_cxx = list.isEmpty() ? QString::null : list.first();
+        Environment env = Environment::systemEnvironment();
+        qtVersion(activeBuildConfiguration())->addToEnvironment(env);
+        qmake_cxx = env.searchInPath(qmake_cxx);
+        m_test = ToolChain::createMinGWToolChain(qmake_cxx, version->mingwDirectory());
+    } else if(t == ToolChain::MSVC) {
+        m_test = ToolChain::createMSVCToolChain(version->msvcVersion());
+    } else if(t == ToolChain::WINCE) {
+        m_test = ToolChain::createWinCEToolChain(version->msvcVersion(), version->wincePlatform());
+    } else if(t == ToolChain::GCC) {
+        QStringList list = rootProjectNode()->variableValue(Internal::CxxCompilerVar);
+        QString qmake_cxx = list.isEmpty() ? QString::null : list.first();
+        Environment env = Environment::systemEnvironment();
+        qtVersion(activeBuildConfiguration())->addToEnvironment(env);
+        qmake_cxx = env.searchInPath(qmake_cxx);
+        m_test = ToolChain::createGccToolChain(qmake_cxx);
+    }
+
+    if (m_test == m_toolChain) {
+        delete m_test;
+    } else {
+        delete m_toolChain;
+        m_toolChain = m_test;
+    }
+    return m_toolChain;
+}
+
 void Qt4Project::updateCodeModel()
 {
     if (debug)
@@ -419,40 +456,17 @@ void Qt4Project::updateCodeModel()
     const QString newQtIncludePath = versionInfo.value(QLatin1String("QT_INSTALL_HEADERS"));
     const QString newQtLibsPath = versionInfo.value(QLatin1String("QT_INSTALL_LIBS"));
 
-    QByteArray predefinedMacros;
-    QtVersion::ToolchainType t = qtVersion(activeBuildConfiguration())->toolchainType();
-    if (t == QtVersion::MinGW || t == QtVersion::OTHER) {
-        QStringList list = rootProjectNode()->variableValue(Internal::CxxCompilerVar);
-        QString qmake_cxx = list.isEmpty() ? QString::null : list.first();
-        qmake_cxx = environment(activeBuildConfiguration()).searchInPath(qmake_cxx);
-        m_preproc.setGcc(qmake_cxx);
-        predefinedMacros = m_preproc.predefinedMacros();
-        foreach (HeaderPath headerPath, m_preproc.systemHeaderPaths()) {
-            if (headerPath.kind() == HeaderPath::FrameworkHeaderPath)
-                allFrameworkPaths.append(headerPath.path());
-            else
-                allIncludePaths.append(headerPath.path());
-        }
-
-    } else if (t == QtVersion::MSVC || t == QtVersion::WINCE) {
-#ifdef QTCREATOR_WITH_MSVC_INCLUDES
-        Environment env = environment(activeBuildConfiguration());
-        allIncludePaths.append(env.value("INCLUDE").split(QLatin1Char(';')));
-#endif
-        predefinedMacros +=
-                "#define __WIN32__\n"
-                "#define __WIN32\n"
-                "#define _WIN32\n"
-                "#define WIN32\n"
-                "#define __WINNT__\n"
-                "#define __WINNT\n"
-                "#define WINNT\n"
-                "#define _X86_\n"
-                "#define __MSVCRT__\n";
+    ToolChain *tc = toolChain(activeBuildConfiguration());
+    QByteArray predefinedMacros = tc->predefinedMacros();
+    QList<HeaderPath> allHeaderPaths = tc->systemHeaderPaths();
+    foreach (HeaderPath headerPath, allHeaderPaths) {
+        if (headerPath.kind() == HeaderPath::FrameworkHeaderPath)
+            allFrameworkPaths.append(headerPath.path());
+        else
+            allIncludePaths.append(headerPath.path());
     }
 
     allIncludePaths.append(newQtIncludePath);
-
     QDir dir(newQtIncludePath);
     foreach (QFileInfo info, dir.entryInfoList(QDir::Dirs)) {
         if (! info.fileName().startsWith(QLatin1String("Qt")))
@@ -681,7 +695,8 @@ Qt4ProFileNode *Qt4Project::rootProjectNode() const
 ProjectExplorer::Environment Qt4Project::baseEnvironment(const QString &buildConfiguration) const
 {
     Environment env = useSystemEnvironment(buildConfiguration) ? Environment(QProcess::systemEnvironment()) : Environment();
-    env = qtVersion(buildConfiguration)->addToEnvironment(env);
+    qtVersion(buildConfiguration)->addToEnvironment(env);
+    toolChain(buildConfiguration)->addToEnvironment(env);
     return env;
 }
 
diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h
index 0c4a5fb57dcaf1ebe9b8edcab745c0957c39fb6a..1c0ed3435994140075aa5c9eee714bf507a0b098 100644
--- a/src/plugins/qt4projectmanager/qt4project.h
+++ b/src/plugins/qt4projectmanager/qt4project.h
@@ -36,13 +36,13 @@
 
 #include "qtversionmanager.h"
 #include "qt4nodes.h"
-#include "gccpreprocessor.h"
 #include "qmakestep.h"
 #include "makestep.h"
 
 #include <coreplugin/ifile.h>
 #include <projectexplorer/applicationrunconfiguration.h>
 #include <projectexplorer/projectnodes.h>
+#include <projectexplorer/toolchain.h>
 
 #include <QtCore/QObject>
 #include <QtCore/QList>
@@ -214,6 +214,10 @@ private:
     static void findProFile(const QString& fileName, Internal::Qt4ProFileNode *root, QList<Internal::Qt4ProFileNode *> &list);
     static bool hasSubNode(Internal::Qt4PriFileNode *root, const QString &path);
 
+    ProjectExplorer::ToolChain *toolChain(const QString &buildConfiguration) const;
+    mutable ProjectExplorer::ToolChain *m_toolChain;
+
+
     QList<Internal::Qt4ProFileNode *> m_applicationProFileChange;
     ProjectExplorer::ProjectExplorerPlugin *projectExplorer() const;
 
@@ -238,7 +242,6 @@ private:
     QTimer m_updateCodeModelTimer;
     QTimer m_addUiFilesTimer;
     QStringList m_uiFilesToAdd;
-    Internal::GCCPreprocessor m_preproc;
 
     friend class Qt4ProjectFile;
 };
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index 4cb8ff322b52a1741919f064876554ff4177e66a..5e18e1f9d483f888d5287af1446be66f8409777e 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -32,13 +32,9 @@ HEADERS = qt4projectmanagerplugin.h \
     msvcparser.h \
     buildparserfactory.h \
     deployhelper.h \
-    msvcenvironment.h \
-    cesdkhandler.h \
     embeddedpropertiespage.h \
     qt4runconfiguration.h \
     speinfo.h \
-    headerpath.h \
-    gccpreprocessor.h \
     qt4buildconfigwidget.h \
     qt4buildenvironmentwidget.h \
     projectloadwizard.h \
@@ -71,12 +67,9 @@ SOURCES = qt4projectmanagerplugin.cpp \
     msvcparser.cpp \
     buildparserfactory.cpp \
     deployhelper.cpp \
-    msvcenvironment.cpp \
-    cesdkhandler.cpp \
     embeddedpropertiespage.cpp \
     qt4runconfiguration.cpp \
     speinfo.cpp \
-    gccpreprocessor.cpp \
     qt4buildconfigwidget.cpp \
     qt4buildenvironmentwidget.cpp \
     projectloadwizard.cpp \
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp
index 780de4ebc6585db60c4a3e934e1c5817ea1139bd..8abc994e919e2047d386cbbde1b5dfb7ecdaa1d0 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.cpp
+++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp
@@ -34,12 +34,12 @@
 #include "qtversionmanager.h"
 
 #include "qt4projectmanagerconstants.h"
-#include "msvcenvironment.h"
-#include "cesdkhandler.h"
 
 #include <coreplugin/icore.h>
 #include <coreplugin/coreconstants.h>
 #include <extensionsystem/pluginmanager.h>
+#include <projectexplorer/cesdkhandler.h>
+#include <projectexplorer/toolchain.h>
 #include <help/helpplugin.h>
 #include <utils/qtcassert.h>
 
@@ -495,35 +495,36 @@ void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
     if (item) {
         int index = m_ui.qtdirList->indexOfTopLevelItem(item);
         m_ui.errorLabel->setText("");
-        QtVersion::ToolchainType t = m_versions.at(index)->toolchainType();
-        if (t == QtVersion::MinGW) {
+        ProjectExplorer::ToolChain::ToolChainType t = m_versions.at(index)->toolchainType();
+        if (t == ProjectExplorer::ToolChain::MinGW) {
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(false);
             makeMingwVisible(true);
             m_ui.mingwPath->setPath(m_versions.at(index)->mingwDirectory());
-        } else if (t == QtVersion::MSVC || t == QtVersion::WINCE){
+        } else if (t == ProjectExplorer::ToolChain::MSVC || t == ProjectExplorer::ToolChain::WINCE){
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(true);
             makeMingwVisible(false);
-            QList<MSVCEnvironment> msvcenvironments = MSVCEnvironment::availableVersions();
-            if (msvcenvironments.count() == 0) {
+            QStringList msvcEnvironments = ProjectExplorer::ToolChain::availableMSVCVersions();
+            if (msvcEnvironments.count() == 0) {
                 m_ui.msvcLabel->setText(tr("No Visual Studio Installation found"));
-            } else if (msvcenvironments.count() == 1) {
-                m_ui.msvcLabel->setText( msvcenvironments.at(0).description());
+            } else if (msvcEnvironments.count() == 1) {
+                //TODO m_ui.msvcLabel->setText( msvcEnvironments.at(0).description());
+                m_ui.msvcLabel->setText("");
             } else {
                  m_ui.msvcComboBox->setVisible(true);
                  m_ui.msvcComboBox->clear();
                  bool block = m_ui.msvcComboBox->blockSignals(true);
-                 foreach(const MSVCEnvironment msvcenv, msvcenvironments) {
-                     m_ui.msvcComboBox->addItem(msvcenv.name());
-                     if (msvcenv.name() == m_versions.at(index)->msvcVersion()) {
+                 foreach(const QString &msvcenv, msvcEnvironments) {
+                     m_ui.msvcComboBox->addItem(msvcenv);
+                     if (msvcenv == m_versions.at(index)->msvcVersion()) {
                          m_ui.msvcComboBox->setCurrentIndex(m_ui.msvcComboBox->count() - 1);
-                         m_ui.msvcLabel->setText(msvcenv.description());
+                         m_ui.msvcLabel->setText(""); //TODO
                      }
                  }
                  m_ui.msvcComboBox->blockSignals(block);
             }
-        } else if (t == QtVersion::INVALID) {
+        } else if (t == ProjectExplorer::ToolChain::INVALID) {
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(false);
             makeMingwVisible(false);
@@ -532,7 +533,7 @@ void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
                                            .arg(m_versions.at(index)->path()));
             else
                 m_ui.errorLabel->setText(tr("%1 is not a valid qt directory").arg(m_versions.at(index)->path()));
-        } else { //QtVersion::Other
+        } else { //ProjectExplorer::ToolChain::GCC
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(false);
             makeMingwVisible(false);
@@ -679,13 +680,14 @@ void QtDirWidget::msvcVersionChanged()
     m_versions[currentItemIndex]->setMsvcVersion(msvcVersion);
 
     //get descriptionx
-    QList<MSVCEnvironment> msvcEnvironments = MSVCEnvironment::availableVersions();
-    foreach(const MSVCEnvironment &msvcEnv, msvcEnvironments) {
-        if (msvcEnv.name() == msvcVersion) {
-            m_ui.msvcLabel->setText(msvcEnv.description());
-            break;
-        }
-    }
+    //TODO
+//    QList<MSVCEnvironment> msvcEnvironments = MSVCEnvironment::availableVersions();
+//    foreach(const MSVCEnvironment &msvcEnv, msvcEnvironments) {
+//        if (msvcEnv.name() == msvcVersion) {
+//            m_ui.msvcLabel->setText(msvcEnv.description());
+//            break;
+//        }
+//    }
 }
 
 QList<QtVersion *> QtDirWidget::versions() const
@@ -1176,21 +1178,21 @@ QString QtVersion::qmakeCommand() const
     return QString::null;
 }
 
-QtVersion::ToolchainType QtVersion::toolchainType() const
+ProjectExplorer::ToolChain::ToolChainType QtVersion::toolchainType() const
 {
     if (!isValid())
-        return INVALID;
+        return ProjectExplorer::ToolChain::INVALID;
     const QString &spec = mkspec();
     if (spec.contains("win32-msvc") || spec.contains(QLatin1String("win32-icc")))
-        return MSVC;
+        return ProjectExplorer::ToolChain::MSVC;
     else if (spec == "win32-g++")
-        return MinGW;
+        return ProjectExplorer::ToolChain::MinGW;
     else if (spec == QString::null)
-        return INVALID;
+        return ProjectExplorer::ToolChain::INVALID;
     else if (spec.startsWith("wince"))
-        return WINCE;
+        return ProjectExplorer::ToolChain::WINCE;
     else
-        return OTHER;
+        return ProjectExplorer::ToolChain::GCC;
 }
 
 QString QtVersion::mingwDirectory() const
@@ -1218,70 +1220,26 @@ QString QtVersion::msvcVersion() const
     return m_msvcVersion;
 }
 
+QString QtVersion::wincePlatform() const
+{
+    qDebug()<<"QtVersion::wincePlatform returning"<<ProjectExplorer::CeSdkHandler::platformName(mkspecPath() + "/qmake.conf");
+    return ProjectExplorer::CeSdkHandler::platformName(mkspecPath() + "/qmake.conf");
+}
+
 void QtVersion::setMsvcVersion(const QString &version)
 {
     m_msvcVersion = version;
 }
 
-Environment QtVersion::addToEnvironment(const Environment &env)
+void QtVersion::addToEnvironment(Environment &env)
 {
-    Environment e(env);
-    e.set("QTDIR", m_path);
+    env.set("QTDIR", m_path);
     QString qtdirbin = versionInfo().value("QT_INSTALL_BINS");
-    e.prependOrSetPath(qtdirbin);
+    env.prependOrSetPath(qtdirbin);
     // add libdir, includedir and bindir
     // or add Mingw dirs
     // or do nothing on other
-    QtVersion::ToolchainType t = toolchainType();
-    if (t == QtVersion::MinGW) {
-        QFileInfo mingwFileInfo(m_mingwDirectory + "/bin");
-        if (mingwFileInfo.exists())
-            e.prependOrSetPath(m_mingwDirectory + "/bin");
-    } else if (t == QtVersion::MSVC) {
-        QList<MSVCEnvironment> list = MSVCEnvironment::availableVersions();
-        if (list.count() == 1) {
-            e = list.at(0).addToEnvironment(e);
-        } else {
-            foreach(const MSVCEnvironment &m, list) {
-                if (m.name() == m_msvcVersion) {
-                    e = m.addToEnvironment(e);
-                    break;
-                }
-            }
-        }
-    } else if (t == QtVersion::WINCE) {
-        QString msvcPath;
-        // Find MSVC path
-        QList<MSVCEnvironment> list = MSVCEnvironment::availableVersions();
-        if (list.count() == 1) {
-            msvcPath = list.at(0).path();
-            e = list.at(0).addToEnvironment(e);
-        } else {
-            foreach(const MSVCEnvironment &m, list) {
-                if (m.name() == m_msvcVersion) {
-                    e = m.addToEnvironment(e);
-                    msvcPath = m.path();
-                    break;
-                }
-            }
-        }
-        msvcPath += "/";
-
-//        qDebug()<<"MSVC path"<<msvcPath;
-//        qDebug()<<"looking for platform name in"<< path() + "/mkspecs/" + mkspec() +"/qmake.conf";
-        // Find Platform name
 
-        QString platformName = CeSdkHandler::platformName(path() + "/mkspecs/" + mkspec()+ "/qmake.conf");
-//        qDebug()<<"Platform Name"<<platformName;
-
-        CeSdkHandler cesdkhandler;
-        cesdkhandler.parse(msvcPath);
-        e = cesdkhandler.find(platformName).addToEnvironment(e);
-    } else if (t == QtVersion::OTHER) {
-        if (!m_prependPath.isEmpty())
-            e.prependOrSetPath(m_prependPath);
-    }
-    return e;
 }
 
 int QtVersion::uniqueId() const
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.h b/src/plugins/qt4projectmanager/qtversionmanager.h
index 11e5ec8235922558fc83d9582fab762c77c18c2e..15e0dab605ee21476df4ea9f3e2959ed9beb063f 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.h
+++ b/src/plugins/qt4projectmanager/qtversionmanager.h
@@ -38,6 +38,7 @@
 
 #include <coreplugin/dialogs/ioptionspage.h>
 #include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/toolchain.h>
 
 #include <QtCore/QDebug>
 #include <QtCore/QPointer>
@@ -73,17 +74,16 @@ public:
     // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
     QHash<QString,QString> versionInfo() const;
 
-    enum ToolchainType { MinGW, MSVC, WINCE, OTHER, INVALID };
-
-    ToolchainType toolchainType() const;
+    ProjectExplorer::ToolChain::ToolChainType toolchainType() const;
 
     QString mingwDirectory() const;
     void setMingwDirectory(const QString &directory);
     QString prependPath() const;
     void setPrependPath(const QString &string);
     QString msvcVersion() const;
+    QString wincePlatform() const;
     void setMsvcVersion(const QString &version);
-    ProjectExplorer::Environment addToEnvironment(const ProjectExplorer::Environment &env);
+    void addToEnvironment(ProjectExplorer::Environment &env);
 
     int uniqueId() const;