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 ****************************************************************************/
45 #include "cachekeys.h"
46 #include "generators/metamakefile.h"
48 #include <qdatetime.h>
50 #include <qfileinfo.h>
53 #include <qtextstream.h>
62 #include <sys/utsname.h>
63 #elif defined(Q_OS_WIN32)
70 #define QT_POPEN _popen
71 #define QT_PCLOSE _pclose
73 #define QT_POPEN popen
74 #define QT_PCLOSE pclose
80 enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST,
81 E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
82 E_FIND, E_SYSTEM, E_UNIQUE, E_QUOTE, E_ESCAPE_EXPAND,
83 E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE,
84 E_SIZE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS };
85 QHash<QString, ExpandFunc> qmake_expandFunctions()
87 static QHash<QString, ExpandFunc> *qmake_expand_functions = 0;
88 if(!qmake_expand_functions) {
89 qmake_expand_functions = new QHash<QString, ExpandFunc>;
90 qmakeAddCacheClear(qmakeDeleteCacheClear<QHash<QString, ExpandFunc> >, (void**)&qmake_expand_functions);
91 qmake_expand_functions->insert("member", E_MEMBER);
92 qmake_expand_functions->insert("first", E_FIRST);
93 qmake_expand_functions->insert("last", E_LAST);
94 qmake_expand_functions->insert("cat", E_CAT);
95 qmake_expand_functions->insert("fromfile", E_FROMFILE);
96 qmake_expand_functions->insert("eval", E_EVAL);
97 qmake_expand_functions->insert("list", E_LIST);
98 qmake_expand_functions->insert("sprintf", E_SPRINTF);
99 qmake_expand_functions->insert("join", E_JOIN);
100 qmake_expand_functions->insert("split", E_SPLIT);
101 qmake_expand_functions->insert("basename", E_BASENAME);
102 qmake_expand_functions->insert("dirname", E_DIRNAME);
103 qmake_expand_functions->insert("section", E_SECTION);
104 qmake_expand_functions->insert("find", E_FIND);
105 qmake_expand_functions->insert("system", E_SYSTEM);
106 qmake_expand_functions->insert("unique", E_UNIQUE);
107 qmake_expand_functions->insert("quote", E_QUOTE);
108 qmake_expand_functions->insert("escape_expand", E_ESCAPE_EXPAND);
109 qmake_expand_functions->insert("upper", E_UPPER);
110 qmake_expand_functions->insert("lower", E_LOWER);
111 qmake_expand_functions->insert("re_escape", E_RE_ESCAPE);
112 qmake_expand_functions->insert("files", E_FILES);
113 qmake_expand_functions->insert("prompt", E_PROMPT);
114 qmake_expand_functions->insert("replace", E_REPLACE);
115 qmake_expand_functions->insert("size", E_SIZE);
116 qmake_expand_functions->insert("sort_depends", E_SORT_DEPENDS);
117 qmake_expand_functions->insert("resolve_depends", E_RESOLVE_DEPENDS);
119 return *qmake_expand_functions;
122 enum TestFunc { T_REQUIRES=1, T_GREATERTHAN, T_LESSTHAN, T_EQUALS,
123 T_EXISTS, T_EXPORT, T_CLEAR, T_UNSET, T_EVAL, T_CONFIG, T_SYSTEM,
124 T_RETURN, T_BREAK, T_NEXT, T_DEFINED, T_CONTAINS, T_INFILE,
125 T_COUNT, T_ISEMPTY, T_INCLUDE, T_LOAD,
126 T_DEBUG, T_ERROR, T_MESSAGE, T_WARNING, T_LOG,
127 T_IF, T_OPTION, T_CACHE, T_MKPATH, T_WRITE_FILE, T_TOUCH };
128 QHash<QString, TestFunc> qmake_testFunctions()
130 static QHash<QString, TestFunc> *qmake_test_functions = 0;
131 if(!qmake_test_functions) {
132 qmake_test_functions = new QHash<QString, TestFunc>;
133 qmake_test_functions->insert("requires", T_REQUIRES);
134 qmake_test_functions->insert("greaterThan", T_GREATERTHAN);
135 qmake_test_functions->insert("lessThan", T_LESSTHAN);
136 qmake_test_functions->insert("equals", T_EQUALS);
137 qmake_test_functions->insert("isEqual", T_EQUALS);
138 qmake_test_functions->insert("exists", T_EXISTS);
139 qmake_test_functions->insert("export", T_EXPORT);
140 qmake_test_functions->insert("clear", T_CLEAR);
141 qmake_test_functions->insert("unset", T_UNSET);
142 qmake_test_functions->insert("eval", T_EVAL);
143 qmake_test_functions->insert("CONFIG", T_CONFIG);
144 qmake_test_functions->insert("if", T_IF);
145 qmake_test_functions->insert("isActiveConfig", T_CONFIG);
146 qmake_test_functions->insert("system", T_SYSTEM);
147 qmake_test_functions->insert("return", T_RETURN);
148 qmake_test_functions->insert("break", T_BREAK);
149 qmake_test_functions->insert("next", T_NEXT);
150 qmake_test_functions->insert("defined", T_DEFINED);
151 qmake_test_functions->insert("contains", T_CONTAINS);
152 qmake_test_functions->insert("infile", T_INFILE);
153 qmake_test_functions->insert("count", T_COUNT);
154 qmake_test_functions->insert("isEmpty", T_ISEMPTY);
155 qmake_test_functions->insert("include", T_INCLUDE);
156 qmake_test_functions->insert("load", T_LOAD);
157 qmake_test_functions->insert("debug", T_DEBUG);
158 qmake_test_functions->insert("error", T_ERROR);
159 qmake_test_functions->insert("message", T_MESSAGE);
160 qmake_test_functions->insert("warning", T_WARNING);
161 qmake_test_functions->insert("log", T_LOG);
162 qmake_test_functions->insert("option", T_OPTION);
163 qmake_test_functions->insert("cache", T_CACHE);
164 qmake_test_functions->insert("mkpath", T_MKPATH);
165 qmake_test_functions->insert("write_file", T_WRITE_FILE);
166 qmake_test_functions->insert("touch", T_TOUCH);
168 return *qmake_test_functions;
177 static QString project_root;
178 static QString project_build_root;
180 static QStringList *all_feature_roots[2] = { 0, 0 };
183 invalidateFeatureRoots()
185 for (int i = 0; i < 2; i++)
186 if (all_feature_roots[i])
187 all_feature_roots[i]->clear();
190 static QString remove_quotes(const QString &arg)
192 const ushort SINGLEQUOTE = '\'';
193 const ushort DOUBLEQUOTE = '"';
195 const QChar *arg_data = arg.data();
196 const ushort first = arg_data->unicode();
197 const int arg_len = arg.length();
198 if(first == SINGLEQUOTE || first == DOUBLEQUOTE) {
199 const ushort last = (arg_data+arg_len-1)->unicode();
201 return arg.mid(1, arg_len-2);
206 static QString varMap(const QString &x)
209 if(ret == "INTERFACES")
211 else if(ret == "QMAKE_POST_BUILD")
212 ret = "QMAKE_POST_LINK";
213 else if(ret == "TARGETDEPS")
214 ret = "POST_TARGETDEPS";
215 else if(ret == "LIBPATH")
216 ret = "QMAKE_LIBDIR";
217 else if(ret == "QMAKE_EXT_MOC")
218 ret = "QMAKE_EXT_CPP_MOC";
219 else if(ret == "QMAKE_MOD_MOC")
220 ret = "QMAKE_H_MOD_MOC";
221 else if(ret == "QMAKE_LFLAGS_SHAPP")
222 ret = "QMAKE_LFLAGS_APP";
223 else if(ret == "PRECOMPH")
224 ret = "PRECOMPILED_HEADER";
225 else if(ret == "PRECOMPCPP")
226 ret = "PRECOMPILED_SOURCE";
227 else if(ret == "INCPATH")
229 else if(ret == "QMAKE_EXTRA_WIN_COMPILERS" || ret == "QMAKE_EXTRA_UNIX_COMPILERS")
230 ret = "QMAKE_EXTRA_COMPILERS";
231 else if(ret == "QMAKE_EXTRA_WIN_TARGETS" || ret == "QMAKE_EXTRA_UNIX_TARGETS")
232 ret = "QMAKE_EXTRA_TARGETS";
233 else if(ret == "QMAKE_EXTRA_UNIX_INCLUDES")
234 ret = "QMAKE_EXTRA_INCLUDES";
235 else if(ret == "QMAKE_EXTRA_UNIX_VARIABLES")
236 ret = "QMAKE_EXTRA_VARIABLES";
237 else if(ret == "QMAKE_RPATH")
238 ret = "QMAKE_LFLAGS_RPATH";
239 else if(ret == "QMAKE_FRAMEWORKDIR")
240 ret = "QMAKE_FRAMEWORKPATH";
241 else if(ret == "QMAKE_FRAMEWORKDIR_FLAGS")
242 ret = "QMAKE_FRAMEWORKPATH_FLAGS";
245 warn_msg(WarnDeprecated, "%s:%d: Variable %s is deprecated; use %s instead.",
246 parser.file.toLatin1().constData(), parser.line_no,
247 x.toLatin1().constData(), ret.toLatin1().constData());
251 static QStringList split_arg_list(const QString ¶ms)
256 const ushort LPAREN = '(';
257 const ushort RPAREN = ')';
258 const ushort SINGLEQUOTE = '\'';
259 const ushort DOUBLEQUOTE = '"';
260 const ushort BACKSLASH = '\\';
261 const ushort COMMA = ',';
262 const ushort SPACE = ' ';
263 //const ushort TAB = '\t';
265 const QChar *params_data = params.data();
266 const int params_len = params.length();
267 for(int last = 0; ;) {
268 while(last < params_len && (params_data[last].unicode() == SPACE
269 /*|| params_data[last].unicode() == TAB*/))
271 for(int x = last, parens = 0; ; x++) {
272 if(x == params_len) {
273 while(x > last && params_data[x-1].unicode() == SPACE)
275 args << params.mid(last, x - last);
276 // Could do a check for unmatched parens here, but split_value_list()
277 // is called on all our output, so mistakes will be caught anyway.
280 ushort unicode = params_data[x].unicode();
281 if(x != (int)params_len-1 && unicode == BACKSLASH &&
282 (params_data[x+1].unicode() == SINGLEQUOTE || params_data[x+1].unicode() == DOUBLEQUOTE)) {
283 x++; //get that 'escape'
284 } else if(quote && unicode == quote) {
286 } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
288 } else if(unicode == RPAREN) {
290 } else if(unicode == LPAREN) {
293 if(!parens && !quote && unicode == COMMA) {
296 while(x > prev && params_data[x-1].unicode() == SPACE)
298 args << params.mid(prev, x - prev);
305 static QStringList split_value_list(const QString &vals)
312 const ushort LPAREN = '(';
313 const ushort RPAREN = ')';
314 const ushort SINGLEQUOTE = '\'';
315 const ushort DOUBLEQUOTE = '"';
316 const ushort BACKSLASH = '\\';
319 const QChar *vals_data = vals.data();
320 const int vals_len = vals.length();
321 for(int x = 0; x < vals_len; x++) {
322 unicode = vals_data[x].unicode();
323 if(x != (int)vals_len-1 && unicode == BACKSLASH &&
324 (vals_data[x+1].unicode() == SINGLEQUOTE || vals_data[x+1].unicode() == DOUBLEQUOTE)) {
325 build += vals_data[x++]; //get that 'escape'
326 } else if(quote && unicode == quote) {
328 } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
330 } else if(unicode == RPAREN) {
332 } else if(unicode == LPAREN) {
336 if(!parens && !quote && (vals_data[x] == Option::field_sep)) {
340 build += vals_data[x];
346 warn_msg(WarnDeprecated, "%s:%d: Unmatched parentheses are deprecated.",
347 parser.file.toLatin1().constData(), parser.line_no);
348 // Could do a check for unmatched quotes here, but doVariableReplaceExpand()
349 // is called on all our output, so mistakes will be caught anyway.
353 //just a parsable entity
356 ParsableBlock() : ref_cnt(1) { }
357 virtual ~ParsableBlock() { }
362 Parse(const QString &t) : text(t){ pi = parser; }
364 QList<Parse> parselist;
366 inline int ref() { return ++ref_cnt; }
367 inline int deref() { return --ref_cnt; }
371 virtual bool continueBlock() = 0;
372 bool eval(QMakeProject *p, QHash<QString, QStringList> &place);
375 bool ParsableBlock::eval(QMakeProject *p, QHash<QString, QStringList> &place)
378 parser_info pi = parser;
379 const int block_count = p->scope_blocks.count();
383 for(int i = 0; i < parselist.count(); i++) {
384 parser = parselist.at(i).pi;
385 if(!(ret = p->parse(parselist.at(i).text, place)) || !continueBlock())
391 while(p->scope_blocks.count() > block_count)
392 p->scope_blocks.pop();
397 struct FunctionBlock : public ParsableBlock
399 FunctionBlock() : calling_place(0), scope_level(1), cause_return(false) { }
401 QHash<QString, QStringList> vars;
402 QHash<QString, QStringList> *calling_place;
403 QStringList return_value;
407 bool exec(const QList<QStringList> &args,
408 QMakeProject *p, QHash<QString, QStringList> &place, QStringList &functionReturn);
409 virtual bool continueBlock() { return !cause_return; }
412 bool FunctionBlock::exec(const QList<QStringList> &args,
413 QMakeProject *proj, QHash<QString, QStringList> &place,
414 QStringList &functionReturn)
418 calling_place = &place;
420 calling_place = &proj->variables();
422 return_value.clear();
423 cause_return = false;
427 vars = proj->variables(); // should be place so that local variables can be inherited
431 vars["ARGS"].clear();
432 for(int i = 0; i < args.count(); i++) {
433 vars["ARGS"] += args[i];
434 vars[QString::number(i+1)] = args[i];
436 bool ret = ParsableBlock::eval(proj, vars);
437 functionReturn = return_value;
441 return_value.clear();
447 struct IteratorBlock : public ParsableBlock
449 IteratorBlock() : scope_level(1), loop_forever(false), cause_break(false), cause_next(false) { }
458 Test(const QString &f, QStringList &a, bool i) : func(f), args(a), invert(i) { pi = parser; }
464 bool loop_forever, cause_break, cause_next;
467 bool exec(QMakeProject *p, QHash<QString, QStringList> &place);
468 virtual bool continueBlock() { return !cause_next && !cause_break; }
470 bool IteratorBlock::exec(QMakeProject *p, QHash<QString, QStringList> &place)
473 QStringList::Iterator it;
476 int iterate_count = 0;
478 IteratorBlock *saved_iterator = p->iterator;
482 while(loop_forever || it != list.end()) {
483 cause_next = cause_break = false;
484 if(!loop_forever && (*it).isEmpty()) { //ignore empty items
489 //set up the loop variable
491 if(!variable.isEmpty()) {
492 va = place[variable];
494 place[variable] = QStringList(QString::number(iterate_count));
496 place[variable] = QStringList(*it);
500 for(QList<Test>::Iterator test_it = test.begin(); test_it != test.end(); ++test_it) {
501 parser = (*test_it).pi;
502 succeed = p->doProjectTest((*test_it).func, (*test_it).args, place);
503 if((*test_it).invert)
509 ret = ParsableBlock::eval(p, place);
510 //restore the variable in the map
511 if(!variable.isEmpty())
512 place[variable] = va;
517 if(!ret || cause_break)
522 p->iterator = saved_iterator;
526 QMakeProject::ScopeBlock::~ScopeBlock()
534 static void qmake_error_msg(const QString &msg)
536 fprintf(stderr, "%s:%d: %s\n", parser.file.toLatin1().constData(), parser.line_no,
537 msg.toLatin1().constData());
541 1) environment variable QMAKEFEATURES (as separated by colons)
542 2) property variable QMAKEFEATURES (as separated by colons)
543 3) <project_root> (where .qmake.cache lives) + FEATURES_DIR
544 4) environment variable QMAKEPATH (as separated by colons) + /mkspecs/FEATURES_DIR
545 5) your QMAKESPEC/features dir
546 6) your data_install/mkspecs/FEATURES_DIR
547 7) your QMAKESPEC/../FEATURES_DIR dir
549 FEATURES_DIR is defined as:
551 1) features/(unix|win32|macx)/
554 QStringList qmake_feature_paths(QMakeProperty *prop, bool host_build)
556 const QString mkspecs_concat = QLatin1String("/mkspecs");
557 const QString base_concat = QLatin1String("/features");
560 switch(Option::target_mode) {
561 case Option::TARG_MACX_MODE: //also a unix
562 concat << base_concat + QLatin1String("/mac");
563 concat << base_concat + QLatin1String("/macx");
564 concat << base_concat + QLatin1String("/unix");
566 default: // Can't happen, just make the compiler shut up
567 case Option::TARG_UNIX_MODE:
568 concat << base_concat + QLatin1String("/unix");
570 case Option::TARG_WIN_MODE:
571 concat << base_concat + QLatin1String("/win32");
574 concat << base_concat;
577 QStringList feature_roots;
578 QByteArray mkspec_path = qgetenv("QMAKEFEATURES");
579 if(!mkspec_path.isNull())
580 feature_roots += splitPathList(QString::fromLocal8Bit(mkspec_path));
582 feature_roots += splitPathList(prop->value("QMAKEFEATURES"));
583 if(!Option::mkfile::cachefile.isEmpty()) {
585 int last_slash = Option::mkfile::cachefile.lastIndexOf(QLatin1Char('/'));
587 path = Option::normalizePath(Option::mkfile::cachefile.left(last_slash), false);
588 for(QStringList::Iterator concat_it = concat.begin();
589 concat_it != concat.end(); ++concat_it)
590 feature_roots << (path + (*concat_it));
592 QByteArray qmakepath = qgetenv("QMAKEPATH");
593 if (!qmakepath.isNull()) {
594 const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
595 for(QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) {
596 for(QStringList::Iterator concat_it = concat.begin();
597 concat_it != concat.end(); ++concat_it)
598 feature_roots << ((*it) + mkspecs_concat + (*concat_it));
601 QString *specp = host_build ? &Option::mkfile::qmakespec : &Option::mkfile::xqmakespec;
602 if (!specp->isEmpty()) {
603 // The spec is already platform-dependent, so no subdirs here.
604 feature_roots << *specp + base_concat;
606 // Also check directly under the root directory of the mkspecs collection
607 QFileInfo specfi(*specp);
608 QDir specrootdir(specfi.absolutePath());
609 while (!specrootdir.isRoot()) {
610 const QString specrootpath = specrootdir.path();
611 if (specrootpath.endsWith(mkspecs_concat)) {
612 if (QFile::exists(specrootpath + base_concat))
613 for (QStringList::Iterator concat_it = concat.begin();
614 concat_it != concat.end(); ++concat_it)
615 feature_roots << (specrootpath + (*concat_it));
621 for(QStringList::Iterator concat_it = concat.begin();
622 concat_it != concat.end(); ++concat_it)
623 feature_roots << (QLibraryInfo::location(QLibraryInfo::HostDataPath) +
624 mkspecs_concat + (*concat_it));
625 feature_roots.removeDuplicates();
626 return feature_roots;
629 QStringList qmake_mkspec_paths()
632 const QString concat = QLatin1String("/mkspecs");
633 QByteArray qmakepath = qgetenv("QMAKEPATH");
634 if (!qmakepath.isEmpty()) {
635 const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
636 for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
637 ret << ((*it) + concat);
639 if (!project_build_root.isEmpty())
640 ret << project_build_root + concat;
641 if (!project_root.isEmpty())
642 ret << project_root + concat;
643 ret << QLibraryInfo::location(QLibraryInfo::DataPath) + concat;
644 ret.removeDuplicates();
649 QMakeProject::~QMakeProject()
658 QMakeProject::init(QMakeProperty *p)
661 prop = new QMakeProperty;
673 QMakeProject::cleanup()
675 for (QHash<QString, FunctionBlock*>::iterator it = replaceFunctions.begin(); it != replaceFunctions.end(); ++it)
676 if (!it.value()->deref())
678 replaceFunctions.clear();
679 for (QHash<QString, FunctionBlock*>::iterator it = testFunctions.begin(); it != testFunctions.end(); ++it)
680 if (!it.value()->deref())
682 testFunctions.clear();
685 // Duplicate project. It is *not* allowed to call the complex read() functions on the copy.
686 QMakeProject::QMakeProject(QMakeProject *p, const QHash<QString, QStringList> *_vars)
688 init(p->properties());
689 vars = _vars ? *_vars : p->variables();
690 host_build = p->host_build;
691 for(QHash<QString, FunctionBlock*>::iterator it = p->replaceFunctions.begin(); it != p->replaceFunctions.end(); ++it) {
693 replaceFunctions.insert(it.key(), it.value());
695 for(QHash<QString, FunctionBlock*>::iterator it = p->testFunctions.begin(); it != p->testFunctions.end(); ++it) {
697 testFunctions.insert(it.key(), it.value());
702 QMakeProject::reset()
704 // scope_blocks starts with one non-ignoring entity
705 scope_blocks.clear();
706 scope_blocks.push(ScopeBlock());
709 backslashWarned = false;
710 need_restart = false;
714 QMakeProject::parse(const QString &t, QHash<QString, QStringList> &place, int numLines)
716 // To preserve the integrity of any UTF-8 characters in .pro file, temporarily replace the
717 // non-breaking space (0xA0) characters with another non-space character, so that
718 // QString::simplified() call will not replace it with space.
719 // Note: There won't be any two byte characters in .pro files, so 0x10A0 should be a safe
720 // replacement character.
721 static QChar nbsp(0xA0);
722 static QChar nbspFix(0x01A0);
724 if (t.indexOf(nbsp) != -1) {
726 s.replace(nbsp, nbspFix);
728 s.replace(nbspFix, nbsp);
733 int hash_mark = s.indexOf("#");
734 if(hash_mark != -1) //good bye comments
735 s = s.left(hash_mark);
736 if(s.isEmpty()) // blank_line
739 if(scope_blocks.top().ignore) {
740 bool continue_parsing = false;
741 // adjust scope for each block which appears on a single line
742 for(int i = 0; i < s.length(); i++) {
744 scope_blocks.push(ScopeBlock(true));
745 } else if(s[i] == '}') {
746 if(scope_blocks.count() == 1) {
747 fprintf(stderr, "Braces mismatch %s:%d\n", parser.file.toLatin1().constData(), parser.line_no);
750 ScopeBlock sb = scope_blocks.pop();
752 sb.iterate->exec(this, place);
756 if(!scope_blocks.top().ignore) {
757 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(),
758 parser.line_no, scope_blocks.count()+1);
759 s = s.mid(i+1).trimmed();
760 continue_parsing = !s.isEmpty();
765 if(!continue_parsing) {
766 debug_msg(1, "Project Parser: %s:%d : Ignored due to block being false.",
767 parser.file.toLatin1().constData(), parser.line_no);
775 const QChar *d = s.unicode();
776 bool function_finished = false;
777 while(d_off < s.length()) {
778 if(*(d+d_off) == QLatin1Char('}')) {
779 function->scope_level--;
780 if(!function->scope_level) {
781 function_finished = true;
784 } else if(*(d+d_off) == QLatin1Char('{')) {
785 function->scope_level++;
787 append += *(d+d_off);
790 if(!append.isEmpty())
791 function->parselist.append(IteratorBlock::Parse(append));
792 if(function_finished) {
794 s = QString(d+d_off, s.length()-d_off);
798 } else if(IteratorBlock *it = scope_blocks.top().iterate) {
801 const QChar *d = s.unicode();
802 bool iterate_finished = false;
803 while(d_off < s.length()) {
804 if(*(d+d_off) == QLatin1Char('}')) {
806 if(!it->scope_level) {
807 iterate_finished = true;
810 } else if(*(d+d_off) == QLatin1Char('{')) {
813 append += *(d+d_off);
816 if(!append.isEmpty())
817 scope_blocks.top().iterate->parselist.append(IteratorBlock::Parse(append));
818 if(iterate_finished) {
819 scope_blocks.top().iterate = 0;
820 bool ret = it->exec(this, place);
830 QString scope, var, op;
832 #define SKIP_WS(d, o, l) while(o < l && (*(d+o) == QLatin1Char(' ') || *(d+o) == QLatin1Char('\t'))) ++o
833 const QChar *d = s.unicode();
835 SKIP_WS(d, d_off, s.length());
836 IteratorBlock *iterator = 0;
837 bool scope_failed = false, else_line = false, or_op=false;
839 int parens = 0, scope_count=0, start_block = 0;
840 while(d_off < s.length()) {
842 if(*(d+d_off) == QLatin1Char('='))
844 if(*(d+d_off) == QLatin1Char('+') || *(d+d_off) == QLatin1Char('-') ||
845 *(d+d_off) == QLatin1Char('*') || *(d+d_off) == QLatin1Char('~')) {
846 if(*(d+d_off+1) == QLatin1Char('=')) {
848 } else if(*(d+d_off+1) == QLatin1Char(' ')) {
849 const QChar *k = d+d_off+1;
851 SKIP_WS(k, k_off, s.length()-d_off);
852 if(*(k+k_off) == QLatin1Char('=')) {
854 qmake_error_msg(QString(d+d_off, 1) + "must be followed immediately by =");
861 if(!quote.isNull()) {
862 if(*(d+d_off) == quote)
864 } else if(*(d+d_off) == '(') {
866 } else if(*(d+d_off) == ')') {
868 } else if(*(d+d_off) == '"' /*|| *(d+d_off) == '\''*/) {
872 if(!parens && quote.isNull() &&
873 (*(d+d_off) == QLatin1Char(':') || *(d+d_off) == QLatin1Char('{') ||
874 *(d+d_off) == QLatin1Char(')') || *(d+d_off) == QLatin1Char('|'))) {
876 scope = var.trimmed();
877 if(*(d+d_off) == QLatin1Char(')'))
878 scope += *(d+d_off); // need this
881 bool test = scope_failed;
882 if(scope.isEmpty()) {
884 } else if(scope.toLower() == "else") { //else is a builtin scope here as it modifies state
885 if(scope_count != 1 || scope_blocks.top().else_status == ScopeBlock::TestNone) {
886 qmake_error_msg(("Unexpected " + scope + " ('" + s + "')").toLatin1());
890 test = (scope_blocks.top().else_status == ScopeBlock::TestSeek);
891 debug_msg(1, "Project Parser: %s:%d : Else%s %s.", parser.file.toLatin1().constData(), parser.line_no,
892 scope == "else" ? "" : QString(" (" + scope + ")").toLatin1().constData(),
893 test ? "considered" : "excluded");
895 QString comp_scope = scope;
896 bool invert_test = (comp_scope.at(0) == QLatin1Char('!'));
898 comp_scope = comp_scope.mid(1);
899 int lparen = comp_scope.indexOf('(');
900 if(or_op == scope_failed) {
901 if(lparen != -1) { // if there is an lparen in the scope, it IS a function
902 int rparen = comp_scope.lastIndexOf(')');
904 qmake_error_msg("Function missing right paren: " + comp_scope);
907 QString func = comp_scope.left(lparen);
908 QStringList args = split_arg_list(comp_scope.mid(lparen+1, rparen - lparen - 1));
910 fprintf(stderr, "%s:%d: No tests can come after a function definition!\n",
911 parser.file.toLatin1().constData(), parser.line_no);
913 } else if(func == "for") { //for is a builtin function here, as it modifies state
914 if(args.count() > 2 || args.count() < 1) {
915 fprintf(stderr, "%s:%d: for(iterate, list) requires two arguments.\n",
916 parser.file.toLatin1().constData(), parser.line_no);
918 } else if(iterator) {
919 fprintf(stderr, "%s:%d unexpected nested for()\n",
920 parser.file.toLatin1().constData(), parser.line_no);
924 iterator = new IteratorBlock;
926 if(args.count() == 1) {
927 doVariableReplace(args[0], place);
929 if(args[0] != "ever") {
932 fprintf(stderr, "%s:%d: for(iterate, list) requires two arguments.\n",
933 parser.file.toLatin1().constData(), parser.line_no);
937 } else if(args.count() == 2) {
938 iterator->variable = args[0];
939 doVariableReplace(args[1], place);
942 QStringList list = place[it_list];
944 if(it_list == "forever") {
945 iterator->loop_forever = true;
947 int dotdot = it_list.indexOf("..");
950 int start = it_list.left(dotdot).toInt(&ok);
952 int end = it_list.mid(dotdot+2).toInt(&ok);
955 for(int i = start; i <= end; i++)
956 list << QString::number(i);
958 for(int i = start; i >= end; i--)
959 list << QString::number(i);
966 iterator->list = list;
968 } else if(iterator) {
969 iterator->test.append(IteratorBlock::Test(func, args, invert_test));
971 } else if(func == "defineTest" || func == "defineReplace") {
972 if(!function_blocks.isEmpty()) {
974 "%s:%d: cannot define a function within another definition.\n",
975 parser.file.toLatin1().constData(), parser.line_no);
978 if(args.count() != 1) {
979 fprintf(stderr, "%s:%d: %s(function_name) requires one argument.\n",
980 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
983 QHash<QString, FunctionBlock*> *map = 0;
984 if(func == "defineTest")
985 map = &testFunctions;
987 map = &replaceFunctions;
989 if(!map || map->contains(args[0])) {
990 fprintf(stderr, "%s:%d: Function[%s] multiply defined.\n",
991 parser.file.toLatin1().constData(), parser.line_no, args[0].toLatin1().constData());
995 function = new FunctionBlock;
996 map->insert(args[0], function);
999 test = doProjectTest(func, args, place);
1000 if(*(d+d_off) == QLatin1Char(')') && d_off == s.length()-1) {
1003 scope_blocks.top().else_status =
1004 (test ? ScopeBlock::TestFound : ScopeBlock::TestSeek);
1005 return true; // assume we are done
1009 QString cscope = comp_scope.trimmed();
1010 doVariableReplace(cscope, place);
1011 test = isActiveConfig(cscope.trimmed(), true, &place);
1017 if(!test && !scope_failed)
1018 debug_msg(1, "Project Parser: %s:%d : Test (%s) failed.", parser.file.toLatin1().constData(),
1019 parser.line_no, scope.toLatin1().constData());
1021 scope_failed = !test;
1022 or_op = (*(d+d_off) == QLatin1Char('|'));
1024 if(*(d+d_off) == QLatin1Char('{')) { // scoping block
1027 for(int off = 0, braces = 0; true; ++off) {
1028 if(*(d+d_off+off) == QLatin1Char('{'))
1030 else if(*(d+d_off+off) == QLatin1Char('}') && braces)
1032 if(!braces || d_off+off == s.length()) {
1033 iterator->parselist.append(s.mid(d_off, off-1));
1035 iterator->scope_level += braces-1;
1042 } else if(!parens && *(d+d_off) == QLatin1Char('}')) {
1045 } else if(!scope_blocks.count()) {
1046 warn_msg(WarnParser, "Possible braces mismatch %s:%d", parser.file.toLatin1().constData(), parser.line_no);
1048 if(scope_blocks.count() == 1) {
1049 fprintf(stderr, "Braces mismatch %s:%d\n", parser.file.toLatin1().constData(), parser.line_no);
1052 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(),
1053 parser.line_no, scope_blocks.count());
1054 ScopeBlock sb = scope_blocks.pop();
1056 sb.iterate->exec(this, place);
1063 var = var.trimmed();
1065 if(!else_line || (else_line && !scope_failed))
1066 scope_blocks.top().else_status = (!scope_failed ? ScopeBlock::TestFound : ScopeBlock::TestSeek);
1068 ScopeBlock next_block(scope_failed);
1069 next_block.iterate = iterator;
1071 next_block.else_status = ScopeBlock::TestNone;
1072 else if(scope_failed)
1073 next_block.else_status = ScopeBlock::TestSeek;
1075 next_block.else_status = ScopeBlock::TestFound;
1076 scope_blocks.push(next_block);
1077 debug_msg(1, "Project Parser: %s:%d : Entering block %d (%d). [%s]", parser.file.toLatin1().constData(),
1078 parser.line_no, scope_blocks.count(), scope_failed, s.toLatin1().constData());
1079 } else if(iterator) {
1080 iterator->parselist.append(QString(var+s.mid(d_off)));
1081 bool ret = iterator->exec(this, place);
1086 if((!scope_count && !var.isEmpty()) || (scope_count == 1 && else_line))
1087 scope_blocks.top().else_status = ScopeBlock::TestNone;
1088 if(d_off == s.length()) {
1089 if(!var.trimmed().isEmpty())
1090 qmake_error_msg(("Parse Error ('" + s + "')").toLatin1());
1091 return var.isEmpty(); // allow just a scope
1094 SKIP_WS(d, d_off, s.length());
1095 for(; d_off < s.length() && op.indexOf('=') == -1; op += *(d+(d_off++)))
1097 op.replace(QRegExp("\\s"), "");
1099 SKIP_WS(d, d_off, s.length());
1100 QString vals = s.mid(d_off); // vals now contains the space separated list of values
1101 int rbraces = vals.count('}'), lbraces = vals.count('{');
1102 if(scope_blocks.count() > 1 && rbraces - lbraces == 1 && vals.endsWith('}')) {
1103 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(),
1104 parser.line_no, scope_blocks.count());
1105 ScopeBlock sb = scope_blocks.pop();
1107 sb.iterate->exec(this, place);
1108 vals.truncate(vals.length()-1);
1109 } else if(rbraces != lbraces) {
1110 warn_msg(WarnParser, "Possible braces mismatch {%s} %s:%d",
1111 vals.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no);
1114 return true; // oh well
1117 doVariableReplace(var, place);
1118 var = varMap(var); //backwards compatibility
1119 if(!var.isEmpty() && Option::mkfile::do_preprocess) {
1120 static QString last_file("*none*");
1121 if(parser.file != last_file) {
1122 fprintf(stdout, "#file %s:%d\n", parser.file.toLatin1().constData(), parser.line_no);
1123 last_file = parser.file;
1125 fprintf(stdout, "%s %s %s\n", var.toLatin1().constData(), op.toLatin1().constData(), vals.toLatin1().constData());
1128 if(vals.contains('=') && numLines > 1)
1129 warn_msg(WarnParser, "Possible accidental line continuation: {%s} at %s:%d",
1130 var.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no);
1132 QStringList &varlist = place[var]; // varlist is the list in the symbol table
1134 if(Option::debug_level >= 1) {
1135 QString tmp_vals = vals;
1136 doVariableReplace(tmp_vals, place);
1137 debug_msg(1, "Project Parser: %s:%d :%s: :%s: (%s)", parser.file.toLatin1().constData(), parser.line_no,
1138 var.toLatin1().constData(), op.toLatin1().constData(), tmp_vals.toLatin1().constData());
1141 // now do the operation
1143 doVariableReplace(vals, place);
1144 if(vals.length() < 4 || vals.at(0) != 's') {
1145 qmake_error_msg(("~= operator only can handle s/// function ('" +
1146 s + "')").toLatin1());
1149 QChar sep = vals.at(1);
1150 QStringList func = vals.split(sep);
1151 if(func.count() < 3 || func.count() > 4) {
1152 qmake_error_msg(("~= operator only can handle s/// function ('" +
1153 s + "')").toLatin1());
1156 bool global = false, case_sense = true, quote = false;
1157 if(func.count() == 4) {
1158 global = func[3].indexOf('g') != -1;
1159 case_sense = func[3].indexOf('i') == -1;
1160 quote = func[3].indexOf('q') != -1;
1162 QString from = func[1], to = func[2];
1164 from = QRegExp::escape(from);
1165 QRegExp regexp(from, case_sense ? Qt::CaseSensitive : Qt::CaseInsensitive);
1166 for(QStringList::Iterator varit = varlist.begin(); varit != varlist.end();) {
1167 if((*varit).contains(regexp)) {
1168 (*varit) = (*varit).replace(regexp, to);
1169 if ((*varit).isEmpty())
1170 varit = varlist.erase(varit);
1179 QStringList vallist;
1181 //doVariableReplace(vals, place);
1182 QStringList tmp = split_value_list(vals);
1183 for(int i = 0; i < tmp.size(); ++i)
1184 vallist += doVariableReplaceExpand(tmp[i], place);
1188 if(!varlist.isEmpty()) {
1189 bool send_warning = false;
1190 if(var != "TEMPLATE" && var != "TARGET") {
1191 QSet<QString> incoming_vals = vallist.toSet();
1192 for(int i = 0; i < varlist.size(); ++i) {
1193 const QString var = varlist.at(i).trimmed();
1194 if(!var.isEmpty() && !incoming_vals.contains(var)) {
1195 send_warning = true;
1201 warn_msg(WarnParser, "Operator=(%s) clears variables previously set: %s:%d",
1202 var.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no);
1206 for(QStringList::ConstIterator valit = vallist.begin();
1207 valit != vallist.end(); ++valit) {
1208 if((*valit).isEmpty())
1210 if((op == "*=" && !varlist.contains((*valit))) ||
1211 op == "=" || op == "+=")
1212 varlist.append((*valit));
1214 varlist.removeAll((*valit));
1216 if(var == "REQUIRES") // special case to get communicated to backends!
1217 doProjectCheckReqs(vallist, place);
1223 QMakeProject::read(QTextStream &file, QHash<QString, QStringList> &place)
1228 while(!file.atEnd()) {
1230 QString line = file.readLine().trimmed();
1231 int prelen = line.length();
1233 int hash_mark = line.indexOf("#");
1234 if(hash_mark != -1) //good bye comments
1235 line = line.left(hash_mark).trimmed();
1236 if(!line.isEmpty() && line.right(1) == "\\") {
1237 if(!line.startsWith("#")) {
1238 line.truncate(line.length() - 1);
1239 s += line + Option::field_sep;
1242 } else if(!line.isEmpty() || (line.isEmpty() && !prelen)) {
1243 if(s.isEmpty() && line.isEmpty())
1245 if(!line.isEmpty()) {
1250 if(!(ret = parse(s, place, numLines))) {
1263 ret = parse(s, place, numLines);
1268 QMakeProject::read(const QString &file, QHash<QString, QStringList> &place)
1270 parser_info pi = parser;
1273 const QString oldpwd = qmake_getpwd();
1274 QString filename = Option::normalizePath(file, false);
1275 bool ret = false, using_stdin = false;
1277 if(filename == QLatin1String("-")) {
1278 qfile.setFileName("");
1279 ret = qfile.open(stdin, QIODevice::ReadOnly);
1281 } else if(QFileInfo(file).isDir()) {
1284 qfile.setFileName(filename);
1285 ret = qfile.open(QIODevice::ReadOnly);
1286 qmake_setpwd(QFileInfo(filename).absolutePath());
1289 parser_info pi = parser;
1290 parser.from_file = true;
1291 parser.file = filename;
1293 if (qfile.peek(3) == QByteArray("\xef\xbb\xbf")) {
1294 //UTF-8 BOM will cause subtle errors
1295 qmake_error_msg("Unexpected UTF-8 BOM found");
1298 QTextStream t(&qfile);
1299 ret = read(t, place);
1304 if (!need_restart && scope_blocks.count() != 1) {
1305 qmake_error_msg("Unterminated conditional block at end of file");
1309 qmake_setpwd(oldpwd);
1314 QMakeProject::read(const QString &project, uchar cmd)
1316 pfile = QFileInfo(project).absoluteFilePath();
1321 QMakeProject::read(uchar cmd)
1324 if ((cmd & ReadSetup) && base_vars.isEmpty()) {
1325 // hack to get the Option stuff in there
1326 base_vars["QMAKE_EXT_CPP"] = Option::cpp_ext;
1327 base_vars["QMAKE_EXT_C"] = Option::c_ext;
1328 base_vars["QMAKE_EXT_H"] = Option::h_ext;
1329 base_vars["QMAKE_SH"] = Option::shellPath;
1330 if(!Option::user_template_prefix.isEmpty())
1331 base_vars["TEMPLATE_PREFIX"] = QStringList(Option::user_template_prefix);
1333 project_build_root.clear();
1335 if (Option::mkfile::do_cache) { // parse the cache
1336 if (Option::mkfile::cachefile.isEmpty()) { //find it as it has not been specified
1337 QDir dir(Option::output_dir);
1338 while (!dir.exists(QLatin1String(".qmake.cache")))
1339 if (dir.isRoot() || !dir.cdUp())
1341 Option::mkfile::cachefile = dir.filePath(QLatin1String(".qmake.cache"));
1342 project_build_root = dir.path();
1344 QFileInfo fi(Option::mkfile::cachefile);
1345 Option::mkfile::cachefile = QDir::cleanPath(fi.absoluteFilePath());
1346 project_build_root = QDir::cleanPath(fi.absolutePath());
1349 QHash<QString, QStringList> cache;
1350 if (!read(Option::mkfile::cachefile, cache)) {
1351 Option::mkfile::cachefile.clear();
1354 if (Option::mkfile::xqmakespec.isEmpty() && !cache["XQMAKESPEC"].isEmpty())
1355 Option::mkfile::xqmakespec = cache["XQMAKESPEC"].first();
1356 if (Option::mkfile::qmakespec.isEmpty() && !cache["QMAKESPEC"].isEmpty()) {
1357 Option::mkfile::qmakespec = cache["QMAKESPEC"].first();
1358 if (Option::mkfile::xqmakespec.isEmpty())
1359 Option::mkfile::xqmakespec = Option::mkfile::qmakespec;
1362 if (Option::output_dir.startsWith(project_build_root))
1363 Option::mkfile::cachefile_depth =
1364 Option::output_dir.mid(project_build_root.length()).count('/');
1368 if (qmake_getpwd() != Option::output_dir || project_build_root.isEmpty()) {
1369 QDir srcdir(qmake_getpwd());
1370 QDir dstdir(Option::output_dir);
1372 if (!project_build_root.isEmpty()) {
1373 // If we already know the build root, just match up the source root with it.
1374 if (dstdir.path() == project_build_root) {
1375 project_root = srcdir.path();
1379 // Look for mkspecs/ in source and build. First to win determines the root.
1380 if (dstdir.exists("mkspecs") || srcdir.exists("mkspecs")) {
1381 project_build_root = dstdir.path();
1382 project_root = srcdir.path();
1383 if (project_root == project_build_root)
1384 project_root.clear();
1388 } while (!srcdir.isRoot() && srcdir.cdUp() && !dstdir.isRoot() && dstdir.cdUp());
1390 project_root.clear();
1394 QString *specp = host_build ? &Option::mkfile::qmakespec : &Option::mkfile::xqmakespec;
1395 QString qmakespec = *specp;
1396 if (qmakespec.isEmpty())
1397 qmakespec = host_build ? "default-host" : "default";
1398 if (QDir::isRelativePath(qmakespec)) {
1399 QStringList mkspec_roots = qmake_mkspec_paths();
1400 debug_msg(2, "Looking for mkspec %s in (%s)", qmakespec.toLatin1().constData(),
1401 mkspec_roots.join("::").toLatin1().constData());
1402 bool found_mkspec = false;
1403 for (QStringList::ConstIterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) {
1404 QString mkspec = (*it) + QLatin1Char('/') + qmakespec;
1405 if (QFile::exists(mkspec)) {
1406 found_mkspec = true;
1407 *specp = qmakespec = mkspec;
1411 if (!found_mkspec) {
1412 fprintf(stderr, "Could not find mkspecs for your QMAKESPEC(%s) after trying:\n\t%s\n",
1413 qmakespec.toLatin1().constData(), mkspec_roots.join("\n\t").toLatin1().constData());
1418 // parse qmake configuration
1419 while(qmakespec.endsWith(QLatin1Char('/')))
1420 qmakespec.truncate(qmakespec.length()-1);
1421 QString spec = qmakespec + QLatin1String("/qmake.conf");
1422 debug_msg(1, "QMAKESPEC conf: reading %s", spec.toLatin1().constData());
1423 if(!read(spec, base_vars)) {
1424 fprintf(stderr, "Failure to read QMAKESPEC conf file %s.\n", spec.toLatin1().constData());
1429 if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) {
1430 debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.toLatin1().constData());
1431 read(Option::mkfile::cachefile, base_vars);
1436 vars = base_vars; // start with the base
1438 for (QHash<QString, QStringList>::ConstIterator it = extra_vars.constBegin();
1439 it != extra_vars.constEnd(); ++it)
1440 vars.insert(it.key(), it.value());
1442 if(cmd & ReadFeatures) {
1443 debug_msg(1, "Processing default_pre: %s", vars["CONFIG"].join("::").toLatin1().constData());
1444 doProjectInclude("default_pre", IncludeFlagFeature, vars);
1448 if(pfile != "-" && vars["TARGET"].isEmpty())
1449 vars["TARGET"].append(QFileInfo(pfile).baseName());
1451 //before commandline
1452 if (cmd & ReadSetup) {
1453 parser.file = "(internal)";
1454 parser.from_file = false;
1455 parser.line_no = 1; //really arg count now.. duh
1457 for(QStringList::ConstIterator it = Option::before_user_vars.begin();
1458 it != Option::before_user_vars.end(); ++it) {
1459 if(!parse((*it), vars)) {
1460 fprintf(stderr, "Argument failed to parse: %s\n", (*it).toLatin1().constData());
1467 // After user configs, to override them
1468 if (!extra_configs.isEmpty()) {
1469 parser.file = "(extra configs)";
1470 parser.from_file = false;
1471 parser.line_no = 1; //really arg count now.. duh
1472 parse("CONFIG += " + extra_configs.join(" "), vars);
1475 if(cmd & ReadProFile) { // parse project file
1476 debug_msg(1, "Project file: reading %s", pfile.toLatin1().constData());
1477 if(pfile != "-" && !QFile::exists(pfile) && !pfile.endsWith(Option::pro_ext))
1478 pfile += Option::pro_ext;
1479 if(!read(pfile, vars))
1488 if (cmd & ReadSetup) {
1489 parser.file = "(internal)";
1490 parser.from_file = false;
1491 parser.line_no = 1; //really arg count now.. duh
1493 for(QStringList::ConstIterator it = Option::after_user_vars.begin();
1494 it != Option::after_user_vars.end(); ++it) {
1495 if(!parse((*it), vars)) {
1496 fprintf(stderr, "Argument failed to parse: %s\n", (*it).toLatin1().constData());
1503 // Again, to ensure the project does not mess with us.
1504 // Specifically, do not allow a project to override debug/release within a
1505 // debug_and_release build pass - it's too late for that at this point anyway.
1506 if (!extra_configs.isEmpty()) {
1507 parser.file = "(extra configs)";
1508 parser.from_file = false;
1509 parser.line_no = 1; //really arg count now.. duh
1510 parse("CONFIG += " + extra_configs.join(" "), vars);
1513 if(cmd & ReadFeatures) {
1514 debug_msg(1, "Processing default_post: %s", vars["CONFIG"].join("::").toLatin1().constData());
1515 doProjectInclude("default_post", IncludeFlagFeature, vars);
1517 QHash<QString, bool> processed;
1518 const QStringList &configs = vars["CONFIG"];
1519 debug_msg(1, "Processing CONFIG features: %s", configs.join("::").toLatin1().constData());
1521 bool finished = true;
1522 for(int i = configs.size()-1; i >= 0; --i) {
1523 const QString config = configs[i].toLower();
1524 if(!processed.contains(config)) {
1525 processed.insert(config, true);
1526 if(doProjectInclude(config, IncludeFlagFeature, vars) == IncludeSuccess) {
1539 void QMakeProject::validateModes()
1541 if (Option::host_mode == Option::HOST_UNKNOWN_MODE
1542 || Option::target_mode == Option::TARG_UNKNOWN_MODE) {
1543 Option::HOST_MODE host_mode;
1544 Option::TARG_MODE target_mode;
1545 const QStringList &gen = base_vars.value("MAKEFILE_GENERATOR");
1546 if (gen.isEmpty()) {
1547 fprintf(stderr, "%s:%d: Using OS scope before setting MAKEFILE_GENERATOR\n",
1548 parser.file.toLatin1().constData(), parser.line_no);
1549 } else if (MetaMakefileGenerator::modesForGenerator(gen.first(),
1550 &host_mode, &target_mode)) {
1551 if (Option::host_mode == Option::HOST_UNKNOWN_MODE) {
1552 Option::host_mode = host_mode;
1553 Option::applyHostMode();
1556 if (Option::target_mode == Option::TARG_UNKNOWN_MODE) {
1557 const QStringList &tgt = base_vars.value("TARGET_PLATFORM");
1558 if (!tgt.isEmpty()) {
1559 const QString &os = tgt.first();
1561 Option::target_mode = Option::TARG_UNIX_MODE;
1562 else if (os == "macx")
1563 Option::target_mode = Option::TARG_MACX_MODE;
1564 else if (os == "win32")
1565 Option::target_mode = Option::TARG_WIN_MODE;
1567 fprintf(stderr, "Unknown target platform specified: %s\n",
1568 os.toLatin1().constData());
1570 Option::target_mode = target_mode;
1578 QMakeProject::resolveSpec(QString *spec, const QString &qmakespec)
1580 if (spec->isEmpty()) {
1581 *spec = QFileInfo(qmakespec).fileName();
1582 if (*spec == "default" || *spec == "default-host") {
1585 int l = readlink(qmakespec.toLatin1().constData(), buffer, 1023);
1588 *spec = QString::fromLatin1(buffer);
1590 // We can't resolve symlinks as they do on Unix, so configure.exe puts the source of the
1591 // qmake.conf at the end of the default/qmake.conf in the QMAKESPEC_ORG variable.
1592 const QStringList &spec_org = base_vars["QMAKESPEC_ORIGINAL"];
1593 if (spec_org.isEmpty()) {
1594 // try again the next time around
1597 *spec = spec_org.at(0);
1599 int lastSlash = spec->lastIndexOf(QLatin1Char('/'));
1600 if (lastSlash != -1)
1601 spec->remove(0, lastSlash + 1);
1608 QMakeProject::isActiveConfig(const QString &x, bool regex, QHash<QString, QStringList> *place)
1613 //magic types for easy flipping
1616 else if(x == "false")
1621 return Option::target_mode == Option::TARG_UNIX_MODE
1622 || Option::target_mode == Option::TARG_MACX_MODE;
1623 } else if (x == "macx" || x == "mac") {
1625 return Option::target_mode == Option::TARG_MACX_MODE;
1626 } else if (x == "win32") {
1628 return Option::target_mode == Option::TARG_WIN_MODE;
1631 if (x == "host_build")
1632 return host_build ? "true" : "false";
1635 static QString hspec, xspec;
1636 resolveSpec(&hspec, Option::mkfile::qmakespec);
1637 resolveSpec(&xspec, Option::mkfile::xqmakespec);
1638 const QString &spec = host_build ? hspec : xspec;
1639 QRegExp re(x, Qt::CaseSensitive, QRegExp::Wildcard);
1640 if((regex && re.exactMatch(spec)) || (!regex && spec == x))
1644 const QStringList &configs = (place ? (*place)["CONFIG"] : vars["CONFIG"]);
1645 for(QStringList::ConstIterator it = configs.begin(); it != configs.end(); ++it) {
1646 if(((regex && re.exactMatch((*it))) || (!regex && (*it) == x)) && re.exactMatch((*it)))
1653 QMakeProject::doProjectTest(QString str, QHash<QString, QStringList> &place)
1655 QString chk = remove_quotes(str);
1658 bool invert_test = (chk.left(1) == "!");
1663 int lparen = chk.indexOf('(');
1664 if(lparen != -1) { // if there is an lparen in the chk, it IS a function
1665 int rparen = chk.indexOf(')', lparen);
1667 qmake_error_msg("Function missing right paren: " + chk);
1669 QString func = chk.left(lparen);
1670 test = doProjectTest(func, chk.mid(lparen+1, rparen - lparen - 1), place);
1673 test = isActiveConfig(chk, true, &place);
1681 QMakeProject::doProjectTest(QString func, const QString ¶ms,
1682 QHash<QString, QStringList> &place)
1684 return doProjectTest(func, split_arg_list(params), place);
1687 QMakeProject::IncludeStatus
1688 QMakeProject::doProjectInclude(QString file, uchar flags, QHash<QString, QStringList> &place)
1690 enum { UnknownFormat, ProFormat, JSFormat } format = UnknownFormat;
1691 if(flags & IncludeFlagFeature) {
1692 if(!file.endsWith(Option::prf_ext))
1693 file += Option::prf_ext;
1694 validateModes(); // init dir_sep
1695 if(file.indexOf(QLatin1Char('/')) == -1 || !QFile::exists(file)) {
1696 QStringList *&feature_roots = all_feature_roots[host_build];
1697 if(!feature_roots) {
1698 feature_roots = new QStringList;
1699 qmakeAddCacheClear(qmakeDeleteCacheClear<QStringList>, (void**)&feature_roots);
1701 if (feature_roots->isEmpty())
1702 *feature_roots = qmake_feature_paths(prop, host_build);
1703 debug_msg(2, "Looking for feature '%s' in (%s)", file.toLatin1().constData(),
1704 feature_roots->join("::").toLatin1().constData());
1706 if(parser.from_file) {
1707 QFileInfo currFile(parser.file), prfFile(file);
1708 if(currFile.fileName() == prfFile.fileName()) {
1709 currFile = QFileInfo(currFile.canonicalFilePath());
1710 for(int root = 0; root < feature_roots->size(); ++root) {
1711 prfFile = QFileInfo(feature_roots->at(root) +
1712 QLatin1Char('/') + file).canonicalFilePath();
1713 if(prfFile == currFile) {
1714 start_root = root+1;
1720 for(int root = start_root; root < feature_roots->size(); ++root) {
1721 QString prf(feature_roots->at(root) + QLatin1Char('/') + file);
1722 if(QFile::exists(prf + Option::js_ext)) {
1724 file = prf + Option::js_ext;
1726 } else if(QFile::exists(prf)) {
1732 if(format == UnknownFormat)
1733 return IncludeNoExist;
1735 if(place["QMAKE_INTERNAL_INCLUDED_FEATURES"].indexOf(file) != -1)
1736 return IncludeFeatureAlreadyLoaded;
1737 place["QMAKE_INTERNAL_INCLUDED_FEATURES"].append(file);
1739 if(QDir::isRelativePath(file)) {
1740 QStringList include_roots;
1741 if(Option::output_dir != qmake_getpwd())
1742 include_roots << qmake_getpwd();
1743 include_roots << Option::output_dir;
1744 for(int root = 0; root < include_roots.size(); ++root) {
1745 QString testName = QDir::fromNativeSeparators(include_roots[root]);
1746 if (!testName.endsWith(QLatin1Char('/')))
1747 testName += QLatin1Char('/');
1749 if(QFile::exists(testName)) {
1755 if(format == UnknownFormat) {
1756 if(QFile::exists(file)) {
1757 if(file.endsWith(Option::js_ext))
1762 return IncludeNoExist;
1765 if(Option::mkfile::do_preprocess) //nice to see this first..
1766 fprintf(stderr, "#switching file %s(%s) - %s:%d\n", (flags & IncludeFlagFeature) ? "load" : "include",
1767 file.toLatin1().constData(),
1768 parser.file.toLatin1().constData(), parser.line_no);
1769 debug_msg(1, "Project Parser: %s'ing file %s.", (flags & IncludeFlagFeature) ? "load" : "include",
1770 file.toLatin1().constData());
1772 QString orig_file = file;
1773 int di = file.lastIndexOf(QLatin1Char('/'));
1774 QString oldpwd = qmake_getpwd();
1776 if(!qmake_setpwd(file.left(file.lastIndexOf(QLatin1Char('/'))))) {
1777 fprintf(stderr, "Cannot find directory: %s\n", file.left(di).toLatin1().constData());
1778 return IncludeFailure;
1781 bool parsed = false;
1782 parser_info pi = parser;
1783 if(format == JSFormat) {
1784 warn_msg(WarnParser, "%s:%d: QtScript support disabled for %s.",
1785 pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData());
1787 if(flags & (IncludeFlagNewProject|IncludeFlagNewParser)) {
1788 // The "project's variables" are used in other places (eg. export()) so it's not
1789 // possible to use "place" everywhere. Instead just set variables and grab them later
1790 QMakeProject proj(prop);
1791 if(flags & IncludeFlagNewParser) {
1792 parsed = proj.read(file, proj.variables()); // parse just that file (fromfile, infile)
1794 parsed = proj.read(file); // parse all aux files (load/include into)
1796 place = proj.variables();
1798 QStack<ScopeBlock> sc = scope_blocks;
1799 IteratorBlock *it = iterator;
1800 FunctionBlock *fu = function;
1801 parsed = read(file, place);
1808 if(place["QMAKE_INTERNAL_INCLUDED_FILES"].indexOf(orig_file) == -1)
1809 place["QMAKE_INTERNAL_INCLUDED_FILES"].append(orig_file);
1811 warn_msg(WarnParser, "%s:%d: Failure to include file %s.",
1812 pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData());
1815 qmake_setpwd(oldpwd);
1817 return IncludeParseFailure;
1818 return IncludeSuccess;
1822 subAll(QStringList *val, const QStringList &diffval)
1824 foreach (const QString &dv, diffval)
1829 quoteValue(const QString &val)
1832 ret.reserve(val.length());
1833 bool quote = val.isEmpty();
1834 bool escaping = false;
1835 for (int i = 0, l = val.length(); i < l; i++) {
1836 QChar c = val.unicode()[i];
1837 ushort uc = c.unicode();
1841 ret += QLatin1String("$$escape_expand(");
1845 ret += QLatin1String("\\\\r");
1848 ret += QLatin1String("\\\\n");
1851 ret += QLatin1String("\\\\t");
1854 ret += QString::fromLatin1("\\\\x%1").arg(uc, 2, 16, QLatin1Char('0'));
1860 ret += QLatin1Char(')');
1864 ret += QLatin1String("\\\\");
1867 ret += QLatin1String("\\\"");
1870 ret += QLatin1String("\\'");
1873 ret += QLatin1String("\\$");
1876 ret += QLatin1String("$${LITERAL_HASH}");
1888 ret += QLatin1Char(')');
1890 ret.prepend(QLatin1Char('"'));
1891 ret.append(QLatin1Char('"'));
1897 writeFile(const QString &name, QIODevice::OpenMode mode, const QString &contents, QString *errStr)
1899 QByteArray bytes = contents.toLocal8Bit();
1901 if (!(mode & QIODevice::Append) && cfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
1902 if (cfile.readAll() == bytes)
1906 if (!cfile.open(mode | QIODevice::WriteOnly | QIODevice::Text)) {
1907 *errStr = cfile.errorString();
1912 if (cfile.error() != QFile::NoError) {
1913 *errStr = cfile.errorString();
1920 getCommandOutput(const QString &args)
1923 if (FILE *proc = QT_POPEN(args.toLatin1().constData(), "r")) {
1924 while (!feof(proc)) {
1925 char buff[10 * 1024];
1926 int read_in = int(fread(buff, 1, sizeof(buff), proc));
1929 out += QByteArray(buff, read_in);
1937 static QString windowsErrorCode()
1939 wchar_t *string = 0;
1940 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1943 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1947 QString ret = QString::fromWCharArray(string);
1948 LocalFree((HLOCAL)string);
1954 QMakeProject::doProjectExpand(QString func, const QString ¶ms,
1955 QHash<QString, QStringList> &place)
1957 return doProjectExpand(func, split_arg_list(params), place);
1961 QMakeProject::doProjectExpand(QString func, QStringList args,
1962 QHash<QString, QStringList> &place)
1964 QList<QStringList> args_list;
1965 for(int i = 0; i < args.size(); ++i) {
1966 QStringList arg = split_value_list(args[i]), tmp;
1967 for(int i = 0; i < arg.size(); ++i)
1968 tmp += doVariableReplaceExpand(arg[i], place);;
1971 return doProjectExpand(func, args_list, place);
1975 populateDeps(const QStringList &deps, const QString &prefix,
1976 QHash<QString, QSet<QString> > &dependencies, QHash<QString, QStringList> &dependees,
1977 QStringList &rootSet, QHash<QString, QStringList> &place)
1979 foreach (const QString &item, deps)
1980 if (!dependencies.contains(item)) {
1981 QSet<QString> &dset = dependencies[item]; // Always create entry
1982 QStringList depends = place.value(prefix + item + ".depends");
1983 if (depends.isEmpty()) {
1986 foreach (const QString &dep, depends) {
1988 dependees[dep] << item;
1990 populateDeps(depends, prefix, dependencies, dependees, rootSet, place);
1996 QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
1997 QHash<QString, QStringList> &place)
1999 func = func.trimmed();
2000 if(replaceFunctions.contains(func)) {
2001 FunctionBlock *defined = replaceFunctions[func];
2002 function_blocks.push(defined);
2004 defined->exec(args_list, this, place, ret);
2005 bool correct = function_blocks.pop() == defined;
2006 Q_ASSERT(correct); Q_UNUSED(correct);
2010 QStringList args; //why don't the builtin functions just use args_list? --Sam
2011 for(int i = 0; i < args_list.size(); ++i)
2012 args += args_list[i].join(QString(Option::field_sep));
2014 ExpandFunc func_t = qmake_expandFunctions().value(func);
2015 if (!func_t && (func_t = qmake_expandFunctions().value(func.toLower())))
2016 warn_msg(WarnDeprecated, "%s:%d: Using uppercased builtin functions is deprecated.",
2017 parser.file.toLatin1().constData(), parser.line_no);
2018 debug_msg(1, "Running project expand: %s(%s) [%d]",
2019 func.toLatin1().constData(), args.join("::").toLatin1().constData(), func_t);
2024 if(args.count() < 1 || args.count() > 3) {
2025 fprintf(stderr, "%s:%d: member(var, start, end) requires three arguments.\n",
2026 parser.file.toLatin1().constData(), parser.line_no);
2029 const QStringList &var = values(args.first(), place);
2030 int start = 0, end = 0;
2031 if(args.count() >= 2) {
2032 QString start_str = args[1];
2033 start = start_str.toInt(&ok);
2035 if(args.count() == 2) {
2036 int dotdot = start_str.indexOf("..");
2038 start = start_str.left(dotdot).toInt(&ok);
2040 end = start_str.mid(dotdot+2).toInt(&ok);
2044 fprintf(stderr, "%s:%d: member() argument 2 (start) '%s' invalid.\n",
2045 parser.file.toLatin1().constData(), parser.line_no,
2046 start_str.toLatin1().constData());
2049 if(args.count() == 3)
2050 end = args[2].toInt(&ok);
2052 fprintf(stderr, "%s:%d: member() argument 3 (end) '%s' invalid.\n",
2053 parser.file.toLatin1().constData(), parser.line_no,
2054 args[2].toLatin1().constData());
2059 start += var.count();
2062 if(start < 0 || start >= var.count() || end < 0 || end >= var.count()) {
2064 } else if(start < end) {
2065 for(int i = start; i <= end && (int)var.count() >= i; i++)
2068 for(int i = start; i >= end && (int)var.count() >= i && i >= 0; i--)
2076 if(args.count() != 1) {
2077 fprintf(stderr, "%s:%d: %s(var) requires one argument.\n",
2078 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
2080 const QStringList &var = values(args.first(), place);
2081 if(!var.isEmpty()) {
2082 if(func_t == E_FIRST)
2083 ret = QStringList(var[0]);
2085 ret = QStringList(var[var.size()-1]);
2090 if(args.count() < 1 || args.count() > 2) {
2091 fprintf(stderr, "%s:%d: cat(file) requires one argument.\n",
2092 parser.file.toLatin1().constData(), parser.line_no);
2094 QString file = Option::normalizePath(args[0]);
2098 bool singleLine = true;
2099 if (args.count() > 1) {
2100 if (!args.at(1).compare(QLatin1String("false"), Qt::CaseInsensitive))
2102 else if (!args.at(1).compare(QLatin1String("blob"), Qt::CaseInsensitive))
2104 else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive))
2108 if(qfile.open(QIODevice::ReadOnly)) {
2109 QTextStream stream(&qfile);
2111 ret += stream.readAll();
2113 while (!stream.atEnd()) {
2115 ret += stream.readLine();
2117 ret += split_value_list(stream.readLine().trimmed());
2127 if(args.count() != 2) {
2128 fprintf(stderr, "%s:%d: fromfile(file, variable) requires two arguments.\n",
2129 parser.file.toLatin1().constData(), parser.line_no);
2131 QString seek_var = args[1], file = Option::normalizePath(args[0]);
2133 QHash<QString, QStringList> tmp;
2134 if(doProjectInclude(file, IncludeFlagNewParser, tmp) == IncludeSuccess) {
2135 if(tmp.contains("QMAKE_INTERNAL_INCLUDED_FILES")) {
2136 QStringList &out = place["QMAKE_INTERNAL_INCLUDED_FILES"];
2137 const QStringList &in = tmp["QMAKE_INTERNAL_INCLUDED_FILES"];
2138 for(int i = 0; i < in.size(); ++i) {
2139 if(out.indexOf(in[i]) == -1)
2143 ret = tmp[seek_var];
2148 if(args.count() < 1 || args.count() > 2) {
2149 fprintf(stderr, "%s:%d: eval(variable) requires one argument.\n",
2150 parser.file.toLatin1().constData(), parser.line_no);
2153 const QHash<QString, QStringList> *source = &place;
2154 if(args.count() == 2) {
2155 if(args.at(1) == "Global") {
2157 } else if(args.at(1) == "Local") {
2160 fprintf(stderr, "%s:%d: unexpected source to eval.\n", parser.file.toLatin1().constData(),
2164 ret += source->value(args.at(0));
2170 tmp.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++);
2171 ret = QStringList(tmp);
2172 QStringList &lst = (*((QHash<QString, QStringList>*)&place))[tmp];
2174 for(QStringList::ConstIterator arg_it = args.begin();
2175 arg_it != args.end(); ++arg_it)
2176 lst += split_value_list((*arg_it));
2179 if(args.count() < 1) {
2180 fprintf(stderr, "%s:%d: sprintf(format, ...) requires one argument.\n",
2181 parser.file.toLatin1().constData(), parser.line_no);
2183 QString tmp = args.at(0);
2184 for(int i = 1; i < args.count(); ++i)
2185 tmp = tmp.arg(args.at(i));
2186 ret = split_value_list(tmp);
2190 if(args.count() < 1 || args.count() > 4) {
2191 fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four"
2192 "arguments.\n", parser.file.toLatin1().constData(), parser.line_no);
2194 QString glue, before, after;
2195 if(args.count() >= 2)
2197 if(args.count() >= 3)
2199 if(args.count() == 4)
2201 const QStringList &var = values(args.first(), place);
2203 ret = split_value_list(before + var.join(glue) + after);
2207 if(args.count() < 1 || args.count() > 2) {
2208 fprintf(stderr, "%s:%d split(var, sep) requires one or two arguments\n",
2209 parser.file.toLatin1().constData(), parser.line_no);
2211 QString sep = QString(Option::field_sep);
2212 if(args.count() >= 2)
2214 QStringList var = values(args.first(), place);
2215 for(QStringList::ConstIterator vit = var.begin(); vit != var.end(); ++vit) {
2216 QStringList lst = (*vit).split(sep);
2217 for(QStringList::ConstIterator spltit = lst.begin(); spltit != lst.end(); ++spltit)
2225 bool regexp = false;
2228 if(func_t == E_SECTION) {
2229 if(args.count() != 3 && args.count() != 4) {
2230 fprintf(stderr, "%s:%d section(var, sep, begin, end) requires three argument\n",
2231 parser.file.toLatin1().constData(), parser.line_no);
2235 beg = args[2].toInt();
2236 if(args.count() == 4)
2237 end = args[3].toInt();
2240 if(args.count() != 1) {
2241 fprintf(stderr, "%s:%d %s(var) requires one argument.\n",
2242 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
2246 sep = "[" + QRegExp::escape(Option::dir_sep) + "/]";
2247 if(func_t == E_DIRNAME)
2254 const QStringList &l = values(var, place);
2255 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
2256 QString separator = sep;
2258 ret += (*it).section(QRegExp(separator), beg, end);
2260 ret += (*it).section(separator, beg, end);
2265 if(args.count() != 2) {
2266 fprintf(stderr, "%s:%d find(var, str) requires two arguments\n",
2267 parser.file.toLatin1().constData(), parser.line_no);
2269 QRegExp regx(args[1]);
2270 const QStringList &var = values(args.first(), place);
2271 for(QStringList::ConstIterator vit = var.begin();
2272 vit != var.end(); ++vit) {
2273 if(regx.indexIn(*vit) != -1)
2279 if(args.count() < 1 || args.count() > 2) {
2280 fprintf(stderr, "%s:%d system(execut) requires one argument.\n",
2281 parser.file.toLatin1().constData(), parser.line_no);
2285 bool singleLine = true;
2286 if (args.count() > 1) {
2287 if (!args.at(1).compare(QLatin1String("false"), Qt::CaseInsensitive))
2289 else if (!args.at(1).compare(QLatin1String("blob"), Qt::CaseInsensitive))
2291 else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive))
2294 QByteArray bytes = getCommandOutput(args.at(0));
2296 QTextStream stream(bytes);
2297 while (!stream.atEnd())
2298 ret += stream.readLine();
2300 QString output = QString::fromLocal8Bit(bytes);
2304 output.replace(QLatin1Char('\t'), QLatin1Char(' '));
2306 output.replace(QLatin1Char('\n'), QLatin1Char(' '));
2307 ret += split_value_list(output);
2313 if(args.count() != 1) {
2314 fprintf(stderr, "%s:%d unique(var) requires one argument.\n",
2315 parser.file.toLatin1().constData(), parser.line_no);
2317 const QStringList &var = values(args.first(), place);
2318 for(int i = 0; i < var.count(); i++) {
2319 if(!ret.contains(var[i]))
2327 case E_ESCAPE_EXPAND: {
2328 for(int i = 0; i < args.size(); ++i) {
2329 QChar *i_data = args[i].data();
2330 int i_len = args[i].length();
2331 for(int x = 0; x < i_len; ++x) {
2332 if(*(i_data+x) == '\\' && x < i_len-1) {
2333 if(*(i_data+x+1) == '\\') {
2338 } mapped_quotes[] = {
2344 for(int i = 0; mapped_quotes[i].in; ++i) {
2345 if(*(i_data+x+1) == mapped_quotes[i].in) {
2346 *(i_data+x) = mapped_quotes[i].out;
2348 memmove(i_data+x+1, i_data+x+2, (i_len-x-2)*sizeof(QChar));
2356 ret.append(QString(i_data, i_len));
2360 for(int i = 0; i < args.size(); ++i)
2361 ret += QRegExp::escape(args[i]);
2365 for(int i = 0; i < args.size(); ++i) {
2366 if(func_t == E_UPPER)
2367 ret += args[i].toUpper();
2369 ret += args[i].toLower();
2373 if(args.count() != 1 && args.count() != 2) {
2374 fprintf(stderr, "%s:%d files(pattern) requires one argument.\n",
2375 parser.file.toLatin1().constData(), parser.line_no);
2377 bool recursive = false;
2378 if(args.count() == 2)
2379 recursive = (args[1].toLower() == "true" || args[1].toInt());
2381 QString r = Option::normalizePath(args[0]);
2382 int slash = r.lastIndexOf(QLatin1Char('/'));
2384 dirs.append(r.left(slash));
2390 QRegExp regex(r, Qt::CaseSensitive, QRegExp::Wildcard);
2391 for(int d = 0; d < dirs.count(); d++) {
2392 QString dir = dirs[d];
2393 if (!dir.isEmpty() && !dir.endsWith(QLatin1Char('/')))
2397 for(int i = 0; i < (int)qdir.count(); ++i) {
2398 if(qdir[i] == "." || qdir[i] == "..")
2400 QString fname = dir + qdir[i];
2401 if(QFileInfo(fname).isDir()) {
2405 if(regex.exactMatch(qdir[i]))
2412 if(args.count() != 1) {
2413 fprintf(stderr, "%s:%d prompt(question) requires one argument.\n",
2414 parser.file.toLatin1().constData(), parser.line_no);
2415 } else if(pfile == "-") {
2416 fprintf(stderr, "%s:%d prompt(question) cannot be used when '-o -' is used.\n",
2417 parser.file.toLatin1().constData(), parser.line_no);
2419 QString msg = fixEnvVariables(args.first());
2420 if(!msg.endsWith("?"))
2422 fprintf(stderr, "Project %s: %s ", func.toUpper().toLatin1().constData(),
2423 msg.toLatin1().constData());
2426 if(qfile.open(stdin, QIODevice::ReadOnly)) {
2427 QTextStream t(&qfile);
2428 ret = split_value_list(t.readLine());
2433 if(args.count() != 3 ) {
2434 fprintf(stderr, "%s:%d replace(var, before, after) requires three arguments\n",
2435 parser.file.toLatin1().constData(), parser.line_no);
2437 const QRegExp before( args[1] );
2438 const QString after( args[2] );
2439 QStringList var = values(args.first(), place);
2440 for(QStringList::Iterator it = var.begin(); it != var.end(); ++it)
2441 ret += it->replace(before, after);
2445 if(args.count() != 1) {
2446 fprintf(stderr, "%s:%d: size(var) requires one argument.\n",
2447 parser.file.toLatin1().constData(), parser.line_no);
2449 int size = values(args[0], place).size();
2450 ret += QString::number(size);
2453 case E_SORT_DEPENDS:
2454 case E_RESOLVE_DEPENDS: {
2455 if(args.count() < 1 || args.count() > 2) {
2456 fprintf(stderr, "%s:%d: %s(var, prefix) requires one or two arguments.\n",
2457 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
2459 QHash<QString, QSet<QString> > dependencies;
2460 QHash<QString, QStringList> dependees;
2461 QStringList rootSet;
2463 QStringList orgList = values(args[0], place);
2464 populateDeps(orgList, (args.count() != 2 ? QString() : args[1]),
2465 dependencies, dependees, rootSet, place);
2467 for (int i = 0; i < rootSet.size(); ++i) {
2468 const QString &item = rootSet.at(i);
2469 if ((func_t == E_RESOLVE_DEPENDS) || orgList.contains(item))
2471 foreach (const QString &dep, dependees[item]) {
2472 QSet<QString> &dset = dependencies[dep];
2473 dset.remove(rootSet.at(i)); // *Don't* use 'item' - rootSet may have changed!
2481 fprintf(stderr, "%s:%d: Unknown replace function: %s\n",
2482 parser.file.toLatin1().constData(), parser.line_no,
2483 func.toLatin1().constData());
2490 QMakeProject::doProjectTest(QString func, QStringList args, QHash<QString, QStringList> &place)
2492 QList<QStringList> args_list;
2493 for(int i = 0; i < args.size(); ++i) {
2494 QStringList arg = split_value_list(args[i]), tmp;
2495 for(int i = 0; i < arg.size(); ++i)
2496 tmp += doVariableReplaceExpand(arg[i], place);
2499 return doProjectTest(func, args_list, place);
2503 QMakeProject::doProjectTest(QString func, QList<QStringList> args_list, QHash<QString, QStringList> &place)
2505 func = func.trimmed();
2507 if(testFunctions.contains(func)) {
2508 FunctionBlock *defined = testFunctions[func];
2510 function_blocks.push(defined);
2511 defined->exec(args_list, this, place, ret);
2512 bool correct = function_blocks.pop() == defined;
2513 Q_ASSERT(correct); Q_UNUSED(correct);
2518 if(ret.first() == "true") {
2520 } else if(ret.first() == "false") {
2524 int val = ret.first().toInt(&ok);
2527 fprintf(stderr, "%s:%d Unexpected return value from test %s [%s].\n",
2528 parser.file.toLatin1().constData(),
2529 parser.line_no, func.toLatin1().constData(),
2530 ret.join("::").toLatin1().constData());
2537 QStringList args; //why don't the builtin functions just use args_list? --Sam
2538 for(int i = 0; i < args_list.size(); ++i)
2539 args += args_list[i].join(QString(Option::field_sep));
2541 TestFunc func_t = qmake_testFunctions().value(func);
2542 debug_msg(1, "Running project test: %s(%s) [%d]",
2543 func.toLatin1().constData(), args.join("::").toLatin1().constData(), func_t);
2547 return doProjectCheckReqs(args, place);
2549 case T_GREATERTHAN: {
2550 if(args.count() != 2) {
2551 fprintf(stderr, "%s:%d: %s(variable, value) requires two arguments.\n", parser.file.toLatin1().constData(),
2552 parser.line_no, func.toLatin1().constData());
2555 QString rhs(args[1]), lhs(values(args[0], place).join(QString(Option::field_sep)));
2557 int rhs_int = rhs.toInt(&ok);
2558 if(ok) { // do integer compare
2559 int lhs_int = lhs.toInt(&ok);
2561 if(func_t == T_GREATERTHAN)
2562 return lhs_int > rhs_int;
2563 return lhs_int < rhs_int;
2566 if(func_t == T_GREATERTHAN)
2570 if(args.count() != 1) {
2571 fprintf(stderr, "%s:%d: if(condition) requires one argument.\n", parser.file.toLatin1().constData(),
2575 const QString cond = args.first();
2576 const QChar *d = cond.unicode();
2578 bool ret = true, or_op = false;
2580 for(int d_off = 0, parens = 0, d_len = cond.size(); d_off < d_len; ++d_off) {
2581 if(!quote.isNull()) {
2582 if(*(d+d_off) == quote)
2584 } else if(*(d+d_off) == '(') {
2586 } else if(*(d+d_off) == ')') {
2588 } else if(*(d+d_off) == '"' /*|| *(d+d_off) == '\''*/) {
2591 if(!parens && quote.isNull() && (*(d+d_off) == QLatin1Char(':') || *(d+d_off) == QLatin1Char('|') || d_off == d_len-1)) {
2592 if(d_off == d_len-1)
2594 if(!test.isEmpty()) {
2596 ret = doProjectTest(test, place);
2599 if(*(d+d_off) == QLatin1Char(':')) {
2601 } else if(*(d+d_off) == QLatin1Char('|')) {
2610 if(args.count() != 2) {
2611 fprintf(stderr, "%s:%d: %s(variable, value) requires two arguments.\n", parser.file.toLatin1().constData(),
2612 parser.line_no, func.toLatin1().constData());
2615 return values(args[0], place).join(QString(Option::field_sep)) == args[1];
2617 if(args.count() != 1) {
2618 fprintf(stderr, "%s:%d: exists(file) requires one argument.\n", parser.file.toLatin1().constData(),
2622 QString file = Option::normalizePath(args.first());
2624 if(QFile::exists(file))
2626 //regular expression I guess
2627 QString dirstr = qmake_getpwd();
2628 int slsh = file.lastIndexOf(QLatin1Char('/'));
2630 dirstr = file.left(slsh+1);
2631 file = file.right(file.length() - slsh - 1);
2633 return QDir(dirstr).entryList(QStringList(file)).count(); }
2635 if(args.count() != 1) {
2636 fprintf(stderr, "%s:%d: export(variable) requires one argument.\n", parser.file.toLatin1().constData(),
2640 for(int i = 0; i < function_blocks.size(); ++i) {
2641 FunctionBlock *f = function_blocks.at(i);
2642 f->vars[args[0]] = values(args[0], place);
2643 if(!i && f->calling_place)
2644 (*f->calling_place)[args[0]] = values(args[0], place);
2648 if(args.count() != 1) {
2649 fprintf(stderr, "%s:%d: clear(variable) requires one argument.\n", parser.file.toLatin1().constData(),
2653 if(!place.contains(args[0]))
2655 place[args[0]].clear();
2658 if(args.count() != 1) {
2659 fprintf(stderr, "%s:%d: unset(variable) requires one argument.\n", parser.file.toLatin1().constData(),
2663 if(!place.contains(args[0]))
2665 place.remove(args[0]);
2668 if(args.count() < 1 && 0) {
2669 fprintf(stderr, "%s:%d: eval(project) requires one argument.\n", parser.file.toLatin1().constData(),
2673 QString project = args.join(" ");
2674 parser_info pi = parser;
2675 parser.from_file = false;
2676 parser.file = "(eval)";
2678 QTextStream t(&project, QIODevice::ReadOnly);
2679 bool ret = read(t, place);
2683 if(args.count() < 1 || args.count() > 2) {
2684 fprintf(stderr, "%s:%d: CONFIG(config) requires one argument.\n", parser.file.toLatin1().constData(),
2688 if(args.count() == 1)
2689 return isActiveConfig(args[0]);
2690 const QStringList mutuals = args[1].split('|');
2691 const QStringList &configs = values("CONFIG", place);
2692 for(int i = configs.size()-1; i >= 0; i--) {
2693 for(int mut = 0; mut < mutuals.count(); mut++) {
2694 if(configs[i] == mutuals[mut].trimmed())
2695 return (configs[i] == args[0]);
2700 if(args.count() < 1 || args.count() > 2) {
2701 fprintf(stderr, "%s:%d: system(exec) requires one argument.\n", parser.file.toLatin1().constData(),
2705 if(args.count() == 2) {
2706 const QString sarg = args[1];
2707 if (sarg.toLower() == "true" || sarg.toInt())
2708 warn_msg(WarnParser, "%s:%d: system()'s second argument is now hard-wired to false.\n",
2709 parser.file.toLatin1().constData(), parser.line_no);
2711 return system(args[0].toLatin1().constData()) == 0;
2713 if(function_blocks.isEmpty()) {
2714 fprintf(stderr, "%s:%d unexpected return()\n",
2715 parser.file.toLatin1().constData(), parser.line_no);
2717 FunctionBlock *f = function_blocks.top();
2718 f->cause_return = true;
2719 if(args_list.count() >= 1)
2720 f->return_value += args_list[0];
2725 iterator->cause_break = true;
2727 fprintf(stderr, "%s:%d unexpected break()\n",
2728 parser.file.toLatin1().constData(), parser.line_no);
2732 iterator->cause_next = true;
2734 fprintf(stderr, "%s:%d unexpected next()\n",
2735 parser.file.toLatin1().constData(), parser.line_no);
2738 if(args.count() < 1 || args.count() > 2) {
2739 fprintf(stderr, "%s:%d: defined(function) requires one argument.\n",
2740 parser.file.toLatin1().constData(), parser.line_no);
2742 if(args.count() > 1) {
2743 if(args[1] == "test")
2744 return testFunctions.contains(args[0]);
2745 else if(args[1] == "replace")
2746 return replaceFunctions.contains(args[0]);
2747 else if(args[1] == "var")
2748 return place.contains(args[0]);
2749 fprintf(stderr, "%s:%d: defined(function, type): unexpected type [%s].\n",
2750 parser.file.toLatin1().constData(), parser.line_no,
2751 args[1].toLatin1().constData());
2753 if(replaceFunctions.contains(args[0]) || testFunctions.contains(args[0]))
2759 if(args.count() < 2 || args.count() > 3) {
2760 fprintf(stderr, "%s:%d: contains(var, val) requires at lesat 2 arguments.\n",
2761 parser.file.toLatin1().constData(), parser.line_no);
2764 QRegExp regx(args[1]);
2765 const QStringList &l = values(args[0], place);
2766 if(args.count() == 2) {
2767 for(int i = 0; i < l.size(); ++i) {
2768 const QString val = l[i];
2769 if(regx.exactMatch(val) || val == args[1])
2773 const QStringList mutuals = args[2].split('|');
2774 for(int i = l.size()-1; i >= 0; i--) {
2775 const QString val = l[i];
2776 for(int mut = 0; mut < mutuals.count(); mut++) {
2777 if(val == mutuals[mut].trimmed())
2778 return (regx.exactMatch(val) || val == args[1]);
2784 if(args.count() < 2 || args.count() > 3) {
2785 fprintf(stderr, "%s:%d: infile(file, var, val) requires at least 2 arguments.\n",
2786 parser.file.toLatin1().constData(), parser.line_no);
2791 QHash<QString, QStringList> tmp;
2792 if(doProjectInclude(Option::normalizePath(args[0]), IncludeFlagNewParser, tmp) == IncludeSuccess) {
2793 if(tmp.contains("QMAKE_INTERNAL_INCLUDED_FILES")) {
2794 QStringList &out = place["QMAKE_INTERNAL_INCLUDED_FILES"];
2795 const QStringList &in = tmp["QMAKE_INTERNAL_INCLUDED_FILES"];
2796 for(int i = 0; i < in.size(); ++i) {
2797 if(out.indexOf(in[i]) == -1)
2801 if(args.count() == 2) {
2802 ret = tmp.contains(args[1]);
2804 QRegExp regx(args[2]);
2805 const QStringList &l = tmp[args[1]];
2806 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
2807 if(regx.exactMatch((*it)) || (*it) == args[2]) {
2816 if(args.count() != 2 && args.count() != 3) {
2817 fprintf(stderr, "%s:%d: count(var, count) requires two arguments.\n", parser.file.toLatin1().constData(),
2821 if(args.count() == 3) {
2822 QString comp = args[2];
2823 if(comp == ">" || comp == "greaterThan")
2824 return values(args[0], place).count() > args[1].toInt();
2826 return values(args[0], place).count() >= args[1].toInt();
2827 if(comp == "<" || comp == "lessThan")
2828 return values(args[0], place).count() < args[1].toInt();
2830 return values(args[0], place).count() <= args[1].toInt();
2831 if(comp == "equals" || comp == "isEqual" || comp == "=" || comp == "==")
2832 return values(args[0], place).count() == args[1].toInt();
2833 fprintf(stderr, "%s:%d: unexpected modifier to count(%s)\n", parser.file.toLatin1().constData(),
2834 parser.line_no, comp.toLatin1().constData());
2837 return values(args[0], place).count() == args[1].toInt();
2839 if(args.count() != 1) {
2840 fprintf(stderr, "%s:%d: isEmpty(var) requires one argument.\n", parser.file.toLatin1().constData(),
2844 return values(args[0], place).isEmpty();
2848 const bool include_statement = (func_t == T_INCLUDE);
2849 bool ignore_error = false;
2850 if(args.count() >= 2) {
2851 if(func_t == T_INCLUDE) {
2852 parseInto = args[1];
2853 if (args.count() == 3){
2854 QString sarg = args[2];
2855 if (sarg.toLower() == "true" || sarg.toInt())
2856 ignore_error = true;
2859 QString sarg = args[1];
2860 ignore_error = (sarg.toLower() == "true" || sarg.toInt());
2862 } else if(args.count() != 1) {
2863 QString func_desc = "load(feature)";
2864 if(include_statement)
2865 func_desc = "include(file)";
2866 fprintf(stderr, "%s:%d: %s requires one argument.\n", parser.file.toLatin1().constData(),
2867 parser.line_no, func_desc.toLatin1().constData());
2870 QString file = Option::normalizePath(args.first());
2871 uchar flags = IncludeFlagNone;
2872 if(!include_statement)
2873 flags |= IncludeFlagFeature;
2874 IncludeStatus stat = IncludeFailure;
2875 if(!parseInto.isEmpty()) {
2876 QHash<QString, QStringList> symbols;
2877 stat = doProjectInclude(file, flags|IncludeFlagNewProject, symbols);
2878 if(stat == IncludeSuccess) {
2879 QHash<QString, QStringList> out_place;
2880 for(QHash<QString, QStringList>::ConstIterator it = place.begin(); it != place.end(); ++it) {
2881 const QString var = it.key();
2882 if(var != parseInto && !var.startsWith(parseInto + "."))
2883 out_place.insert(var, it.value());
2885 for(QHash<QString, QStringList>::ConstIterator it = symbols.begin(); it != symbols.end(); ++it) {
2886 const QString var = it.key();
2887 if(!var.startsWith("."))
2888 out_place.insert(parseInto + "." + it.key(), it.value());
2893 stat = doProjectInclude(file, flags, place);
2895 if(stat == IncludeFeatureAlreadyLoaded) {
2896 warn_msg(WarnParser, "%s:%d: Duplicate of loaded feature %s",
2897 parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData());
2898 } else if(stat == IncludeNoExist && !ignore_error) {
2899 warn_msg(WarnAll, "%s:%d: Unable to find file for inclusion %s",
2900 parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData());
2902 } else if(stat >= IncludeFailure) {
2904 printf("Project LOAD(): Feature %s cannot be found.\n", file.toLatin1().constData());
2906 #if defined(QT_BUILD_QMAKE_LIBRARY)
2916 if(args.count() != 2) {
2917 fprintf(stderr, "%s:%d: debug(level, message) requires one argument.\n", parser.file.toLatin1().constData(),
2921 QString msg = fixEnvVariables(args[1]);
2922 debug_msg(args[0].toInt(), "Project DEBUG: %s", msg.toLatin1().constData());
2928 if(args.count() != 1) {
2929 fprintf(stderr, "%s:%d: %s(message) requires one argument.\n", parser.file.toLatin1().constData(),
2930 parser.line_no, func.toLatin1().constData());
2933 QString msg = fixEnvVariables(args.first());
2934 if (func_t == T_LOG) {
2935 fputs(msg.toLatin1().constData(), stderr);
2937 fprintf(stderr, "Project %s: %s\n", func.toUpper().toLatin1().constData(), msg.toLatin1().constData());
2938 if (func == "error")
2939 #if defined(QT_BUILD_QMAKE_LIBRARY)
2947 if (args.count() != 1) {
2948 fprintf(stderr, "%s:%d: option() requires one argument.\n",
2949 parser.file.toLatin1().constData(), parser.line_no);
2952 if (args.first() == "recursive") {
2954 } else if (args.first() == "host_build") {
2955 if (!host_build && isActiveConfig("cross_compile")) {
2957 need_restart = true;
2960 fprintf(stderr, "%s:%d: unrecognized option() argument '%s'.\n",
2961 parser.file.toLatin1().constData(), parser.line_no,
2962 args.first().toLatin1().constData());
2967 if (args.count() > 3) {
2968 fprintf(stderr, "%s:%d: cache(var, [set|add|sub] [transient], [srcvar]) requires one to three arguments.\n",
2969 parser.file.toLatin1().constData(), parser.line_no);
2972 bool persist = true;
2973 enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet;
2975 if (args.count() >= 2) {
2976 foreach (const QString &opt, split_value_list(args.at(1))) {
2977 if (opt == QLatin1String("transient")) {
2979 } else if (opt == QLatin1String("set")) {
2981 } else if (opt == QLatin1String("add")) {
2983 } else if (opt == QLatin1String("sub")) {
2986 fprintf(stderr, "%s:%d: cache(): invalid flag %s.\n",
2987 parser.file.toLatin1().constData(), parser.line_no,
2988 opt.toLatin1().constData());
2992 if (args.count() >= 3) {
2993 srcvar = args.at(2);
2994 } else if (mode != CacheSet) {
2995 fprintf(stderr, "%s:%d: cache(): modes other than 'set' require a source variable.\n",
2996 parser.file.toLatin1().constData(), parser.line_no);
3001 QString dstvar = args.at(0);
3002 if (!dstvar.isEmpty()) {
3003 if (srcvar.isEmpty())
3005 if (!place.contains(srcvar)) {
3006 fprintf(stderr, "%s:%d: variable %s is not defined.\n",
3007 parser.file.toLatin1().constData(), parser.line_no,
3008 srcvar.toLatin1().constData());
3011 // The current ("native") value can differ from the cached value, e.g., the current
3012 // CONFIG will typically have more values than the cached one. Therefore we deal with
3014 const QStringList diffval = values(srcvar, place);
3015 const QStringList oldval = base_vars.value(dstvar);
3017 if (mode == CacheSet) {
3021 if (mode == CacheAdd)
3024 subAll(&newval, diffval);
3026 // We assume that whatever got the cached value to be what it is now will do so
3027 // the next time as well, so it is OK that the early exit here will skip the
3028 // persisting as well.
3029 if (oldval == newval)
3031 base_vars[dstvar] = newval;
3035 if (mode == CacheAdd)
3036 varstr += QLatin1String(" +=");
3037 else if (mode == CacheSub)
3038 varstr += QLatin1String(" -=");
3040 varstr += QLatin1String(" =");
3041 if (diffval.count() == 1) {
3042 varstr += QLatin1Char(' ');
3043 varstr += quoteValue(diffval.at(0));
3044 } else if (!diffval.isEmpty()) {
3045 foreach (const QString &vval, diffval) {
3046 varstr += QLatin1String(" \\\n ");
3047 varstr += quoteValue(vval);
3050 varstr += QLatin1Char('\n');
3052 if (Option::mkfile::cachefile.isEmpty()) {
3053 Option::mkfile::cachefile = Option::output_dir + QLatin1String("/.qmake.cache");
3054 printf("Info: creating cache file %s\n",
3055 Option::mkfile::cachefile.toLatin1().constData());
3056 project_build_root = Option::output_dir;
3057 project_root = values("_PRO_FILE_PWD_", place).first();
3058 if (project_root == project_build_root)
3059 project_root.clear();
3060 invalidateFeatureRoots();
3062 QFileInfo qfi(Option::mkfile::cachefile);
3063 if (!QDir::current().mkpath(qfi.path())) {
3064 fprintf(stderr, "%s:%d: ERROR creating cache directory %s\n",
3065 parser.file.toLatin1().constData(), parser.line_no,
3066 qfi.path().toLatin1().constData());
3070 if (!writeFile(Option::mkfile::cachefile, QIODevice::Append, varstr, &errStr)) {
3071 fprintf(stderr, "ERROR writing cache file %s: %s\n",
3072 Option::mkfile::cachefile.toLatin1().constData(), errStr.toLatin1().constData());
3073 #if defined(QT_BUILD_QMAKE_LIBRARY)
3081 if (args.count() != 1) {
3082 fprintf(stderr, "%s:%d: mkpath(name) requires one argument.\n",
3083 parser.file.toLatin1().constData(), parser.line_no);
3086 if (!QDir::current().mkpath(args.at(0))) {
3087 fprintf(stderr, "%s:%d: ERROR creating directory %s\n",
3088 parser.file.toLatin1().constData(), parser.line_no,
3089 QDir::toNativeSeparators(args.at(0)).toLatin1().constData());
3093 case T_WRITE_FILE: {
3094 if (args.count() > 3) {
3095 fprintf(stderr, "%s:%d: write_file(name, [content var, [append]]) requires one to three arguments.\n",
3096 parser.file.toLatin1().constData(), parser.line_no);
3099 QIODevice::OpenMode mode = QIODevice::Truncate;
3101 if (args.count() >= 2) {
3102 QStringList vals = values(args.at(1), place);
3103 if (!vals.isEmpty())
3104 contents = vals.join(QLatin1String("\n")) + QLatin1Char('\n');
3105 if (args.count() >= 3)
3106 if (!args.at(2).compare(QLatin1String("append"), Qt::CaseInsensitive))
3107 mode = QIODevice::Append;
3109 QFileInfo qfi(args.at(0));
3110 if (!QDir::current().mkpath(qfi.path())) {
3111 fprintf(stderr, "%s:%d: ERROR creating directory %s\n",
3112 parser.file.toLatin1().constData(), parser.line_no,
3113 qfi.path().toLatin1().constData());
3117 if (!writeFile(args.at(0), mode, contents, &errStr)) {
3118 fprintf(stderr, "%s:%d ERROR writing %s: %s\n",
3119 parser.file.toLatin1().constData(), parser.line_no,
3120 args.at(0).toLatin1().constData(), errStr.toLatin1().constData());
3125 if (args.count() != 2) {
3126 fprintf(stderr, "%s:%d: touch(file, reffile) requires two arguments.\n",
3127 parser.file.toLatin1().constData(), parser.line_no);
3132 if (stat(args.at(1).toLocal8Bit().constData(), &st)) {
3133 fprintf(stderr, "%s:%d: ERROR: cannot stat() reference file %s: %s.\n",
3134 parser.file.toLatin1().constData(), parser.line_no,
3135 args.at(1).toLatin1().constData(), strerror(errno));
3139 utb.actime = time(0);
3140 utb.modtime = st.st_mtime;
3141 if (utime(args.at(0).toLocal8Bit().constData(), &utb)) {
3142 fprintf(stderr, "%s:%d: ERROR: cannot touch %s: %s.\n",
3143 parser.file.toLatin1().constData(), parser.line_no,
3144 args.at(0).toLatin1().constData(), strerror(errno));
3148 HANDLE rHand = CreateFile((wchar_t*)args.at(1).utf16(),
3149 GENERIC_READ, FILE_SHARE_READ,
3150 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3151 if (rHand == INVALID_HANDLE_VALUE) {
3152 fprintf(stderr, "%s:%d: ERROR: cannot open() reference file %s: %s.\n",
3153 parser.file.toLatin1().constData(), parser.line_no,
3154 args.at(1).toLatin1().constData(),
3155 windowsErrorCode().toLatin1().constData());
3159 GetFileTime(rHand, 0, 0, &ft);
3161 HANDLE wHand = CreateFile((wchar_t*)args.at(0).utf16(),
3162 GENERIC_WRITE, FILE_SHARE_READ,
3163 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3164 if (wHand == INVALID_HANDLE_VALUE) {
3165 fprintf(stderr, "%s:%d: ERROR: cannot open %s: %s.\n",
3166 parser.file.toLatin1().constData(), parser.line_no,
3167 args.at(0).toLatin1().constData(),
3168 windowsErrorCode().toLatin1().constData());
3171 SetFileTime(wHand, 0, 0, &ft);
3176 fprintf(stderr, "%s:%d: Unknown test function: %s\n", parser.file.toLatin1().constData(), parser.line_no,
3177 func.toLatin1().constData());
3183 QMakeProject::doProjectCheckReqs(const QStringList &deps, QHash<QString, QStringList> &place)
3186 for(QStringList::ConstIterator it = deps.begin(); it != deps.end(); ++it) {
3187 bool test = doProjectTest((*it), place);
3189 debug_msg(1, "Project Parser: %s:%d Failed test: REQUIRES = %s",
3190 parser.file.toLatin1().constData(), parser.line_no,
3191 (*it).toLatin1().constData());
3192 place["QMAKE_FAILED_REQUIREMENTS"].append((*it));
3200 QMakeProject::test(const QString &v)
3202 QHash<QString, QStringList> tmp = vars;
3203 return doProjectTest(v, tmp);
3207 QMakeProject::test(const QString &func, const QList<QStringList> &args)
3209 QHash<QString, QStringList> tmp = vars;
3210 return doProjectTest(func, args, tmp);
3214 QMakeProject::expand(const QString &str)
3217 QHash<QString, QStringList> tmp = vars;
3218 const QStringList ret = doVariableReplaceExpand(str, tmp, &ok);
3221 return QStringList();
3225 QMakeProject::expand(const QString &str, const QString &file, int line)
3228 parser_info pi = parser;
3230 parser.line_no = line;
3231 parser.from_file = false;
3232 QHash<QString, QStringList> tmp = vars;
3233 const QStringList ret = doVariableReplaceExpand(str, tmp, &ok);
3235 return ok ? ret.join(QString(Option::field_sep)) : QString();
3239 QMakeProject::expand(const QString &func, const QList<QStringList> &args)
3241 QHash<QString, QStringList> tmp = vars;
3242 return doProjectExpand(func, args, tmp);
3246 QMakeProject::doVariableReplace(QString &str, QHash<QString, QStringList> &place)
3249 str = doVariableReplaceExpand(str, place, &ret).join(QString(Option::field_sep));
3254 QMakeProject::doVariableReplaceExpand(const QString &str, QHash<QString, QStringList> &place, bool *ok)
3262 const ushort LSQUARE = '[';
3263 const ushort RSQUARE = ']';
3264 const ushort LCURLY = '{';
3265 const ushort RCURLY = '}';
3266 const ushort LPAREN = '(';
3267 const ushort RPAREN = ')';
3268 const ushort DOLLAR = '$';
3269 const ushort SLASH = '\\';
3270 const ushort UNDERSCORE = '_';
3271 const ushort DOT = '.';
3272 const ushort SPACE = ' ';
3273 const ushort TAB = '\t';
3274 const ushort SINGLEQUOTE = '\'';
3275 const ushort DOUBLEQUOTE = '"';
3277 ushort unicode, quote = 0;
3278 const QChar *str_data = str.data();
3279 const int str_len = str.length();
3286 for(int i = 0; i < str_len; ++i) {
3287 unicode = str_data[i].unicode();
3288 const int start_var = i;
3289 if(unicode == DOLLAR && str_len > i+2) {
3290 unicode = str_data[++i].unicode();
3291 if(unicode == DOLLAR) {
3295 enum { VAR, ENVIRON, FUNCTION, PROPERTY } var_type = VAR;
3296 unicode = str_data[++i].unicode();
3297 if(unicode == LSQUARE) {
3298 unicode = str_data[++i].unicode();
3300 var_type = PROPERTY;
3301 } else if(unicode == LCURLY) {
3302 unicode = str_data[++i].unicode();
3305 } else if(unicode == LPAREN) {
3306 unicode = str_data[++i].unicode();
3311 if(!(unicode & (0xFF<<8)) &&
3312 unicode != DOT && unicode != UNDERSCORE &&
3313 //unicode != SINGLEQUOTE && unicode != DOUBLEQUOTE &&
3314 (unicode < 'a' || unicode > 'z') && (unicode < 'A' || unicode > 'Z') &&
3315 (unicode < '0' || unicode > '9') && (!term || unicode != '/'))
3317 var.append(QChar(unicode));
3320 unicode = str_data[i].unicode();
3321 // at this point, i points to either the 'term' or 'next' character (which is in unicode)
3323 if(var_type == VAR && unicode == LPAREN) {
3324 var_type = FUNCTION;
3329 unicode = str_data[i].unicode();
3330 if(unicode == LPAREN) {
3332 } else if(unicode == RPAREN) {
3337 args.append(QChar(unicode));
3340 unicode = str_data[i].unicode();
3343 // at this point i is pointing to the 'next' character (which is in unicode)
3344 // this might actually be a term character since you can do $${func()}
3347 if(unicode != term) {
3348 qmake_error_msg("Missing " + QString(term) + " terminator [found " + (unicode?QString(unicode):QString("end-of-line")) + "]");
3351 return QStringList();
3354 // move the 'cursor' back to the last char of the thing we were looking at
3357 // since i never points to the 'next' character, there is no reason for this to be set
3360 QStringList replacement;
3361 if(var_type == ENVIRON) {
3362 replacement = split_value_list(QString::fromLocal8Bit(qgetenv(var.toLatin1().constData())));
3363 } else if(var_type == PROPERTY) {
3365 replacement = split_value_list(prop->value(var));
3366 } else if(var_type == FUNCTION) {
3367 replacement = doProjectExpand(var, args, place);
3368 } else if(var_type == VAR) {
3369 replacement = values(var, place);
3371 if(!(replaced++) && start_var)
3372 current = str.left(start_var);
3373 if(!replacement.isEmpty()) {
3375 current += replacement.join(QString(Option::field_sep));
3377 current += replacement.takeFirst();
3378 if(!replacement.isEmpty()) {
3379 if(!current.isEmpty())
3380 ret.append(current);
3381 current = replacement.takeLast();
3382 if(!replacement.isEmpty())
3387 debug_msg(2, "Project Parser [var replace]: %s -> %s",
3388 str.toLatin1().constData(), var.toLatin1().constData(),
3389 replacement.join("::").toLatin1().constData());
3392 current.append("$");
3395 if(quote && unicode == quote) {
3398 } else if(unicode == SLASH) {
3399 bool escape = false;
3400 const char *symbols = "[]{}()$\\'\"";
3401 for(const char *s = symbols; *s; ++s) {
3402 if(str_data[i+1].unicode() == (ushort)*s) {
3406 current = str.left(start_var);
3407 current.append(str.at(i));
3411 if(!escape && !backslashWarned) {
3412 backslashWarned = true;
3413 warn_msg(WarnDeprecated, "%s:%d: Unescaped backslashes are deprecated.",
3414 parser.file.toLatin1().constData(), parser.line_no);
3416 if(escape || !replaced)
3418 } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
3421 if(!(replaced++) && i)
3422 current = str.left(i);
3423 } else if(!quote && (unicode == SPACE || unicode == TAB)) {
3425 if(!current.isEmpty()) {
3426 ret.append(current);
3430 if(replaced && unicode)
3431 current.append(QChar(unicode));
3434 ret = QStringList(str);
3435 else if(!current.isEmpty())
3436 ret.append(current);
3437 //qDebug() << "REPLACE" << str << ret;
3439 warn_msg(WarnDeprecated, "%s:%d: Unmatched quotes are deprecated.",
3440 parser.file.toLatin1().constData(), parser.line_no);
3444 QStringList &QMakeProject::values(const QString &_var, QHash<QString, QStringList> &place)
3446 QString var = varMap(_var);
3447 if(var == QLatin1String("LITERAL_WHITESPACE")) { //a real space in a token)
3448 var = ".BUILTIN." + var;
3449 place[var] = QStringList(QLatin1String("\t"));
3450 } else if(var == QLatin1String("LITERAL_DOLLAR")) { //a real $
3451 var = ".BUILTIN." + var;
3452 place[var] = QStringList(QLatin1String("$"));
3453 } else if(var == QLatin1String("LITERAL_HASH")) { //a real #
3454 var = ".BUILTIN." + var;
3455 place[var] = QStringList("#");
3456 } else if(var == QLatin1String("OUT_PWD")) { //the out going dir
3457 var = ".BUILTIN." + var;
3458 place[var] = QStringList(Option::output_dir);
3459 } else if(var == QLatin1String("PWD") || //current working dir (of _FILE_)
3460 var == QLatin1String("IN_PWD")) {
3461 var = ".BUILTIN." + var;
3462 place[var] = QStringList(qmake_getpwd());
3463 } else if(var == QLatin1String("DIR_SEPARATOR")) {
3465 var = ".BUILTIN." + var;
3466 place[var] = QStringList(Option::dir_sep);
3467 } else if(var == QLatin1String("DIRLIST_SEPARATOR")) {
3468 var = ".BUILTIN." + var;
3469 place[var] = QStringList(Option::dirlist_sep);
3470 } else if(var == QLatin1String("_LINE_")) { //parser line number
3471 var = ".BUILTIN." + var;
3472 place[var] = QStringList(QString::number(parser.line_no));
3473 } else if(var == QLatin1String("_FILE_")) { //parser file
3474 var = ".BUILTIN." + var;
3475 place[var] = QStringList(parser.file);
3476 } else if(var == QLatin1String("_DATE_")) { //current date/time
3477 var = ".BUILTIN." + var;
3478 place[var] = QStringList(QDateTime::currentDateTime().toString());
3479 } else if(var == QLatin1String("_PRO_FILE_")) {
3480 var = ".BUILTIN." + var;
3481 place[var] = QStringList(pfile);
3482 } else if(var == QLatin1String("_PRO_FILE_PWD_")) {
3483 var = ".BUILTIN." + var;
3484 place[var] = QStringList(pfile.isEmpty() ? qmake_getpwd() : QFileInfo(pfile).absolutePath());
3485 } else if(var == QLatin1String("_QMAKE_CACHE_")) {
3486 var = ".BUILTIN." + var;
3487 if(Option::mkfile::do_cache)
3488 place[var] = QStringList(Option::mkfile::cachefile);
3489 } else if(var == QLatin1String("TEMPLATE")) {
3490 if(!Option::user_template.isEmpty()) {
3491 var = ".BUILTIN.USER." + var;
3492 place[var] = QStringList(Option::user_template);
3494 QString orig_template, real_template;
3495 if(!place[var].isEmpty())
3496 orig_template = place[var].first();
3497 real_template = orig_template.isEmpty() ? "app" : orig_template;
3498 if(!Option::user_template_prefix.isEmpty() && !orig_template.startsWith(Option::user_template_prefix))
3499 real_template.prepend(Option::user_template_prefix);
3500 if(real_template != orig_template) {
3501 var = ".BUILTIN." + var;
3502 place[var] = QStringList(real_template);
3505 } else if(var.startsWith(QLatin1String("QMAKE_HOST."))) {
3506 QString ret, type = var.mid(11);
3507 #if defined(Q_OS_WIN32)
3510 } else if(type == "name") {
3511 DWORD name_length = 1024;
3513 if (GetComputerName(name, &name_length))
3514 ret = QString::fromWCharArray(name);
3515 } else if(type == "version" || type == "version_string") {
3516 QSysInfo::WinVersion ver = QSysInfo::WindowsVersion;
3517 if(type == "version")
3518 ret = QString::number(ver);
3519 else if(ver == QSysInfo::WV_Me)
3521 else if(ver == QSysInfo::WV_95)
3523 else if(ver == QSysInfo::WV_98)
3525 else if(ver == QSysInfo::WV_NT)
3527 else if(ver == QSysInfo::WV_2000)
3529 else if(ver == QSysInfo::WV_2000)
3531 else if(ver == QSysInfo::WV_XP)
3533 else if(ver == QSysInfo::WV_VISTA)
3537 } else if(type == "arch") {
3539 GetSystemInfo(&info);
3540 switch(info.wProcessorArchitecture) {
3541 #ifdef PROCESSOR_ARCHITECTURE_AMD64
3542 case PROCESSOR_ARCHITECTURE_AMD64:
3546 case PROCESSOR_ARCHITECTURE_INTEL:
3549 case PROCESSOR_ARCHITECTURE_IA64:
3550 #ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
3551 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
3560 #elif defined(Q_OS_UNIX)
3561 struct utsname name;
3565 else if(type == "name")
3566 ret = name.nodename;
3567 else if(type == "version")
3569 else if(type == "version_string")
3571 else if(type == "arch")
3575 var = ".BUILTIN.HOST." + type;
3576 place[var] = QStringList(ret);
3577 } else if (var == QLatin1String("QMAKE_DIR_SEP")) {
3578 if (place[var].isEmpty())
3579 return values("DIR_SEPARATOR", place);
3580 } else if (var == QLatin1String("QMAKE_EXT_OBJ")) {
3581 if (place[var].isEmpty()) {
3582 var = ".BUILTIN." + var;
3583 place[var] = QStringList(Option::obj_ext);
3585 } else if (var == QLatin1String("QMAKE_QMAKE")) {
3586 if (place[var].isEmpty())
3587 place[var] = QStringList(Option::fixPathToTargetOS(
3588 !Option::qmake_abslocation.isEmpty()
3589 ? Option::qmake_abslocation
3590 : QLibraryInfo::location(QLibraryInfo::HostBinariesPath) + "/qmake",
3593 #if defined(Q_OS_WIN32) && defined(Q_CC_MSVC)
3594 else if(var.startsWith(QLatin1String("QMAKE_TARGET."))) {
3595 QString ret, type = var.mid(13);
3596 if(type == "arch") {
3597 QString paths = QString::fromLocal8Bit(qgetenv("PATH"));
3598 QString vcBin64 = QString::fromLocal8Bit(qgetenv("VCINSTALLDIR"));
3599 if (!vcBin64.endsWith('\\'))
3600 vcBin64.append('\\');
3601 vcBin64.append("bin\\amd64");
3602 QString vcBinX86_64 = QString::fromLocal8Bit(qgetenv("VCINSTALLDIR"));
3603 if (!vcBinX86_64.endsWith('\\'))
3604 vcBinX86_64.append('\\');
3605 vcBinX86_64.append("bin\\x86_amd64");
3606 if(paths.contains(vcBin64,Qt::CaseInsensitive) || paths.contains(vcBinX86_64,Qt::CaseInsensitive))
3611 place[var] = QStringList(ret);
3614 //qDebug("REPLACE [%s]->[%s]", qPrintable(var), qPrintable(place[var].join("::")));
3618 bool QMakeProject::isEmpty(const QString &v)
3620 QHash<QString, QStringList>::ConstIterator it = vars.constFind(varMap(v));
3621 return it == vars.constEnd() || it->isEmpty();