1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include "cachekeys.h"
48 #include <qsettings.h>
55 const char *Option::application_argv0 = 0;
56 QString Option::prf_ext;
57 QString Option::js_ext;
58 QString Option::prl_ext;
59 QString Option::libtool_ext;
60 QString Option::pkgcfg_ext;
61 QString Option::ui_ext;
62 QStringList Option::h_ext;
63 QString Option::cpp_moc_ext;
64 QString Option::h_moc_ext;
65 QStringList Option::cpp_ext;
66 QStringList Option::c_ext;
67 QString Option::obj_ext;
68 QString Option::lex_ext;
69 QString Option::yacc_ext;
70 QString Option::pro_ext;
71 QString Option::mmp_ext;
72 QString Option::dir_sep;
73 QString Option::dirlist_sep;
74 QString Option::h_moc_mod;
75 QString Option::cpp_moc_mod;
76 QString Option::yacc_mod;
77 QString Option::lex_mod;
78 QString Option::sysenv_mod;
79 QString Option::res_ext;
80 char Option::field_sep;
83 Option::QMAKE_MODE Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
86 QString Option::qmake_abslocation;
87 int Option::warn_level = WarnLogic | WarnDeprecated;
88 int Option::debug_level = 0;
90 QString Option::output_dir;
91 Option::QMAKE_RECURSIVE Option::recursive = Option::QMAKE_RECURSIVE_DEFAULT;
92 QStringList Option::before_user_vars;
93 QStringList Option::after_user_vars;
94 QString Option::user_template;
95 QString Option::user_template_prefix;
96 QStringList Option::shellPath;
97 Option::HOST_MODE Option::host_mode = Option::HOST_UNKNOWN_MODE;
98 Option::TARG_MODE Option::target_mode = Option::TARG_UNKNOWN_MODE;
99 bool Option::target_mode_overridden = false;
101 //QMAKE_*_PROPERTY stuff
102 QStringList Option::prop::properties;
104 //QMAKE_GENERATE_PROJECT stuff
105 bool Option::projfile::do_pwd = true;
106 QStringList Option::projfile::project_dirs;
108 //QMAKE_GENERATE_MAKEFILE stuff
109 QString Option::mkfile::qmakespec;
110 int Option::mkfile::cachefile_depth = -1;
111 bool Option::mkfile::do_deps = true;
112 bool Option::mkfile::do_mocs = true;
113 bool Option::mkfile::do_dep_heuristics = true;
114 bool Option::mkfile::do_preprocess = false;
115 bool Option::mkfile::do_stub_makefile = false;
116 bool Option::mkfile::do_cache = true;
117 QString Option::mkfile::project_root;
118 QString Option::mkfile::project_build_root;
119 QString Option::mkfile::cachefile;
120 QStringList Option::mkfile::project_files;
121 QString Option::mkfile::qmakespec_commandline;
123 static Option::QMAKE_MODE default_mode(QString progname)
125 int s = progname.lastIndexOf(QDir::separator());
127 progname = progname.right(progname.length() - (s + 1));
128 if(progname == "qmakegen")
129 return Option::QMAKE_GENERATE_PROJECT;
130 else if(progname == "qt-config")
131 return Option::QMAKE_QUERY_PROPERTY;
132 return Option::QMAKE_GENERATE_MAKEFILE;
135 static QString detectProjectFile(const QString &path)
139 if(dir.exists(dir.dirName() + Option::pro_ext)) {
140 ret = dir.filePath(dir.dirName()) + Option::pro_ext;
141 } else { //last try..
142 QStringList profiles = dir.entryList(QStringList("*" + Option::pro_ext));
143 if(profiles.count() == 1)
144 ret = dir.filePath(profiles.at(0));
149 static QString cleanSpec(const QString &spec)
151 QString ret = QDir::cleanPath(spec);
152 if (ret.contains('/')) {
153 const QFileInfo specDirInfo(ret);
154 if (specDirInfo.exists() && specDirInfo.isDir())
155 ret = QDir::cleanPath(specDirInfo.absoluteFilePath());
160 QString project_builtin_regx();
161 bool usage(const char *a0)
163 fprintf(stdout, "Usage: %s [mode] [options] [files]\n"
165 "QMake has two modes, one mode for generating project files based on\n"
166 "some heuristics, and the other for generating makefiles. Normally you\n"
167 "shouldn't need to specify a mode, as makefile generation is the default\n"
168 "mode for qmake, but you may use this to test qmake on an existing project\n"
171 " -project Put qmake into project file generation mode%s\n"
172 " In this mode qmake interprets files as files to\n"
175 " Note: The created .pro file probably will \n"
176 " need to be edited. For example add the QT variable to \n"
177 " specify what modules are required.\n"
178 " -makefile Put qmake into makefile generation mode%s\n"
179 " In this mode qmake interprets files as project files to\n"
180 " be processed, if skipped qmake will try to find a project\n"
181 " file in your current working directory\n"
183 "Warnings Options:\n"
184 " -Wnone Turn off all warnings; specific ones may be re-enabled by\n"
185 " later -W options\n"
186 " -Wall Turn on all warnings\n"
187 " -Wparser Turn on parser warnings\n"
188 " -Wlogic Turn on logic warnings (on by default)\n"
189 " -Wdeprecated Turn on deprecation warnings (on by default)\n"
192 " * You can place any variable assignment in options and it will be *\n"
193 " * processed as if it was in [files]. These assignments will be parsed *\n"
194 " * before [files]. *\n"
195 " -o file Write output to file\n"
196 " -d Increase debug level\n"
197 " -t templ Overrides TEMPLATE as templ\n"
198 " -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value\n"
200 " -v Version information\n"
201 " -after All variable assignments after this will be\n"
202 " parsed after [files]\n"
203 " -norecursive Don't do a recursive search\n"
204 " -recursive Do a recursive search\n"
205 " -set <prop> <value> Set persistent property\n"
206 " -unset <prop> Unset persistent property\n"
207 " -query <prop> Query persistent property. Show all if <prop> is empty.\n"
208 " -cache file Use file as cache [makefile mode only]\n"
209 " -spec spec Use spec as QMAKESPEC [makefile mode only]\n"
210 " -nocache Don't use a cache file [makefile mode only]\n"
211 " -nodepend Don't generate dependencies [makefile mode only]\n"
212 " -nomoc Don't generate moc targets [makefile mode only]\n"
213 " -nopwd Don't look for files in pwd [project mode only]\n"
215 default_mode(a0) == Option::QMAKE_GENERATE_PROJECT ? " (default)" : "", project_builtin_regx().toLatin1().constData(),
216 default_mode(a0) == Option::QMAKE_GENERATE_MAKEFILE ? " (default)" : ""
222 Option::parseCommandLine(int argc, char **argv, int skip)
224 QStringList user_configs;
227 for(int x = skip; x < argc; x++) {
228 if(*argv[x] == '-' && strlen(argv[x]) > 1) { /* options */
229 QString opt = argv[x] + 1;
231 //first param is a mode, or we default
233 bool specified = true;
234 if(opt == "project") {
235 Option::recursive = Option::QMAKE_RECURSIVE_YES;
236 Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT;
237 } else if(opt == "prl") {
238 Option::mkfile::do_deps = false;
239 Option::mkfile::do_mocs = false;
240 Option::qmake_mode = Option::QMAKE_GENERATE_PRL;
241 } else if(opt == "set") {
242 Option::qmake_mode = Option::QMAKE_SET_PROPERTY;
243 } else if(opt == "unset") {
244 Option::qmake_mode = Option::QMAKE_UNSET_PROPERTY;
245 } else if(opt == "query") {
246 Option::qmake_mode = Option::QMAKE_QUERY_PROPERTY;
247 } else if(opt == "makefile") {
248 Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
256 if(opt == "o" || opt == "output") {
257 Option::output.setFileName(argv[++x]);
258 } else if(opt == "after") {
260 } else if(opt == "t" || opt == "template") {
261 Option::user_template = argv[++x];
262 } else if(opt == "tp" || opt == "template_prefix") {
263 Option::user_template_prefix = argv[++x];
264 } else if(opt == "macx") {
265 fprintf(stderr, "-macx is deprecated.\n");
266 Option::host_mode = HOST_MACX_MODE;
267 Option::target_mode = TARG_MACX_MODE;
268 Option::target_mode_overridden = true;
269 } else if(opt == "unix") {
270 fprintf(stderr, "-unix is deprecated.\n");
271 Option::host_mode = HOST_UNIX_MODE;
272 Option::target_mode = TARG_UNIX_MODE;
273 Option::target_mode_overridden = true;
274 } else if(opt == "win32") {
275 fprintf(stderr, "-win32 is deprecated.\n");
276 Option::host_mode = HOST_WIN_MODE;
277 Option::target_mode = TARG_WIN_MODE;
278 Option::target_mode_overridden = true;
279 } else if(opt == "integrity") {
280 Option::target_mode = TARG_INTEGRITY_MODE;
281 } else if(opt == "d") {
282 Option::debug_level++;
283 } else if(opt == "version" || opt == "v" || opt == "-version") {
286 "Using Qt version %s in %s\n",
287 qmake_version(), QT_VERSION_STR,
288 QLibraryInfo::location(QLibraryInfo::LibrariesPath).toLatin1().constData());
289 #ifdef QMAKE_OPENSOURCE_VERSION
290 fprintf(stdout, "QMake is Open Source software from Nokia Corporation and/or its subsidiary(-ies).\n");
292 return Option::QMAKE_CMDLINE_BAIL;
293 } else if(opt == "h" || opt == "help") {
294 return Option::QMAKE_CMDLINE_SHOW_USAGE;
295 } else if(opt == "Wall") {
296 Option::warn_level |= WarnAll;
297 } else if(opt == "Wparser") {
298 Option::warn_level |= WarnParser;
299 } else if(opt == "Wlogic") {
300 Option::warn_level |= WarnLogic;
301 } else if(opt == "Wdeprecated") {
302 Option::warn_level |= WarnDeprecated;
303 } else if(opt == "Wnone") {
304 Option::warn_level = WarnNone;
305 } else if(opt == "r" || opt == "recursive") {
306 Option::recursive = Option::QMAKE_RECURSIVE_YES;
307 } else if(opt == "nr" || opt == "norecursive") {
308 Option::recursive = Option::QMAKE_RECURSIVE_NO;
309 } else if(opt == "config") {
310 user_configs += argv[++x];
312 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
313 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
314 if(opt == "nodepend" || opt == "nodepends") {
315 Option::mkfile::do_deps = false;
316 } else if(opt == "nomoc") {
317 Option::mkfile::do_mocs = false;
318 } else if(opt == "nocache") {
319 Option::mkfile::do_cache = false;
320 } else if(opt == "createstub") {
321 Option::mkfile::do_stub_makefile = true;
322 } else if(opt == "nodependheuristics") {
323 Option::mkfile::do_dep_heuristics = false;
324 } else if(opt == "E") {
325 fprintf(stderr, "-E is deprecated. Use -d instead.\n");
326 Option::mkfile::do_preprocess = true;
327 } else if(opt == "cache") {
328 Option::mkfile::cachefile = argv[++x];
329 } else if(opt == "platform" || opt == "spec") {
330 Option::mkfile::qmakespec = cleanSpec(argv[++x]);
331 Option::mkfile::qmakespec_commandline = argv[x];
333 fprintf(stderr, "***Unknown option -%s\n", opt.toLatin1().constData());
334 return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
336 } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
338 Option::projfile::do_pwd = false;
340 fprintf(stderr, "***Unknown option -%s\n", opt.toLatin1().constData());
341 return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
346 QString arg = argv[x];
347 if(arg.indexOf('=') != -1) {
349 Option::before_user_vars.append(arg);
351 Option::after_user_vars.append(arg);
354 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY ||
355 Option::qmake_mode == Option::QMAKE_SET_PROPERTY ||
356 Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) {
357 Option::prop::properties.append(arg);
360 if(!fi.makeAbsolute()) //strange
362 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
363 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
365 QString proj = detectProjectFile(arg);
369 Option::mkfile::project_files.append(arg);
370 } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
371 Option::projfile::project_dirs.append(arg);
377 return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
383 if (!user_configs.isEmpty())
384 Option::before_user_vars += "CONFIG += " + user_configs.join(" ");
386 return Option::QMAKE_CMDLINE_SUCCESS;
390 static QStringList detectShellPath()
393 QString path = qgetenv("PATH");
394 QStringList pathlist = path.toLower().split(";");
395 for (int i = 0; i < pathlist.count(); i++) {
396 QString maybeSh = pathlist.at(i) + "/sh.exe";
397 if (QFile::exists(maybeSh)) {
398 paths.append(maybeSh);
406 Option::init(int argc, char **argv)
408 Option::application_argv0 = 0;
409 Option::cpp_moc_mod = "";
410 Option::h_moc_mod = "moc_";
411 Option::lex_mod = "_lex";
412 Option::yacc_mod = "_yacc";
413 Option::prl_ext = ".prl";
414 Option::libtool_ext = ".la";
415 Option::pkgcfg_ext = ".pc";
416 Option::prf_ext = ".prf";
417 Option::js_ext = ".js";
418 Option::ui_ext = ".ui";
419 Option::h_ext << ".h" << ".hpp" << ".hh" << ".hxx";
420 Option::c_ext << ".c";
422 Option::h_ext << ".H";
424 Option::cpp_moc_ext = ".moc";
425 Option::h_moc_ext = ".cpp";
426 Option::cpp_ext << ".cpp" << ".cc" << ".cxx";
428 Option::cpp_ext << ".C";
430 Option::lex_ext = ".l";
431 Option::yacc_ext = ".y";
432 Option::pro_ext = ".pro";
433 Option::mmp_ext = ".mmp";
435 Option::dirlist_sep = ";";
436 Option::shellPath = detectShellPath();
437 Option::res_ext = ".res";
439 Option::dirlist_sep = ":";
440 Option::shellPath = QStringList("sh");
442 Option::sysenv_mod = "QMAKE_ENV_";
443 Option::field_sep = ' ';
446 Option::application_argv0 = argv[0];
447 QString argv0 = argv[0];
448 if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
449 Option::qmake_mode = default_mode(argv0);
450 if(!argv0.isEmpty() && !QFileInfo(argv0).isRelative()) {
451 Option::qmake_abslocation = argv0;
452 } else if (argv0.contains(QLatin1Char('/'))
454 || argv0.contains(QLatin1Char('\\'))
457 Option::qmake_abslocation = QDir::current().absoluteFilePath(argv0);
458 } else { //in the PATH
459 QByteArray pEnv = qgetenv("PATH");
460 QDir currentDir = QDir::current();
462 QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(";"));
464 QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(":"));
466 for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
469 QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
473 if (QFile::exists(candidate)) {
474 Option::qmake_abslocation = candidate;
479 if(!Option::qmake_abslocation.isNull())
480 Option::qmake_abslocation = QDir::cleanPath(Option::qmake_abslocation);
482 Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
485 const QByteArray envflags = qgetenv("QMAKEFLAGS");
486 if (!envflags.isNull()) {
487 int env_argc = 0, env_size = 0, currlen=0;
488 char quote = 0, **env_argv = NULL;
489 for (int i = 0; i < envflags.size(); ++i) {
490 if (!quote && (envflags.at(i) == '\'' || envflags.at(i) == '"')) {
491 quote = envflags.at(i);
492 } else if (envflags.at(i) == quote) {
494 } else if (!quote && envflags.at(i) == ' ') {
495 if (currlen && env_argv && env_argv[env_argc]) {
496 env_argv[env_argc][currlen] = '\0';
501 if(!env_argv || env_argc > env_size) {
502 env_argv = (char **)realloc(env_argv, sizeof(char *)*(env_size+=10));
503 for(int i2 = env_argc; i2 < env_size; i2++)
506 if(!env_argv[env_argc]) {
508 env_argv[env_argc] = (char*)malloc(255);
511 env_argv[env_argc][currlen++] = envflags.at(i);
515 if(env_argv[env_argc]) {
516 env_argv[env_argc][currlen] = '\0';
520 parseCommandLine(env_argc, env_argv);
521 for(int i2 = 0; i2 < env_size; i2++) {
529 int ret = parseCommandLine(argc, argv, 1);
530 if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
531 if ((ret & Option::QMAKE_CMDLINE_SHOW_USAGE) != 0)
534 //return ret == QMAKE_CMDLINE_SHOW_USAGE ? usage(argv[0]) : false;
538 //last chance for defaults
539 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
540 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
541 if(Option::mkfile::qmakespec.isNull() || Option::mkfile::qmakespec.isEmpty())
542 Option::mkfile::qmakespec = QString::fromLocal8Bit(qgetenv("QMAKESPEC").constData());
544 //try REALLY hard to do it for them, lazy..
545 if(Option::mkfile::project_files.isEmpty()) {
546 QString proj = detectProjectFile(qmake_getpwd());
548 Option::mkfile::project_files.append(proj);
549 #ifndef QT_BUILD_QMAKE_LIBRARY
550 if(Option::mkfile::project_files.isEmpty()) {
552 return Option::QMAKE_CMDLINE_ERROR;
556 } else if (Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
557 #if defined(Q_OS_MAC)
558 Option::host_mode = Option::HOST_MACX_MODE;
559 Option::target_mode = Option::TARG_MACX_MODE;
560 #elif defined(Q_OS_UNIX)
561 Option::host_mode = Option::HOST_UNIX_MODE;
562 Option::target_mode = Option::TARG_UNIX_MODE;
564 Option::host_mode = Option::HOST_WIN_MODE;
565 Option::target_mode = Option::TARG_WIN_MODE;
569 //defaults for globals
570 if (Option::host_mode != Option::HOST_UNKNOWN_MODE)
572 return QMAKE_CMDLINE_SUCCESS;
575 void Option::applyHostMode()
577 if (Option::host_mode == Option::HOST_WIN_MODE) {
578 Option::dir_sep = "\\";
579 Option::obj_ext = ".obj";
581 Option::dir_sep = "/";
582 Option::obj_ext = ".o";
586 QStringList Option::mkspecPaths()
589 const QString concat = QLatin1String("/mkspecs");
591 QByteArray qmakepath = qgetenv("QMAKEPATH");
592 if (!qmakepath.isEmpty()) {
593 const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
594 for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
595 ret << ((*it) + concat);
597 if (!Option::mkfile::project_build_root.isEmpty())
598 ret << Option::mkfile::project_build_root + concat;
599 if (!Option::mkfile::project_root.isEmpty())
600 ret << Option::mkfile::project_root + concat;
601 ret << QLibraryInfo::location(QLibraryInfo::HostDataPath) + concat;
602 ret.removeDuplicates();
606 bool Option::resolveSpec(QString *spec)
608 QString qmakespec = fixEnvVariables(*spec);
609 if (qmakespec.isEmpty())
610 qmakespec = "default";
611 if (QDir::isRelativePath(qmakespec)) {
612 QStringList mkspec_roots = mkspecPaths();
613 debug_msg(2, "Looking for mkspec %s in (%s)", qmakespec.toLatin1().constData(),
614 mkspec_roots.join("::").toLatin1().constData());
615 for (QStringList::ConstIterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) {
616 QString mkspec = (*it) + QLatin1Char('/') + qmakespec;
617 if (QFile::exists(mkspec)) {
622 fprintf(stderr, "Could not find mkspecs for your QMAKESPEC(%s) after trying:\n\t%s\n",
623 qmakespec.toLatin1().constData(), mkspec_roots.join("\n\t").toLatin1().constData());
629 bool Option::prepareProject(const QString &pfile)
631 mkfile::project_build_root.clear();
632 if (mkfile::do_cache) {
633 if (mkfile::cachefile.isEmpty()) { //find it as it has not been specified
634 QDir dir(output_dir);
635 while (!dir.exists(QLatin1String(".qmake.cache")))
636 if (dir.isRoot() || !dir.cdUp())
638 mkfile::cachefile = dir.filePath(QLatin1String(".qmake.cache"));
639 mkfile::project_build_root = dir.path();
641 QFileInfo fi(mkfile::cachefile);
642 mkfile::cachefile = QDir::cleanPath(fi.absoluteFilePath());
643 mkfile::project_build_root = QDir::cleanPath(fi.absolutePath());
646 if (mkfile::qmakespec.isEmpty()) {
648 if (!cproj.read(mkfile::cachefile, QMakeProject::ReadProFile))
650 mkfile::qmakespec = cproj.first(QLatin1String("QMAKESPEC"));
655 QString srcpath = (pfile != "-")
656 ? QDir::cleanPath(QFileInfo(pfile).absolutePath()) : qmake_getpwd();
657 if (srcpath != output_dir || mkfile::project_build_root.isEmpty()) {
658 QDir srcdir(srcpath);
659 QDir dstdir(output_dir);
661 if (!mkfile::project_build_root.isEmpty()) {
662 // If we already know the build root, just match up the source root with it.
663 if (dstdir.path() == mkfile::project_build_root) {
664 mkfile::project_root = srcdir.path();
668 // Look for mkspecs/ in source and build. First to win determines the root.
669 if (dstdir.exists("mkspecs") || srcdir.exists("mkspecs")) {
670 mkfile::project_build_root = dstdir.path();
671 mkfile::project_root = srcdir.path();
672 if (mkfile::project_root == mkfile::project_build_root)
673 mkfile::project_root.clear();
677 } while (!srcdir.isRoot() && srcdir.cdUp() && !dstdir.isRoot() && dstdir.cdUp());
679 mkfile::project_root.clear();
682 if (!resolveSpec(&Option::mkfile::qmakespec))
688 bool Option::postProcessProject(QMakeProject *project)
690 Option::cpp_ext = project->variables()["QMAKE_EXT_CPP"];
691 if(cpp_ext.isEmpty())
692 cpp_ext << ".cpp"; //something must be there
693 Option::h_ext = project->variables()["QMAKE_EXT_H"];
696 Option::c_ext = project->variables()["QMAKE_EXT_C"];
698 c_ext << ".c"; //something must be there
700 if(!project->isEmpty("QMAKE_EXT_RES"))
701 Option::res_ext = project->first("QMAKE_EXT_RES");
702 if(!project->isEmpty("QMAKE_EXT_PKGCONFIG"))
703 Option::pkgcfg_ext = project->first("QMAKE_EXT_PKGCONFIG");
704 if(!project->isEmpty("QMAKE_EXT_LIBTOOL"))
705 Option::libtool_ext = project->first("QMAKE_EXT_LIBTOOL");
706 if(!project->isEmpty("QMAKE_EXT_PRL"))
707 Option::prl_ext = project->first("QMAKE_EXT_PRL");
708 if(!project->isEmpty("QMAKE_EXT_PRF"))
709 Option::prf_ext = project->first("QMAKE_EXT_PRF");
710 if(!project->isEmpty("QMAKE_EXT_JS"))
711 Option::prf_ext = project->first("QMAKE_EXT_JS");
712 if(!project->isEmpty("QMAKE_EXT_UI"))
713 Option::ui_ext = project->first("QMAKE_EXT_UI");
714 if(!project->isEmpty("QMAKE_EXT_CPP_MOC"))
715 Option::cpp_moc_ext = project->first("QMAKE_EXT_CPP_MOC");
716 if(!project->isEmpty("QMAKE_EXT_H_MOC"))
717 Option::h_moc_ext = project->first("QMAKE_EXT_H_MOC");
718 if(!project->isEmpty("QMAKE_EXT_LEX"))
719 Option::lex_ext = project->first("QMAKE_EXT_LEX");
720 if(!project->isEmpty("QMAKE_EXT_YACC"))
721 Option::yacc_ext = project->first("QMAKE_EXT_YACC");
722 if(!project->isEmpty("QMAKE_EXT_OBJ"))
723 Option::obj_ext = project->first("QMAKE_EXT_OBJ");
724 if(!project->isEmpty("QMAKE_H_MOD_MOC"))
725 Option::h_moc_mod = project->first("QMAKE_H_MOD_MOC");
726 if(!project->isEmpty("QMAKE_CPP_MOD_MOC"))
727 Option::cpp_moc_mod = project->first("QMAKE_CPP_MOD_MOC");
728 if(!project->isEmpty("QMAKE_MOD_LEX"))
729 Option::lex_mod = project->first("QMAKE_MOD_LEX");
730 if(!project->isEmpty("QMAKE_MOD_YACC"))
731 Option::yacc_mod = project->first("QMAKE_MOD_YACC");
732 if(!project->isEmpty("QMAKE_DIR_SEP"))
733 Option::dir_sep = project->first("QMAKE_DIR_SEP");
734 if(!project->isEmpty("QMAKE_DIRLIST_SEP"))
735 Option::dirlist_sep = project->first("QMAKE_DIRLIST_SEP");
736 if(!project->isEmpty("QMAKE_MOD_SYSTEM_ENV"))
737 Option::sysenv_mod = project->first("QMAKE_MOD_SYSTEM_ENV");
742 Option::fixString(QString string, uchar flags)
744 //const QString orig_string = string;
745 static QHash<FixStringCacheKey, QString> *cache = 0;
747 cache = new QHash<FixStringCacheKey, QString>;
748 qmakeAddCacheClear(qmakeDeleteCacheClear<QHash<FixStringCacheKey, QString> >, (void**)&cache);
750 FixStringCacheKey cacheKey(string, flags);
752 QHash<FixStringCacheKey, QString>::const_iterator it = cache->constFind(cacheKey);
754 if (it != cache->constEnd()) {
755 //qDebug() << "Fix (cached) " << orig_string << "->" << it.value();
759 //fix the environment variables
760 if(flags & Option::FixEnvVars) {
762 static QRegExp reg_var("\\$\\(.*\\)");
763 reg_var.setMinimal(true);
764 while((rep = reg_var.indexIn(string)) != -1)
765 string.replace(rep, reg_var.matchedLength(),
766 QString::fromLocal8Bit(qgetenv(string.mid(rep + 2, reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
769 //canonicalize it (and treat as a path)
770 if(flags & Option::FixPathCanonicalize) {
772 string = QFileInfo(string).canonicalFilePath();
774 string = QDir::cleanPath(string);
777 if(string.length() > 2 && string[0].isLetter() && string[1] == QLatin1Char(':'))
778 string[0] = string[0].toLower();
780 bool localSep = (flags & Option::FixPathToLocalSeparators) != 0;
781 bool targetSep = (flags & Option::FixPathToTargetSeparators) != 0;
782 bool normalSep = (flags & Option::FixPathToNormalSeparators) != 0;
784 // either none or only one active flag
785 Q_ASSERT(localSep + targetSep + normalSep <= 1);
787 if (flags & Option::FixPathToNormalSeparators) {
788 string = string.replace('\\', '/');
789 } else if (flags & Option::FixPathToLocalSeparators) {
790 #if defined(Q_OS_WIN32)
791 string = string.replace('/', '\\');
793 string = string.replace('\\', '/');
795 } else if(flags & Option::FixPathToTargetSeparators) {
796 string = string.replace('/', Option::dir_sep).replace('\\', Option::dir_sep);
799 if ((string.startsWith("\"") && string.endsWith("\"")) ||
800 (string.startsWith("\'") && string.endsWith("\'")))
801 string = string.mid(1, string.length()-2);
804 //qDebug() << "Fix" << orig_string << "->" << string;
805 cache->insert(cacheKey, string);
809 const char *qmake_version()
811 static char *ret = NULL;
814 ret = (char *)malloc(15);
815 qmakeAddCacheClear(qmakeFreeCacheClear, (void**)&ret);
816 #if defined(_MSC_VER) && _MSC_VER >= 1400
817 sprintf_s(ret, 15, "%d.%02d%c", QMAKE_VERSION_MAJOR, QMAKE_VERSION_MINOR, 'a' + QMAKE_VERSION_PATCH);
819 sprintf(ret, "%d.%02d%c", QMAKE_VERSION_MAJOR, QMAKE_VERSION_MINOR, 'a' + QMAKE_VERSION_PATCH);
824 void debug_msg_internal(int level, const char *fmt, ...)
826 if(Option::debug_level < level)
828 fprintf(stderr, "DEBUG %d: ", level);
832 vfprintf(stderr, fmt, ap);
835 fprintf(stderr, "\n");
838 void warn_msg(QMakeWarn type, const char *fmt, ...)
840 if(!(Option::warn_level & type))
842 fprintf(stderr, "WARNING: ");
846 vfprintf(stderr, fmt, ap);
849 fprintf(stderr, "\n");
852 class QMakeCacheClearItem {
854 qmakeCacheClearFunc func;
857 QMakeCacheClearItem(qmakeCacheClearFunc f, void **d) : func(f), data(d) { }
858 ~QMakeCacheClearItem() {
863 static QList<QMakeCacheClearItem*> cache_items;
868 qDeleteAll(cache_items);
873 qmakeAddCacheClear(qmakeCacheClearFunc func, void **data)
875 cache_items.append(new QMakeCacheClearItem(func, data));
878 QString qmake_libraryInfoFile()
880 if(!Option::qmake_abslocation.isEmpty())
881 return QDir(QFileInfo(Option::qmake_abslocation).absolutePath()).filePath("qt.conf");