OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemotoolchain.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "maemotoolchain.h"
35
36 #include "maemoconstants.h"
37 #include "maemoglobal.h"
38
39 #include <QtCore/QDir>
40 #include <QtCore/QStringBuilder>
41 #include <QtCore/QTextStream>
42
43 using namespace ProjectExplorer;
44
45 namespace Qt4ProjectManager {
46 namespace Internal {
47
48 MaemoToolChain::MaemoToolChain(const QtVersion *qtVersion)
49     : GccToolChain(MaemoGlobal::targetRoot(qtVersion) % QLatin1String("/bin/gcc"))
50     , m_sysrootInitialized(false)
51     , m_qtVersion(qtVersion)
52 {
53 }
54
55 MaemoToolChain::~MaemoToolChain()
56 {
57 }
58
59 ProjectExplorer::ToolChainType MaemoToolChain::type() const
60 {
61     return ProjectExplorer::ToolChain_GCC_MAEMO;
62 }
63
64 void MaemoToolChain::addToEnvironment(Utils::Environment &env)
65 {
66     const QString maddeRoot = MaemoGlobal::maddeRoot(m_qtVersion);
67     env.prependOrSetPath(QDir::toNativeSeparators(QString("%1/bin")
68         .arg(maddeRoot)));
69     env.prependOrSetPath(QDir::toNativeSeparators(QString("%1/bin")
70         .arg(MaemoGlobal::targetRoot(m_qtVersion))));
71
72     // put this into environment to make pkg-config stuff work
73     env.prependOrSet(QLatin1String("SYSROOT_DIR"), sysroot());
74     env.prependOrSetPath(QDir::toNativeSeparators(QString("%1/madbin")
75         .arg(maddeRoot)));
76     env.prependOrSetPath(QDir::toNativeSeparators(QString("%1/madlib")
77         .arg(maddeRoot)));
78     env.prependOrSet(QLatin1String("PERL5LIB"),
79         QDir::toNativeSeparators(QString("%1/madlib/perl5").arg(maddeRoot)));
80 }
81
82 QString MaemoToolChain::makeCommand() const
83 {
84     return QLatin1String("make" EXEC_SUFFIX);
85 }
86
87 bool MaemoToolChain::equals(const ToolChain *other) const
88 {
89     const MaemoToolChain *toolChain = static_cast<const MaemoToolChain*> (other);
90     return other->type() == type() && toolChain->m_qtVersion == m_qtVersion;
91 }
92
93 QString MaemoToolChain::sysroot() const
94 {
95     if (!m_sysrootInitialized)
96         setSysroot();
97     return m_sysrootRoot;
98 }
99
100 void MaemoToolChain::setSysroot() const
101 {
102     QFile file(QDir::cleanPath(MaemoGlobal::targetRoot(m_qtVersion))
103         + QLatin1String("/information"));
104     if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
105         QTextStream stream(&file);
106         while (!stream.atEnd()) {
107             const QString &line = stream.readLine().trimmed();
108             const QStringList &list = line.split(QLatin1Char(' '));
109             if (list.count() <= 1)
110                 continue;
111             if (list.at(0) == QLatin1String("sysroot")) {
112                 m_sysrootRoot = MaemoGlobal::maddeRoot(m_qtVersion)
113                     + QLatin1String("/sysroots/") + list.at(1);
114             }
115         }
116     }
117
118     m_sysrootInitialized = true;
119 }
120
121 } // namespace Internal
122 } // namespace Qt4ProjectManager