2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:13:29 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-09-19 12:28:29 +00:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef MAKEFILE_H
|
|
|
|
#define MAKEFILE_H
|
|
|
|
|
|
|
|
#include "option.h"
|
|
|
|
#include "project.h"
|
|
|
|
#include "makefiledeps.h"
|
|
|
|
#include <qtextstream.h>
|
|
|
|
#include <qlist.h>
|
|
|
|
#include <qhash.h>
|
|
|
|
#include <qfileinfo.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#define QT_POPEN _popen
|
|
|
|
#define QT_PCLOSE _pclose
|
|
|
|
#else
|
|
|
|
#define QT_POPEN popen
|
|
|
|
#define QT_PCLOSE pclose
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct ReplaceExtraCompilerCacheKey
|
|
|
|
{
|
|
|
|
mutable uint hash;
|
|
|
|
QString var, in, out, pwd;
|
|
|
|
ReplaceExtraCompilerCacheKey(const QString &v, const QStringList &i, const QStringList &o);
|
|
|
|
bool operator==(const ReplaceExtraCompilerCacheKey &f) const;
|
|
|
|
inline uint hashCode() const {
|
|
|
|
if(!hash)
|
2012-07-24 13:45:44 +00:00
|
|
|
hash = qHash(var) ^ qHash(in) ^ qHash(out) /*^ qHash(pwd)*/;
|
2011-04-27 10:05:43 +00:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
inline uint qHash(const ReplaceExtraCompilerCacheKey &f) { return f.hashCode(); }
|
|
|
|
|
|
|
|
struct ReplaceExtraCompilerCacheKey;
|
|
|
|
|
|
|
|
class MakefileGenerator : protected QMakeSourceFileInfo
|
|
|
|
{
|
|
|
|
QString spec;
|
|
|
|
bool init_opath_already, init_already, no_io;
|
|
|
|
QHash<QString, bool> init_compiler_already;
|
2013-02-28 11:40:16 +00:00
|
|
|
QString makedir, chkexists;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString build_args(const QString &outdir=QString());
|
|
|
|
|
|
|
|
//internal caches
|
|
|
|
mutable QHash<QString, QMakeLocalFileName> depHeuristicsCache;
|
|
|
|
mutable QHash<QString, QStringList> dependsCache;
|
|
|
|
mutable QHash<ReplaceExtraCompilerCacheKey, QString> extraCompilerVariablesCache;
|
|
|
|
|
|
|
|
protected:
|
2013-03-06 13:53:36 +00:00
|
|
|
enum TARG_MODE { TARG_UNIX_MODE, TARG_MAC_MODE, TARG_WIN_MODE } target_mode;
|
2012-04-17 10:15:39 +00:00
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList createObjectList(const ProStringList &sources);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//makefile style generator functions
|
2012-08-20 11:04:39 +00:00
|
|
|
void writeObj(QTextStream &, const char *src);
|
2012-09-06 10:21:38 +00:00
|
|
|
void writeInstalls(QTextStream &t, bool noBuild=false);
|
2011-04-27 10:05:43 +00:00
|
|
|
void writeHeader(QTextStream &t);
|
|
|
|
void writeSubDirs(QTextStream &t);
|
2012-05-18 14:59:22 +00:00
|
|
|
void writeMakeQmake(QTextStream &t, bool noDummyQmakeAll = false);
|
2011-04-27 10:05:43 +00:00
|
|
|
void writeExtraVariables(QTextStream &t);
|
|
|
|
void writeExtraTargets(QTextStream &t);
|
|
|
|
void writeExtraCompilerTargets(QTextStream &t);
|
|
|
|
void writeExtraCompilerVariables(QTextStream &t);
|
|
|
|
virtual bool writeStubMakefile(QTextStream &t);
|
|
|
|
virtual bool writeMakefile(QTextStream &t);
|
|
|
|
|
|
|
|
QString pkgConfigPrefix() const;
|
|
|
|
QString pkgConfigFileName(bool fixify=true);
|
|
|
|
QString pkgConfigFixPath(QString) const;
|
|
|
|
void writePkgConfigFile(); // for pkg-config
|
|
|
|
|
|
|
|
//generating subtarget makefiles
|
|
|
|
struct SubTarget
|
|
|
|
{
|
|
|
|
QString name;
|
|
|
|
QString in_directory, out_directory;
|
|
|
|
QString profile, target, makefile;
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList depends;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
enum SubTargetFlags {
|
|
|
|
SubTargetInstalls=0x01,
|
|
|
|
SubTargetOrdered=0x02,
|
|
|
|
SubTargetSkipDefaultVariables=0x04,
|
|
|
|
SubTargetSkipDefaultTargets=0x08,
|
|
|
|
|
|
|
|
SubTargetsNoFlags=0x00
|
|
|
|
};
|
|
|
|
QList<MakefileGenerator::SubTarget*> findSubDirsSubTargets() const;
|
2012-05-18 20:13:51 +00:00
|
|
|
void writeSubTargetCall(QTextStream &t,
|
|
|
|
const QString &in_directory, const QString &in, const QString &out_directory, const QString &out,
|
2012-04-25 15:12:53 +00:00
|
|
|
const QString &out_directory_cdin, const QString &makefilein);
|
2011-05-03 07:52:30 +00:00
|
|
|
virtual void writeSubMakeCall(QTextStream &t, const QString &outDirectory_cdin,
|
2012-04-25 15:12:53 +00:00
|
|
|
const QString &makeFileIn);
|
2011-04-27 10:05:43 +00:00
|
|
|
void writeSubTargets(QTextStream &t, QList<SubTarget*> subtargets, int flags);
|
|
|
|
|
|
|
|
//extra compiler interface
|
2012-09-06 10:21:38 +00:00
|
|
|
bool verifyExtraCompiler(const ProString &c, const QString &f);
|
2011-04-27 10:05:43 +00:00
|
|
|
virtual QString replaceExtraCompilerVariables(const QString &, const QStringList &, const QStringList &);
|
|
|
|
inline QString replaceExtraCompilerVariables(const QString &val, const QString &in, const QString &out)
|
|
|
|
{ return replaceExtraCompilerVariables(val, QStringList(in), QStringList(out)); }
|
|
|
|
|
|
|
|
//interface to the source file info
|
|
|
|
QMakeLocalFileName fixPathForFile(const QMakeLocalFileName &, bool);
|
|
|
|
QMakeLocalFileName findFileForDep(const QMakeLocalFileName &, const QMakeLocalFileName &);
|
|
|
|
QFileInfo findFileInfo(const QMakeLocalFileName &);
|
|
|
|
QMakeProject *project;
|
|
|
|
|
|
|
|
//escape
|
|
|
|
virtual QString unescapeFilePath(const QString &path) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString unescapeFilePath(const ProString &path) const;
|
2011-04-27 10:05:43 +00:00
|
|
|
virtual QStringList unescapeFilePaths(const QStringList &path) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList unescapeFilePaths(const ProStringList &path) const;
|
2011-04-27 10:05:43 +00:00
|
|
|
virtual QString escapeFilePath(const QString &path) const { return path; }
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString escapeFilePath(const ProString &path) const;
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList escapeFilePaths(const QStringList &paths) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList escapeFilePaths(const ProStringList &paths) const;
|
|
|
|
virtual QString escapeDependencyPath(const QString &path) const { return escapeFilePath(path); }
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList escapeDependencyPaths(const QStringList &paths) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList escapeDependencyPaths(const ProStringList &paths) const;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//initialization
|
|
|
|
void verifyCompilers();
|
|
|
|
virtual void init();
|
|
|
|
void initOutPaths();
|
|
|
|
struct Compiler
|
|
|
|
{
|
|
|
|
QString variable_in;
|
|
|
|
enum CompilerFlag {
|
qmake: Allow extra compilers to have the makefile depend on its inputs
And enable this configuration option for the resource compiler. This
results in a re-run of qmake whenever you touch a qrc file, which is
needed to keep the dependencies up to date. Otherwise you might end
up in the situation where you add a file to a qrc, edit the file some
time later, but a rebuild does not regenerate a cpp file and compile
that, so the final binary is stale.
Technically this dependency problem is present for all source files,
and qrc files are no different than any cpp file that you add a new
header #include to, or adding a Q_OBJECT macro to a header. To pick
up these changes we have to re-run qmake, so that qmake can run its
internal dependency checking, and any extra compiler dependency
commands.
The reason we're making this change for rcc files it that conceptually
people treat them as a "project" files, and expect them to behave similarly
to .pro or .pri files, in that editing the file will invalidate the
makefile. In practice this is often what happens when adding new
headers, as you touch the project file when changing the HEADERS
variable.
Task-number: QTBUG-13334
Change-Id: If69149678e7fba6d812d31dcc17877427f9a6122
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
2011-11-24 15:03:19 +00:00
|
|
|
CompilerNoFlags = 0x00,
|
|
|
|
CompilerBuiltin = 0x01,
|
|
|
|
CompilerNoCheckDeps = 0x02,
|
|
|
|
CompilerRemoveNoExist = 0x04,
|
|
|
|
CompilerAddInputsAsMakefileDeps = 0x08
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
uint flags, type;
|
|
|
|
};
|
|
|
|
void initCompiler(const Compiler &comp);
|
|
|
|
enum VPATHFlag {
|
|
|
|
VPATH_NoFlag = 0x00,
|
|
|
|
VPATH_WarnMissingFiles = 0x01,
|
|
|
|
VPATH_RemoveMissingFiles = 0x02,
|
|
|
|
VPATH_NoFixify = 0x04
|
|
|
|
};
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList findFilesInVPATH(ProStringList l, uchar flags, const QString &var="");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
inline int findExecutable(const QStringList &cmdline)
|
|
|
|
{ int ret; canExecute(cmdline, &ret); return ret; }
|
|
|
|
bool canExecute(const QStringList &cmdline, int *argv0) const;
|
|
|
|
inline bool canExecute(const QString &cmdline) const
|
|
|
|
{ return canExecute(cmdline.split(' '), 0); }
|
|
|
|
|
|
|
|
bool mkdir(const QString &dir) const;
|
|
|
|
QString mkdir_p_asstring(const QString &dir, bool escape=true) const;
|
|
|
|
|
2012-06-26 13:32:17 +00:00
|
|
|
QString specdir();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
//subclasses can use these to query information about how the generator was "run"
|
2012-08-09 16:54:40 +00:00
|
|
|
QString buildArgs();
|
2012-06-26 13:29:35 +00:00
|
|
|
QString fixifySpecdir(const QString &spec, const QString &outdir);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
virtual QStringList &findDependencies(const QString &file);
|
|
|
|
virtual bool doDepends() const { return Option::mkfile::do_deps; }
|
|
|
|
|
2012-08-20 11:04:39 +00:00
|
|
|
void filterIncludedFiles(const char *);
|
2011-04-27 10:05:43 +00:00
|
|
|
virtual void processSources() {
|
|
|
|
filterIncludedFiles("SOURCES");
|
|
|
|
filterIncludedFiles("GENERATED_SOURCES");
|
|
|
|
}
|
|
|
|
|
|
|
|
//for installs
|
|
|
|
virtual QString defaultInstall(const QString &);
|
|
|
|
|
|
|
|
//for prl
|
|
|
|
QString prlFileName(bool fixify=true);
|
|
|
|
void writePrlFile();
|
|
|
|
bool processPrlFile(QString &);
|
|
|
|
virtual void processPrlFiles();
|
|
|
|
virtual void writePrlFile(QTextStream &);
|
|
|
|
|
|
|
|
//make sure libraries are found
|
|
|
|
virtual bool findLibraries();
|
|
|
|
|
|
|
|
//for retrieving values and lists of values
|
2012-09-06 10:21:38 +00:00
|
|
|
virtual QString var(const ProKey &var);
|
|
|
|
QString varGlue(const ProKey &var, const QString &before, const QString &glue, const QString &after);
|
|
|
|
QString fileVarGlue(const ProKey &var, const QString &before, const QString &glue, const QString &after);
|
|
|
|
QString varList(const ProKey &var);
|
|
|
|
QString val(const ProStringList &varList);
|
2011-04-27 10:05:43 +00:00
|
|
|
QString val(const QStringList &varList);
|
|
|
|
QString valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after);
|
2012-09-06 10:21:38 +00:00
|
|
|
QString valGlue(const ProStringList &varList, const QString &before, const QString &glue, const QString &after);
|
2011-04-27 10:05:43 +00:00
|
|
|
QString valList(const QStringList &varList);
|
2012-09-06 10:21:38 +00:00
|
|
|
QString valList(const ProStringList &varList);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QString filePrefixRoot(const QString &, const QString &);
|
|
|
|
|
|
|
|
//file fixification to unify all file names into a single pattern
|
|
|
|
enum FileFixifyType { FileFixifyAbsolute, FileFixifyRelative, FileFixifyDefault };
|
|
|
|
QString fileFixify(const QString& file, const QString &out_dir=QString(),
|
|
|
|
const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const;
|
|
|
|
inline QString fileFixify(const QString& file, FileFixifyType fix, bool canon=true) const
|
|
|
|
{ return fileFixify(file, QString(), QString(), fix, canon); }
|
|
|
|
QStringList fileFixify(const QStringList& files, const QString &out_dir=QString(),
|
|
|
|
const QString &in_dir=QString(), FileFixifyType fix=FileFixifyDefault, bool canon=true) const;
|
|
|
|
inline QStringList fileFixify(const QStringList& files, FileFixifyType fix, bool canon=true) const
|
|
|
|
{ return fileFixify(files, QString(), QString(), fix, canon); }
|
|
|
|
|
2013-01-10 23:30:41 +00:00
|
|
|
QString installMetaFile(const ProKey &replace_rule, const QString &src, const QString &dst);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
public:
|
|
|
|
MakefileGenerator();
|
|
|
|
virtual ~MakefileGenerator();
|
|
|
|
QMakeProject *projectFile() const;
|
|
|
|
void setProjectFile(QMakeProject *p);
|
|
|
|
|
|
|
|
void setNoIO(bool o);
|
|
|
|
bool noIO() const;
|
|
|
|
|
|
|
|
inline bool exists(QString file) const { return fileInfo(file).exists(); }
|
|
|
|
QFileInfo fileInfo(QString file) const;
|
|
|
|
|
|
|
|
static MakefileGenerator *create(QMakeProject *);
|
|
|
|
virtual bool write();
|
|
|
|
virtual bool writeProjectMakefile();
|
|
|
|
virtual bool supportsMetaBuild() { return true; }
|
|
|
|
virtual bool supportsMergedBuilds() { return false; }
|
|
|
|
virtual bool mergeBuildProject(MakefileGenerator * /*other*/) { return false; }
|
|
|
|
virtual bool openOutput(QFile &, const QString &build) const;
|
2012-05-03 18:50:19 +00:00
|
|
|
bool isWindowsShell() const { return Option::dir_sep == QLatin1String("\\"); }
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void MakefileGenerator::setNoIO(bool o)
|
|
|
|
{ no_io = o; }
|
|
|
|
|
|
|
|
inline bool MakefileGenerator::noIO() const
|
|
|
|
{ return no_io; }
|
|
|
|
|
|
|
|
inline QString MakefileGenerator::defaultInstall(const QString &)
|
|
|
|
{ return QString(""); }
|
|
|
|
|
|
|
|
inline bool MakefileGenerator::findLibraries()
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
inline MakefileGenerator::~MakefileGenerator()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // MAKEFILE_H
|