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;
87 QStringList extra_configs;
88 QHash<QString, QStringList> vars, base_vars, extra_vars;
89 bool parse(const QString &text, QHash<QString, QStringList> &place, int line_count=1);
93 IncludeFeatureAlreadyLoaded,
99 IncludeFlagNone = 0x00,
100 IncludeFlagFeature = 0x01,
101 IncludeFlagNewParser = 0x02,
102 IncludeFlagNewProject = 0x04
104 IncludeStatus doProjectInclude(QString file, uchar flags, QHash<QString, QStringList> &place);
106 bool doProjectCheckReqs(const QStringList &deps, QHash<QString, QStringList> &place);
107 bool doVariableReplace(QString &str, QHash<QString, QStringList> &place);
108 QStringList doVariableReplaceExpand(const QString &str, QHash<QString, QStringList> &place, bool *ok=0);
109 void init(QMakeProperty *);
110 QStringList &values(const QString &v, QHash<QString, QStringList> &place);
111 void validateModes();
112 void resolveSpec(QString *spec, const QString &qmakespec);
115 QMakeProject(QMakeProperty *p = 0) { init(p); }
116 QMakeProject(QMakeProject *p, const QHash<QString, QStringList> *nvars=0);
119 void setExtraVars(const QHash<QString, QStringList> &_vars) { extra_vars = _vars; }
120 void setExtraConfigs(const QStringList &_cfgs) { extra_configs = _cfgs; }
122 enum { ReadProFile=0x01, ReadSetup=0x02, ReadFeatures=0x04, ReadAll=0xFF };
123 inline bool parse(const QString &text) { return parse(text, vars); }
124 bool read(const QString &project, uchar cmd=ReadAll);
125 bool read(uchar cmd=ReadAll);
127 QStringList userExpandFunctions() { return replaceFunctions.keys(); }
128 QStringList userTestFunctions() { return testFunctions.keys(); }
130 QString projectFile();
131 inline QMakeProperty *properties() { return prop; }
133 bool doProjectTest(QString str, QHash<QString, QStringList> &place);
134 bool doProjectTest(QString func, const QString ¶ms,
135 QHash<QString, QStringList> &place);
136 bool doProjectTest(QString func, QStringList args,
137 QHash<QString, QStringList> &place);
138 bool doProjectTest(QString func, QList<QStringList> args,
139 QHash<QString, QStringList> &place);
140 QStringList doProjectExpand(QString func, const QString ¶ms,
141 QHash<QString, QStringList> &place);
142 QStringList doProjectExpand(QString func, QStringList args,
143 QHash<QString, QStringList> &place);
144 QStringList doProjectExpand(QString func, QList<QStringList> args,
145 QHash<QString, QStringList> &place);
147 QStringList expand(const QString &v);
148 QString expand(const QString &v, const QString &file, int line);
149 QStringList expand(const QString &func, const QList<QStringList> &args);
150 bool test(const QString &v);
151 bool test(const QString &func, const QList<QStringList> &args);
152 bool isActiveConfig(const QString &x, bool regex=false,
153 QHash<QString, QStringList> *place=NULL);
155 bool isSet(const QString &v); // No compat mapping, no magic variables
156 bool isEmpty(const QString &v); // With compat mapping, but no magic variables
157 QStringList &values(const QString &v); // With compat mapping and magic variables
158 QString first(const QString &v); // ditto
159 QHash<QString, QStringList> &variables(); // No compat mapping and magic, obviously
161 bool isRecursive() const { return recursive; }
164 friend class MakefileGenerator;
165 bool read(const QString &file, QHash<QString, QStringList> &place);
166 bool read(QTextStream &file, QHash<QString, QStringList> &place);
169 Q_DECLARE_METATYPE(QMakeProject*)
171 inline QString QMakeProject::projectFile()
174 return QString("(stdin)");
178 inline QStringList &QMakeProject::values(const QString &v)
179 { return values(v, vars); }
181 inline bool QMakeProject::isSet(const QString &v)
182 { return vars.contains(v); }
184 inline QString QMakeProject::first(const QString &v)
186 const QStringList vals = values(v);
192 inline QHash<QString, QStringList> &QMakeProject::variables()