pbuilder_pbx.cpp

来自「Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3」· C++ 代码 · 共 1,038 行 · 第 1/3 页

CPP
1,038
字号
		    QString r = opt.right(opt.length() - 2);		    fixEnvVariables(r);		    libdirs.append(r);		} else if(opt == "-prebind") {		    project->variables()["QMAKE_DO_PREBINDING"].append("TRUE");		    remove = TRUE;		} else if(opt.startsWith("-l")) {		    name = opt.right(opt.length() - 2);		    QString lib("lib" + name);		    for(QStringList::Iterator lit = libdirs.begin(); lit != libdirs.end(); ++lit) {			if(project->isActiveConfig("link_prl")) {			    /* This isn't real nice, but it is real usefull. This looks in a prl			       for what the library will ultimately be called so we can stick it			       in the ProjectFile. If the prl format ever changes (not likely) then			       this will not really work. However, more concerning is that it will			       encode the version number in the Project file which might be a bad			       things in days to come? --Sam			    */			    QString lib_file = (*lit) + Option::dir_sep + lib;			    if(QMakeMetaInfo::libExists(lib_file)) {				QMakeMetaInfo libinfo;				if(libinfo.readLib(lib_file)) {				    if(!libinfo.isEmpty("QMAKE_PRL_TARGET")) {					library = (*lit) + Option::dir_sep + libinfo.first("QMAKE_PRL_TARGET");					debug_msg(1, "pbuilder: Found library (%s) via PRL %s (%s)", 						  opt.latin1(), lib_file.latin1(), library.latin1());					remove = TRUE;				    }				}			    }			}			if(!remove) {			    QString extns[] = { ".dylib", ".so", ".a", QString::null };			    for(int n = 0; !remove && !extns[n].isNull(); n++) {				QString tmp =  (*lit) + Option::dir_sep + lib + extns[n];				if(QFile::exists(tmp)) {				    library = tmp;				    debug_msg(1, "pbuilder: Found library (%s) via %s", 					      opt.latin1(), library.latin1());				    remove = TRUE;				}			    }			}		    }		} else if(opt == "-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(opt == "-undefined") {		    ++it; //the next option is not a library..		} else if(opt.left(1) != "-") {		    remove = TRUE;		    library = opt;		}		if(!library.isEmpty()) {		    if(name.isEmpty()) {			int slsh = library.findRev(Option::dir_sep);			if(slsh != -1)			    name = library.right(library.length() - slsh - 1);		    }		    library = fileFixify(library);		    QString key = keyFor(library);		    bool is_frmwrk = (library.endsWith(".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 = " << reftypeForFile(library) << ";" << "\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 = pbx_dir + Option::dir_sep + "qt_sublibs.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 << "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");	mkfile = 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"];	if(!tmp.isEmpty()) {	    QString grp("External Frameworks and Libraries"), key = keyFor(grp);	    project->variables()["QMAKE_PBX_GROUPS"].append(key);	    t << "\t\t" << key << " = {" << "\n"	      << "\t\t\t" << "children = (" << "\n"	      << varGlue("QMAKE_PBX_LIBRARIES", "\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" << "path = \"\";" << "\n"	      << "\t\t\t" << "refType = 4;" << "\n"	      << "\t\t" << "};" << "\n";	}    }    {	QString grp("Frameworks & Libraries"), 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_BUILD_LIBRARIES", "\t\t\t\t", ",\n\t\t\t\t", "\n")	  << "\t\t\t" << ");" << "\n"	  << "\t\t\t" << "isa = PBXFrameworksBuildPhase;" << "\n"	  << "\t\t\t" << "name = \"" << grp << "\";" << "\n"	  << "\t\t" << "};" << "\n";    }    if(project->isActiveConfig("resource_fork") && !project->isActiveConfig("console") &&       project->first("TEMPLATE") == "app") { //BUNDLE RESOURCES	QString grp("Bundle Resources"), 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"	  << (!project->isEmpty("RC_FILE") ? keyFor("ICNS_FILE_REFERENCE") : QString(""))	  << "\t\t\t" << ");" << "\n"	  << "\t\t\t" << "isa = PBXResourcesBuildPhase;" << "\n"	  << "\t\t\t" << "name = \"" << grp << "\";" << "\n"	  << "\t\t" << "};" << "\n";    }    //DUMP EVERYTHING THAT TIES THE ABOVE TOGETHER    //PRODUCTS    {	QString grp("Products"), key = keyFor(grp);	project->variables()["QMAKE_PBX_GROUPS"].append(key);	t << "\t\t" << key << " = {" << "\n"	  << "\t\t\t" << "children = (" << "\n"	  << "\t\t\t\t" << keyFor("QMAKE_PBX_REFERENCE") << "\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" << "};" << "\n";    }    { //INSTALL BUILDPHASE (sh script)	QString targ = project->first("TARGET");	if(project->first("TEMPLATE") == "app" ||	   (project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") &&	    project->isActiveConfig("frameworklib")))	    targ = project->first("QMAKE_ORIG_TARGET");	int slsh = targ.findRev(Option::dir_sep);	if(slsh != -1)	    targ = targ.right(targ.length() - slsh - 1);	fixEnvVariables(targ);	QStringList links;	if(project->first("TEMPLATE") == "app") {	    if(project->isActiveConfig("resource_fork") && !project->isActiveConfig("console"))		targ += ".app";	} else if(!project->isActiveConfig("staticlib") &&	   !project->isActiveConfig("frameworklib")) {	    QString li[] = { "TARGET_", "TARGET_x", "TARGET_x.y", QString::null };	    for(int n = 0; !li[n].isNull(); n++) {		QString t = project->first(li[n]);		slsh = t.findRev(Option::dir_sep);		if(slsh != -1)		    t = t.right(t.length() - slsh);		fixEnvVariables(t);		links << t;	    }	}	QString script = pbx_dir + Option::dir_sep + "qt_install.sh";	QFile shf(script);	if(shf.open(IO_WriteOnly | IO_Translate)) {	    debug_msg(1, "pbuilder: Creating file: %s", script.latin1());	    QString targ = project->first("QMAKE_ORIG_TARGET"), cpflags;	    if(project->first("TEMPLATE") == "app") {		targ = project->first("TARGET");		if(project->isActiveConfig("resource_fork") && !project->isActiveConfig("console")) {		    targ += ".app";		    cpflags += "-r ";		}	    } else if(!project->isActiveConfig("frameworklib")) {		if(project->isActiveConfig("staticlib"))		    targ = project->first("TARGET");		else		    targ = project->first("TARGET_");		int slsh = targ.findRev(Option::dir_sep);		if(slsh != -1)		    targ = targ.right(targ.length() - slsh - 1);	    }	    QTextStream sht(&shf);	    QString dstdir = project->first("DESTDIR");	    fixEnvVariables(dstdir);	    sht << "#!/bin/sh" << endl;	    //copy the actual target	    sht << "OUT_TARG=\"" << targ << "\"\n" 		<< "[ -z \"$BUILD_ROOT\" ] || OUT_TARG=\"${BUILD_ROOT}/${OUT_TARG}\"" << endl;	    sht << "[ \"$OUT_TARG\" = \"" 		<< (dstdir.isEmpty() ? QDir::currentDirPath() + QDir::separator(): dstdir) << targ << "\" ] || " 		<< "[ \"$OUT_TARG\" = \"" << targ << "\" ] || " 		<< "cp -r \"$OUT_TARG\" " << "\"" << dstdir << targ << "\"" << endl;	    //rename as a framework	    if(project->first("TEMPLATE") == "lib" && project->isActiveConfig("frameworklib"))		sht << "ln -sf \"" << targ <<  "\" " << "\"" << dstdir << targ << "\"" << endl;	    //create all the version symlinks (just to be like unixmake)	    for(QStringList::Iterator it = links.begin(); it != links.end(); ++it) {		if(targ != (*it)) 		    sht << "ln -sf \"" << targ <<  "\" " << "\"" << dstdir << (*it) << "\"" << endl;	    }	    shf.close();#ifdef Q_OS_UNIX	    chmod(script.latin1(), S_IRWXU | S_IRWXG);#endif	    QString phase_key = keyFor("QMAKE_PBX_INSTALL_BUILDPHASE");	    script = fileFixify(script, QDir::currentDirPath());	    project->variables()["QMAKE_PBX_BUILDPHASES"].append(phase_key);	    t << "\t\t" << phase_key << " = {" << "\n"	      << "\t\t\t" << "buildActionMask = 8;" << "\n" //only on install!	      << "\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 Install\";" << "\n"	      << "\t\t\t" << "neededFileNames = (" << "\n"	      << "\t\t\t" << ");" << "\n"	      << "\t\t\t" << "shellPath = /bin/sh;" << "\n"	      << "\t\t\t" << "shellScript = \"" << script << "\";" << "\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" << "name = " << project->first("QMAKE_ORIG_TARGET") << ";" << "\n"      << "\t\t\t" << "path = \"\";" << "\n"      << "\t\t\t" << "refType = 4;" << "\n"      << "\t\t" << "};" << "\n";    //REFERENCE    t << "\t\t" << keyFor("QMAKE_PBX_REFERENCE") << " = {" << "\n";    if(project->first("TEMPLATE") == "app") {	QString targ = project->first("QMAKE_ORIG_TARGET");	if(project->isActiveConfig("resource_fork") && !project->isActiveConfig("console")) {	    targ += ".app";	    t << "\t\t\t" << "isa = PBXApplicationReference;" << "\n";	} else {	    t << "\t\t\t" << "isa = PBXExecutableFileReference;" << "\n";	}	QString app = (!project->isEmpty("DESTDIR") ? project->first("DESTDIR") + project->first("QMAKE_ORIG_TARGET") : 		       QDir::currentDirPath()) + Option::dir_sep + targ;	t << "\t\t\t" << "name = " <<  targ << ";" << "\n"	  << "\t\t\t" << "path = \"" << targ << "\";" << "\n"	  << "\t\t\t" << "refType = " << reftypeForFile(app) << ";" << "\n";    } else {	QString lib = project->first("QMAKE_ORIG_TARGET");	if(project->isActiveConfig("staticlib")) {	    lib = project->first("TARGET");	} else if(!project->isActiveConfig("frameworklib")) {	    if(project->isActiveConfig("plugin"))		lib = project->first("TARGET");	    else		lib = project->first("TARGET_");	}	int slsh = lib.findRev(Option::dir_sep);	if(slsh != -1)	    lib = lib.right(lib.length() - slsh - 1);	t << "\t\t\t" << "isa = PBXLibraryReference;" << "\n"	  << "\t\t\t" << "path = " << lib << ";\n"	  << "\t\t\t" << "refType = " << reftypeForFile(lib) << ";" << "\n";    }    t << "\t\t" << "};" << "\n";    //TARGET    t << "\t\t" << keyFor("QMAKE_PBX_TARGET") << " = {" << "\n"      << "\t\t\t" << "buildPhases = (" << "\n"      << varGlue("QMAKE_PBX_BUILDPHASES", "\t\t\t\t", ",\n\t\t\t\t", "\n")      << "\t\t\t" << ");" << "\n"      << "\t\t\t" << "buildSettings = {" << "\n"      << "\t\t\t\t" << "CC = \"" << fixEnvsList("QMAKE_CC") << "\";" << "\n"      << "\t\t\t\t" << "CPLUSPLUS = \"" << fixEnvsList("QMAKE_CXX") << "\";" << "\n"      << "\t\t\t\t" << "FRAMEWORK_SEARCH_PATHS = \"\";" << "\n"      << "\t\t\t\t" << "HEADER_SEARCH_PATHS = \"" << fixEnvsList("INCLUDEPATH") << " " << fixEnvs(specdir()) << "\";" << "\n"      << "\t\t\t\t" << "LIBRARY_SEARCH_PATHS = \"" << var("QMAKE_PBX_LIBPATHS") << "\";" << "\n"      << "\t\t\t\t" << "OPTIMIZATION_CFLAGS = \"\";" << "\n"      << "\t\t\t\t" << "OTHER_CFLAGS = \"" <<	fixEnvsList("QMAKE_CFLAGS") << varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") <<	varGlue("DEFINES"," -D"," -D","") << "\";" << "\n"      << "\t\t\t\t" << "LEXFLAGS = \"" << var("QMAKE_LEXFLAGS") << "\";" << "\n"      << "\t\t\t\t" << "YACCFLAGS = \"" << var("QMAKE_YACCFLAGS") << "\";" << "\n"      << "\t\t\t\t" << "OTHER_CPLUSPLUSFLAGS = \"" <<	fixEnvsList("QMAKE_CXXFLAGS") << varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") <<

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?