📄 metamakefile.cpp
字号:
//done
return createMakefileGenerator(build_proj);
}
return 0;
}
class SubdirsMetaMakefileGenerator : public MetaMakefileGenerator
{
bool init_flag;
private:
struct Subdir {
Subdir() : makefile(0), indent(0) { }
~Subdir() { delete makefile; }
QString input_dir;
QString output_dir, output_file;
MetaMakefileGenerator *makefile;
int indent;
};
QList<Subdir *> subs;
MakefileGenerator *processBuild(const QString &);
public:
SubdirsMetaMakefileGenerator(QMakeProject *p, bool op) : MetaMakefileGenerator(p, op), init_flag(false) { }
virtual ~SubdirsMetaMakefileGenerator();
virtual bool init();
virtual int type() const { return SUBDIRSMETATYPE; }
virtual bool write(const QString &);
};
bool
SubdirsMetaMakefileGenerator::init()
{
if(init_flag)
return false;
init_flag = true;
if(Option::recursive) {
const QString old_output_dir = Option::output_dir;
const QString oldpwd = qmake_getpwd();
const QStringList &subdirs = project->values("SUBDIRS");
static int recurseDepth = -1;
++recurseDepth;
for(int i = 0; i < subdirs.size(); ++i) {
Subdir *sub = new Subdir;
sub->indent = recurseDepth;
QFileInfo subdir(subdirs.at(i));
if(subdir.isDir())
subdir = QFileInfo(subdirs.at(i) + "/" + subdir.fileName() + Option::pro_ext);
//handle sub project
QMakeProject *sub_proj = new QMakeProject(project->properities());
for (int ind = 0; ind < sub->indent; ++ind)
printf(" ");
printf("Reading %s\n", subdir.absoluteFilePath().toLatin1().constData());
sub->input_dir = subdir.absolutePath();
qmake_setpwd(sub->input_dir);
sub->output_dir = qmake_getpwd(); //this is not going to work for shadow builds ### --Sam
Option::output_dir = sub->output_dir;
if(Option::output_dir.at(Option::output_dir.length()-1) != QLatin1Char('/'))
Option::output_dir += QLatin1Char('/');
sub_proj->read(subdir.fileName());
if(!sub_proj->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
fprintf(stderr, "Project file(%s) not recursed because all requirements not met:\n\t%s\n",
subdir.fileName().toLatin1().constData(),
sub_proj->values("QMAKE_FAILED_REQUIREMENTS").join(" ").toLatin1().constData());
delete sub;
delete sub_proj;
continue;
}
sub->makefile = MetaMakefileGenerator::createMetaGenerator(sub_proj);
if(0 && sub->makefile->type() == SUBDIRSMETATYPE) {
subs.append(sub);
} else {
const QString &output_name = Option::output.fileName();
Option::output.setFileName(sub->output_file);
sub->makefile->write(sub->output_dir);
delete sub;
qmakeClearCaches();
sub = 0;
Option::output.setFileName(output_name);
}
Option::output_dir = old_output_dir;
qmake_setpwd(oldpwd);
}
--recurseDepth;
Option::output_dir = old_output_dir;
qmake_setpwd(oldpwd);
}
Subdir *self = new Subdir;
self->input_dir = qmake_getpwd();
self->output_dir = Option::output_dir;
self->output_file = Option::output.fileName();
self->makefile = new BuildsMetaMakefileGenerator(project, false);
self->makefile->init();
subs.append(self);
return true;
}
bool
SubdirsMetaMakefileGenerator::write(const QString &passpwd)
{
bool ret = true;
const QString &oldpwd = qmake_getpwd();
const QString &output_dir = Option::output_dir;
const QString &output_name = Option::output.fileName();
for(int i = 0; ret && i < subs.count(); i++) {
const Subdir *sub = subs.at(i);
qmake_setpwd(subs.at(i)->input_dir);
Option::output_dir = QFileInfo(subs.at(i)->output_dir).absoluteFilePath();
if(Option::output_dir.at(Option::output_dir.length()-1) != QLatin1Char('/'))
Option::output_dir += QLatin1Char('/');
Option::output.setFileName(subs.at(i)->output_file);
if(i != subs.count()-1) {
for (int ind = 0; ind < sub->indent; ++ind)
printf(" ");
printf("Writing %s\n", QDir::cleanPath(Option::output_dir+"/"+
Option::output.fileName()).toLatin1().constData());
}
QString writepwd = Option::fixPathToLocalOS(qmake_getpwd());
if(!writepwd.startsWith(Option::fixPathToLocalOS(passpwd)))
writepwd = passpwd;
if(!(ret = subs.at(i)->makefile->write(writepwd)))
break;
qmake_setpwd(oldpwd);
}
//restore because I'm paranoid
Option::output.setFileName(output_name);
Option::output_dir = output_dir;
return ret;
}
SubdirsMetaMakefileGenerator::~SubdirsMetaMakefileGenerator()
{
for(int i = 0; i < subs.count(); i++)
delete subs[i];
subs.clear();
}
//Factory things
#include "unixmake.h"
#include "mingw_make.h"
#include "projectgenerator.h"
#include "pbuilder_pbx.h"
#ifndef QMAKE_OPENSOURCE_EDITION
# include "msvc_nmake.h"
# include "borland_bmake.h"
# include "metrowerks_xml.h"
# include "msvc_dsp.h"
# include "msvc_vcproj.h"
#endif
MakefileGenerator *
MetaMakefileGenerator::createMakefileGenerator(QMakeProject *proj, bool noIO)
{
MakefileGenerator *mkfile = NULL;
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
mkfile = new ProjectGenerator;
mkfile->setProjectFile(proj);
return mkfile;
}
QString gen = proj->first("MAKEFILE_GENERATOR");
if(gen.isEmpty()) {
fprintf(stderr, "No generator specified in config file: %s\n",
proj->projectFile().toLatin1().constData());
} else if(gen == "UNIX") {
mkfile = new UnixMakefileGenerator;
} else if(gen == "MINGW") {
mkfile = new MingwMakefileGenerator;
} else if(gen == "PROJECTBUILDER" || gen == "XCODE") {
mkfile = new ProjectBuilderMakefileGenerator;
#ifndef QMAKE_OPENSOURCE_EDITION
} else if(gen == "MSVC") {
// Visual Studio =< v6.0
if(proj->first("TEMPLATE").indexOf(QRegExp("^vc.*")) != -1)
mkfile = new DspMakefileGenerator;
else
mkfile = new NmakeMakefileGenerator;
} else if(gen == "MSVC.NET") {
// Visual Studio >= v7.0
if(proj->first("TEMPLATE").indexOf(QRegExp("^vc.*")) != -1)
mkfile = new VcprojGenerator;
else
mkfile = new NmakeMakefileGenerator;
} else if(gen == "BMAKE") {
mkfile = new BorlandMakefileGenerator;
} else if(gen == "METROWERKS") {
mkfile = new MetrowerksMakefileGenerator;
#endif
} else {
fprintf(stderr, "Unknown generator specified: %s\n", gen.toLatin1().constData());
}
if (mkfile) {
mkfile->setNoIO(noIO);
mkfile->setProjectFile(proj);
}
return mkfile;
}
MetaMakefileGenerator *
MetaMakefileGenerator::createMetaGenerator(QMakeProject *proj, bool op)
{
MetaMakefileGenerator *ret = 0;
if((Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
Option::qmake_mode == Option::QMAKE_GENERATE_PRL)) {
if(proj->first("TEMPLATE").endsWith("subdirs"))
ret = new SubdirsMetaMakefileGenerator(proj, op);
}
if(!ret)
ret = new BuildsMetaMakefileGenerator(proj, op);
ret->init();
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -