0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 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 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
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 |
void generatePrint(const QString pathName);
|
|
95 |
|
|
96 |
//makefile style generator functions
|
|
97 |
void writeObj(QTextStream &, const QString &src);
|
|
98 |
void writeInstalls(QTextStream &t, const QString &installs, bool noBuild=false);
|
|
99 |
void writeHeader(QTextStream &t);
|
|
100 |
void writeSubDirs(QTextStream &t);
|
|
101 |
void writeMakeQmake(QTextStream &t);
|
|
102 |
void writeExtraVariables(QTextStream &t);
|
|
103 |
void writeExtraTargets(QTextStream &t);
|
|
104 |
void writeExtraCompilerTargets(QTextStream &t);
|
|
105 |
void writeExtraCompilerVariables(QTextStream &t);
|
|
106 |
virtual bool writeStubMakefile(QTextStream &t);
|
|
107 |
virtual bool writeMakefile(QTextStream &t);
|
|
108 |
|
|
109 |
//generating subtarget makefiles
|
|
110 |
struct SubTarget
|
|
111 |
{
|
|
112 |
QString name;
|
|
113 |
QString in_directory, out_directory;
|
|
114 |
QString profile, target, makefile;
|
|
115 |
QStringList depends;
|
|
116 |
};
|
|
117 |
enum SubTargetFlags {
|
|
118 |
SubTargetInstalls=0x01,
|
|
119 |
SubTargetOrdered=0x02,
|
|
120 |
SubTargetSkipDefaultVariables=0x04,
|
|
121 |
SubTargetSkipDefaultTargets=0x08,
|
|
122 |
|
|
123 |
SubTargetsNoFlags=0x00
|
|
124 |
};
|
|
125 |
QList<MakefileGenerator::SubTarget*> findSubDirsSubTargets() const;
|
|
126 |
void writeSubTargets(QTextStream &t, QList<SubTarget*> subtargets, int flags);
|
|
127 |
|
|
128 |
//extra compiler interface
|
|
129 |
bool verifyExtraCompiler(const QString &c, const QString &f);
|
|
130 |
virtual QString replaceExtraCompilerVariables(const QString &, const QStringList &, const QStringList &);
|
|
131 |
inline QString replaceExtraCompilerVariables(const QString &val, const QString &in, const QString &out)
|
|
132 |
{ return replaceExtraCompilerVariables(val, QStringList(in), QStringList(out)); }
|
|
133 |
|
|
134 |
//interface to the source file info
|
|
135 |
QMakeLocalFileName fixPathForFile(const QMakeLocalFileName &, bool);
|
|
136 |
QMakeLocalFileName findFileForDep(const QMakeLocalFileName &, const QMakeLocalFileName &);
|
|
137 |
QFileInfo findFileInfo(const QMakeLocalFileName &);
|
|
138 |
QMakeProject *project;
|
|
139 |
|
|
140 |
//escape
|
|
141 |
virtual QString unescapeFilePath(const QString &path) const;
|
|
142 |
virtual QStringList unescapeFilePaths(const QStringList &path) const;
|
|
143 |
virtual QString escapeFilePath(const QString &path) const { return path; }
|
|
144 |
virtual QString escapeDependencyPath(const QString &path) const { return escapeFilePath(path); }
|
|
145 |
QStringList escapeFilePaths(const QStringList &paths) const;
|
|
146 |
QStringList escapeDependencyPaths(const QStringList &paths) const;
|
|
147 |
|
|
148 |
//initialization
|
|
149 |
void verifyCompilers();
|
|
150 |
virtual void init();
|
|
151 |
void initOutPaths();
|
|
152 |
struct Compiler
|
|
153 |
{
|
|
154 |
QString variable_in;
|
|
155 |
enum CompilerFlag {
|
|
156 |
CompilerNoFlags = 0x00,
|
|
157 |
CompilerBuiltin = 0x01,
|
|
158 |
CompilerNoCheckDeps = 0x02,
|
|
159 |
CompilerRemoveNoExist = 0x04
|
|
160 |
};
|
|
161 |
uint flags, type;
|
|
162 |
};
|
|
163 |
void initCompiler(const Compiler &comp);
|
|
164 |
enum VPATHFlag {
|
|
165 |
VPATH_NoFlag = 0x00,
|
|
166 |
VPATH_WarnMissingFiles = 0x01,
|
|
167 |
VPATH_RemoveMissingFiles = 0x02,
|
|
168 |
VPATH_NoFixify = 0x04
|
|
169 |
};
|
|
170 |
QStringList findFilesInVPATH(QStringList l, uchar flags, const QString &var="");
|
|
171 |
|
|
172 |
inline int findExecutable(const QStringList &cmdline)
|
|
173 |
{ int ret; canExecute(cmdline, &ret); return ret; }
|
|
174 |
bool canExecute(const QStringList &cmdline, int *argv0) const;
|
|
175 |
inline bool canExecute(const QString &cmdline) const
|
|
176 |
{ return canExecute(cmdline.split(' '), 0); }
|
|
177 |
|
|
178 |
bool mkdir(const QString &dir) const;
|
|
179 |
QString mkdir_p_asstring(const QString &dir, bool escape=true) const;
|
|
180 |
|
|
181 |
//subclasses can use these to query information about how the generator was "run"
|
|
182 |
QString buildArgs(const QString &outdir=QString());
|
|
183 |
QString specdir(const QString &outdir=QString());
|
|
184 |
|
|
185 |
virtual QStringList &findDependencies(const QString &file);
|
|
186 |
virtual bool doDepends() const { return Option::mkfile::do_deps; }
|
|
187 |
|
|
188 |
void filterIncludedFiles(const QString &);
|
|
189 |
virtual void processSources() {
|
|
190 |
filterIncludedFiles("SOURCES");
|
|
191 |
filterIncludedFiles("GENERATED_SOURCES");
|
|
192 |
}
|
|
193 |
|
|
194 |
//for cross-platform dependent directories
|
|
195 |
virtual void usePlatformDir();
|
|
196 |
|
|
197 |
//for installs
|
|
198 |
virtual QString defaultInstall(const QString &);
|
|
199 |
|
|
200 |
//for prl
|
|
201 |
QString prlFileName(bool fixify=true);
|
|
202 |
void writePrlFile();
|
|
203 |
bool processPrlFile(QString &);
|
|
204 |
virtual void processPrlVariable(const QString &, const QStringList &);
|
|
205 |
virtual void processPrlFiles();
|
|
206 |
virtual void writePrlFile(QTextStream &);
|
|
207 |
|
|
208 |
//make sure libraries are found
|
|
209 |
virtual bool findLibraries();
|
|
210 |
|
|
211 |
//for retrieving values and lists of values
|
|
212 |
virtual QString var(const QString &var);
|
|
213 |
QString varGlue(const QString &var, const QString &before, const QString &glue, const QString &after);
|
|
214 |
QString varList(const QString &var);
|
|
215 |
QString val(const QStringList &varList);
|
|
216 |
QString valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after);
|
|
217 |
QString valList(const QStringList &varList);
|
|
218 |
|
|
219 |
QString filePrefixRoot(const QString &, const QString &);
|
|
220 |
|
|
221 |
//file fixification to unify all file names into a single pattern
|
|
222 |
enum FileFixifyType { FileFixifyAbsolute, FileFixifyRelative, FileFixifyDefault };
|
|
223 |
QString fileFixify(const QString& file, const QString &out_dir=QString(),
|
|
224 |
const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const;
|
|
225 |
inline QString fileFixify(const QString& file, FileFixifyType fix, bool canon=true) const
|
|
226 |
{ return fileFixify(file, QString(), QString(), fix, canon); }
|
|
227 |
QStringList fileFixify(const QStringList& files, const QString &out_dir=QString(),
|
|
228 |
const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const;
|
|
229 |
inline QStringList fileFixify(const QStringList& files, FileFixifyType fix, bool canon=true) const
|
|
230 |
{ return fileFixify(files, QString(), QString(), fix, canon); }
|
|
231 |
|
|
232 |
public:
|
|
233 |
MakefileGenerator();
|
|
234 |
virtual ~MakefileGenerator();
|
|
235 |
QMakeProject *projectFile() const;
|
|
236 |
void setProjectFile(QMakeProject *p);
|
|
237 |
|
|
238 |
void setNoIO(bool o);
|
|
239 |
bool noIO() const;
|
|
240 |
|
|
241 |
inline bool exists(QString file) const { return fileInfo(file).exists(); }
|
|
242 |
QFileInfo fileInfo(QString file) const;
|
|
243 |
|
|
244 |
static MakefileGenerator *create(QMakeProject *);
|
|
245 |
virtual bool write();
|
|
246 |
virtual bool writeProjectMakefile();
|
|
247 |
virtual bool supportsMetaBuild() { return true; }
|
|
248 |
virtual bool supportsMergedBuilds() { return false; }
|
|
249 |
virtual bool mergeBuildProject(MakefileGenerator * /*other*/) { return false; }
|
|
250 |
virtual bool openOutput(QFile &, const QString &build) const;
|
|
251 |
virtual bool isWindowsShell() const { return Option::target_mode == Option::TARG_WIN_MODE; }
|
|
252 |
};
|
|
253 |
|
|
254 |
inline void MakefileGenerator::setNoIO(bool o)
|
|
255 |
{ no_io = o; }
|
|
256 |
|
|
257 |
inline bool MakefileGenerator::noIO() const
|
|
258 |
{ return no_io; }
|
|
259 |
|
|
260 |
inline QString MakefileGenerator::defaultInstall(const QString &)
|
|
261 |
{ return QString(""); }
|
|
262 |
|
|
263 |
inline bool MakefileGenerator::findLibraries()
|
|
264 |
{ return true; }
|
|
265 |
|
|
266 |
inline MakefileGenerator::~MakefileGenerator()
|
|
267 |
{ }
|
|
268 |
|
|
269 |
QT_END_NAMESPACE
|
|
270 |
|
|
271 |
#endif // MAKEFILE_H
|