pbuilder_pbx.cpp
来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 735 行 · 第 1/2 页
CPP
735 行
/****************************************************************************** $Id: qt/pbuilder_pbx.cpp 3.0.3 edited Mar 11 05:36 $**** Definition of ________ class.**** Created : 970521**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of the network module of the Qt GUI Toolkit.**** 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 <qdir.h>#include <qdict.h>#include <qregexp.h>#include <stdlib.h>#include <time.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") { writeSubdirs(t, FALSE); return TRUE; } return FALSE;}boolProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t){ QStringList tmp; int i; //HEADER t << "// !$*UTF8*$!" << "\n" << "{" << "\n" << "\t" << "archiveVersion = 1;" << "\n" << "\t" << "classes = {" << "\n" << "\t" << "};" << "\n" << "\t" << "objectVersion = 34;" << "\n" << "\t" << "objects = {" << endl; //MAKE QMAKE equivlant if(!project->isActiveConfig("no_autoqmake") && project->projectFile() != "(stdin)") { QString mkfile = Option::output_dir + Option::dir_sep + "qt_makeqmake.mak"; QFile mkf(mkfile); if(mkf.open(IO_WriteOnly | IO_Translate)) { debug_msg(0, "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"); fileFixify(mkfile, QDir::currentDirPath()); project->variables()["QMAKE_PBX_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 QString srcs[] = { "SOURCES", "SRCMOC", "UICIMPLS", QString::null }; for(i = 0; !srcs[i].isNull(); i++) { tmp = project->variables()[srcs[i]]; for(QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) { QString file = (*it); if(file.right(Option::moc_ext.length()) == Option::moc_ext) { continue; } else if(!project->isEmpty("YACCIMPLS")) { QStringList yaccs = project->variables()["YACCIMPLS"]; for(QStringList::Iterator yit = yaccs.begin(); yit != yaccs.end(); yit++) { if((*yit) == (*it)) { file = project->first("YACCSOURCES"); break; } } } else if(!project->isEmpty("LEXIMPLS") && !project->isActiveConfig("lex_included")) { QStringList lexs = project->variables()["LEXIMPLS"]; for(QStringList::Iterator lit = lexs.begin(); lit != lexs.end(); lit++) { if((*lit) == (*it)) { file = project->first("LEXSOURCES"); break; } } } fileFixify(file); QString key = keyFor(file); project->variables()["QMAKE_PBX_" + srcs[i]].append(key); //source reference t << "\t\t" << key << " = {" << "\n" << "\t\t\t" << "isa = PBXFileReference;" << "\n" << "\t\t\t" << "path = \"" << file << "\";" << "\n" << "\t\t\t" << "refType = 4;" << "\n" << "\t\t" << "};" << "\n"; //build reference QString obj_key = file + ".o"; obj_key = keyFor(obj_key); t << "\t\t" << obj_key << " = {" << "\n" << "\t\t\t" << "fileRef = " << key << ";" << "\n" << "\t\t\t" << "isa = PBXBuildFile;" << "\n" << "\t\t\t" << "settings = {" << "\n" << "\t\t\t\t" << "ATTRIBUTES = (" << "\n" << "\t\t\t\t" << ");" << "\n" << "\t\t\t" << "};" << "\n" << "\t\t" << "};" << "\n"; project->variables()["QMAKE_PBX_OBJ"].append(obj_key); } tmp = project->variables()["QMAKE_PBX_" + srcs[i]]; if(!tmp.isEmpty()) { QString grp; if(srcs[i] == "SOURCES") grp = "Sources"; else if(srcs[i] == "SRCMOC") grp = "Mocables"; else if(srcs[i] == "UICIMPLS") grp = "UICables"; QString grp_key = keyFor(grp); project->variables()["QMAKE_PBX_GROUPS"].append(grp_key); t << "\t\t" << grp_key << " = {" << "\n" << "\t\t\t" << "children = (" << "\n" << varGlue("QMAKE_PBX_" + srcs[i], "\t\t\t\t", ",\n\t\t\t\t", "\n") << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXGroup;" << "\n" << "\t\t\t" << "name = " << grp << ";" << "\n" << "\t\t\t" << "refType = 4;" << "\n" << "\t\t" << "};" << "\n"; } } //PREPROCESS BUILDPHASE (just a makefile) if(!project->isEmpty("UICIMPLS") || !project->isEmpty("SRCMOC")) { QString mkfile = Option::output_dir + Option::dir_sep + "qt_preprocess.mak"; QFile mkf(mkfile); if(mkf.open(IO_WriteOnly | IO_Translate)) { debug_msg(0, "Creating file: %s", mkfile.latin1()); QTextStream mkt(&mkf); writeHeader(mkt); mkt << "MOC = " << var("QMAKE_MOC") << endl; mkt << "UIC = " << var("QMAKE_UIC") << endl << endl; mkt << "FORMS = " << varList("UICIMPLS") << endl; mkt << "MOCS = " << varList("SRCMOC") << endl; mkt << "preprocess: $(FORMS) $(MOCS)" << endl << endl; writeUicSrc(mkt, "FORMS"); writeMocSrc(mkt, "HEADERS"); writeMocSrc(mkt, "SOURCES"); writeMocSrc(mkt, "UICDECLS"); mkf.close(); } QString phase_key = keyFor("QMAKE_PBX_PREPROCESST_BUILDPHASE"); fileFixify(mkfile, QDir::currentDirPath()); project->variables()["QMAKE_PBX_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"// << varGlue("QMAKE_PBX_UICIMPLS", "\t\t\t\t", ",\n\t\t\t\t", "")// << varGlue("QMAKE_PBX_SRCMOC", ",\n\t\t\t\t", ",\n\t\t\t\t", "\n") << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXShellScriptBuildPhase;" << "\n" << "\t\t\t" << "name = \"Qt Preprocessors\";" << "\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"; } //SOURCE BUILDPHASE if(!project->isEmpty("QMAKE_PBX_OBJ")) { QString grp = "Build Sources", key = keyFor(grp); project->variables()["QMAKE_PBX_BUILDPHASES"].append(key); t << "\t\t" << key << " = {" << "\n" << "\t\t\t" << "buildActionMask = 2147483647;" << "\n" << "\t\t\t" << "files = (" << "\n" << varGlue("QMAKE_PBX_OBJ", "\t\t\t\t", ",\n\t\t\t\t", "\n") << "\t\t\t" << ");" << "\n" << "\t\t\t" << "isa = PBXSourcesBuildPhase;" << "\n" << "\t\t\t" << "name = \"" << grp << "\";" << "\n" << "\t\t" << "};" << "\n"; } //DUMP LIBRARIES QStringList &libdirs = project->variables()["QMAKE_PBX_LIBPATHS"]; QString libs[] = { "QMAKE_LIBDIR_FLAGS", "QMAKE_LIBS", QString::null }; for(i = 0; !libs[i].isNull(); i++) { tmp = project->variables()[libs[i]]; for(QStringList::Iterator it = tmp.begin(); it != tmp.end();) { bool remove = FALSE; QString library, name; if((*it).left(2) == "-L") { QString r = (*it).right((*it).length() - 2); fixEnvVariables(r); libdirs.append(r); } else if((*it).left(2) == "-l") { name = (*it).right((*it).length() - 2); QString lib("lib" + name + "."); for(QStringList::Iterator lit = libdirs.begin(); lit != libdirs.end(); ++lit) { QString extns[] = { "dylib", "so", "a", QString::null }; for(int n = 0; !extns[n].isNull(); n++) { QString tmp = (*lit) + Option::dir_sep + lib + extns[n]; if(QFile::exists(tmp)) { library = tmp; //don't remove, so it gets into LDFLAGS for now -- FIXME //remove = TRUE break; } } } } else if((*it) == "-framework") { ++it; if(it == tmp.end()) break; QStringList &fdirs = project->variables()["QMAKE_FRAMEWORKDIR"]; if(fdirs.isEmpty()) fdirs.append("/System/Library/Frameworks/"); for(QStringList::Iterator fit = fdirs.begin(); fit != fdirs.end(); ++fit) { if(QFile::exists((*fit) + QDir::separator() + (*it) + ".framework")) { --it; it = tmp.remove(it); remove = TRUE; library = (*fit) + Option::dir_sep + (*it) + ".framework"; break; } } } else if((*it).left(1) != "-") { remove = TRUE; library = (*it); } if(!library.isEmpty()) { if(name.isEmpty()) { int slsh = library.findRev(Option::dir_sep); if(slsh != -1) name = library.right(library.length() - slsh - 1); } fileFixify(library); QString key = keyFor(library); bool is_frmwrk = (library.right(10) == ".framework"); t << "\t\t" << key << " = {" << "\n" << "\t\t\t" << "isa = " << (is_frmwrk ? "PBXFrameworkReference" : "PBXFileReference") << ";" << "\n" << "\t\t\t" << "name = \"" << name << "\";" << "\n" << "\t\t\t" << "path = \"" << library << "\";" << "\n" << "\t\t\t" << "refType = 0;" << "\n" << "\t\t" << "};" << "\n"; project->variables()["QMAKE_PBX_LIBRARIES"].append(key); QString obj_key = library + ".o"; obj_key = keyFor(obj_key); t << "\t\t" << obj_key << " = {" << "\n" << "\t\t\t" << "fileRef = " << key << ";" << "\n" << "\t\t\t" << "isa = PBXBuildFile;" << "\n" << "\t\t\t" << "settings = {" << "\n" << "\t\t\t" << "};" << "\n" << "\t\t" << "};" << "\n"; project->variables()["QMAKE_PBX_BUILD_LIBRARIES"].append(obj_key); } if(remove) it = tmp.remove(it); else ++it; } project->variables()[libs[i]] = tmp; } //SUBLIBS BUILDPHASE (just another makefile) if(!project->isEmpty("SUBLIBS")) { QString mkfile = Option::output_dir + Option::dir_sep + "qt_sublibs.mak"; QFile mkf(mkfile); if(mkf.open(IO_WriteOnly | IO_Translate)) { debug_msg(0, "Creating file: %s", mkfile.latin1()); QTextStream mkt(&mkf); writeHeader(mkt); mkt << "SUBLIBS= "; tmp = project->variables()["SUBLIBS"]; QStringList::Iterator it; for(it = tmp.begin(); it != tmp.end(); ++it) t << "tmp/lib" << (*it) << ".a "; t << endl << endl; mkt << "sublibs: $(SUBLIBS)" << endl << endl; tmp = project->variables()["SUBLIBS"]; for(it = tmp.begin(); it != tmp.end(); ++it) t << "tmp/lib" << (*it) << ".a" << ":\n\t" << var(QString("MAKELIB") + (*it)) << endl << endl; mkf.close(); } QString phase_key = keyFor("QMAKE_PBX_SUBLIBS_BUILDPHASE"); fileFixify(mkfile, QDir::currentDirPath()); project->variables()["QMAKE_PBX_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 Sublibs\";" << "\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"; } //LIBRARY BUILDPHASE if(!project->isEmpty("QMAKE_PBX_LIBRARIES")) { tmp = project->variables()["QMAKE_PBX_LIBRARIES"];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?