1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <qstringlist.h>
46 #include <qtextstream.h>
50 #include <qmetatype.h>
64 enum TestStatus { TestNone, TestFound, TestSeek };
65 ScopeBlock() : iterate(0), ignore(false), else_status(TestNone) { }
66 ScopeBlock(bool i) : iterate(0), ignore(i), else_status(TestNone) { }
68 IteratorBlock *iterate;
69 uint ignore : 1, else_status : 2;
71 friend struct ParsableBlock;
72 friend struct IteratorBlock;
73 friend struct FunctionBlock;
75 QStack<ScopeBlock> scope_blocks;
76 QStack<FunctionBlock *> function_blocks;
77 IteratorBlock *iterator;
78 FunctionBlock *function;
79 QHash<QString, FunctionBlock*> testFunctions, replaceFunctions;
85 QString project_build_root;
89 QString real_spec, short_spec;
93 QStringList extra_configs;
94 QHash<QString, QStringList> vars, init_vars, base_vars, extra_vars;
95 bool parse(const QString &text, QHash<QString, QStringList> &place, int line_count=1);
99 IncludeFeatureAlreadyLoaded,
105 IncludeFlagNone = 0x00,
106 IncludeFlagFeature = 0x01,
107 IncludeFlagNewParser = 0x02,
108 IncludeFlagNewProject = 0x04
110 IncludeStatus doProjectInclude(QString file, uchar flags, QHash<QString, QStringList> &place);
112 bool doProjectCheckReqs(const QStringList &deps, QHash<QString, QStringList> &place);
113 bool doVariableReplace(QString &str, QHash<QString, QStringList> &place);
114 QStringList doVariableReplaceExpand(const QString &str, QHash<QString, QStringList> &place, bool *ok=0);
115 void init(QMakeProperty *);
119 QStringList &values(const QString &v, QHash<QString, QStringList> &place);
120 QStringList magicValues(const QString &v, const QHash<QString, QStringList> &place) const;
121 QStringList qmakeFeaturePaths();
124 QMakeProject(QMakeProperty *p = 0) { init(p); }
125 QMakeProject(QMakeProject *p, const QHash<QString, QStringList> *nvars=0);
128 void setExtraVars(const QHash<QString, QStringList> &_vars) { extra_vars = _vars; }
129 void setExtraConfigs(const QStringList &_cfgs) { extra_configs = _cfgs; }
131 enum { ReadProFile=0x01, ReadSetup=0x02, ReadFeatures=0x04, ReadAll=0xFF };
132 inline bool parse(const QString &text) { return parse(text, vars); }
133 bool read(const QString &project, uchar cmd=ReadAll);
134 bool read(uchar cmd=ReadAll);
136 QStringList userExpandFunctions() { return replaceFunctions.keys(); }
137 QStringList userTestFunctions() { return testFunctions.keys(); }
139 QString projectFile();
140 QString buildRoot() const { return project_build_root; }
141 QString confFile() const { return conffile; }
142 QString cacheFile() const { return cachefile; }
143 QString specDir() const { return real_spec; }
144 inline QMakeProperty *properties() { return prop; }
146 bool doProjectTest(QString str, QHash<QString, QStringList> &place);
147 bool doProjectTest(QString func, const QString ¶ms,
148 QHash<QString, QStringList> &place);
149 bool doProjectTest(QString func, QStringList args,
150 QHash<QString, QStringList> &place);
151 bool doProjectTest(QString func, QList<QStringList> args,
152 QHash<QString, QStringList> &place);
153 QStringList doProjectExpand(QString func, const QString ¶ms,
154 QHash<QString, QStringList> &place);
155 QStringList doProjectExpand(QString func, QStringList args,
156 QHash<QString, QStringList> &place);
157 QStringList doProjectExpand(QString func, QList<QStringList> args,
158 QHash<QString, QStringList> &place);
160 QStringList expand(const QString &v);
161 QString expand(const QString &v, const QString &file, int line);
162 QStringList expand(const QString &func, const QList<QStringList> &args);
163 bool test(const QString &v);
164 bool test(const QString &func, const QList<QStringList> &args);
165 bool isActiveConfig(const QString &x, bool regex=false,
166 QHash<QString, QStringList> *place=NULL);
168 bool isSet(const QString &v) const { return vars.contains(v); }
169 bool isEmpty(const QString &v) const;
170 QStringList values(const QString &v) const { return vars[v]; }
171 QStringList &values(const QString &v) { return vars[v]; }
172 QString first(const QString &v) const;
173 int intValue(const QString &v, int defaultValue = 0) const;
174 const QHash<QString, QStringList> &variables() const { return vars; }
175 QHash<QString, QStringList> &variables() { return vars; }
179 bool isHostBuild() const { return host_build; }
182 friend class MakefileGenerator;
183 bool read(const QString &file, QHash<QString, QStringList> &place);
184 bool read(QTextStream &file, QHash<QString, QStringList> &place);
187 Q_DECLARE_METATYPE(QMakeProject*)
189 inline QString QMakeProject::projectFile()
192 return QString("(stdin)");
196 inline QString QMakeProject::first(const QString &v) const
198 const QStringList vals = values(v);
204 inline int QMakeProject::intValue(const QString &v, int defaultValue) const
206 const QString str = first(v);
207 if (!str.isEmpty()) {
209 int i = str.toInt(&ok);