MetaMakefileGenerator * MetaMakefileGenerator::createMetaGenerator(QMakeProject *proj, const QString &name, 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, name, op); } if(!ret) ret = new BuildsMetaMakefileGenerator(proj, name, op); ret->init(); return ret; }
int runQMake(int argc, char **argv) { // stderr is unbuffered by default, but stdout buffering depends on whether // there is a terminal attached. Buffering can make output from stderr and stdout // appear out of sync, so force stdout to be unbuffered as well. // This is particularly important for things like QtCreator and scripted builds. setvbuf(stdout, (char *)NULL, _IONBF, 0); // parse command line int ret = Option::init(argc, argv); if(ret != Option::QMAKE_CMDLINE_SUCCESS) { if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0) return 1; return 0; } QString oldpwd = qmake_getpwd(); #ifdef Q_WS_WIN if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/"))) #endif { if(oldpwd.right(1) != QString(QChar(QDir::separator()))) oldpwd += QDir::separator(); } Option::output_dir = oldpwd; //for now this is the output dir if(Option::output.fileName() != "-") { QFileInfo fi(Option::output); QString dir; if(fi.isDir()) { dir = fi.filePath(); } else { QString tmp_dir = fi.path(); if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir)) dir = tmp_dir; } if(!dir.isNull() && dir != ".") Option::output_dir = dir; if(QDir::isRelativePath(Option::output_dir)) Option::output_dir.prepend(oldpwd); Option::output_dir = QDir::cleanPath(Option::output_dir); } QMakeProperty prop; if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY || Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) return prop.exec() ? 0 : 101; QMakeProject project(&prop); int exit_val = 0; QStringList files; if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) files << "(*hack*)"; //we don't even use files, but we do the for() body once else files = Option::mkfile::project_files; for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) { if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { QString fn = Option::fixPathToLocalOS((*pfile)); if(!QFile::exists(fn)) { fprintf(stderr, "Cannot find file: %s.\n", fn.toLatin1().constData()); exit_val = 2; continue; } //setup pwd properly debug_msg(1, "Resetting dir to: %s", oldpwd.toLatin1().constData()); qmake_setpwd(oldpwd); //reset the old pwd int di = fn.lastIndexOf(QDir::separator()); if(di != -1) { debug_msg(1, "Changing dir to: %s", fn.left(di).toLatin1().constData()); if(!qmake_setpwd(fn.left(di))) fprintf(stderr, "Cannot find directory: %s\n", fn.left(di).toLatin1().constData()); fn = fn.right(fn.length() - di - 1); } // read project.. if(!project.read(fn)) { fprintf(stderr, "Error processing project file: %s\n", fn == "-" ? "(stdin)" : (*pfile).toLatin1().constData()); exit_val = 3; continue; } if(Option::mkfile::do_preprocess) //no need to create makefile continue; } bool success = true; MetaMakefileGenerator *mkfile = MetaMakefileGenerator::createMetaGenerator(&project, QString(), false, &success); if (!success) exit_val = 3; if(mkfile && !mkfile->write(oldpwd)) { if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) fprintf(stderr, "Unable to generate project file.\n"); else fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).toLatin1().constData()); exit_val = 5; } delete mkfile; mkfile = NULL; } qmakeClearCaches(); return exit_val; }
int runQMake(int argc, char **argv) { // parse command line int ret = Option::init(argc, argv); if(ret != Option::QMAKE_CMDLINE_SUCCESS) { if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0) return 1; return 0; } // report Qt usage for commercial customers with a "metered license" (currently experimental) #if QT_EDITION != QT_EDITION_OPENSOURCE QString reporterPath = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator() + "qtusagereporter"; #if defined(Q_OS_WIN) reporterPath += ".exe"; #endif if (QFile::exists(reporterPath)) system(qPrintable(reporterPath + " qmake")); #endif QString oldpwd = qmake_getpwd(); #ifdef Q_WS_WIN if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/"))) #endif { if(oldpwd.right(1) != QString(QChar(QDir::separator()))) oldpwd += QDir::separator(); } Option::output_dir = oldpwd; //for now this is the output dir if(Option::output.fileName() != "-") { QFileInfo fi(Option::output); QString dir; if(fi.isDir()) { dir = fi.filePath(); } else { QString tmp_dir = fi.path(); if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir)) dir = tmp_dir; } if(!dir.isNull() && dir != ".") Option::output_dir = dir; if(QDir::isRelativePath(Option::output_dir)) Option::output_dir.prepend(oldpwd); Option::output_dir = QDir::cleanPath(Option::output_dir); } QMakeProperty prop; if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY) return prop.exec() ? 0 : 101; QMakeProject project(&prop); int exit_val = 0; QStringList files; if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) files << "(*hack*)"; //we don't even use files, but we do the for() body once else files = Option::mkfile::project_files; for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) { if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { QString fn = Option::fixPathToLocalOS((*pfile)); if(!QFile::exists(fn)) { fprintf(stderr, "Cannot find file: %s.\n", fn.toLatin1().constData()); exit_val = 2; continue; } //setup pwd properly debug_msg(1, "Resetting dir to: %s", oldpwd.toLatin1().constData()); qmake_setpwd(oldpwd); //reset the old pwd int di = fn.lastIndexOf(Option::dir_sep); if(di != -1) { debug_msg(1, "Changing dir to: %s", fn.left(di).toLatin1().constData()); if(!qmake_setpwd(fn.left(di))) fprintf(stderr, "Cannot find directory: %s\n", fn.left(di).toLatin1().constData()); fn = fn.right(fn.length() - di - 1); } // read project.. if(!project.read(fn)) { fprintf(stderr, "Error processing project file: %s\n", fn == "-" ? "(stdin)" : (*pfile).toLatin1().constData()); exit_val = 3; continue; } if(Option::mkfile::do_preprocess) //no need to create makefile continue; } MetaMakefileGenerator *mkfile = MetaMakefileGenerator::createMetaGenerator(&project, QString(), false); if(mkfile && !mkfile->write(oldpwd)) { if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) fprintf(stderr, "Unable to generate project file.\n"); else fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).toLatin1().constData()); exit_val = 5; } delete mkfile; mkfile = NULL; } qmakeClearCaches(); return exit_val; }