bool usage(const char *a0) { fprintf(stdout, "Usage: %s [mode] [options] [files]\n" "\n" "QMake has two modes, one mode for generating project files based on\n" "some heuristics, and the other for generating makefiles. Normally you\n" "shouldn't need to specify a mode, as makefile generation is the default\n" "mode for qmake, but you may use this to test qmake on an existing project\n" "\n" "Mode:\n" " -project Put qmake into project file generation mode%s\n" " In this mode qmake interprets files as files to\n" " be built,\n" " defaults to %s\n" " Note: The created .pro file probably will \n" " need to be edited. For example add the QT variable to \n" " specify what modules are required.\n" " -makefile Put qmake into makefile generation mode%s\n" " In this mode qmake interprets files as project files to\n" " be processed, if skipped qmake will try to find a project\n" " file in your current working directory\n" "\n" "Warnings Options:\n" " -Wnone Turn off all warnings; specific ones may be re-enabled by\n" " later -W options\n" " -Wall Turn on all warnings\n" " -Wparser Turn on parser warnings\n" " -Wlogic Turn on logic warnings (on by default)\n" " -Wdeprecated Turn on deprecation warnings (on by default)\n" "\n" "Options:\n" " * You can place any variable assignment in options and it will be *\n" " * processed as if it was in [files]. These assignments will be parsed *\n" " * before [files]. *\n" " -o file Write output to file\n" " -d Increase debug level\n" " -t templ Overrides TEMPLATE as templ\n" " -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value\n" " -help This help\n" " -v Version information\n" " -after All variable assignments after this will be\n" " parsed after [files]\n" " -norecursive Don't do a recursive search\n" " -recursive Do a recursive search\n" " -set <prop> <value> Set persistent property\n" " -unset <prop> Unset persistent property\n" " -query <prop> Query persistent property. Show all if <prop> is empty.\n" " -cache file Use file as cache [makefile mode only]\n" " -spec spec Use spec as QMAKESPEC [makefile mode only]\n" " -nocache Don't use a cache file [makefile mode only]\n" " -nodepend Don't generate dependencies [makefile mode only]\n" " -nomoc Don't generate moc targets [makefile mode only]\n" " -nopwd Don't look for files in pwd [project mode only]\n" ,a0, default_mode(a0) == Option::QMAKE_GENERATE_PROJECT ? " (default)" : "", project_builtin_regx().toLatin1().constData(), default_mode(a0) == Option::QMAKE_GENERATE_MAKEFILE ? " (default)" : "" ); return false; }
bool usage(const char *a0) { fprintf(stdout, "Usage: %s [mode] [options] [files]\n" "\n" " QMake has two modes, one mode for generating project files based on\n" "some heuristics, and the other for generating makefiles. Normally you\n" "shouldn't need to specify a mode, as makefile generation is the default\n" "mode for qmake, but you may use this to test qmake on an existing project\n" "\n" "Mode:\n" "\t-project Put qmake into project file generation mode%s\n" "\t In this mode qmake interprets files as files to\n" "\t be built,\n" "\t defaults to %s\n" "\t-makefile Put qmake into makefile generation mode%s\n" "\t In this mode qmake interprets files as project files to\n" "\t be processed, if skipped qmake will try to find a project\n" "\t file in your current working directory\n" "\n" "Warnings Options:\n" "\t-Wnone Turn off all warnings\n" "\t-Wall Turn on all warnings\n" "\t-Wparser Turn on parser warnings\n" "\t-Wlogic Turn on logic warnings\n" "\n" "Options:\n" "\t * You can place any variable assignment in options and it will be *\n" "\t * processed as if it was in [files]. These assignments will be parsed *\n" "\t * before [files]. *\n" "\t-o file Write output to file\n" "\t-unix Run in unix mode\n" "\t-win32 Run in win32 mode\n" "\t-os2 Run in OS/2 mode\n" "\t-macx Run in Mac OS X mode\n" "\t-d Increase debug level\n" "\t-t templ Overrides TEMPLATE as templ\n" "\t-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value\n" "\t-help This help\n" "\t-v Version information\n" "\t-after All variable assignments after this will be\n" "\t parsed after [files]\n" "\t-cache file Use file as cache [makefile mode only]\n" "\t-spec spec Use spec as QMAKESPEC [makefile mode only]\n" "\t-nocache Don't use a cache file [makefile mode only]\n" "\t-nodepend Don't generate dependencies [makefile mode only]\n" "\t-nomoc Don't generate moc targets [makefile mode only]\n" "\t-nopwd Don't look for files in pwd [ project mode only]\n" "\t-norecursive Don't do a recursive search [ project mode only]\n" ,a0, default_mode(a0) == Option::QMAKE_GENERATE_PROJECT ? " (default)" : "", project_builtin_regx().latin1(), default_mode(a0) == Option::QMAKE_GENERATE_MAKEFILE ? " (default)" : ""); return FALSE; }
void ProjectGenerator::init() { if(init_flag) return; int file_count = 0; init_flag = true; verifyCompilers(); project->read(QMakeProject::ReadFeatures); project->variables()["CONFIG"].clear(); QMap<QString, QStringList> &v = project->variables(); QString templ = Option::user_template.isEmpty() ? QString("app") : Option::user_template; if(!Option::user_template_prefix.isEmpty()) templ.prepend(Option::user_template_prefix); v["TEMPLATE_ASSIGN"] += templ; //figure out target if(Option::output.fileName() == "-") v["TARGET_ASSIGN"] = QStringList("unknown"); else v["TARGET_ASSIGN"] = QStringList(QFileInfo(Option::output).baseName()); //the scary stuff if(project->first("TEMPLATE_ASSIGN") != "subdirs") { QString builtin_regex = project_builtin_regx(); QStringList dirs = Option::projfile::project_dirs; if(Option::projfile::do_pwd) { if(!v["INCLUDEPATH"].contains(".")) v["INCLUDEPATH"] += "."; dirs.prepend(qmake_getpwd()); } for(int i = 0; i < dirs.count(); ++i) { QString dir, regex, pd = dirs.at(i); bool add_depend = false; if(exists(pd)) { QFileInfo fi(fileInfo(pd)); if(fi.isDir()) { dir = pd; add_depend = true; if(dir.right(1) != Option::dir_sep) dir += Option::dir_sep; if(Option::recursive) { QStringList files = QDir(dir).entryList(QDir::Files); for(int i = 0; i < (int)files.count(); i++) { if(files[i] != "." && files[i] != "..") dirs.append(dir + files[i] + QDir::separator() + builtin_regex); } } regex = builtin_regex; } else { QString file = pd; int s = file.lastIndexOf(Option::dir_sep); if(s != -1) dir = file.left(s+1); if(addFile(file)) { add_depend = true; file_count++; } } } else { //regexp regex = pd; } if(!regex.isEmpty()) { int s = regex.lastIndexOf(Option::dir_sep); if(s != -1) { dir = regex.left(s+1); regex = regex.right(regex.length() - (s+1)); } if(Option::recursive) { QStringList entries = QDir(dir).entryList(QDir::Dirs); for(int i = 0; i < (int)entries.count(); i++) { if(entries[i] != "." && entries[i] != "..") { dirs.append(dir + entries[i] + QDir::separator() + regex); } } } QStringList files = QDir(dir).entryList(QDir::nameFiltersFromString(regex)); for(int i = 0; i < (int)files.count(); i++) { QString file = dir + files[i]; if (addFile(file)) { add_depend = true; file_count++; } } } if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir, Qt::CaseInsensitive)) { QFileInfo fi(fileInfo(dir)); if(fi.absoluteFilePath() != qmake_getpwd()) v["DEPENDPATH"] += fileFixify(dir); } } } if(!file_count) { //shall we try a subdir? QStringList knownDirs = Option::projfile::project_dirs; if(Option::projfile::do_pwd) knownDirs.prepend("."); const QString out_file = fileFixify(Option::output.fileName()); for(int i = 0; i < knownDirs.count(); ++i) { QString pd = knownDirs.at(i); if(exists(pd)) { QString newdir = pd; QFileInfo fi(fileInfo(newdir)); if(fi.isDir()) { newdir = fileFixify(newdir); QStringList &subdirs = v["SUBDIRS"]; if(exists(fi.filePath() + QDir::separator() + fi.fileName() + Option::pro_ext) && !subdirs.contains(newdir, Qt::CaseInsensitive)) { subdirs.append(newdir); } else { QStringList profiles = QDir(newdir).entryList(QStringList("*" + Option::pro_ext), QDir::Files); for(int i = 0; i < (int)profiles.count(); i++) { QString nd = newdir; if(nd == ".") nd = ""; else if(!nd.isEmpty() && !nd.endsWith(QString(QChar(QDir::separator())))) nd += QDir::separator(); nd += profiles[i]; fileFixify(nd); if(profiles[i] != "." && profiles[i] != ".." && !subdirs.contains(nd, Qt::CaseInsensitive) && !out_file.endsWith(nd)) subdirs.append(nd); } } if(Option::recursive) { QStringList dirs = QDir(newdir).entryList(QDir::Dirs); for(int i = 0; i < (int)dirs.count(); i++) { QString nd = fileFixify(newdir + QDir::separator() + dirs[i]); if(dirs[i] != "." && dirs[i] != ".." && !knownDirs.contains(nd, Qt::CaseInsensitive)) knownDirs.append(nd); } } } } else { //regexp QString regx = pd, dir; int s = regx.lastIndexOf(Option::dir_sep); if(s != -1) { dir = regx.left(s+1); regx = regx.right(regx.length() - (s+1)); } QStringList files = QDir(dir).entryList(QDir::nameFiltersFromString(regx), QDir::Dirs); QStringList &subdirs = v["SUBDIRS"]; for(int i = 0; i < (int)files.count(); i++) { QString newdir(dir + files[i]); QFileInfo fi(fileInfo(newdir)); if(fi.fileName() != "." && fi.fileName() != "..") { newdir = fileFixify(newdir); if(exists(fi.filePath() + QDir::separator() + fi.fileName() + Option::pro_ext) && !subdirs.contains(newdir)) { subdirs.append(newdir); } else { QStringList profiles = QDir(newdir).entryList(QStringList("*" + Option::pro_ext), QDir::Files); for(int i = 0; i < (int)profiles.count(); i++) { QString nd = newdir + QDir::separator() + files[i]; fileFixify(nd); if(files[i] != "." && files[i] != ".." && !subdirs.contains(nd, Qt::CaseInsensitive)) { if(newdir + files[i] != Option::output_dir + Option::output.fileName()) subdirs.append(nd); } } } if(Option::recursive && !knownDirs.contains(newdir, Qt::CaseInsensitive)) knownDirs.append(newdir); } } } } v["TEMPLATE_ASSIGN"] = QStringList("subdirs"); return; } //setup deplist QList<QMakeLocalFileName> deplist; { const QStringList &d = v["DEPENDPATH"]; for(int i = 0; i < d.size(); ++i) deplist.append(QMakeLocalFileName(d[i])); } setDependencyPaths(deplist); QStringList &h = v["HEADERS"]; bool no_qt_files = true; QString srcs[] = { "SOURCES", "YACCSOURCES", "LEXSOURCES", "FORMS", QString() }; for(int i = 0; !srcs[i].isNull(); i++) { const QStringList &l = v[srcs[i]]; QMakeSourceFileInfo::SourceFileType type = QMakeSourceFileInfo::TYPE_C; QMakeSourceFileInfo::addSourceFiles(l, QMakeSourceFileInfo::SEEK_DEPS, type); for(int i = 0; i < l.size(); ++i) { QStringList tmp = QMakeSourceFileInfo::dependencies(l[i]); if(!tmp.isEmpty()) { for(int dep_it = 0; dep_it < tmp.size(); ++dep_it) { QString dep = tmp[dep_it]; dep = fixPathToQmake(dep); QString file_dir = dep.section(Option::dir_sep, 0, -2), file_no_path = dep.section(Option::dir_sep, -1); if(!file_dir.isEmpty()) { for(int inc_it = 0; inc_it < deplist.size(); ++inc_it) { QMakeLocalFileName inc = deplist[inc_it]; if(inc.local() == file_dir && !v["INCLUDEPATH"].contains(inc.real(), Qt::CaseInsensitive)) v["INCLUDEPATH"] += inc.real(); } } if(no_qt_files && file_no_path.indexOf(QRegExp("^q[a-z_0-9].h$")) != -1) no_qt_files = false; QString h_ext; for(int hit = 0; hit < Option::h_ext.size(); ++hit) { if(dep.endsWith(Option::h_ext.at(hit))) { h_ext = Option::h_ext.at(hit); break; } } if(!h_ext.isEmpty()) { for(int cppit = 0; cppit < Option::cpp_ext.size(); ++cppit) { QString src(dep.left(dep.length() - h_ext.length()) + Option::cpp_ext.at(cppit)); if(exists(src)) { QStringList &srcl = v["SOURCES"]; if(!srcl.contains(src, Qt::CaseInsensitive)) srcl.append(src); } } } else if(dep.endsWith(Option::lex_ext) && file_no_path.startsWith(Option::lex_mod)) { addConfig("lex_included"); } if(!h.contains(dep, Qt::CaseInsensitive)) h += dep; } } } } //strip out files that are actually output from internal compilers (ie temporary files) const QStringList &quc = project->variables()["QMAKE_EXTRA_COMPILERS"]; for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { QString tmp_out = project->variables()[(*it) + ".output"].first(); if(tmp_out.isEmpty()) continue; QStringList var_out = project->variables()[(*it) + ".variable_out"]; bool defaults = var_out.isEmpty(); for(int i = 0; i < var_out.size(); ++i) { QString v = var_out.at(i); if(v.startsWith("GENERATED_")) { defaults = true; break; } } if(defaults) { var_out << "SOURCES"; var_out << "HEADERS"; var_out << "FORMS"; } const QStringList &tmp = project->variables()[(*it) + ".input"]; for(QStringList::ConstIterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) { QStringList &inputs = project->variables()[(*it2)]; for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) { QString path = replaceExtraCompilerVariables(tmp_out, (*input), QString()); path = fixPathToQmake(path).section('/', -1); for(int i = 0; i < var_out.size(); ++i) { QString v = var_out.at(i); QStringList &list = project->variables()[v]; for(int src = 0; src < list.size(); ) { if(list[src] == path || list[src].endsWith("/" + path)) list.removeAt(src); else ++src; } } } } } }
void ProjectGenerator::init() { if(init_flag) return; int file_count = 0; init_flag = TRUE; QMap<QString, QStringList> &v = project->variables(); QString templ = Option::user_template.isEmpty() ? QString("app") : Option::user_template; if(!Option::user_template_prefix.isEmpty()) templ.prepend(Option::user_template_prefix); v["TEMPLATE_ASSIGN"] += templ; //figure out target if(Option::output.name() == "-" || Option::output.name().isEmpty()) v["TARGET"] = QStringList("unknown"); //the scary stuff if(project->first("TEMPLATE_ASSIGN") != "subdirs") { QString builtin_regex = project_builtin_regx(); QStringList dirs = Option::projfile::project_dirs; if(Option::projfile::do_pwd) { if(!v["INCLUDEPATH"].contains(".")) v["INCLUDEPATH"] += "."; dirs.prepend(QDir::currentDirPath()); } for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { QString dir, regex; bool add_depend = FALSE; if(QFile::exists((*pd))) { QFileInfo fi((*pd)); if(fi.isDir()) { dir = (*pd); add_depend = TRUE; if(dir.right(1) != Option::dir_sep) dir += Option::dir_sep; if(Option::projfile::do_recursive) { QDir d(dir); d.setFilter(QDir::Dirs); for(int i = 0; i < (int)d.count(); i++) { if(d[i] != "." && d[i] != "..") dirs.append(dir + d[i] + QDir::separator() + builtin_regex); } } regex = builtin_regex; } else { QString file = (*pd); int s = file.findRev(Option::dir_sep); if(s != -1) dir = file.left(s+1); if(addFile(file)) { add_depend = TRUE; file_count++; } } } else { //regexp regex = (*pd); } if(!regex.isEmpty()) { int s = regex.findRev(Option::dir_sep); if(s != -1) { dir = regex.left(s+1); regex = regex.right(regex.length() - (s+1)); } if(Option::projfile::do_recursive) { QDir d(dir); d.setFilter(QDir::Dirs); for(int i = 0; i < (int)d.count(); i++) { if(d[i] != "." && d[i] != "..") dirs.append(dir + d[i] + QDir::separator() + regex); } } QDir d(dir, regex); for(int i = 0; i < (int)d.count(); i++) { QString file = dir + d[i]; if (addFile(file)) { add_depend = TRUE; file_count++; } } } if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir)) { QFileInfo fi(dir); if(fi.absFilePath() != QDir::currentDirPath()) v["DEPENDPATH"] += fileFixify(dir); } } } if(!file_count) { //shall we try a subdir? QStringList dirs = Option::projfile::project_dirs; if(Option::projfile::do_pwd) dirs.prepend("."); const QString out_file = fileFixify(Option::output.name()); for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { if(QFile::exists((*pd))) { QString newdir = (*pd); QFileInfo fi(newdir); if(fi.isDir()) { newdir = fileFixify(newdir); QStringList &subdirs = v["SUBDIRS"]; if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && !subdirs.contains(newdir)) { subdirs.append(newdir); } else { QDir d(newdir, "*.pro"); d.setFilter(QDir::Files); for(int i = 0; i < (int)d.count(); i++) { QString nd = newdir; if(nd == ".") nd = ""; else if(!nd.isEmpty() && !nd.endsWith(QString(QChar(QDir::separator())))) nd += QDir::separator(); nd += d[i]; fileFixify(nd); if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd) && !out_file.endsWith(nd)) subdirs.append(nd); } } if(Option::projfile::do_recursive) { QDir d(newdir); d.setFilter(QDir::Dirs); for(int i = 0; i < (int)d.count(); i++) { QString nd = fileFixify(newdir + QDir::separator() + d[i]); if(d[i] != "." && d[i] != ".." && !dirs.contains(nd)) dirs.append(nd); } } } } else { //regexp QString regx = (*pd), dir; int s = regx.findRev(Option::dir_sep); if(s != -1) { dir = regx.left(s+1); regx = regx.right(regx.length() - (s+1)); } QDir d(dir, regx); d.setFilter(QDir::Dirs); QStringList &subdirs = v["SUBDIRS"]; for(int i = 0; i < (int)d.count(); i++) { QString newdir(dir + d[i]); QFileInfo fi(newdir); if(fi.fileName() != "." && fi.fileName() != "..") { newdir = fileFixify(newdir); if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && !subdirs.contains(newdir)) { subdirs.append(newdir); } else { QDir d(newdir, "*.pro"); d.setFilter(QDir::Files); for(int i = 0; i < (int)d.count(); i++) { QString nd = newdir + QDir::separator() + d[i]; fileFixify(nd); if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) { if(newdir + d[i] != Option::output_dir + Option::output.name()) subdirs.append(nd); } } } if(Option::projfile::do_recursive && !dirs.contains(newdir)) dirs.append(newdir); } } } } v["TEMPLATE_ASSIGN"] = "subdirs"; return; } QPtrList<MakefileDependDir> deplist; deplist.setAutoDelete(TRUE); { QStringList &d = v["DEPENDPATH"]; for(QStringList::Iterator it = d.begin(); it != d.end(); ++it) { QString r = (*it), l = Option::fixPathToLocalOS((*it)); deplist.append(new MakefileDependDir(r, l)); } } QStringList &h = v["HEADERS"]; bool no_qt_files = TRUE; QString srcs[] = { "SOURCES", "YACCSOURCES", "LEXSOURCES", "INTERFACES", QString::null }; for(int i = 0; !srcs[i].isNull(); i++) { QStringList &l = v[srcs[i]]; for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) { if(generateDependencies(deplist, (*val_it), TRUE)) { QStringList &tmp = findDependencies((*val_it)); if(!tmp.isEmpty()) { for(QStringList::Iterator dep_it = tmp.begin(); dep_it != tmp.end(); ++dep_it) { QString file_dir = (*dep_it).section(Option::dir_sep, 0, -2), file_no_path = (*dep_it).section(Option::dir_sep, -1); if(!file_dir.isEmpty()) { for(MakefileDependDir *mdd = deplist.first(); mdd; mdd = deplist.next()) { if(mdd->local_dir == file_dir && !v["INCLUDEPATH"].contains(mdd->real_dir)) v["INCLUDEPATH"] += mdd->real_dir; } } if(no_qt_files && file_no_path.find(QRegExp("^q[a-z_0-9].h$")) != -1) no_qt_files = FALSE; QString h_ext; for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) { if((*dep_it).endsWith((*hit))) { h_ext = (*hit); break; } } if(!h_ext.isEmpty()) { if((*dep_it).left(1).lower() == "q") { QString qhdr = (*dep_it).lower(); if(file_no_path == "qthread.h") addConfig("thread"); } for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) { QString src((*dep_it).left((*dep_it).length() - h_ext.length()) + (*cppit)); if(QFile::exists(src)) { bool exists = FALSE; QStringList &srcl = v["SOURCES"]; for(QStringList::Iterator src_it = srcl.begin(); src_it != srcl.end(); ++src_it) { if((*src_it).lower() == src.lower()) { exists = TRUE; break; } } if(!exists) srcl.append(src); } } } else if((*dep_it).endsWith(Option::lex_ext) && file_no_path.startsWith(Option::lex_mod)) { addConfig("lex_included"); } if(!h.contains((*dep_it))) { if(generateMocList((*dep_it)) && !findMocDestination((*dep_it)).isEmpty()) h += (*dep_it); } } } } } } if(h.isEmpty()) addConfig("moc", FALSE); //if we find a file that matches an forms it needn't be included in the project QStringList &u = v["INTERFACES"]; QString no_ui[] = { "SOURCES", "HEADERS", QString::null }; { for(int i = 0; !no_ui[i].isNull(); i++) { QStringList &l = v[no_ui[i]]; for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ) { bool found = FALSE; for(QStringList::Iterator ui_it = u.begin(); ui_it != u.end(); ++ui_it) { QString s1 = (*val_it).right((*val_it).length() - ((*val_it).findRev(Option::dir_sep) + 1)); if(s1.findRev('.') != -1) s1 = s1.left(s1.findRev('.')) + Option::ui_ext; QString u1 = (*ui_it).right((*ui_it).length() - ((*ui_it).findRev(Option::dir_sep) + 1)); if(s1 == u1) { found = TRUE; break; } } if(!found && (*val_it).endsWith(Option::cpp_moc_ext)) found = TRUE; if(found) val_it = l.remove(val_it); else ++val_it; } } } }