| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: makefile.h 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Definition of MakefileGenerator class.
|
|---|
| 5 | **
|
|---|
| 6 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
|---|
| 7 | **
|
|---|
| 8 | ** This file is part of qmake.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 11 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 12 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 13 | **
|
|---|
| 14 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 15 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 16 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 17 | ** packaging of this file.
|
|---|
| 18 | **
|
|---|
| 19 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 20 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 21 | ** with the Software.
|
|---|
| 22 | **
|
|---|
| 23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 25 | **
|
|---|
| 26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 27 | ** information about Qt Commercial License Agreements.
|
|---|
| 28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 30 | **
|
|---|
| 31 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 32 | ** not clear to you.
|
|---|
| 33 | **
|
|---|
| 34 | **********************************************************************/
|
|---|
| 35 | #ifndef __MAKEFILE_H__
|
|---|
| 36 | #define __MAKEFILE_H__
|
|---|
| 37 |
|
|---|
| 38 | #include "option.h"
|
|---|
| 39 | #include "project.h"
|
|---|
| 40 | #include <qtextstream.h>
|
|---|
| 41 |
|
|---|
| 42 | #ifdef Q_OS_WIN32
|
|---|
| 43 | #define QT_POPEN _popen
|
|---|
| 44 | #else
|
|---|
| 45 | #define QT_POPEN popen
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | class MakefileGenerator
|
|---|
| 49 | {
|
|---|
| 50 | QString spec;
|
|---|
| 51 | bool init_opath_already, init_already, moc_aware, no_io;
|
|---|
| 52 | QStringList createObjectList(const QString &var);
|
|---|
| 53 | QString build_args();
|
|---|
| 54 | QString dependencyKey(const QString &file) const;
|
|---|
| 55 | QMap<QString, bool> depProcessed;
|
|---|
| 56 | QMap<QString, QString> depHeuristics, fileFixed;
|
|---|
| 57 | QMap<QString, QString> mocablesToMOC, mocablesFromMOC;
|
|---|
| 58 | QMap<QString, QStringList> depends;
|
|---|
| 59 |
|
|---|
| 60 | protected:
|
|---|
| 61 | void writeObj(QTextStream &, const QString &obj, const QString &src);
|
|---|
| 62 | void writeUicSrc(QTextStream &, const QString &ui);
|
|---|
| 63 | void writeMocObj(QTextStream &, const QString &obj, const QString &src);
|
|---|
| 64 | void writeMocSrc(QTextStream &, const QString &src);
|
|---|
| 65 | void writeLexSrc(QTextStream &, const QString &lex);
|
|---|
| 66 | void writeYaccSrc(QTextStream &, const QString &yac);
|
|---|
| 67 | void writeInstalls(QTextStream &t, const QString &installs);
|
|---|
| 68 | void writeImageObj(QTextStream &t, const QString &obj);
|
|---|
| 69 | void writeImageSrc(QTextStream &t, const QString &images);
|
|---|
| 70 |
|
|---|
| 71 | protected:
|
|---|
| 72 |
|
|---|
| 73 | QMakeProject *project;
|
|---|
| 74 |
|
|---|
| 75 | class MakefileDependDir {
|
|---|
| 76 | public:
|
|---|
| 77 | MakefileDependDir(const QString &r, const QString &l) : real_dir(r), local_dir(l) { }
|
|---|
| 78 | QString real_dir, local_dir;
|
|---|
| 79 | };
|
|---|
| 80 | bool generateDependencies(QPtrList<MakefileDependDir> &dirs, const QString &x, bool recurse);
|
|---|
| 81 |
|
|---|
| 82 | QString buildArgs();
|
|---|
| 83 |
|
|---|
| 84 | QString specdir();
|
|---|
| 85 | QString cleanFilePath(const QString &file) const;
|
|---|
| 86 | bool generateMocList(const QString &fn);
|
|---|
| 87 |
|
|---|
| 88 | QString findMocSource(const QString &moc_file) const;
|
|---|
| 89 | QString findMocDestination(const QString &src_file) const;
|
|---|
| 90 | virtual QStringList &findDependencies(const QString &file);
|
|---|
| 91 |
|
|---|
| 92 | void setNoIO(bool o);
|
|---|
| 93 | bool noIO() const;
|
|---|
| 94 |
|
|---|
| 95 | void setMocAware(bool o);
|
|---|
| 96 | bool mocAware() const;
|
|---|
| 97 | void logicWarn(const QString &, const QString &);
|
|---|
| 98 |
|
|---|
| 99 | virtual bool doDepends() const { return Option::mkfile::do_deps; }
|
|---|
| 100 | bool writeHeader(QTextStream &);
|
|---|
| 101 | virtual bool writeMakefile(QTextStream &);
|
|---|
| 102 | virtual bool writeMakeQmake(QTextStream &);
|
|---|
| 103 | void initOutPaths();
|
|---|
| 104 | virtual void init();
|
|---|
| 105 |
|
|---|
| 106 | //for cross-platform dependent directories
|
|---|
| 107 | virtual void usePlatformDir();
|
|---|
| 108 |
|
|---|
| 109 | //for installs
|
|---|
| 110 | virtual QString defaultInstall(const QString &);
|
|---|
| 111 |
|
|---|
| 112 | //for prl
|
|---|
| 113 | bool processPrlFile(QString &);
|
|---|
| 114 | virtual void processPrlVariable(const QString &, const QStringList &);
|
|---|
| 115 | virtual void processPrlFiles();
|
|---|
| 116 | virtual void writePrlFile(QTextStream &);
|
|---|
| 117 |
|
|---|
| 118 | //make sure libraries are found
|
|---|
| 119 | virtual bool findLibraries();
|
|---|
| 120 | virtual QString findDependency(const QString &);
|
|---|
| 121 |
|
|---|
| 122 | void setProcessedDependencies(const QString &file, bool b);
|
|---|
| 123 | bool processedDependencies(const QString &file);
|
|---|
| 124 |
|
|---|
| 125 | virtual QString var(const QString &var);
|
|---|
| 126 | QString varGlue(const QString &var, const QString &before, const QString &glue, const QString &after);
|
|---|
| 127 | QString varList(const QString &var);
|
|---|
| 128 | QString val(const QStringList &varList);
|
|---|
| 129 | QString valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after);
|
|---|
| 130 | QString valList(const QStringList &varList);
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 | QString fileFixify(const QString& file, const QString &out_dir=QString::null,
|
|---|
| 134 | const QString &in_dir=QString::null, bool force_fix=FALSE, bool canon=TRUE) const;
|
|---|
| 135 | QStringList fileFixify(const QStringList& files, const QString &out_dir=QString::null,
|
|---|
| 136 | const QString &in_dir=QString::null, bool force_fix=FALSE, bool canon=TRUE) const;
|
|---|
| 137 | public:
|
|---|
| 138 | MakefileGenerator(QMakeProject *p);
|
|---|
| 139 | virtual ~MakefileGenerator();
|
|---|
| 140 |
|
|---|
| 141 | static MakefileGenerator *create(QMakeProject *);
|
|---|
| 142 | virtual bool write();
|
|---|
| 143 | virtual bool openOutput(QFile &) const;
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | inline QString MakefileGenerator::findMocSource(const QString &moc_file) const
|
|---|
| 147 | {
|
|---|
| 148 | QString tmp = cleanFilePath(moc_file);
|
|---|
| 149 | if (mocablesFromMOC.contains(tmp))
|
|---|
| 150 | return mocablesFromMOC[tmp];
|
|---|
| 151 | else
|
|---|
| 152 | return QString("");
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | inline QString MakefileGenerator::findMocDestination(const QString &src_file) const
|
|---|
| 156 | {
|
|---|
| 157 | QString tmp = cleanFilePath(src_file);
|
|---|
| 158 | if (mocablesToMOC.contains(tmp))
|
|---|
| 159 | return mocablesToMOC[tmp];
|
|---|
| 160 | else
|
|---|
| 161 | return QString("");
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | inline void MakefileGenerator::setMocAware(bool o)
|
|---|
| 165 | { moc_aware = o; }
|
|---|
| 166 |
|
|---|
| 167 | inline bool MakefileGenerator::mocAware() const
|
|---|
| 168 | { return moc_aware; }
|
|---|
| 169 |
|
|---|
| 170 | inline void MakefileGenerator::setNoIO(bool o)
|
|---|
| 171 | { no_io = o; }
|
|---|
| 172 |
|
|---|
| 173 | inline bool MakefileGenerator::noIO() const
|
|---|
| 174 | { return no_io; }
|
|---|
| 175 |
|
|---|
| 176 | inline QString MakefileGenerator::defaultInstall(const QString &)
|
|---|
| 177 | { return QString(""); }
|
|---|
| 178 |
|
|---|
| 179 | inline bool MakefileGenerator::findLibraries()
|
|---|
| 180 | { return TRUE; }
|
|---|
| 181 |
|
|---|
| 182 | inline QString MakefileGenerator::findDependency(const QString &)
|
|---|
| 183 | { return QString(""); }
|
|---|
| 184 |
|
|---|
| 185 | inline MakefileGenerator::~MakefileGenerator()
|
|---|
| 186 | { }
|
|---|
| 187 |
|
|---|
| 188 | QString mkdir_p_asstring(const QString &dir);
|
|---|
| 189 |
|
|---|
| 190 | #endif /* __MAKEFILE_H__ */
|
|---|