| 1 | /****************************************************************************
 | 
|---|
| 2 | **
 | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 | 
|---|
| 4 | ** All rights reserved.
 | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
 | 
|---|
| 6 | **
 | 
|---|
| 7 | ** This file is part of the qmake application of the Qt Toolkit.
 | 
|---|
| 8 | **
 | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
 | 
|---|
| 10 | ** Commercial Usage
 | 
|---|
| 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.
 | 
|---|
| 15 | **
 | 
|---|
| 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.
 | 
|---|
| 23 | **
 | 
|---|
| 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.
 | 
|---|
| 27 | **
 | 
|---|
| 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.
 | 
|---|
| 35 | **
 | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
 | 
|---|
| 37 | ** Nokia at qt-info@nokia.com.
 | 
|---|
| 38 | ** $QT_END_LICENSE$
 | 
|---|
| 39 | **
 | 
|---|
| 40 | ****************************************************************************/
 | 
|---|
| 41 | 
 | 
|---|
| 42 | #ifndef PROJECT_H
 | 
|---|
| 43 | #define PROJECT_H
 | 
|---|
| 44 | 
 | 
|---|
| 45 | #include <qstringlist.h>
 | 
|---|
| 46 | #include <qtextstream.h>
 | 
|---|
| 47 | #include <qstring.h>
 | 
|---|
| 48 | #include <qstack.h>
 | 
|---|
| 49 | #include <qmap.h>
 | 
|---|
| 50 | #include <qmetatype.h>
 | 
|---|
| 51 | 
 | 
|---|
| 52 | QT_BEGIN_NAMESPACE
 | 
|---|
| 53 | 
 | 
|---|
| 54 | class QMakeProperty;
 | 
|---|
| 55 | 
 | 
|---|
| 56 | struct ParsableBlock;
 | 
|---|
| 57 | struct IteratorBlock;
 | 
|---|
| 58 | struct FunctionBlock;
 | 
|---|
| 59 | 
 | 
|---|
| 60 | class QMakeProject
 | 
|---|
| 61 | {
 | 
|---|
| 62 |     struct ScopeBlock
 | 
|---|
| 63 |     {
 | 
|---|
| 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) { }
 | 
|---|
| 67 |         ~ScopeBlock();
 | 
|---|
| 68 |         IteratorBlock *iterate;
 | 
|---|
| 69 |         uint ignore : 1, else_status : 2;
 | 
|---|
| 70 |     };
 | 
|---|
| 71 |     friend struct ParsableBlock;
 | 
|---|
| 72 |     friend struct IteratorBlock;
 | 
|---|
| 73 |     friend struct FunctionBlock;
 | 
|---|
| 74 | 
 | 
|---|
| 75 |     QStack<ScopeBlock> scope_blocks;
 | 
|---|
| 76 |     QStack<FunctionBlock *> function_blocks;
 | 
|---|
| 77 |     IteratorBlock *iterator;
 | 
|---|
| 78 |     FunctionBlock *function;
 | 
|---|
| 79 |     QMap<QString, FunctionBlock*> testFunctions, replaceFunctions;
 | 
|---|
| 80 | 
 | 
|---|
| 81 |     bool recursive;
 | 
|---|
| 82 |     bool own_prop;
 | 
|---|
| 83 |     bool backslashWarned;
 | 
|---|
| 84 |     QString pfile, cfile;
 | 
|---|
| 85 |     QMakeProperty *prop;
 | 
|---|
| 86 |     void reset();
 | 
|---|
| 87 |     QMap<QString, QStringList> vars, base_vars, cache;
 | 
|---|
| 88 |     bool parse(const QString &text, QMap<QString, QStringList> &place, int line_count=1);
 | 
|---|
| 89 | 
 | 
|---|
| 90 |     enum IncludeStatus {
 | 
|---|
| 91 |         IncludeSuccess,
 | 
|---|
| 92 |         IncludeFeatureAlreadyLoaded,
 | 
|---|
| 93 |         IncludeFailure,
 | 
|---|
| 94 |         IncludeNoExist,
 | 
|---|
| 95 |         IncludeParseFailure
 | 
|---|
| 96 |     };
 | 
|---|
| 97 |     enum IncludeFlags {
 | 
|---|
| 98 |         IncludeFlagNone = 0x00,
 | 
|---|
| 99 |         IncludeFlagFeature = 0x01,
 | 
|---|
| 100 |         IncludeFlagNewParser = 0x02,
 | 
|---|
| 101 |         IncludeFlagNewProject = 0x04
 | 
|---|
| 102 |     };
 | 
|---|
| 103 |     IncludeStatus doProjectInclude(QString file, uchar flags, QMap<QString, QStringList> &place);
 | 
|---|
| 104 | 
 | 
|---|
| 105 |     bool doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringList> &place);
 | 
|---|
| 106 |     bool doVariableReplace(QString &str, QMap<QString, QStringList> &place);
 | 
|---|
| 107 |     QStringList doVariableReplaceExpand(const QString &str, QMap<QString, QStringList> &place, bool *ok=0);
 | 
|---|
| 108 |     void init(QMakeProperty *, const QMap<QString, QStringList> *);
 | 
|---|
| 109 |     QStringList &values(const QString &v, QMap<QString, QStringList> &place);
 | 
|---|
| 110 |     void validateModes();
 | 
|---|
| 111 | 
 | 
|---|
| 112 | public:
 | 
|---|
| 113 |     QMakeProject() { init(0, 0); }
 | 
|---|
| 114 |     QMakeProject(QMakeProperty *p) { init(p, 0); }
 | 
|---|
| 115 |     QMakeProject(QMakeProject *p, const QMap<QString, QStringList> *nvars=0);
 | 
