1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the qmake application of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
45 #include <qstringlist.h>
46 #include <qtextstream.h>
50 #include <qmetatype.h>
52 #ifndef QT_BUILD_QMAKE_LIBRARY
53 # define QTSCRIPT_SUPPORT
56 #ifdef QTSCRIPT_SUPPORT
57 # include <qscriptengine.h>
72 enum TestStatus
{ TestNone
, TestFound
, TestSeek
};
73 ScopeBlock() : iterate(0), ignore(false), else_status(TestNone
) { }
74 ScopeBlock(bool i
) : iterate(0), ignore(i
), else_status(TestNone
) { }
76 IteratorBlock
*iterate
;
77 uint ignore
: 1, else_status
: 2;
79 friend struct ParsableBlock
;
80 friend struct IteratorBlock
;
81 friend struct FunctionBlock
;
83 #ifdef QTSCRIPT_SUPPORT
86 QStack
<ScopeBlock
> scope_blocks
;
87 QStack
<FunctionBlock
*> function_blocks
;
88 IteratorBlock
*iterator
;
89 FunctionBlock
*function
;
90 QMap
<QString
, FunctionBlock
*> testFunctions
, replaceFunctions
;
96 QMap
<QString
, QStringList
> vars
, base_vars
, cache
;
97 bool parse(const QString
&text
, QMap
<QString
, QStringList
> &place
, int line_count
=1);
101 IncludeFeatureAlreadyLoaded
,
107 IncludeFlagNone
= 0x00,
108 IncludeFlagFeature
= 0x01,
109 IncludeFlagNewParser
= 0x02,
110 IncludeFlagNewProject
= 0x04
112 IncludeStatus
doProjectInclude(QString file
, uchar flags
, QMap
<QString
, QStringList
> &place
);
114 bool doProjectCheckReqs(const QStringList
&deps
, QMap
<QString
, QStringList
> &place
);
115 bool doVariableReplace(QString
&str
, QMap
<QString
, QStringList
> &place
);
116 QStringList
doVariableReplaceExpand(const QString
&str
, QMap
<QString
, QStringList
> &place
, bool *ok
=0);
117 void init(QMakeProperty
*, const QMap
<QString
, QStringList
> *);
118 QStringList
&values(const QString
&v
, QMap
<QString
, QStringList
> &place
);
121 QMakeProject() { init(0, 0); }
122 QMakeProject(QMakeProperty
*p
) { init(p
, 0); }
123 QMakeProject(QMakeProject
*p
, const QMap
<QString
, QStringList
> *nvars
=0);
124 QMakeProject(const QMap
<QString
, QStringList
> &nvars
) { init(0, &nvars
); }
125 QMakeProject(QMakeProperty
*p
, const QMap
<QString
, QStringList
> &nvars
) { init(p
, &nvars
); }
128 enum { ReadCache
=0x01, ReadConf
=0x02, ReadCmdLine
=0x04, ReadProFile
=0x08,
129 ReadPostFiles
=0x10, ReadFeatures
=0x20, ReadConfigs
=0x40, ReadAll
=0xFF };
130 inline bool parse(const QString
&text
) { return parse(text
, vars
); }
131 bool read(const QString
&project
, uchar cmd
=ReadAll
);
132 bool read(uchar cmd
=ReadAll
);
134 QStringList
userExpandFunctions() { return replaceFunctions
.keys(); }
135 QStringList
userTestFunctions() { return testFunctions
.keys(); }
137 QString
projectFile();
138 QString
configFile();
139 inline QMakeProperty
*properties() { return prop
; }
141 bool doProjectTest(QString str
, QMap
<QString
, QStringList
> &place
);
142 bool doProjectTest(QString func
, const QString
¶ms
,
143 QMap
<QString
, QStringList
> &place
);
144 bool doProjectTest(QString func
, QStringList args
,
145 QMap
<QString
, QStringList
> &place
);
146 bool doProjectTest(QString func
, QList
<QStringList
> args
,
147 QMap
<QString
, QStringList
> &place
);
148 QStringList
doProjectExpand(QString func
, const QString
¶ms
,
149 QMap
<QString
, QStringList
> &place
);
150 QStringList
doProjectExpand(QString func
, QStringList args
,
151 QMap
<QString
, QStringList
> &place
);
152 QStringList
doProjectExpand(QString func
, QList
<QStringList
> args
,
153 QMap
<QString
, QStringList
> &place
);
155 QStringList
expand(const QString
&v
);
156 QStringList
expand(const QString
&func
, const QList
<QStringList
> &args
);
157 bool test(const QString
&v
);
158 bool test(const QString
&func
, const QList
<QStringList
> &args
);
159 bool isActiveConfig(const QString
&x
, bool regex
=false,
160 QMap
<QString
, QStringList
> *place
=NULL
);
162 bool isSet(const QString
&v
);
163 bool isEmpty(const QString
&v
);
164 QStringList
&values(const QString
&v
);
165 QString
first(const QString
&v
);
166 QMap
<QString
, QStringList
> &variables();
169 friend class MakefileGenerator
;
170 bool read(const QString
&file
, QMap
<QString
, QStringList
> &place
);
171 bool read(QTextStream
&file
, QMap
<QString
, QStringList
> &place
);
174 Q_DECLARE_METATYPE(QMakeProject
*)
176 inline QString
QMakeProject::projectFile()
179 return QString("(stdin)");
183 inline QString
QMakeProject::configFile()
186 inline QStringList
&QMakeProject::values(const QString
&v
)
187 { return values(v
, vars
); }
189 inline bool QMakeProject::isEmpty(const QString
&v
)
190 { return !isSet(v
) || values(v
).isEmpty(); }
192 inline bool QMakeProject::isSet(const QString
&v
)
193 { return vars
.contains(v
); }
195 inline QString
QMakeProject::first(const QString
&v
)
197 const QStringList vals
= values(v
);
203 inline QMap
<QString
, QStringList
> &QMakeProject::variables()