Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the qmake application of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
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, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef MAKEFILE_H |
43 | #define MAKEFILE_H |
44 | |
45 | #include "option.h" |
46 | #include "project.h" |
47 | #include "makefiledeps.h" |
48 | #include <qtextstream.h> |
49 | #include <qlist.h> |
50 | #include <qhash.h> |
51 | #include <qfileinfo.h> |
52 | |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | #ifdef Q_OS_WIN32 |
56 | #define QT_POPEN _popen |
57 | #define QT_PCLOSE _pclose |
58 | #else |
59 | #define QT_POPEN popen |
60 | #define QT_PCLOSE pclose |
61 | #endif |
62 | |
63 | struct ReplaceExtraCompilerCacheKey |
64 | { |
65 | mutable uint hash; |
66 | QString var, in, out, pwd; |
67 | ReplaceExtraCompilerCacheKey(const QString &v, const QStringList &i, const QStringList &o); |
68 | bool operator==(const ReplaceExtraCompilerCacheKey &f) const; |
69 | inline uint hashCode() const { |
70 | if(!hash) |
71 | hash = qHash(var) ^ qHash(in) ^ qHash(out) /*^ qHash(pwd)*/; |
72 | return hash; |
73 | } |
74 | }; |
75 | inline uint qHash(const ReplaceExtraCompilerCacheKey &f) { return f.hashCode(); } |
76 | |
77 | struct ReplaceExtraCompilerCacheKey; |
78 | |
79 | class MakefileGenerator : protected QMakeSourceFileInfo |
80 | { |
81 | QString spec; |
82 | bool init_opath_already, init_already, no_io; |
83 | QHash<QString, bool> init_compiler_already; |
84 | QString build_args(const QString &outdir=QString()); |
85 | void checkMultipleDefinition(const QString &, const QString &); |
86 | |
87 | //internal caches |
88 | mutable QHash<QString, QMakeLocalFileName> depHeuristicsCache; |
89 | mutable QHash<QString, QStringList> dependsCache; |
90 | mutable QHash<ReplaceExtraCompilerCacheKey, QString> extraCompilerVariablesCache; |
91 | |
92 | protected: |
93 | QStringList createObjectList(const QStringList &sources); |
94 | |
95 | //makefile style generator functions |
96 | void writeObj(QTextStream &, const QString &src); |
97 | void writeInstalls(QTextStream &t, const QString &installs, bool noBuild=false); |
98 | void writeHeader(QTextStream &t); |
99 | void writeSubDirs(QTextStream &t); |
100 | void writeMakeQmake(QTextStream &t); |
101 | void writeExtraVariables(QTextStream &t); |
102 | void writeExtraTargets(QTextStream &t); |
103 | void writeExtraCompilerTargets(QTextStream &t); |
104 | void writeExtraCompilerVariables(QTextStream &t); |
105 | virtual bool writeStubMakefile(QTextStream &t); |
106 | virtual bool writeMakefile(QTextStream &t); |
107 | |
108 | QString pkgConfigPrefix() const; |
109 | QString pkgConfigFileName(bool fixify=true); |
110 | QString pkgConfigFixPath(QString) const; |
111 | void writePkgConfigFile(); // for pkg-config |
112 | |
113 | //generating subtarget makefiles |
114 | struct SubTarget |
115 | { |
116 | QString name; |
117 | QString in_directory, out_directory; |
118 | QString profile, target, makefile; |
119 | QStringList depends; |
120 | }; |
121 | enum SubTargetFlags { |
122 | SubTargetInstalls=0x01, |
123 | SubTargetOrdered=0x02, |
124 | SubTargetSkipDefaultVariables=0x04, |
125 | SubTargetSkipDefaultTargets=0x08, |
126 | |
127 | SubTargetsNoFlags=0x00 |
128 | }; |
129 | QList<MakefileGenerator::SubTarget*> findSubDirsSubTargets() const; |
130 | virtual void writeSubMakeCall(QTextStream &t, const QString &outDirectory_cdin, |
131 | const QString &makeFileIn, const QString &outDirectory_cdout); |
132 | void writeSubTargets(QTextStream &t, QList<SubTarget*> subtargets, int flags); |
133 | |
134 | //extra compiler interface |
135 | bool verifyExtraCompiler(const QString &c, const QString &f); |
136 | virtual QString replaceExtraCompilerVariables(const QString &, const QStringList &, const QStringList &); |
137 | inline QString replaceExtraCompilerVariables(const QString &val, const QString &in, const QString &out) |
138 | { return replaceExtraCompilerVariables(val, QStringList(in), QStringList(out)); } |
139 | |
140 | //interface to the source file info |
141 | QMakeLocalFileName fixPathForFile(const QMakeLocalFileName &, bool); |
142 | QMakeLocalFileName findFileForDep(const QMakeLocalFileName &, const QMakeLocalFileName &); |
143 | QFileInfo findFileInfo(const QMakeLocalFileName &); |
144 | QMakeProject *project; |
145 | |
146 | //escape |
147 | virtual QString unescapeFilePath(const QString &path) const; |
148 | virtual QStringList unescapeFilePaths(const QStringList &path) const; |
149 | virtual QString escapeFilePath(const QString &path) const { return path; } |
150 | virtual QString escapeDependencyPath(const QString &path) const { return escapeFilePath(path); } |
151 | QStringList escapeFilePaths(const QStringList &paths) const; |
152 | QStringList escapeDependencyPaths(const QStringList &paths) const; |
153 | |
154 | //initialization |
155 | void verifyCompilers(); |
156 | virtual void init(); |
157 | void initOutPaths(); |
158 | struct Compiler |
159 | { |
160 | QString variable_in; |
161 | enum CompilerFlag { |
162 | CompilerNoFlags = 0x00, |
163 | CompilerBuiltin = 0x01, |
164 | CompilerNoCheckDeps = 0x02, |
165 | CompilerRemoveNoExist = 0x04 |
166 | }; |
167 | uint flags, type; |
168 | }; |
169 | void initCompiler(const Compiler &comp); |
170 | enum VPATHFlag { |
171 | VPATH_NoFlag = 0x00, |
172 | VPATH_WarnMissingFiles = 0x01, |
173 | VPATH_RemoveMissingFiles = 0x02, |
174 | VPATH_NoFixify = 0x04 |
175 | }; |
176 | QStringList findFilesInVPATH(QStringList l, uchar flags, const QString &var=""); |
177 | |
178 | inline int findExecutable(const QStringList &cmdline) |
179 | { int ret; canExecute(cmdline, &ret); return ret; } |
180 | bool canExecute(const QStringList &cmdline, int *argv0) const; |
181 | inline bool canExecute(const QString &cmdline) const |
182 | { return canExecute(cmdline.split( |
183 | |
184 | bool mkdir(const QString &dir) const; |
185 | QString mkdir_p_asstring(const QString &dir, bool escape=true) const; |
186 | |
187 | //subclasses can use these to query information about how the generator was "run" |
188 | QString buildArgs(const QString &outdir=QString()); |
189 | QString specdir(const QString &outdir=QString()); |
190 | |
191 | virtual QStringList &findDependencies(const QString &file); |
192 | virtual bool doDepends() const { return Option::mkfile::do_deps; } |
193 | |
194 | void filterIncludedFiles(const QString &); |
195 | virtual void processSources() { |
196 | filterIncludedFiles("SOURCES"); |
197 | filterIncludedFiles("GENERATED_SOURCES"); |
198 | } |
199 | |
200 | //for cross-platform dependent directories |
201 | virtual void usePlatformDir(); |
202 | |
203 | //for installs |
204 | virtual QString defaultInstall(const QString &); |
205 | |
206 | //for prl |
207 | QString prlFileName(bool fixify=true); |
208 | void writePrlFile(); |
209 | bool processPrlFile(QString &); |
210 | virtual void processPrlVariable(const QString &, const QStringList &); |
211 | virtual void processPrlFiles(); |
212 | virtual void writePrlFile(QTextStream &); |
213 | |
214 | //make sure libraries are found |
215 | virtual bool findLibraries(); |
216 | |
217 | //for retrieving values and lists of values |
218 | virtual QString var(const QString &var); |
219 | QString varGlue(const QString &var, const QString &before, const QString &glue, const QString &after); |
220 | QString varList(const QString &var); |
221 | QString val(const QStringList &varList); |
222 | QString valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after); |
223 | QString valList(const QStringList &varList); |
224 | |
225 | QString filePrefixRoot(const QString &, const QString &); |
226 | |
227 | //file fixification to unify all file names into a single pattern |
228 | enum FileFixifyType { FileFixifyAbsolute, FileFixifyRelative, FileFixifyDefault }; |
229 | QString fileFixify(const QString& file, const QString &out_dir=QString(), |
230 | const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const; |
231 | inline QString fileFixify(const QString& file, FileFixifyType fix, bool canon=true) const |
232 | { return fileFixify(file, QString(), QString(), fix, canon); } |
233 | QStringList fileFixify(const QStringList& files, const QString &out_dir=QString(), |
234 | const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const; |
235 | inline QStringList fileFixify(const QStringList& files, FileFixifyType fix, bool canon=true) const |
236 | { return fileFixify(files, QString(), QString(), fix, canon); } |
237 | |
238 | public: |
239 | MakefileGenerator(); |
240 | virtual ~MakefileGenerator(); |
241 | QMakeProject *projectFile() const; |
242 | void setProjectFile(QMakeProject *p); |
243 | |
244 | void setNoIO(bool o); |
245 | bool noIO() const; |
246 | |
247 | inline bool exists(QString file) const { return fileInfo(file).exists(); } |
248 | QFileInfo fileInfo(QString file) const; |
249 | |
250 | static MakefileGenerator *create(QMakeProject *); |
251 | virtual bool write(); |
252 | virtual bool writeProjectMakefile(); |
253 | virtual bool supportsMetaBuild() { return true; } |
254 | virtual bool supportsMergedBuilds() { return false; } |
255 | virtual bool mergeBuildProject(MakefileGenerator * /*other*/) { return false; } |
256 | virtual bool openOutput(QFile &, const QString &build) const; |
257 | virtual bool isWindowsShell() const { return Option::host_mode == Option::HOST_WIN_MODE; } |
258 | virtual bool isForSymbianSbsv2() const { return false; } // FIXME: killme - i'm ugly! |
259 | |
260 | /* The next one is to avoid having SymbianCommonGenerator as a virtually |
261 | inherited class of this class. Instead it is without a base class |
262 | (avoiding the virtual inheritance problem), and is allowed to use |
263 | functions defined in here. |
264 | |
265 | To illustrate: |
266 | +-------------------+ |
267 | | MakefileGenerator | |
268 | +-------------------+ |
269 | ^ ^ |
270 | | | |
271 | | X <-- Avoid this inheritance |
272 | | | |
273 | +------------------------+ +------------------------+ |
274 | | UnixMakefileGenerator | | SymbianCommonGenerator | |
275 | | or | | | |
276 | | NmakeMakefileGenerator | | | |
277 | +------------------------+ +------------------------+ |
278 | ^ ^ |
279 | | | |
280 | | | |
281 | | | |
282 | +-----------------------------+ |
283 | | SymbianMakefileTemplate<> | |
284 | +-----------------------------+ |
285 | |
286 | We want to avoid the famous diamond problem, because if we have that, we need |
287 | virtual inheritance, which not all compilers like. Therefore, we break the |
288 | link as illustrated. Instead, we have a pointer to MakefileGenerator inside |
289 | SymbianCommonGenerator, and allows full access by making it a friend here. |
290 | */ |
291 | friend class SymbianCommonGenerator; |
292 | }; |
293 | |
294 | inline void MakefileGenerator::setNoIO(bool o) |
295 | { no_io = o; } |
296 | |
297 | inline bool MakefileGenerator::noIO() const |
298 | { return no_io; } |
299 | |
300 | inline QString MakefileGenerator::defaultInstall(const QString &) |
301 | { return QString(""); } |
302 | |
303 | inline bool MakefileGenerator::findLibraries() |
304 | { return true; } |
305 | |
306 | inline MakefileGenerator::~MakefileGenerator() |
307 | { } |
308 | |
309 | QT_END_NAMESPACE |
310 | |
311 | #endif // MAKEFILE_H |
312 |
Warning: That file was not part of the compilation database. It may have many parsing errors.