1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the qmake application of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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 | //generating subtarget makefiles
|
---|
109 | struct SubTarget
|
---|
110 | {
|
---|
111 | QString name;
|
---|
112 | QString in_directory, out_directory;
|
---|
113 | QString profile, target, makefile;
|
---|
114 | QStringList depends;
|
---|
115 | };
|
---|
116 | enum SubTargetFlags {
|
---|
117 | SubTargetInstalls=0x01,
|
---|
118 | SubTargetOrdered=0x02,
|
---|
119 |
|
---|
120 | SubTargetsNoFlags=0x00
|
---|
121 | };
|
---|
122 | void writeSubTargets(QTextStream &t, QList<SubTarget*> subtargets, int flags);
|
---|
123 |
|
---|
124 | //extra compiler interface
|
---|
125 | bool verifyExtraCompiler(const QString &c, const QString &f);
|
---|
126 | virtual QString replaceExtraCompilerVariables(const QString &, const QStringList &, const QStringList &);
|
---|
127 | inline QString replaceExtraCompilerVariables(const QString &val, const QString &in, const QString &out)
|
---|
128 | { return replaceExtraCompilerVariables(val, QStringList(in), QStringList(out)); }
|
---|
129 |
|
---|
130 | //interface to the source file info
|
---|
131 | QMakeLocalFileName fixPathForFile(const QMakeLocalFileName &, bool);
|
---|
132 | QMakeLocalFileName findFileForDep(const QMakeLocalFileName &, const QMakeLocalFileName &);
|
---|
133 | QFileInfo findFileInfo(const QMakeLocalFileName &);
|
---|
134 | QMakeProject *project;
|
---|
135 |
|
---|
136 | //escape
|
---|
137 | virtual QString unescapeFilePath(const QString &path) const;
|
---|
138 | virtual QStringList unescapeFilePaths(const QStringList &path) const;
|
---|
139 | virtual QString escapeFilePath(const QString &path) const { return path; }
|
---|
140 | virtual QString escapeDependencyPath(const QString &path) const { return escapeFilePath(path); }
|
---|
141 | QStringList escapeFilePaths(const QStringList &paths) const;
|
---|
142 | QStringList escapeDependencyPaths(const QStringList &paths) const;
|
---|
143 |
|
---|
144 | //initialization
|
---|
145 | void verifyCompilers();
|
---|
146 | virtual void init();
|
---|
147 | void initOutPaths();
|
---|
148 | struct Compiler
|
---|
149 | {
|
---|
150 | QString variable_in;
|
---|
151 | enum CompilerFlag {
|
---|
152 | CompilerNoFlags = 0x00,
|
---|
153 | CompilerBuiltin = 0x01,
|
---|
154 | CompilerNoCheckDeps = 0x02,
|
---|
155 | CompilerRemoveNoExist = 0x04
|
---|
156 | };
|
---|
157 | uint flags, type;
|
---|
158 | };
|
---|
159 | void initCompiler(const Compiler &comp);
|
---|
160 | enum VPATHFlag {
|
---|
161 | VPATH_NoFlag = 0x00,
|
---|
162 | VPATH_WarnMissingFiles = 0x01,
|
---|
163 | VPATH_RemoveMissingFiles = 0x02,
|
---|
164 | VPATH_NoFixify = 0x04
|
---|
165 | };
|
---|
166 | QStringList findFilesInVPATH(QStringList l, uchar flags, const QString &var="");
|
---|
167 |
|
---|
168 | inline int findExecutable(const QStringList &cmdline)
|
---|
169 | { int ret; canExecute(cmdline, &ret); return ret; }
|
---|
170 | bool canExecute(const QStringList &cmdline, int *argv0) const;
|
---|
171 | inline bool canExecute(const QString &cmdline) const
|
---|
172 | { return canExecute(cmdline.split(' '), 0); }
|
---|
173 |
|
---|
174 | bool mkdir(const QString &dir) const;
|
---|
175 | QString mkdir_p_asstring(const QString &dir, bool escape=true) const;
|
---|
176 |
|
---|
177 | //subclasses can use these to query information about how the generator was "run"
|
---|
178 | QString buildArgs(const QString &outdir=QString());
|
---|
179 | QString specdir(const QString &outdir=QString());
|
---|
180 |
|
---|
181 | virtual QStringList &findDependencies(const QString &file);
|
---|
182 | virtual bool doDepends() const { return Option::mkfile::do_deps; }
|
---|
183 |
|
---|
184 | void filterIncludedFiles(const QString &);
|
---|
185 | virtual void processSources() {
|
---|
186 | filterIncludedFiles("SOURCES");
|
---|
187 | filterIncludedFiles("GENERATED_SOURCES");
|
---|
188 | }
|
---|
189 |
|
---|
190 | //for cross-platform dependent directories
|
---|
191 | virtual void usePlatformDir();
|
---|
192 |
|
---|
193 | //for installs
|
---|
194 | virtual QString defaultInstall(const QString &);
|
---|
195 |
|
---|
196 | //for prl
|
---|
197 | QString prlFileName(bool fixify=true);
|
---|
198 | void writePrlFile();
|
---|
199 | bool processPrlFile(QString &);
|
---|
200 | virtual void processPrlVariable(const QString &, const QStringList &);
|
---|
201 | virtual void processPrlFiles();
|
---|
202 | virtual void writePrlFile(QTextStream &);
|
---|
203 |
|
---|
204 | //make sure libraries are found
|
---|
205 | virtual bool findLibraries();
|
---|
206 |
|
---|
207 | //for retrieving values and lists of values
|
---|
208 | virtual QString var(const QString &var);
|
---|
209 | QString varGlue(const QString &var, const QString &before, const QString &glue, const QString &after);
|
---|
210 | QString varList(const QString &var);
|
---|
211 | QString val(const QStringList &varList);
|
---|
212 | QString valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after);
|
---|
213 | QString valList(const QStringList &varList);
|
---|
214 |
|
---|
215 | QString filePrefixRoot(const QString &, const QString &);
|
---|
216 |
|
---|
217 | //file fixification to unify all file names into a single pattern
|
---|
218 | enum FileFixifyType { FileFixifyAbsolute, FileFixifyRelative, FileFixifyDefault };
|
---|
219 | QString fileFixify(const QString& file, const QString &out_dir=QString(),
|
---|
220 | const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const;
|
---|
221 | inline QString fileFixify(const QString& file, FileFixifyType fix, bool canon=true) const
|
---|
222 | { return fileFixify(file, QString(), QString(), fix, canon); }
|
---|
223 | QStringList fileFixify(const QStringList& files, const QString &out_dir=QString(),
|
---|
224 | const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const;
|
---|
225 | inline QStringList fileFixify(const QStringList& files, FileFixifyType fix, bool canon=true) const
|
---|
226 | { return fileFixify(files, QString(), QString(), fix, canon); }
|
---|
227 |
|
---|
228 | public:
|
---|
229 | MakefileGenerator();
|
---|
230 | virtual ~MakefileGenerator();
|
---|
231 | QMakeProject *projectFile() const;
|
---|
232 | void setProjectFile(QMakeProject *p);
|
---|
233 |
|
---|
234 | void setNoIO(bool o);
|
---|
235 | bool noIO() const;
|
---|
236 |
|
---|
237 | inline bool exists(QString file) const { return fileInfo(file).exists(); }
|
---|
238 | QFileInfo fileInfo(QString file) const;
|
---|
239 |
|
---|
240 | static MakefileGenerator *create(QMakeProject *);
|
---|
241 | virtual bool write();
|
---|
242 | virtual bool writeProjectMakefile();
|
---|
243 | virtual bool supportsMetaBuild() { return true; }
|
---|
244 | virtual bool supportsMergedBuilds() { return false; }
|
---|
245 | virtual bool mergeBuildProject(MakefileGenerator * /*other*/) { return false; }
|
---|
246 | virtual bool openOutput(QFile &, const QString &build) const;
|
---|
247 | virtual bool isWindowsShell() const { return Option::target_mode == Option::TARG_WIN_MODE; }
|
---|
248 | };
|
---|
249 |
|
---|
250 | inline void MakefileGenerator::setNoIO(bool o)
|
---|
251 | { no_io = o; }
|
---|
252 |
|
---|
253 | inline bool MakefileGenerator::noIO() const
|
---|
254 | { return no_io; }
|
---|
255 |
|
---|
256 | inline QString MakefileGenerator::defaultInstall(const QString &)
|
---|
257 | { return QString(""); }
|
---|
258 |
|
---|
259 | inline bool MakefileGenerator::findLibraries()
|
---|
260 | { return true; }
|
---|
261 |
|
---|
262 | inline MakefileGenerator::~MakefileGenerator()
|
---|
263 | { }
|
---|
264 |
|
---|
265 | QT_END_NAMESPACE
|
---|
266 |
|
---|
267 | #endif // MAKEFILE_H
|
---|