aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qt4projectmanager/qt-s60/rvcttoolchain.cpp
blob: 9b38fca40fab13f2d77d102b37a4030bfe22bd0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "rvcttoolchain.h"

#include "qt4project.h"

using namespace ProjectExplorer;
using namespace Qt4ProjectManager::Internal;

RVCTToolChain::RVCTToolChain(S60Devices::Device device, ToolChain::ToolChainType type,
                             const QString &makeTargetBase)
    : m_versionUpToDate(false),
    m_deviceId(device.id),
    m_deviceName(device.name),
    m_deviceRoot(device.epocRoot),
    m_type(type),
    m_makeTargetBase(makeTargetBase)
{
}

ToolChain::ToolChainType RVCTToolChain::type() const
{
    return m_type;
}

void RVCTToolChain::updateVersion()
{
    if (m_versionUpToDate)
        return;
    m_versionUpToDate = true;
    m_major = 0;
    m_minor = 0;
    m_build = 0;
    QProcess armcc;
    ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
    addToEnvironment(env);
    armcc.setEnvironment(env.toStringList());
    armcc.start("armcc", QStringList());
    armcc.closeWriteChannel();
    armcc.waitForFinished();
    QString versionLine = armcc.readAllStandardOutput();
    versionLine += armcc.readAllStandardError();
    QRegExp versionRegExp("RVCT(\\d*)\\.(\\d*).*\\[Build.(\\d*)\\]",
        Qt::CaseInsensitive);
    if (versionRegExp.indexIn(versionLine) != -1) {
        m_major = versionRegExp.cap(1).toInt();
	m_minor = versionRegExp.cap(2).toInt();
	m_build = versionRegExp.cap(3).toInt();
    }
}

QByteArray RVCTToolChain::predefinedMacros()
{
    // see http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0205f/Babbacdb.html
    updateVersion();
    QByteArray ba = QString::fromLocal8Bit(
        "#define __arm__arm__\n"
        "#define __ARMCC_VERSION %1%2%3%4\n"
        "#define __ARRAY_OPERATORS\n"
        "#define _BOOL\n"
        "#define c_plusplus\n"
        "#define __cplusplus\n"
        "#define __CC_ARM\n"
        "#define __EDG__\n"
        "#define __STDC__\n"
        "#define __STDC_VERSION__\n"
        "#define __TARGET_FEATURE_DOUBLEWORD\n"
        "#define __TARGET_FEATURE_DSPMUL\n"
        "#define __TARGET_FEATURE_HALFWORD\n"
        "#define __TARGET_FEATURE_THUMB\n"
        "#define _WCHAR_T\n"
        ).arg(m_major, 1, 10, QLatin1Char('0'))
        .arg(m_minor, 1, 10, QLatin1Char('0'))
        .arg("0")
        .arg(m_build, 3, 10, QLatin1Char('0')).toLocal8Bit();
    return ba;
}

QList<HeaderPath> RVCTToolChain::systemHeaderPaths()
{
    if (m_systemHeaderPaths.isEmpty()) {
        updateVersion();
        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        QString rvctInclude = env.value(QString::fromLatin1("RVCT%1%2INC").arg(m_major).arg(m_minor));
        if (!rvctInclude.isEmpty())
            m_systemHeaderPaths.append(HeaderPath(rvctInclude, HeaderPath::GlobalHeaderPath));
        m_systemHeaderPaths.append(HeaderPath(QString("%1\\epoc32\\include").arg(m_deviceRoot), HeaderPath::GlobalHeaderPath));
        m_systemHeaderPaths.append(HeaderPath(QString("%1\\epoc32\\include\\stdapis").arg(m_deviceRoot), HeaderPath::GlobalHeaderPath));
        m_systemHeaderPaths.append(HeaderPath(QString("%1\\epoc32\\include\\stdapis\\sys").arg(m_deviceRoot), HeaderPath::GlobalHeaderPath));
        m_systemHeaderPaths.append(HeaderPath(QString("%1\\epoc32\\include\\variant").arg(m_deviceRoot), HeaderPath::GlobalHeaderPath));
    }
    return m_systemHeaderPaths;
}

void RVCTToolChain::addToEnvironment(ProjectExplorer::Environment &env)
{
    env.prependOrSetPath(QString("%1\\epoc32\\tools").arg(m_deviceRoot)); // e.g. make.exe
    env.prependOrSetPath(QString("%1\\epoc32\\gcc\\bin").arg(m_deviceRoot)); // e.g. gcc.exe
    env.set("EPOCDEVICE", QString("%1:%2").arg(m_deviceId, m_deviceName));
    env.set("EPOCROOT", S60Devices::cleanedRootPath(m_deviceRoot));
}

QString RVCTToolChain::makeCommand() const
{
    return "make";
}

QString RVCTToolChain::defaultMakeTarget() const
{
    const Qt4Project *qt4project = qobject_cast<const Qt4Project *>(m_project);
    if (qt4project) {
        if (!(QtVersion::QmakeBuildConfig(qt4project->value(
                qt4project->activeBuildConfiguration(),
                "buildConfiguration").toInt()) & QtVersion::DebugBuild)) {
            return QString::fromLocal8Bit("release-%1").arg(m_makeTargetBase);
        }
    }
    return QString::fromLocal8Bit("debug-%1").arg(m_makeTargetBase);
}

bool RVCTToolChain::equals(ToolChain *other) const
{
    return (other->type() == type()
            && m_deviceId == static_cast<RVCTToolChain *>(other)->m_deviceId
            && m_deviceName == static_cast<RVCTToolChain *>(other)->m_deviceName);
}

void RVCTToolChain::setProject(const ProjectExplorer::Project *project)
{
    m_project = project;
}