|---|
| 116 |     QMakeProject(const QMap<QString, QStringList> &nvars) { init(0, &nvars); }
 | 
|---|
| 117 |     QMakeProject(QMakeProperty *p, const QMap<QString, QStringList> &nvars) { init(p, &nvars); }
 | 
|---|
| 118 |     ~QMakeProject();
 | 
|---|
| 119 | 
 | 
|---|
| 120 |     enum { ReadCache=0x01, ReadConf=0x02, ReadCmdLine=0x04, ReadProFile=0x08,
 | 
|---|
| 121 |            ReadFeatures=0x20, ReadConfigs=0x40, ReadAll=0xFF };
 | 
|---|
| 122 |     inline bool parse(const QString &text) { return parse(text, vars); }
 | 
|---|
| 123 |     bool read(const QString &project, uchar cmd=ReadAll);
 | 
|---|
| 124 |     bool read(uchar cmd=ReadAll);
 | 
|---|
| 125 | 
 | 
|---|
| 126 |     QStringList userExpandFunctions() { return replaceFunctions.keys(); }
 | 
|---|
| 127 |     QStringList userTestFunctions() { return testFunctions.keys(); }
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     QString projectFile();
 | 
|---|
| 130 |     inline QMakeProperty *properties() { return prop; }
 | 
|---|
| 131 | 
 | 
|---|
| 132 |     bool doProjectTest(QString str, QMap<QString, QStringList> &place);
 | 
|---|
| 133 |     bool doProjectTest(QString func, const QString ¶ms,
 | 
|---|
| 134 |                        QMap<QString, QStringList> &place);
 | 
|---|
| 135 |     bool doProjectTest(QString func, QStringList args,
 | 
|---|
| 136 |                        QMap<QString, QStringList> &place);
 | 
|---|
| 137 |     bool doProjectTest(QString func, QList<QStringList> args,
 | 
|---|
| 138 |                        QMap<QString, QStringList> &place);
 | 
|---|
| 139 |     QStringList doProjectExpand(QString func, const QString ¶ms,
 | 
|---|
| 140 |                                 QMap<QString, QStringList> &place);
 | 
|---|
| 141 |     QStringList doProjectExpand(QString func, QStringList args,
 | 
|---|
| 142 |                                 QMap<QString, QStringList> &place);
 | 
|---|
| 143 |     QStringList doProjectExpand(QString func, QList<QStringList> args,
 | 
|---|
| 144 |                                 QMap<QString, QStringList> &place);
 | 
|---|
| 145 | 
 | 
|---|
| 146 |     QStringList expand(const QString &v);
 | 
|---|
| 147 |     QStringList expand(const QString &func, const QList<QStringList> &args);
 | 
|---|
| 148 |     bool test(const QString &v);
 | 
|---|
| 149 |     bool test(const QString &func, const QList<QStringList> &args);
 | 
|---|
| 150 |     bool isActiveConfig(const QString &x, bool regex=false,
 | 
|---|
| 151 |                         QMap<QString, QStringList> *place=NULL);
 | 
|---|
| 152 | 
 | 
|---|
| 153 |     bool isSet(const QString &v); // No compat mapping, no magic variables
 | 
|---|
| 154 |     bool isEmpty(const QString &v); // With compat mapping, but no magic variables
 | 
|---|
| 155 |     QStringList &values(const QString &v); // With compat mapping and magic variables
 | 
|---|
| 156 |     QString first(const QString &v); // ditto
 | 
|---|
| 157 |     QMap<QString, QStringList> &variables(); // No compat mapping and magic, obviously
 | 
|---|
| 158 | 
 | 
|---|
| 159 |     bool isRecursive() const { return recursive; }
 | 
|---|
| 160 | 
 | 
|---|
| 161 | protected:
 | 
|---|
| 162 |     friend class MakefileGenerator;
 | 
|---|
| 163 |     bool read(const QString &file, QMap<QString, QStringList> &place);
 | 
|---|
| 164 |     bool read(QTextStream &file, QMap<QString, QStringList> &place);
 | 
|---|
| 165 | 
 | 
|---|
| 166 | };
 | 
|---|
| 167 | Q_DECLARE_METATYPE(QMakeProject*)
 | 
|---|
| 168 | 
 | 
|---|
| 169 | inline QString QMakeProject::projectFile()
 | 
|---|
| 170 | {
 | 
|---|
| 171 |     if (pfile == "-")
 | 
|---|
| 172 |         return QString("(stdin)");
 | 
|---|
| 173 |     return pfile;
 | 
|---|
| 174 | }
 | 
|---|
| 175 | 
 | 
|---|
| 176 | inline QStringList &QMakeProject::values(const QString &v)
 | 
|---|
| 177 | { return values(v, vars); }
 | 
|---|
| 178 | 
 | 
|---|
| 179 | inline bool QMakeProject::isSet(const QString &v)
 | 
|---|
| 180 | { return vars.contains(v); }
 | 
|---|
| 181 | 
 | 
|---|
| 182 | inline QString QMakeProject::first(const QString &v)
 | 
|---|
| 183 | {
 | 
|---|
| 184 |     const QStringList vals = values(v);
 | 
|---|
| 185 |     if(vals.isEmpty())
 | 
|---|
| 186 |         return QString("");
 | 
|---|
| 187 |     return vals.first();
 | 
|---|
| 188 | }
 | 
|---|
| 189 | 
 | 
|---|
| 190 | inline QMap<QString, QStringList> &QMakeProject::variables()
 | 
|---|
| 191 | { return vars; }
 | 
|---|
| 192 | 
 | 
|---|
| 193 | QT_END_NAMESPACE
 | 
|---|
| 194 | 
 | 
|---|
| 195 | #endif // PROJECT_H
 | 
|---|