summaryrefslogtreecommitdiffstats
path: root/qmake/option.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmake/option.cpp')
-rw-r--r--qmake/option.cpp295
1 files changed, 132 insertions, 163 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp
index 570b54de43..7bb37946c6 100644
--- a/qmake/option.cpp
+++ b/qmake/option.cpp
@@ -51,6 +51,11 @@
QT_BEGIN_NAMESPACE
+EvalHandler Option::evalHandler;
+QMakeGlobals *Option::globals;
+ProFileCache *Option::proFileCache;
+QMakeParser *Option::parser;
+
//convenience
const char *Option::application_argv0 = 0;
QString Option::prf_ext;
@@ -67,7 +72,6 @@ QString Option::lex_ext;
QString Option::yacc_ext;
QString Option::pro_ext;
QString Option::dir_sep;
-QString Option::dirlist_sep;
QString Option::h_moc_mod;
QString Option::yacc_mod;
QString Option::lex_mod;
@@ -78,17 +82,12 @@ char Option::field_sep;
Option::QMAKE_MODE Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
//all modes
-QString Option::qmake_abslocation;
QStringList Option::qmake_args;
int Option::warn_level = WarnLogic | WarnDeprecated;
int Option::debug_level = 0;
QFile Option::output;
QString Option::output_dir;
bool Option::recursive = false;
-QStringList Option::before_user_vars;
-QStringList Option::after_user_vars;
-QString Option::user_template;
-QString Option::user_template_prefix;
//QMAKE_*_PROPERTY stuff
QStringList Option::prop::properties;
@@ -98,18 +97,12 @@ bool Option::projfile::do_pwd = true;
QStringList Option::projfile::project_dirs;
//QMAKE_GENERATE_MAKEFILE stuff
-QString Option::mkfile::qmakespec;
-QString Option::mkfile::xqmakespec;
int Option::mkfile::cachefile_depth = -1;
bool Option::mkfile::do_deps = true;
bool Option::mkfile::do_mocs = true;
bool Option::mkfile::do_dep_heuristics = true;
bool Option::mkfile::do_preprocess = false;
bool Option::mkfile::do_stub_makefile = false;
-bool Option::mkfile::do_cache = true;
-QString Option::mkfile::source_root;
-QString Option::mkfile::build_root;
-QString Option::mkfile::cachefile;
QStringList Option::mkfile::project_files;
static Option::QMAKE_MODE default_mode(QString progname)
@@ -138,17 +131,6 @@ static QString detectProjectFile(const QString &path)
return ret;
}
-static QString cleanSpec(const QString &spec)
-{
- QString ret = QDir::cleanPath(spec);
- if (ret.contains('/')) {
- const QFileInfo specDirInfo(ret);
- if (specDirInfo.exists() && specDirInfo.isDir())
- ret = QDir::cleanPath(specDirInfo.absoluteFilePath());
- }
- return ret;
-}
-
QString project_builtin_regx();
bool usage(const char *a0)
{
@@ -213,102 +195,87 @@ bool usage(const char *a0)
int
Option::parseCommandLine(QStringList &args)
{
- QStringList user_configs;
-
- bool before = true;
- args << QString(); // Avoid bounds checking for options which take an argument
- for (int x = 0; x < args.size() - 1; ) {
- QString arg = args.at(x);
- if (arg.size() > 1 && arg.startsWith('-')) { /* options */
- QString opt = arg.mid(1);
- if(opt == "o" || opt == "output") {
- Option::output.setFileName(args.at(x + 1));
- args.erase(args.begin() + x, args.begin() + x + 2);
- continue;
- } else if(opt == "after") {
- before = false;
- } else if(opt == "t" || opt == "template") {
- Option::user_template = args.at(++x);
- } else if(opt == "tp" || opt == "template_prefix") {
- Option::user_template_prefix = args.at(++x);
- } else if(opt == "unix") {
- Option::dir_sep = "/";
- } else if(opt == "win32") {
- Option::dir_sep = "\\";
- } else if(opt == "d") {
- Option::debug_level++;
- } else if(opt == "version" || opt == "v" || opt == "-version") {
- fprintf(stdout,
- "QMake version %s\n"
- "Using Qt version %s in %s\n",
- qmake_version(), QT_VERSION_STR,
- QLibraryInfo::location(QLibraryInfo::LibrariesPath).toLatin1().constData());
+ QMakeCmdLineParserState state(QDir::currentPath());
+ enum { ArgNone, ArgOutput } argState = ArgNone;
+ int x = 0;
+ while (x < args.count()) {
+ switch (argState) {
+ case ArgOutput:
+ Option::output.setFileName(args.at(x--));
+ args.erase(args.begin() + x, args.begin() + x + 2);
+ argState = ArgNone;
+ continue;
+ default:
+ QMakeGlobals::ArgumentReturn cmdRet = globals->addCommandLineArguments(state, args, &x);
+ if (cmdRet == QMakeGlobals::ArgumentsOk)
+ break;
+ if (cmdRet == QMakeGlobals::ArgumentMalformed) {
+ fprintf(stderr, "***Option %s requires a parameter\n", qPrintable(args.at(x - 1)));
+ return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
+ }
+ Q_ASSERT(cmdRet == QMakeGlobals::ArgumentUnknown);
+ QString arg = args.at(x);
+ if (arg.startsWith(QLatin1Char('-'))) {
+ if (arg == "-d") {
+ Option::debug_level++;
+ } else if (arg == "-v" || arg == "-version" || arg == "--version") {
+ fprintf(stdout,
+ "QMake version %s\n"
+ "Using Qt version %s in %s\n",
+ qmake_version(), QT_VERSION_STR,
+ QLibraryInfo::location(QLibraryInfo::LibrariesPath).toLatin1().constData());
#ifdef QMAKE_OPENSOURCE_VERSION
- fprintf(stdout, "QMake is Open Source software from Nokia Corporation and/or its subsidiary(-ies).\n");
+ fprintf(stdout, "QMake is Open Source software from Nokia Corporation and/or its subsidiary(-ies).\n");
#endif
- return Option::QMAKE_CMDLINE_BAIL;
- } else if(opt == "h" || opt == "help") {
- return Option::QMAKE_CMDLINE_SHOW_USAGE;
- } else if(opt == "Wall") {
- Option::warn_level |= WarnAll;
- } else if(opt == "Wparser") {
- Option::warn_level |= WarnParser;
- } else if(opt == "Wlogic") {
- Option::warn_level |= WarnLogic;
- } else if(opt == "Wdeprecated") {
- Option::warn_level |= WarnDeprecated;
- } else if(opt == "Wnone") {
- Option::warn_level = WarnNone;
- } else if(opt == "r" || opt == "recursive") {
- Option::recursive = true;
- args.removeAt(x);
- continue;
- } else if(opt == "nr" || opt == "norecursive") {
- Option::recursive = false;
- args.removeAt(x);
- continue;
- } else if(opt == "config") {
- user_configs += args.at(++x);
- } else {
- if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
- Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
- if(opt == "nodepend" || opt == "nodepends") {
- Option::mkfile::do_deps = false;
- } else if(opt == "nomoc") {
- Option::mkfile::do_mocs = false;
- } else if(opt == "nocache") {
- Option::mkfile::do_cache = false;
- } else if(opt == "createstub") {
- Option::mkfile::do_stub_makefile = true;
- } else if(opt == "nodependheuristics") {
- Option::mkfile::do_dep_heuristics = false;
- } else if(opt == "E") {
- Option::mkfile::do_preprocess = true;
- } else if(opt == "cache") {
- Option::mkfile::cachefile = args.at(++x);
- } else if(opt == "platform" || opt == "spec") {
- Option::mkfile::qmakespec = args[x] = cleanSpec(args.at(++x));
- } else if (opt == "xplatform" || opt == "xspec") {
- Option::mkfile::xqmakespec = args[x] = cleanSpec(args.at(x));
- } else {
- fprintf(stderr, "***Unknown option -%s\n", opt.toLatin1().constData());
- return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
- }
- } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
- if(opt == "nopwd") {
- Option::projfile::do_pwd = false;
- } else {
- fprintf(stderr, "***Unknown option -%s\n", opt.toLatin1().constData());
- return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
+ return Option::QMAKE_CMDLINE_BAIL;
+ } else if (arg == "-h" || arg == "-help" || arg == "--help") {
+ return Option::QMAKE_CMDLINE_SHOW_USAGE;
+ } else if (arg == "-Wall") {
+ Option::warn_level |= WarnAll;
+ } else if (arg == "-Wparser") {
+ Option::warn_level |= WarnParser;
+ } else if (arg == "-Wlogic") {
+ Option::warn_level |= WarnLogic;
+ } else if (arg == "-Wdeprecated") {
+ Option::warn_level |= WarnDeprecated;
+ } else if (arg == "-Wnone") {
+ Option::warn_level = WarnNone;
+ } else if (arg == "-r" || arg == "-recursive") {
+ Option::recursive = true;
+ args.removeAt(x);
+ continue;
+ } else if (arg == "-nr" || arg == "-norecursive") {
+ Option::recursive = false;
+ args.removeAt(x);
+ continue;
+ } else if (arg == "-o" || arg == "-output") {
+ argState = ArgOutput;
+ } else {
+ if (Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
+ Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
+ if (arg == "-nodepend" || arg == "-nodepends") {
+ Option::mkfile::do_deps = false;
+ } else if (arg == "-nomoc") {
+ Option::mkfile::do_mocs = false;
+ } else if (arg == "-createstub") {
+ Option::mkfile::do_stub_makefile = true;
+ } else if (arg == "-nodependheuristics") {
+ Option::mkfile::do_dep_heuristics = false;
+ } else if (arg == "-E") {
+ Option::mkfile::do_preprocess = true;
+ } else {
+ fprintf(stderr, "***Unknown option %s\n", arg.toLatin1().constData());
+ return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
+ }
+ } else if (Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
+ if (arg == "-nopwd") {
+ Option::projfile::do_pwd = false;
+ } else {
+ fprintf(stderr, "***Unknown option %s\n", arg.toLatin1().constData());
+ return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
+ }
}
}
- }
- } else {
- if(arg.indexOf('=') != -1) {
- if(before)
- Option::before_user_vars.append(arg);
- else
- Option::after_user_vars.append(arg);
} else {
bool handled = true;
if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY ||
@@ -342,14 +309,12 @@ Option::parseCommandLine(QStringList &args)
}
x++;
}
-
- if (!user_configs.isEmpty())
- Option::before_user_vars += "CONFIG += " + user_configs.join(" ");
-
- if (Option::mkfile::xqmakespec.isEmpty())
- Option::mkfile::xqmakespec = Option::mkfile::qmakespec;
-
- args.takeLast();
+ if (argState != ArgNone) {
+ fprintf(stderr, "***Option %s requires a parameter\n", qPrintable(args.at(x - 1)));
+ return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
+ }
+ globals->commitCommandLineArguments(state);
+ globals->debugLevel = Option::debug_level;
return Option::QMAKE_CMDLINE_SUCCESS;
}
@@ -359,13 +324,6 @@ Option::init(int argc, char **argv)
Option::application_argv0 = 0;
Option::prf_ext = ".prf";
Option::pro_ext = ".pro";
-#ifdef Q_OS_WIN
- Option::dir_sep = "\\";
- Option::dirlist_sep = ";";
-#else
- Option::dir_sep = "/";
- Option::dirlist_sep = ":";
-#endif
Option::field_sep = ' ';
if(argc && argv) {
@@ -374,13 +332,13 @@ Option::init(int argc, char **argv)
if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
Option::qmake_mode = default_mode(argv0);
if(!argv0.isEmpty() && !QFileInfo(argv0).isRelative()) {
- Option::qmake_abslocation = argv0;
+ globals->qmake_abslocation = argv0;
} else if (argv0.contains(QLatin1Char('/'))
#ifdef Q_OS_WIN
|| argv0.contains(QLatin1Char('\\'))
#endif
) { //relative PWD
- Option::qmake_abslocation = QDir::current().absoluteFilePath(argv0);
+ globals->qmake_abslocation = QDir::current().absoluteFilePath(argv0);
} else { //in the PATH
QByteArray pEnv = qgetenv("PATH");
QDir currentDir = QDir::current();
@@ -397,16 +355,16 @@ Option::init(int argc, char **argv)
candidate += ".exe";
#endif
if (QFile::exists(candidate)) {
- Option::qmake_abslocation = candidate;
+ globals->qmake_abslocation = candidate;
break;
}
}
}
- if(!Option::qmake_abslocation.isNull())
- Option::qmake_abslocation = QDir::cleanPath(Option::qmake_abslocation);
+ if (!globals->qmake_abslocation.isNull())
+ globals->qmake_abslocation = QDir::cleanPath(globals->qmake_abslocation);
else // This is rather unlikely to ever happen on a modern system ...
- Option::qmake_abslocation = QLibraryInfo::rawLocation(QLibraryInfo::HostBinariesPath,
- QLibraryInfo::EffectivePaths) +
+ globals->qmake_abslocation = QLibraryInfo::rawLocation(QLibraryInfo::HostBinariesPath,
+ QLibraryInfo::EffectivePaths) +
#ifdef Q_OS_WIN
"/qmake.exe";
#else
@@ -485,13 +443,7 @@ Option::init(int argc, char **argv)
//last chance for defaults
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
- if (Option::mkfile::xqmakespec.isEmpty())
- Option::mkfile::xqmakespec = QString::fromLocal8Bit(qgetenv("XQMAKESPEC").constData());
- if (Option::mkfile::qmakespec.isEmpty()) {
- Option::mkfile::qmakespec = QString::fromLocal8Bit(qgetenv("QMAKESPEC").constData());
- if (Option::mkfile::xqmakespec.isEmpty())
- Option::mkfile::xqmakespec = Option::mkfile::qmakespec;
- }
+ globals->useEnvironment();
//try REALLY hard to do it for them, lazy..
if(Option::mkfile::project_files.isEmpty()) {
@@ -513,23 +465,7 @@ Option::init(int argc, char **argv)
void Option::prepareProject(const QString &pfile)
{
QString srcpath = QDir::cleanPath(QFileInfo(pfile).absolutePath());
- if (srcpath != output_dir) {
- if (!srcpath.endsWith(QLatin1Char('/')))
- srcpath += QLatin1Char('/');
- QString dstpath = output_dir;
- if (!dstpath.endsWith(QLatin1Char('/')))
- dstpath += QLatin1Char('/');
- int srcLen = srcpath.length();
- int dstLen = dstpath.length();
- int lastSl = -1;
- while (++lastSl, srcpath.at(--srcLen) == dstpath.at(--dstLen))
- if (srcpath.at(srcLen) == QLatin1Char('/'))
- lastSl = 0;
- mkfile::source_root = srcpath.left(srcLen + lastSl);
- mkfile::build_root = dstpath.left(dstLen + lastSl);
- } else {
- mkfile::source_root.clear();
- }
+ globals->setDirectories(srcpath, output_dir);
}
bool Option::postProcessProject(QMakeProject *project)
@@ -550,6 +486,8 @@ bool Option::postProcessProject(QMakeProject *project)
Option::lex_mod = project->first("QMAKE_MOD_LEX").toQString();
Option::yacc_mod = project->first("QMAKE_MOD_YACC").toQString();
+ Option::dir_sep = project->dirSep().toQString();
+
if (Option::output_dir.startsWith(project->buildRoot()))
Option::mkfile::cachefile_depth =
Option::output_dir.mid(project->buildRoot().length()).count('/');
@@ -665,6 +603,37 @@ void warn_msg(QMakeWarn type, const char *fmt, ...)
fprintf(stderr, "\n");
}
+void EvalHandler::message(int type, const QString &msg, const QString &fileName, int lineNo)
+{
+ QString pfx;
+ if ((type & QMakeHandler::CategoryMask) == QMakeHandler::WarningMessage) {
+ int code = (type & QMakeHandler::CodeMask);
+ if ((code == QMakeHandler::WarnLanguage && !(Option::warn_level & WarnParser))
+ || (code == QMakeHandler::WarnDeprecated && !(Option::warn_level & WarnDeprecated)))
+ return;
+ pfx = QString::fromLatin1("WARNING: ");
+ }
+ if (lineNo > 0)
+ fprintf(stderr, "%s%s:%d: %s\n", qPrintable(pfx), qPrintable(fileName), lineNo, qPrintable(msg));
+ else if (lineNo)
+ fprintf(stderr, "%s%s: %s\n", qPrintable(pfx), qPrintable(fileName), qPrintable(msg));
+ else
+ fprintf(stderr, "%s%s\n", qPrintable(pfx), qPrintable(msg));
+}
+
+void EvalHandler::fileMessage(const QString &msg)
+{
+ fprintf(stderr, "%s\n", qPrintable(msg));
+}
+
+void EvalHandler::aboutToEval(ProFile *, ProFile *, EvalFileType)
+{
+}
+
+void EvalHandler::doneWithEval(ProFile *)
+{
+}
+
class QMakeCacheClearItem {
private:
qmakeCacheClearFunc func;
@@ -693,8 +662,8 @@ qmakeAddCacheClear(qmakeCacheClearFunc func, void **data)
QString qmake_libraryInfoFile()
{
- if(!Option::qmake_abslocation.isEmpty())
- return QDir(QFileInfo(Option::qmake_abslocation).absolutePath()).filePath("qt.conf");
+ if (!Option::globals->qmake_abslocation.isEmpty())
+ return QDir(QFileInfo(Option::globals->qmake_abslocation).absolutePath()).filePath("qt.conf");
return QString();
}