📄 pbuilder_pbx.cpp
字号:
/****************************************************************************** $Id: qt/pbuilder_pbx.cpp 3.3.4 edited Dec 17 22:42 $**** Implementation of ProjectBuilderMakefileGenerator class.**** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.**** This file is part of qmake.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition licenses may use this** file in accordance with the Qt Commercial License Agreement provided** with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "pbuilder_pbx.h"#include "option.h"#include "meta.h"#include <qdir.h>#include <qdict.h>#include <qregexp.h>#include <stdlib.h>#include <time.h>#include "qtmd5.h"#ifdef Q_OS_UNIX# include <sys/types.h># include <sys/stat.h>#endif// Note: this is fairly hacky, but it does the job...ProjectBuilderMakefileGenerator::ProjectBuilderMakefileGenerator(QMakeProject *p) : UnixMakefileGenerator(p){}boolProjectBuilderMakefileGenerator::writeMakefile(QTextStream &t){ if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) { /* for now just dump, I need to generated an empty xml or something.. */ fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n", var("QMAKE_FAILED_REQUIREMENTS").latin1()); return TRUE; } project->variables()["MAKEFILE"].clear(); project->variables()["MAKEFILE"].append("Makefile"); if(project->first("TEMPLATE") == "app" || project->first("TEMPLATE") == "lib") return writeMakeParts(t); else if(project->first("TEMPLATE") == "subdirs") return writeSubdirs(t, FALSE); return FALSE;}boolProjectBuilderMakefileGenerator::writeSubdirs(QTextStream &t, bool direct){ QString mkwrap = fileFixify(pbx_dir + Option::dir_sep + ".." + Option::dir_sep + project->first("MAKEFILE"), QDir::currentDirPath()); QFile mkwrapf(mkwrap); if(mkwrapf.open(IO_WriteOnly | IO_Translate)) { debug_msg(1, "pbuilder: Creating file: %s", mkwrap.latin1()); QTextStream mkwrapt(&mkwrapf); UnixMakefileGenerator::writeSubdirs(mkwrapt, direct); } //HEADER t << "// !$*UTF8*$!" << "\n" << "{" << "\n" << "\t" << "archiveVersion = 1;" << "\n" << "\t" << "classes = {" << "\n" << "\t" << "};" << "\n" << "\t" << "objectVersion = " << pbuilderVersion() << ";" << "\n" << "\t" << "objects = {" << endl; //SUBDIRS QStringList subdirs = project->variables()["SUBDIRS"]; QString oldpwd = QDir::currentDirPath(); QMap<QString, QStringList> groups; for(QStringList::Iterator it = subdirs.begin(); it != subdirs.end(); ++it) { QFileInfo fi(Option::fixPathToLocalOS((*it), TRUE)); if(fi.exists()) { if(fi.isDir()) { QString profile = (*it); if(!profile.endsWith(Option::dir_sep)) profile += Option::dir_sep; profile += fi.baseName() + ".pro"; subdirs.append(profile); } else { QMakeProject tmp_proj; QString dir = fi.dirPath(), fn = fi.fileName(); if(!dir.isEmpty()) { if(!QDir::setCurrent(dir)) fprintf(stderr, "Cannot find directory: %s\n", dir.latin1()); } if(tmp_proj.read(fn, oldpwd)) { if(Option::debug_level) { QMap<QString, QStringList> &vars = tmp_proj.variables(); for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it) { if(it.key().left(1) != "." && !it.data().isEmpty()) debug_msg(1, "%s: %s === %s", fn.latin1(), it.key().latin1(), it.data().join(" :: ").latin1()); } } if(tmp_proj.first("TEMPLATE") == "subdirs") { subdirs += fileFixify(tmp_proj.variables()["SUBDIRS"]); } else if(tmp_proj.first("TEMPLATE") == "app" || tmp_proj.first("TEMPLATE") == "lib") { QString pbxproj = QDir::currentDirPath() + Option::dir_sep + tmp_proj.first("TARGET") + projectSuffix(); if(!QFile::exists(pbxproj)) { warn_msg(WarnLogic, "Ignored (not found) '%s'", pbxproj.latin1()); goto nextfile; // # Dirty! } project->variables()["QMAKE_PBX_SUBDIRS"] += pbxproj; //PROJECTREF { bool in_root = TRUE; QString name = QDir::currentDirPath(); QString project_key = keyFor(pbxproj + "_PROJECTREF"); if(project->isActiveConfig("flat")) { QString flat_file = fileFixify(name, oldpwd, Option::output_dir, TRUE); if(flat_file.find(Option::dir_sep) != -1) { QStringList dirs = QStringList::split(Option::dir_sep, flat_file); name = dirs.back(); } } else { QString flat_file = fileFixify(name, oldpwd, Option::output_dir, TRUE); if(QDir::isRelativePath(flat_file) && flat_file.find(Option::dir_sep) != -1) { QString last_grp("QMAKE_PBX_HEIR_GROUP"); QStringList dirs = QStringList::split(Option::dir_sep, flat_file); name = dirs.back(); for(QStringList::Iterator dir_it = dirs.begin(); dir_it != dirs.end(); ++dir_it) { QString new_grp(last_grp + Option::dir_sep + (*dir_it)), new_grp_key(keyFor(new_grp)); if(dir_it == dirs.begin()) { if(!groups.contains(new_grp)) project->variables()["QMAKE_PBX_GROUPS"].append(new_grp_key); } else { if(!groups[last_grp].contains(new_grp_key)) groups[last_grp] += new_grp_key; } last_grp = new_grp; } groups[last_grp] += project_key; in_root = FALSE; } } if(in_root) project->variables()["QMAKE_PBX_GROUPS"] += project_key; t << "\t\t" << project_key << " = {" << "\n" << "\t\t\t" << "isa = PBXFileReference;" << "\n" << "\t\t\t" << "name = " << tmp_proj.first("TARGET") << ";" << "\n" << "\t\t\t" << "path = " << pbxproj << ";" << "\n" << "\t\t\t" << "refType = 0;" << "\n" << "\t\t\t" << "sourceTree = \"<absolute>\";" << "\n" << "\t\t" << "};" << "\n"; //PRODUCTGROUP t << "\t\t" << keyFor(pbxproj + "_PRODUCTGROUP") << " = {" << "\n" << "\t\t\t" << "children = (" << "\n" << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXGroup;" << "\n" << "\t\t\t" << "name = Products;" << "\n" << "\t\t\t" << "refType = 4;" << "\n" << "\t\t\t" << "sourceTree = \"<group>\";" << "\n" << "\t\t" << "};" << "\n"; } } }nextfile: QDir::setCurrent(oldpwd); } } } for(QMap<QString, QStringList>::Iterator grp_it = groups.begin(); grp_it != groups.end(); ++grp_it) { t << "\t\t" << keyFor(grp_it.key()) << " = {" << "\n" << "\t\t\t" << "isa = PBXGroup;" << "\n" << "\t\t\t" << "children = (" << "\n" << valGlue(grp_it.data(), "\t\t\t\t", ",\n\t\t\t\t", "\n") << "\t\t\t" << ");" << "\n" << "\t\t\t" << "name = \"" << grp_it.key().section(Option::dir_sep, -1) << "\";" << "\n" << "\t\t\t" << "refType = 4;" << "\n" << "\t\t" << "};" << "\n"; } //DUMP EVERYTHING THAT TIES THE ABOVE TOGETHER //BUILDSTYLE QString active_buildstyle;#if 0 for(int as_release = 0; as_release < 2; as_release++) #else bool as_release = !project->isActiveConfig("debug");#endif { QString key = keyFor("QMAKE_PBX_" + QString(as_release ? "RELEASE" : "DEBUG")); if(project->isActiveConfig("debug") != as_release) active_buildstyle = key; project->variables()["QMAKE_PBX_BUILDSTYLES"].append(key); t << "\t\t" << key << " = {" << "\n" << "\t\t\t" << "buildRules = (" << "\n" << "\t\t\t" << ");" << "\n" << "\t\t\t" << "buildSettings = {" << "\n" << "\t\t\t\t" << "COPY_PHASE_STRIP = " << (as_release ? "YES" : "NO") << ";" << "\n"; if(as_release) t << "\t\t\t\t" << "DEBUGGING_SYMBOLS = NO;" << "\n"; t << "\t\t\t" << "};" << "\n" << "\t\t\t" << "isa = PBXBuildStyle;" << "\n" << "\t\t\t" << "name = " << (as_release ? "Deployment" : "Development") << ";" << "\n" << "\t\t" << "};" << "\n"; } //ROOT_GROUP t << "\t\t" << keyFor("QMAKE_PBX_ROOT_GROUP") << " = {" << "\n" << "\t\t\t" << "children = (" << "\n" << varGlue("QMAKE_PBX_GROUPS", "\t\t\t\t", ",\n\t\t\t\t", "\n") << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXGroup;" << "\n" << "\t\t\t" << "refType = 4;" << "\n" << "\t\t\t" << "sourceTree = \"<group>\";" << "\n" << "\t\t" << "};" << "\n"; //ROOT t << "\t\t" << keyFor("QMAKE_PBX_ROOT") << " = {" << "\n" << "\t\t\t" << "buildSettings = {" << "\n" << "\t\t\t" << "};" << "\n" << "\t\t\t" << "buildStyles = (" << "\n" << varGlue("QMAKE_PBX_BUILDSTYLES", "\t\t\t\t", ",\n\t\t\t\t", "\n") << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXProject;" << "\n" << "\t\t\t" << "mainGroup = " << keyFor("QMAKE_PBX_ROOT_GROUP") << ";" << "\n" << "\t\t\t" << "projectDirPath = \"\";" << "\n" << "\t\t\t" << "projectReferences = (" << "\n"; { QStringList &libdirs = project->variables()["QMAKE_PBX_SUBDIRS"]; for(QStringList::Iterator it = libdirs.begin(); it != libdirs.end(); ++it) t << "\t\t\t\t" << "{" << "\n" << "\t\t\t\t\t" << "ProductGroup = " << keyFor((*it) + "_PRODUCTGROUP") << ";" << "\n" << "\t\t\t\t\t" << "ProjectRef = " << keyFor((*it) + "_PROJECTREF") << ";" << "\n" << "\t\t\t\t" << "}," << "\n"; } t << "\t\t\t" << ");" << "\n" << "\t\t\t" << "targets = (" << "\n" << "\t\t\t" << ");" << "\n" << "\t\t" << "};" << "\n"; //FOOTER t << "\t" << "};" << "\n" << "\t" << "rootObject = " << keyFor("QMAKE_PBX_ROOT") << ";" << "\n" << "}" << endl; return TRUE;}boolProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t){ int i; QStringList tmp; bool did_preprocess = FALSE; //HEADER t << "// !$*UTF8*$!" << "\n" << "{" << "\n" << "\t" << "archiveVersion = 1;" << "\n" << "\t" << "classes = {" << "\n" << "\t" << "};" << "\n" << "\t" << "objectVersion = " << pbuilderVersion() << ";" << "\n" << "\t" << "objects = {" << endl; //MAKE QMAKE equivlant if(!project->isActiveConfig("no_autoqmake") && project->projectFile() != "(stdin)") { QString mkfile = pbx_dir + Option::dir_sep + "qt_makeqmake.mak"; QFile mkf(mkfile); if(mkf.open(IO_WriteOnly | IO_Translate)) { debug_msg(1, "pbuilder: Creating file: %s", mkfile.latin1()); QTextStream mkt(&mkf); writeHeader(mkt); mkt << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("$(QTDIR)/bin/qmake") : var("QMAKE_QMAKE")) << endl; writeMakeQmake(mkt); mkf.close(); } QString phase_key = keyFor("QMAKE_PBX_MAKEQMAKE_BUILDPHASE"); mkfile = fileFixify(mkfile, QDir::currentDirPath()); project->variables()["QMAKE_PBX_PRESCRIPT_BUILDPHASES"].append(phase_key); t << "\t\t" << phase_key << " = {" << "\n" << "\t\t\t" << "buildActionMask = 2147483647;" << "\n" << "\t\t\t" << "files = (" << "\n" << "\t\t\t" << ");" << "\n" << "\t\t\t" << "generatedFileNames = (" << "\n" << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXShellScriptBuildPhase;" << "\n" << "\t\t\t" << "name = \"Qt Qmake\";" << "\n" << "\t\t\t" << "neededFileNames = (" << "\n" << "\t\t\t" << ");" << "\n" << "\t\t\t" << "shellPath = /bin/sh;" << "\n" << "\t\t\t" << "shellScript = \"make -C " << QDir::currentDirPath() << " -f " << mkfile << "\";" << "\n" << "\t\t" << "};" << "\n"; } //DUMP SOURCES QMap<QString, QStringList> groups; QString srcs[] = { "HEADERS", "SOURCES", "SRCMOC", "UICIMPLS", "QMAKE_IMAGE_COLLECTION", "FORMS", "QMAKE_INTERNAL_INCLUDED_FILES", QString::null }; for(i = 0; !srcs[i].isNull(); i++) { tmp = project->variables()[srcs[i]]; if(srcs[i] == "QMAKE_INTERNAL_INCLUDED_FILES") { QString pfile = project->projectFile(); if(pfile != "(stdin)") tmp.prepend(pfile); } QStringList &src_list = project->variables()["QMAKE_PBX_" + srcs[i]]; QStringList &root_group_list = project->variables()["QMAKE_PBX_GROUPS"]; //hard coded groups.. QString src_group; if(srcs[i] == "SOURCES") src_group = "Sources"; else if(srcs[i] == "HEADERS") src_group = "Headers"; else if(srcs[i] == "SRCMOC") src_group = "Sources [moc]"; else if(srcs[i] == "UICIMPLS" || srcs[i] == "FORMS") src_group = "Sources [uic]"; else if(srcs[i] == "QMAKE_IMAGE_COLLECTION") src_group = "Sources [images]"; else if(srcs[i] == "QMAKE_INTERNAL_INCLUDED_FILES") src_group = "Sources [qmake]"; for(QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) { QStringList files = (*it); bool buildable = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -