2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:03:39 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 03:06:31 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 09:34:08 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 09:34:08 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "option.h"
|
|
|
|
#include "cachekeys.h"
|
|
|
|
#include <qdir.h>
|
|
|
|
#include <qregexp.h>
|
|
|
|
#include <qhash.h>
|
|
|
|
#include <qdebug.h>
|
|
|
|
#include <qsettings.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
//convenience
|
|
|
|
const char *Option::application_argv0 = 0;
|
|
|
|
QString Option::prf_ext;
|
|
|
|
QString Option::prl_ext;
|
|
|
|
QString Option::libtool_ext;
|
|
|
|
QString Option::pkgcfg_ext;
|
|
|
|
QString Option::ui_ext;
|
|
|
|
QStringList Option::h_ext;
|
|
|
|
QString Option::cpp_moc_ext;
|
|
|
|
QStringList Option::cpp_ext;
|
|
|
|
QStringList Option::c_ext;
|
|
|
|
QString Option::obj_ext;
|
|
|
|
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;
|
|
|
|
QString Option::res_ext;
|
|
|
|
char Option::field_sep;
|
|
|
|
|
|
|
|
//mode
|
|
|
|
Option::QMAKE_MODE Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
|
|
|
|
|
|
|
|
//all modes
|
|
|
|
QString Option::qmake_abslocation;
|
2012-08-09 16:54:40 +00:00
|
|
|
QStringList Option::qmake_args;
|
2011-04-27 10:05:43 +00:00
|
|
|
int Option::warn_level = WarnLogic | WarnDeprecated;
|
|
|
|
int Option::debug_level = 0;
|
|
|
|
QFile Option::output;
|
|
|
|
QString Option::output_dir;
|
2012-05-04 18:02:35 +00:00
|
|
|
bool Option::recursive = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
//QMAKE_GENERATE_PROJECT stuff
|
|
|
|
bool Option::projfile::do_pwd = true;
|
|
|
|
QStringList Option::projfile::project_dirs;
|
|
|
|
|
|
|
|
//QMAKE_GENERATE_MAKEFILE stuff
|
|
|
|
QString Option::mkfile::qmakespec;
|
2012-01-31 17:36:18 +00:00
|
|
|
QString Option::mkfile::xqmakespec;
|
2011-04-27 10:05:43 +00:00
|
|
|
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;
|
2012-05-09 13:29:25 +00:00
|
|
|
QString Option::mkfile::source_root;
|
|
|
|
QString Option::mkfile::build_root;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString Option::mkfile::cachefile;
|
|
|
|
QStringList Option::mkfile::project_files;
|
|
|
|
|
|
|
|
static Option::QMAKE_MODE default_mode(QString progname)
|
|
|
|
{
|
|
|
|
int s = progname.lastIndexOf(QDir::separator());
|
|
|
|
if(s != -1)
|
|
|
|
progname = progname.right(progname.length() - (s + 1));
|
|
|
|
if(progname == "qmakegen")
|
|
|
|
return Option::QMAKE_GENERATE_PROJECT;
|
|
|
|
else if(progname == "qt-config")
|
|
|
|
return Option::QMAKE_QUERY_PROPERTY;
|
|
|
|
return Option::QMAKE_GENERATE_MAKEFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString detectProjectFile(const QString &path)
|
|
|
|
{
|
|
|
|
QString ret;
|
|
|
|
QDir dir(path);
|
|
|
|
if(dir.exists(dir.dirName() + Option::pro_ext)) {
|
|
|
|
ret = dir.filePath(dir.dirName()) + Option::pro_ext;
|
|
|
|
} else { //last try..
|
|
|
|
QStringList profiles = dir.entryList(QStringList("*" + Option::pro_ext));
|
|
|
|
if(profiles.count() == 1)
|
|
|
|
ret = dir.filePath(profiles.at(0));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-24 11:11:51 +00:00
|
|
|
static QString cleanSpec(const QString &spec)
|
|
|
|
{
|
|
|
|
QString ret = QDir::cleanPath(spec);
|
2012-03-06 12:13:09 +00:00
|
|
|
if (ret.contains('/')) {
|
|
|
|
const QFileInfo specDirInfo(ret);
|
|
|
|
if (specDirInfo.exists() && specDirInfo.isDir())
|
|
|
|
ret = QDir::cleanPath(specDirInfo.absoluteFilePath());
|
|
|
|
}
|
2012-02-24 11:11:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QString project_builtin_regx();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-08-09 16:45:48 +00:00
|
|
|
Option::parseCommandLine(QStringList &args)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-02 18:31:57 +00:00
|
|
|
QStringList user_configs;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool before = true;
|
2012-08-09 16:45:48 +00:00
|
|
|
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);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(opt == "o" || opt == "output") {
|
2012-08-09 16:54:40 +00:00
|
|
|
Option::output.setFileName(args.at(x + 1));
|
|
|
|
args.erase(args.begin() + x, args.begin() + x + 2);
|
|
|
|
continue;
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "after") {
|
|
|
|
before = false;
|
|
|
|
} else if(opt == "t" || opt == "template") {
|
2012-08-09 16:45:48 +00:00
|
|
|
Option::user_template = args.at(++x);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "tp" || opt == "template_prefix") {
|
2012-08-09 16:45:48 +00:00
|
|
|
Option::user_template_prefix = args.at(++x);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "unix") {
|
2012-05-03 18:59:14 +00:00
|
|
|
Option::dir_sep = "/";
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "win32") {
|
2012-05-03 18:59:14 +00:00
|
|
|
Option::dir_sep = "\\";
|
2011-04-27 10:05:43 +00:00
|
|
|
} 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());
|
|
|
|
#ifdef QMAKE_OPENSOURCE_VERSION
|
|
|
|
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") {
|
2012-05-04 18:02:35 +00:00
|
|
|
Option::recursive = true;
|
2012-08-09 16:54:40 +00:00
|
|
|
args.removeAt(x);
|
|
|
|
continue;
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "nr" || opt == "norecursive") {
|
2012-05-04 18:02:35 +00:00
|
|
|
Option::recursive = false;
|
2012-08-09 16:54:40 +00:00
|
|
|
args.removeAt(x);
|
|
|
|
continue;
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "config") {
|
2012-08-09 16:45:48 +00:00
|
|
|
user_configs += args.at(++x);
|
2011-04-27 10:05:43 +00:00
|
|
|
} 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") {
|
2012-08-09 16:45:48 +00:00
|
|
|
Option::mkfile::cachefile = args.at(++x);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if(opt == "platform" || opt == "spec") {
|
2012-08-09 16:54:40 +00:00
|
|
|
Option::mkfile::qmakespec = args[x] = cleanSpec(args.at(++x));
|
2012-01-31 17:36:18 +00:00
|
|
|
} else if (opt == "xplatform" || opt == "xspec") {
|
2012-08-09 16:54:40 +00:00
|
|
|
Option::mkfile::xqmakespec = args[x] = cleanSpec(args.at(x));
|
2011-04-27 10:05:43 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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 ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_SET_PROPERTY ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) {
|
|
|
|
Option::prop::properties.append(arg);
|
|
|
|
} else {
|
|
|
|
QFileInfo fi(arg);
|
|
|
|
if(!fi.makeAbsolute()) //strange
|
|
|
|
arg = fi.filePath();
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
|
|
|
if(fi.isDir()) {
|
|
|
|
QString proj = detectProjectFile(arg);
|
|
|
|
if (!proj.isNull())
|
|
|
|
arg = proj;
|
|
|
|
}
|
|
|
|
Option::mkfile::project_files.append(arg);
|
|
|
|
} else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
|
|
|
|
Option::projfile::project_dirs.append(arg);
|
|
|
|
} else {
|
|
|
|
handled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!handled) {
|
|
|
|
return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
|
|
|
|
}
|
2012-08-09 16:54:40 +00:00
|
|
|
args.removeAt(x);
|
|
|
|
continue;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-09 16:45:48 +00:00
|
|
|
x++;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 18:31:57 +00:00
|
|
|
if (!user_configs.isEmpty())
|
|
|
|
Option::before_user_vars += "CONFIG += " + user_configs.join(" ");
|
|
|
|
|
2012-01-31 17:36:18 +00:00
|
|
|
if (Option::mkfile::xqmakespec.isEmpty())
|
|
|
|
Option::mkfile::xqmakespec = Option::mkfile::qmakespec;
|
|
|
|
|
2012-08-09 16:45:48 +00:00
|
|
|
args.takeLast();
|
2011-04-27 10:05:43 +00:00
|
|
|
return Option::QMAKE_CMDLINE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Option::init(int argc, char **argv)
|
|
|
|
{
|
|
|
|
Option::application_argv0 = 0;
|
|
|
|
Option::prf_ext = ".prf";
|
|
|
|
Option::pro_ext = ".pro";
|
|
|
|
#ifdef Q_OS_WIN
|
2012-05-03 18:59:14 +00:00
|
|
|
Option::dir_sep = "\\";
|
2011-04-27 10:05:43 +00:00
|
|
|
Option::dirlist_sep = ";";
|
|
|
|
#else
|
2012-05-03 18:59:14 +00:00
|
|
|
Option::dir_sep = "/";
|
2011-04-27 10:05:43 +00:00
|
|
|
Option::dirlist_sep = ":";
|
|
|
|
#endif
|
|
|
|
Option::field_sep = ' ';
|
|
|
|
|
|
|
|
if(argc && argv) {
|
|
|
|
Option::application_argv0 = argv[0];
|
|
|
|
QString argv0 = argv[0];
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
|
|
|
|
Option::qmake_mode = default_mode(argv0);
|
|
|
|
if(!argv0.isEmpty() && !QFileInfo(argv0).isRelative()) {
|
|
|
|
Option::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);
|
|
|
|
} else { //in the PATH
|
|
|
|
QByteArray pEnv = qgetenv("PATH");
|
|
|
|
QDir currentDir = QDir::current();
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(";"));
|
|
|
|
#else
|
|
|
|
QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(":"));
|
|
|
|
#endif
|
|
|
|
for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
|
|
|
|
if ((*p).isEmpty())
|
|
|
|
continue;
|
|
|
|
QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
candidate += ".exe";
|
|
|
|
#endif
|
|
|
|
if (QFile::exists(candidate)) {
|
|
|
|
Option::qmake_abslocation = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!Option::qmake_abslocation.isNull())
|
|
|
|
Option::qmake_abslocation = QDir::cleanPath(Option::qmake_abslocation);
|
2012-04-23 10:06:59 +00:00
|
|
|
else // This is rather unlikely to ever happen on a modern system ...
|
|
|
|
Option::qmake_abslocation = QLibraryInfo::rawLocation(QLibraryInfo::HostBinariesPath,
|
|
|
|
QLibraryInfo::EffectivePaths) +
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
"/qmake.exe";
|
|
|
|
#else
|
|
|
|
"/qmake";
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QByteArray envflags = qgetenv("QMAKEFLAGS");
|
|
|
|
if (!envflags.isNull()) {
|
2012-08-09 16:45:48 +00:00
|
|
|
QStringList args;
|
|
|
|
QByteArray buf = "";
|
|
|
|
char quote = 0;
|
|
|
|
bool hasWord = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < envflags.size(); ++i) {
|
2012-08-09 16:45:48 +00:00
|
|
|
char c = envflags.at(i);
|
|
|
|
if (!quote && (c == '\'' || c == '"')) {
|
|
|
|
quote = c;
|
|
|
|
} else if (c == quote) {
|
2011-04-27 10:05:43 +00:00
|
|
|
quote = 0;
|
2012-08-09 16:45:48 +00:00
|
|
|
} else if (!quote && c == ' ') {
|
|
|
|
if (hasWord) {
|
|
|
|
args << QString::fromLocal8Bit(buf);
|
|
|
|
hasWord = false;
|
|
|
|
buf = "";
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-09 16:45:48 +00:00
|
|
|
buf += c;
|
|
|
|
hasWord = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-09 16:45:48 +00:00
|
|
|
if (hasWord)
|
|
|
|
args << QString::fromLocal8Bit(buf);
|
|
|
|
parseCommandLine(args);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
if(argc && argv) {
|
2012-08-09 16:45:48 +00:00
|
|
|
QStringList args;
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
args << QString::fromLocal8Bit(argv[i]);
|
|
|
|
|
|
|
|
while (!args.isEmpty()) {
|
|
|
|
QString opt = args.at(0);
|
2012-08-09 14:13:56 +00:00
|
|
|
if (opt == "-project") {
|
|
|
|
Option::recursive = true;
|
|
|
|
Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT;
|
|
|
|
} else if (opt == "-prl") {
|
|
|
|
Option::mkfile::do_deps = false;
|
|
|
|
Option::mkfile::do_mocs = false;
|
|
|
|
Option::qmake_mode = Option::QMAKE_GENERATE_PRL;
|
|
|
|
} else if (opt == "-set") {
|
|
|
|
Option::qmake_mode = Option::QMAKE_SET_PROPERTY;
|
|
|
|
} else if (opt == "-unset") {
|
|
|
|
Option::qmake_mode = Option::QMAKE_UNSET_PROPERTY;
|
|
|
|
} else if (opt == "-query") {
|
|
|
|
Option::qmake_mode = Option::QMAKE_QUERY_PROPERTY;
|
|
|
|
} else if (opt == "-makefile") {
|
|
|
|
Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-08-09 16:45:48 +00:00
|
|
|
args.takeFirst();
|
2012-08-09 14:13:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-09 16:45:48 +00:00
|
|
|
int ret = parseCommandLine(args);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
|
|
|
|
if ((ret & Option::QMAKE_CMDLINE_SHOW_USAGE) != 0)
|
|
|
|
usage(argv[0]);
|
|
|
|
return ret;
|
|
|
|
//return ret == QMAKE_CMDLINE_SHOW_USAGE ? usage(argv[0]) : false;
|
|
|
|
}
|
2012-08-09 16:54:40 +00:00
|
|
|
Option::qmake_args = args;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//last chance for defaults
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
2012-01-31 17:36:18 +00:00
|
|
|
if (Option::mkfile::xqmakespec.isEmpty())
|
|
|
|
Option::mkfile::xqmakespec = QString::fromLocal8Bit(qgetenv("XQMAKESPEC").constData());
|
|
|
|
if (Option::mkfile::qmakespec.isEmpty()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
Option::mkfile::qmakespec = QString::fromLocal8Bit(qgetenv("QMAKESPEC").constData());
|
2012-01-31 17:36:18 +00:00
|
|
|
if (Option::mkfile::xqmakespec.isEmpty())
|
|
|
|
Option::mkfile::xqmakespec = Option::mkfile::qmakespec;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//try REALLY hard to do it for them, lazy..
|
|
|
|
if(Option::mkfile::project_files.isEmpty()) {
|
|
|
|
QString proj = detectProjectFile(qmake_getpwd());
|
|
|
|
if(!proj.isNull())
|
|
|
|
Option::mkfile::project_files.append(proj);
|
|
|
|
#ifndef QT_BUILD_QMAKE_LIBRARY
|
|
|
|
if(Option::mkfile::project_files.isEmpty()) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return Option::QMAKE_CMDLINE_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 15:12:53 +00:00
|
|
|
return QMAKE_CMDLINE_SUCCESS;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 13:29:25 +00:00
|
|
|
void Option::prepareProject(const QString &pfile)
|
|
|
|
{
|
2012-08-28 08:12:36 +00:00
|
|
|
QString srcpath = QDir::cleanPath(QFileInfo(pfile).absolutePath());
|
2012-05-09 13:29:25 +00:00
|
|
|
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();
|
2012-06-24 15:22:23 +00:00
|
|
|
int lastSl = -1;
|
2012-05-09 13:29:25 +00:00
|
|
|
while (++lastSl, srcpath.at(--srcLen) == dstpath.at(--dstLen))
|
|
|
|
if (srcpath.at(srcLen) == QLatin1Char('/'))
|
2012-06-24 15:22:23 +00:00
|
|
|
lastSl = 0;
|
2012-05-09 13:29:25 +00:00
|
|
|
mkfile::source_root = srcpath.left(srcLen + lastSl);
|
|
|
|
mkfile::build_root = dstpath.left(dstLen + lastSl);
|
|
|
|
} else {
|
|
|
|
mkfile::source_root.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool Option::postProcessProject(QMakeProject *project)
|
|
|
|
{
|
2012-04-23 16:08:16 +00:00
|
|
|
Option::cpp_ext = project->values("QMAKE_EXT_CPP");
|
|
|
|
Option::h_ext = project->values("QMAKE_EXT_H");
|
|
|
|
Option::c_ext = project->values("QMAKE_EXT_C");
|
2012-04-20 18:27:15 +00:00
|
|
|
Option::res_ext = project->first("QMAKE_EXT_RES");
|
|
|
|
Option::pkgcfg_ext = project->first("QMAKE_EXT_PKGCONFIG");
|
|
|
|
Option::libtool_ext = project->first("QMAKE_EXT_LIBTOOL");
|
|
|
|
Option::prl_ext = project->first("QMAKE_EXT_PRL");
|
|
|
|
Option::ui_ext = project->first("QMAKE_EXT_UI");
|
|
|
|
Option::cpp_moc_ext = project->first("QMAKE_EXT_CPP_MOC");
|
|
|
|
Option::lex_ext = project->first("QMAKE_EXT_LEX");
|
|
|
|
Option::yacc_ext = project->first("QMAKE_EXT_YACC");
|
|
|
|
Option::obj_ext = project->first("QMAKE_EXT_OBJ");
|
|
|
|
Option::h_moc_mod = project->first("QMAKE_H_MOD_MOC");
|
|
|
|
Option::lex_mod = project->first("QMAKE_MOD_LEX");
|
|
|
|
Option::yacc_mod = project->first("QMAKE_MOD_YACC");
|
2012-06-12 18:15:41 +00:00
|
|
|
|
|
|
|
if (Option::output_dir.startsWith(project->buildRoot()))
|
|
|
|
Option::mkfile::cachefile_depth =
|
|
|
|
Option::output_dir.mid(project->buildRoot().length()).count('/');
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
Option::fixString(QString string, uchar flags)
|
|
|
|
{
|
|
|
|
//const QString orig_string = string;
|
|
|
|
static QHash<FixStringCacheKey, QString> *cache = 0;
|
|
|
|
if(!cache) {
|
|
|
|
cache = new QHash<FixStringCacheKey, QString>;
|
|
|
|
qmakeAddCacheClear(qmakeDeleteCacheClear<QHash<FixStringCacheKey, QString> >, (void**)&cache);
|
|
|
|
}
|
|
|
|
FixStringCacheKey cacheKey(string, flags);
|
|
|
|
|
|
|
|
QHash<FixStringCacheKey, QString>::const_iterator it = cache->constFind(cacheKey);
|
|
|
|
|
|
|
|
if (it != cache->constEnd()) {
|
|
|
|
//qDebug() << "Fix (cached) " << orig_string << "->" << it.value();
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
//fix the environment variables
|
|
|
|
if(flags & Option::FixEnvVars) {
|
|
|
|
int rep;
|
|
|
|
static QRegExp reg_var("\\$\\(.*\\)");
|
|
|
|
reg_var.setMinimal(true);
|
|
|
|
while((rep = reg_var.indexIn(string)) != -1)
|
|
|
|
string.replace(rep, reg_var.matchedLength(),
|
|
|
|
QString::fromLocal8Bit(qgetenv(string.mid(rep + 2, reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//canonicalize it (and treat as a path)
|
|
|
|
if(flags & Option::FixPathCanonicalize) {
|
|
|
|
#if 0
|
|
|
|
string = QFileInfo(string).canonicalFilePath();
|
|
|
|
#endif
|
|
|
|
string = QDir::cleanPath(string);
|
|
|
|
}
|
|
|
|
|
2011-11-15 08:34:38 +00:00
|
|
|
bool localSep = (flags & Option::FixPathToLocalSeparators) != 0;
|
|
|
|
bool targetSep = (flags & Option::FixPathToTargetSeparators) != 0;
|
|
|
|
bool normalSep = (flags & Option::FixPathToNormalSeparators) != 0;
|
|
|
|
|
|
|
|
// either none or only one active flag
|
|
|
|
Q_ASSERT(localSep + targetSep + normalSep <= 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
//fix separators
|
2011-11-15 08:34:38 +00:00
|
|
|
if (flags & Option::FixPathToNormalSeparators) {
|
|
|
|
string = string.replace('\\', '/');
|
|
|
|
} else if (flags & Option::FixPathToLocalSeparators) {
|
2011-04-27 10:05:43 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
string = string.replace('/', '\\');
|
|
|
|
#else
|
|
|
|
string = string.replace('\\', '/');
|
|
|
|
#endif
|
|
|
|
} else if(flags & Option::FixPathToTargetSeparators) {
|
|
|
|
string = string.replace('/', Option::dir_sep).replace('\\', Option::dir_sep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((string.startsWith("\"") && string.endsWith("\"")) ||
|
|
|
|
(string.startsWith("\'") && string.endsWith("\'")))
|
|
|
|
string = string.mid(1, string.length()-2);
|
|
|
|
|
|
|
|
//cache
|
|
|
|
//qDebug() << "Fix" << orig_string << "->" << string;
|
|
|
|
cache->insert(cacheKey, string);
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *qmake_version()
|
|
|
|
{
|
|
|
|
static char *ret = NULL;
|
|
|
|
if(ret)
|
|
|
|
return ret;
|
|
|
|
ret = (char *)malloc(15);
|
|
|
|
qmakeAddCacheClear(qmakeFreeCacheClear, (void**)&ret);
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
sprintf_s(ret, 15, "%d.%02d%c", QMAKE_VERSION_MAJOR, QMAKE_VERSION_MINOR, 'a' + QMAKE_VERSION_PATCH);
|
|
|
|
#else
|
|
|
|
sprintf(ret, "%d.%02d%c", QMAKE_VERSION_MAJOR, QMAKE_VERSION_MINOR, 'a' + QMAKE_VERSION_PATCH);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void debug_msg_internal(int level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
if(Option::debug_level < level)
|
|
|
|
return;
|
|
|
|
fprintf(stderr, "DEBUG %d: ", level);
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void warn_msg(QMakeWarn type, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
if(!(Option::warn_level & type))
|
|
|
|
return;
|
|
|
|
fprintf(stderr, "WARNING: ");
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
class QMakeCacheClearItem {
|
|
|
|
private:
|
|
|
|
qmakeCacheClearFunc func;
|
|
|
|
void **data;
|
|
|
|
public:
|
|
|
|
QMakeCacheClearItem(qmakeCacheClearFunc f, void **d) : func(f), data(d) { }
|
|
|
|
~QMakeCacheClearItem() {
|
|
|
|
(*func)(*data);
|
|
|
|
*data = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static QList<QMakeCacheClearItem*> cache_items;
|
|
|
|
|
|
|
|
void
|
|
|
|
qmakeClearCaches()
|
|
|
|
{
|
|
|
|
qDeleteAll(cache_items);
|
|
|
|
cache_items.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qmakeAddCacheClear(qmakeCacheClearFunc func, void **data)
|
|
|
|
{
|
|
|
|
cache_items.append(new QMakeCacheClearItem(func, data));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString qmake_libraryInfoFile()
|
|
|
|
{
|
2011-09-09 16:41:52 +00:00
|
|
|
if(!Option::qmake_abslocation.isEmpty())
|
|
|
|
return QDir(QFileInfo(Option::qmake_abslocation).absolutePath()).filePath("qt.conf");
|
|
|
|
return QString();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|