source: trunk/qmake/project.cpp@ 769

Last change on this file since 769 was 769, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

File size: 123.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the qmake application of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "project.h"
43#include "property.h"
44#include "option.h"
45#include "cachekeys.h"
46
47#include <qdatetime.h>
48#include <qfile.h>
49#include <qfileinfo.h>
50#include <qdir.h>
51#include <qregexp.h>
52#include <qtextstream.h>
53#include <qstack.h>
54#include <qhash.h>
55#include <qdebug.h>
56#ifdef Q_OS_UNIX
57#include <unistd.h>
58#include <sys/utsname.h>
59#elif defined(Q_OS_WIN32)
60#include <windows.h>
61#elif defined(Q_OS_OS2)
62#include <qt_os2.h>
63#endif
64#include <stdio.h>
65#include <stdlib.h>
66
67// Included from tools/shared
68#include <symbian/epocroot.h>
69
70#ifdef Q_OS_WIN32
71#define QT_POPEN _popen
72#define QT_PCLOSE _pclose
73#else
74#define QT_POPEN popen
75#define QT_PCLOSE pclose
76#endif
77
78QT_BEGIN_NAMESPACE
79
80//expand fucntions
81enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST,
82 E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
83 E_FIND, E_SYSTEM, E_UNIQUE, E_QUOTE, E_ESCAPE_EXPAND,
84 E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE,
85 E_SIZE, E_GENERATE_UID };
86QMap<QString, ExpandFunc> qmake_expandFunctions()
87{
88 static QMap<QString, ExpandFunc> *qmake_expand_functions = 0;
89 if(!qmake_expand_functions) {
90 qmake_expand_functions = new QMap<QString, ExpandFunc>;
91 qmakeAddCacheClear(qmakeDeleteCacheClear_QMapStringInt, (void**)&qmake_expand_functions);
92 qmake_expand_functions->insert("member", E_MEMBER);
93 qmake_expand_functions->insert("first", E_FIRST);
94 qmake_expand_functions->insert("last", E_LAST);
95 qmake_expand_functions->insert("cat", E_CAT);
96 qmake_expand_functions->insert("fromfile", E_FROMFILE);
97 qmake_expand_functions->insert("eval", E_EVAL);
98 qmake_expand_functions->insert("list", E_LIST);
99 qmake_expand_functions->insert("sprintf", E_SPRINTF);
100 qmake_expand_functions->insert("join", E_JOIN);
101 qmake_expand_functions->insert("split", E_SPLIT);
102 qmake_expand_functions->insert("basename", E_BASENAME);
103 qmake_expand_functions->insert("dirname", E_DIRNAME);
104 qmake_expand_functions->insert("section", E_SECTION);
105 qmake_expand_functions->insert("find", E_FIND);
106 qmake_expand_functions->insert("system", E_SYSTEM);
107 qmake_expand_functions->insert("unique", E_UNIQUE);
108 qmake_expand_functions->insert("quote", E_QUOTE);
109 qmake_expand_functions->insert("escape_expand", E_ESCAPE_EXPAND);
110 qmake_expand_functions->insert("upper", E_UPPER);
111 qmake_expand_functions->insert("lower", E_LOWER);
112 qmake_expand_functions->insert("re_escape", E_RE_ESCAPE);
113 qmake_expand_functions->insert("files", E_FILES);
114 qmake_expand_functions->insert("prompt", E_PROMPT);
115 qmake_expand_functions->insert("replace", E_REPLACE);
116 qmake_expand_functions->insert("size", E_SIZE);
117 qmake_expand_functions->insert("generate_uid", E_GENERATE_UID);
118 }
119 return *qmake_expand_functions;
120}
121//replace functions
122enum 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, T_DEBUG, T_ERROR,
126 T_MESSAGE, T_WARNING, T_IF };
127QMap<QString, TestFunc> qmake_testFunctions()
128{
129 static QMap<QString, TestFunc> *qmake_test_functions = 0;
130 if(!qmake_test_functions) {
131 qmake_test_functions = new QMap<QString, TestFunc>;
132 qmake_test_functions->insert("requires", T_REQUIRES);
133 qmake_test_functions->insert("greaterThan", T_GREATERTHAN);
134 qmake_test_functions->insert("lessThan", T_LESSTHAN);
135 qmake_test_functions->insert("equals", T_EQUALS);
136 qmake_test_functions->insert("isEqual", T_EQUALS);
137 qmake_test_functions->insert("exists", T_EXISTS);
138 qmake_test_functions->insert("export", T_EXPORT);
139 qmake_test_functions->insert("clear", T_CLEAR);
140 qmake_test_functions->insert("unset", T_UNSET);
141 qmake_test_functions->insert("eval", T_EVAL);
142 qmake_test_functions->insert("CONFIG", T_CONFIG);
143 qmake_test_functions->insert("if", T_IF);
144 qmake_test_functions->insert("isActiveConfig", T_CONFIG);
145 qmake_test_functions->insert("system", T_SYSTEM);
146 qmake_test_functions->insert("return", T_RETURN);
147 qmake_test_functions->insert("break", T_BREAK);
148 qmake_test_functions->insert("next", T_NEXT);
149 qmake_test_functions->insert("defined", T_DEFINED);
150 qmake_test_functions->insert("contains", T_CONTAINS);
151 qmake_test_functions->insert("infile", T_INFILE);
152 qmake_test_functions->insert("count", T_COUNT);
153 qmake_test_functions->insert("isEmpty", T_ISEMPTY);
154 qmake_test_functions->insert("include", T_INCLUDE);
155 qmake_test_functions->insert("load", T_LOAD);
156 qmake_test_functions->insert("debug", T_DEBUG);
157 qmake_test_functions->insert("error", T_ERROR);
158 qmake_test_functions->insert("message", T_MESSAGE);
159 qmake_test_functions->insert("warning", T_WARNING);
160 }
161 return *qmake_test_functions;
162}
163
164struct parser_info {
165 QString file;
166 int line_no;
167 bool from_file;
168} parser;
169
170static QString remove_quotes(const QString &arg)
171{
172 const ushort SINGLEQUOTE = '\'';
173 const ushort DOUBLEQUOTE = '"';
174
175 const QChar *arg_data = arg.data();
176 const ushort first = arg_data->unicode();
177 const int arg_len = arg.length();
178 if(first == SINGLEQUOTE || first == DOUBLEQUOTE) {
179 const ushort last = (arg_data+arg_len-1)->unicode();
180 if(last == first)
181 return arg.mid(1, arg_len-2);
182 }
183 return arg;
184}
185
186static QString varMap(const QString &x)
187{
188 QString ret(x);
189 if(ret.startsWith("TMAKE")) //tmake no more!
190 ret = "QMAKE" + ret.mid(5);
191 else if(ret == "INTERFACES")
192 ret = "FORMS";
193 else if(ret == "QMAKE_POST_BUILD")
194 ret = "QMAKE_POST_LINK";
195 else if(ret == "TARGETDEPS")
196 ret = "POST_TARGETDEPS";
197 else if(ret == "LIBPATH")
198 ret = "QMAKE_LIBDIR";
199 else if(ret == "QMAKE_EXT_MOC")
200 ret = "QMAKE_EXT_CPP_MOC";
201 else if(ret == "QMAKE_MOD_MOC")
202 ret = "QMAKE_H_MOD_MOC";
203 else if(ret == "QMAKE_LFLAGS_SHAPP")
204 ret = "QMAKE_LFLAGS_APP";
205 else if(ret == "PRECOMPH")
206 ret = "PRECOMPILED_HEADER";
207 else if(ret == "PRECOMPCPP")
208 ret = "PRECOMPILED_SOURCE";
209 else if(ret == "INCPATH")
210 ret = "INCLUDEPATH";
211 else if(ret == "QMAKE_EXTRA_WIN_COMPILERS" || ret == "QMAKE_EXTRA_UNIX_COMPILERS")
212 ret = "QMAKE_EXTRA_COMPILERS";
213 else if(ret == "QMAKE_EXTRA_WIN_TARGETS" || ret == "QMAKE_EXTRA_UNIX_TARGETS")
214 ret = "QMAKE_EXTRA_TARGETS";
215 else if(ret == "QMAKE_EXTRA_UNIX_INCLUDES")
216 ret = "QMAKE_EXTRA_INCLUDES";
217 else if(ret == "QMAKE_EXTRA_UNIX_VARIABLES")
218 ret = "QMAKE_EXTRA_VARIABLES";
219 else if(ret == "QMAKE_RPATH")
220 ret = "QMAKE_LFLAGS_RPATH";
221 else if(ret == "QMAKE_FRAMEWORKDIR")
222 ret = "QMAKE_FRAMEWORKPATH";
223 else if(ret == "QMAKE_FRAMEWORKDIR_FLAGS")
224 ret = "QMAKE_FRAMEWORKPATH_FLAGS";
225 return ret;
226}
227
228static QStringList split_arg_list(QString params)
229{
230 int quote = 0;
231 QStringList args;
232
233 const ushort LPAREN = '(';
234 const ushort RPAREN = ')';
235 const ushort SINGLEQUOTE = '\'';
236 const ushort DOUBLEQUOTE = '"';
237 const ushort COMMA = ',';
238 const ushort SPACE = ' ';
239 //const ushort TAB = '\t';
240
241 ushort unicode;
242 const QChar *params_data = params.data();
243 const int params_len = params.length();
244 int last = 0;
245 while(last < params_len && (params_data[last].unicode() == SPACE
246 /*|| params_data[last].unicode() == TAB*/))
247 ++last;
248 for(int x = last, parens = 0; x <= params_len; x++) {
249 unicode = params_data[x].unicode();
250 if(x == params_len) {
251 while(x && params_data[x-1].unicode() == SPACE)
252 --x;
253 QString mid(params_data+last, x-last);
254 if(quote) {
255 if(mid[0] == quote && mid[(int)mid.length()-1] == quote)
256 mid = mid.mid(1, mid.length()-2);
257 quote = 0;
258 }
259 args << mid;
260 break;
261 }
262 if(unicode == LPAREN) {
263 --parens;
264 } else if(unicode == RPAREN) {
265 ++parens;
266 } else if(quote && unicode == quote) {
267 quote = 0;
268 } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
269 quote = unicode;
270 }
271 if(!parens && !quote && unicode == COMMA) {
272 QString mid = params.mid(last, x - last).trimmed();
273 args << mid;
274 last = x+1;
275 while(last < params_len && (params_data[last].unicode() == SPACE
276 /*|| params_data[last].unicode() == TAB*/))
277 ++last;
278 }
279 }
280 return args;
281}
282
283static QStringList split_value_list(const QString &vals, bool do_semicolon=false)
284{
285 QString build;
286 QStringList ret;
287 QStack<char> quote;
288
289 const ushort LPAREN = '(';
290 const ushort RPAREN = ')';
291 const ushort SINGLEQUOTE = '\'';
292 const ushort DOUBLEQUOTE = '"';
293 const ushort BACKSLASH = '\\';
294 const ushort SEMICOLON = ';';
295
296 ushort unicode;
297 const QChar *vals_data = vals.data();
298 const int vals_len = vals.length();
299 for(int x = 0, parens = 0; x < vals_len; x++) {
300 unicode = vals_data[x].unicode();
301 if(x != (int)vals_len-1 && unicode == BACKSLASH &&
302 (vals_data[x+1].unicode() == SINGLEQUOTE || vals_data[x+1].unicode() == DOUBLEQUOTE)) {
303 build += vals_data[x++]; //get that 'escape'
304 } else if(!quote.isEmpty() && unicode == quote.top()) {
305 quote.pop();
306 } else if(unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE) {
307 quote.push(unicode);
308 } else if(unicode == RPAREN) {
309 --parens;
310 } else if(unicode == LPAREN) {
311 ++parens;
312 }
313
314 if(!parens && quote.isEmpty() && ((do_semicolon && unicode == SEMICOLON) ||
315 vals_data[x] == Option::field_sep)) {
316 ret << build;
317 build.clear();
318 } else {
319 build += vals_data[x];
320 }
321 }
322 if(!build.isEmpty())
323 ret << build;
324 return ret;
325}
326
327//just a parsable entity
328struct ParsableBlock
329{
330 ParsableBlock() : ref_cnt(1) { }
331 virtual ~ParsableBlock() { }
332
333 struct Parse {
334 QString text;
335 parser_info pi;
336 Parse(const QString &t) : text(t){ pi = parser; }
337 };
338 QList<Parse> parselist;
339
340 inline int ref() { return ++ref_cnt; }
341 inline int deref() { return --ref_cnt; }
342
343protected:
344 int ref_cnt;
345 virtual bool continueBlock() = 0;
346 bool eval(QMakeProject *p, QMap<QString, QStringList> &place);
347};
348
349bool ParsableBlock::eval(QMakeProject *p, QMap<QString, QStringList> &place)
350{
351 //save state
352 parser_info pi = parser;
353 const int block_count = p->scope_blocks.count();
354
355 //execute
356 bool ret = true;
357 for(int i = 0; i < parselist.count(); i++) {
358 parser = parselist.at(i).pi;
359 if(!(ret = p->parse(parselist.at(i).text, place)) || !continueBlock())
360 break;
361 }
362
363 //restore state
364 parser = pi;
365 while(p->scope_blocks.count() > block_count)
366 p->scope_blocks.pop();
367 return ret;
368}
369
370//defined functions
371struct FunctionBlock : public ParsableBlock
372{
373 FunctionBlock() : calling_place(0), scope_level(1), cause_return(false) { }
374
375 QMap<QString, QStringList> vars;
376 QMap<QString, QStringList> *calling_place;
377 QStringList return_value;
378 int scope_level;
379 bool cause_return;
380
381 bool exec(const QList<QStringList> &args,
382 QMakeProject *p, QMap<QString, QStringList> &place, QStringList &functionReturn);
383 virtual bool continueBlock() { return !cause_return; }
384};
385
386bool FunctionBlock::exec(const QList<QStringList> &args,
387 QMakeProject *proj, QMap<QString, QStringList> &place,
388 QStringList &functionReturn)
389{
390 //save state
391#if 1
392 calling_place = &place;
393#else
394 calling_place = &proj->variables();
395#endif
396 return_value.clear();
397 cause_return = false;
398
399 //execute
400#if 0
401 vars = proj->variables(); // should be place so that local variables can be inherited
402#else
403 vars = place;
404#endif
405 vars["ARGS"].clear();
406 for(int i = 0; i < args.count(); i++) {
407 vars["ARGS"] += args[i];
408 vars[QString::number(i+1)] = args[i];
409 }
410 bool ret = ParsableBlock::eval(proj, vars);
411 functionReturn = return_value;
412
413 //restore state
414 calling_place = 0;
415 return_value.clear();
416 vars.clear();
417 return ret;
418}
419
420//loops
421struct IteratorBlock : public ParsableBlock
422{
423 IteratorBlock() : scope_level(1), loop_forever(false), cause_break(false), cause_next(false) { }
424
425 int scope_level;
426
427 struct Test {
428 QString func;
429 QStringList args;
430 bool invert;
431 parser_info pi;
432 Test(const QString &f, QStringList &a, bool i) : func(f), args(a), invert(i) { pi = parser; }
433 };
434 QList<Test> test;
435
436 QString variable;
437
438 bool loop_forever, cause_break, cause_next;
439 QStringList list;
440
441 bool exec(QMakeProject *p, QMap<QString, QStringList> &place);
442 virtual bool continueBlock() { return !cause_next && !cause_break; }
443};
444bool IteratorBlock::exec(QMakeProject *p, QMap<QString, QStringList> &place)
445{
446 bool ret = true;
447 QStringList::Iterator it;
448 if(!loop_forever)
449 it = list.begin();
450 int iterate_count = 0;
451 //save state
452 IteratorBlock *saved_iterator = p->iterator;
453 p->iterator = this;
454
455 //do the loop
456 while(loop_forever || it != list.end()) {
457 cause_next = cause_break = false;
458 if(!loop_forever && (*it).isEmpty()) { //ignore empty items
459 ++it;
460 continue;
461 }
462
463 //set up the loop variable
464 QStringList va;
465 if(!variable.isEmpty()) {
466 va = place[variable];
467 if(loop_forever)
468 place[variable] = QStringList(QString::number(iterate_count));
469 else
470 place[variable] = QStringList(*it);
471 }
472 //do the iterations
473 bool succeed = true;
474 for(QList<Test>::Iterator test_it = test.begin(); test_it != test.end(); ++test_it) {
475 parser = (*test_it).pi;
476 succeed = p->doProjectTest((*test_it).func, (*test_it).args, place);
477 if((*test_it).invert)
478 succeed = !succeed;
479 if(!succeed)
480 break;
481 }
482 if(succeed)
483 ret = ParsableBlock::eval(p, place);
484 //restore the variable in the map
485 if(!variable.isEmpty())
486 place[variable] = va;
487 //loop counters
488 if(!loop_forever)
489 ++it;
490 iterate_count++;
491 if(!ret || cause_break)
492 break;
493 }
494
495 //restore state
496 p->iterator = saved_iterator;
497 return ret;
498}
499
500QMakeProject::ScopeBlock::~ScopeBlock()
501{
502#if 0
503 if(iterate)
504 delete iterate;
505#endif
506}
507
508static void qmake_error_msg(const QString &msg)
509{
510 fprintf(stderr, "%s:%d: %s\n", parser.file.toLatin1().constData(), parser.line_no,
511 msg.toLatin1().constData());
512}
513
514enum isForSymbian_enum {
515 isForSymbian_NOT_SET = -1,
516 isForSymbian_FALSE = 0,
517 isForSymbian_ABLD = 1,
518 isForSymbian_SBSV2 = 2,
519};
520
521static isForSymbian_enum isForSymbian_value = isForSymbian_NOT_SET;
522
523// Checking for symbian build is primarily determined from the qmake spec,
524// but if that is not specified, detect if symbian is the default spec
525// by checking the MAKEFILE_GENERATOR variable value.
526static void init_symbian(const QMap<QString, QStringList>& vars)
527{
528 if (isForSymbian_value != isForSymbian_NOT_SET)
529 return;
530
531 QString spec = QFileInfo(Option::mkfile::qmakespec).fileName();
532 if (spec.startsWith("symbian-abld", Qt::CaseInsensitive)) {
533 isForSymbian_value = isForSymbian_ABLD;
534 } else if (spec.startsWith("symbian-sbsv2", Qt::CaseInsensitive)) {
535 isForSymbian_value = isForSymbian_SBSV2;
536 } else {
537 QStringList generatorList = vars["MAKEFILE_GENERATOR"];
538
539 if (!generatorList.isEmpty()) {
540 QString generator = generatorList.first();
541 if (generator.startsWith("SYMBIAN_ABLD"))
542 isForSymbian_value = isForSymbian_ABLD;
543 else if (generator.startsWith("SYMBIAN_SBSV2"))
544 isForSymbian_value = isForSymbian_SBSV2;
545 else
546 isForSymbian_value = isForSymbian_FALSE;
547 } else {
548 isForSymbian_value = isForSymbian_FALSE;
549 }
550 }
551
552 // Force recursive on Symbian, as non-recursive is not really a viable option there
553 if (isForSymbian_value != isForSymbian_FALSE)
554 Option::recursive = true;
555}
556
557bool isForSymbian()
558{
559 // If isForSymbian_value has not been initialized explicitly yet,
560 // call initializer with dummy map to check qmake spec.
561 if (isForSymbian_value == isForSymbian_NOT_SET)
562 init_symbian(QMap<QString, QStringList>());
563
564 return (isForSymbian_value != isForSymbian_FALSE);
565}
566
567bool isForSymbianSbsv2()
568{
569 // If isForSymbian_value has not been initialized explicitly yet,
570 // call initializer with dummy map to check qmake spec.
571 if (isForSymbian_value == isForSymbian_NOT_SET)
572 init_symbian(QMap<QString, QStringList>());
573
574 return (isForSymbian_value == isForSymbian_SBSV2);
575}
576
577/*
578 1) environment variable QMAKEFEATURES (as separated by colons)
579 2) property variable QMAKEFEATURES (as separated by colons)
580 3) <project_root> (where .qmake.cache lives) + FEATURES_DIR
581 4) environment variable QMAKEPATH (as separated by colons) + /mkspecs/FEATURES_DIR
582 5) your QMAKESPEC/features dir
583 6) your data_install/mkspecs/FEATURES_DIR
584 7) your QMAKESPEC/../FEATURES_DIR dir
585
586 FEATURES_DIR is defined as:
587
588 1) features/(unix|win32|macx)/
589 2) features/
590*/
591QStringList qmake_feature_paths(QMakeProperty *prop=0)
592{
593 QStringList concat;
594 {
595 const QString base_concat = QDir::separator() + QString("features");
596 switch(Option::target_mode) {
597 case Option::TARG_MACX_MODE: //also a unix
598 concat << base_concat + QDir::separator() + "mac";
599 concat << base_concat + QDir::separator() + "macx";
600 concat << base_concat + QDir::separator() + "unix";
601 break;
602 case Option::TARG_UNIX_MODE:
603 {
604 if (isForSymbian())
605 concat << base_concat + QDir::separator() + "symbian";
606 else
607 concat << base_concat + QDir::separator() + "unix";
608 break;
609 }
610 case Option::TARG_WIN_MODE:
611 {
612 if (isForSymbian())
613 concat << base_concat + QDir::separator() + "symbian";
614 else
615 concat << base_concat + QDir::separator() + "win32";
616 break;
617 }
618 case Option::TARG_OS2_MODE:
619 concat << base_concat + QDir::separator() + "os2";
620 break;
621 case Option::TARG_MAC9_MODE:
622 concat << base_concat + QDir::separator() + "mac";
623 concat << base_concat + QDir::separator() + "mac9";
624 break;
625 }
626 concat << base_concat;
627 }
628 const QString mkspecs_concat = QDir::separator() + QString("mkspecs");
629 QStringList feature_roots;
630 QByteArray mkspec_path = qgetenv("QMAKEFEATURES");
631 if(!mkspec_path.isNull())
632 feature_roots += splitPathList(QString::fromLocal8Bit(mkspec_path));
633 if(prop)
634 feature_roots += splitPathList(prop->value("QMAKEFEATURES"));
635 if(!Option::mkfile::cachefile.isEmpty()) {
636 QString path;
637 int last_slash = Option::mkfile::cachefile.lastIndexOf(Option::dir_sep);
638 if(last_slash != -1)
639 path = Option::fixPathToLocalOS(Option::mkfile::cachefile.left(last_slash));
640 for(QStringList::Iterator concat_it = concat.begin();
641 concat_it != concat.end(); ++concat_it)
642 feature_roots << (path + (*concat_it));
643 }
644 QByteArray qmakepath = qgetenv("QMAKEPATH");
645 if (!qmakepath.isNull()) {
646 const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
647 for(QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) {
648 for(QStringList::Iterator concat_it = concat.begin();
649 concat_it != concat.end(); ++concat_it)
650 feature_roots << ((*it) + mkspecs_concat + (*concat_it));
651 }
652 }
653 if(!Option::mkfile::qmakespec.isEmpty())
654 feature_roots << Option::mkfile::qmakespec + QDir::separator() + "features";
655 if(!Option::mkfile::qmakespec.isEmpty()) {
656 QFileInfo specfi(Option::mkfile::qmakespec);
657 QDir specdir(specfi.absoluteFilePath());
658 while(!specdir.isRoot()) {
659 if(!specdir.cdUp() || specdir.isRoot())
660 break;
661 if(QFile::exists(specdir.path() + QDir::separator() + "features")) {
662 for(QStringList::Iterator concat_it = concat.begin();
663 concat_it != concat.end(); ++concat_it)
664 feature_roots << (specdir.path() + (*concat_it));
665 break;
666 }
667 }
668 }
669 for(QStringList::Iterator concat_it = concat.begin();
670 concat_it != concat.end(); ++concat_it)
671 feature_roots << (QLibraryInfo::location(QLibraryInfo::PrefixPath) +
672 mkspecs_concat + (*concat_it));
673 for(QStringList::Iterator concat_it = concat.begin();
674 concat_it != concat.end(); ++concat_it)
675 feature_roots << (QLibraryInfo::location(QLibraryInfo::DataPath) +
676 mkspecs_concat + (*concat_it));
677 return feature_roots;
678}
679
680QStringList qmake_mkspec_paths()
681{
682 QStringList ret;
683 const QString concat = QDir::separator() + QString("mkspecs");
684 QByteArray qmakepath = qgetenv("QMAKEPATH");
685 if (!qmakepath.isEmpty()) {
686 const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
687 for(QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
688 ret << ((*it) + concat);
689 }
690 ret << QLibraryInfo::location(QLibraryInfo::DataPath) + concat;
691
692 return ret;
693}
694
695class QMakeProjectEnv
696{
697 QStringList envs;
698public:
699 QMakeProjectEnv() { }
700 QMakeProjectEnv(QMakeProject *p) { execute(p->variables()); }
701 QMakeProjectEnv(const QMap<QString, QStringList> &values) { execute(values); }
702
703 void execute(QMakeProject *p) { execute(p->variables()); }
704 void execute(const QMap<QString, QStringList> &values) {
705#ifdef Q_OS_UNIX
706 for(QMap<QString, QStringList>::ConstIterator it = values.begin(); it != values.end(); ++it) {
707 const QString var = it.key(), val = it.value().join(" ");
708 if(!var.startsWith(".")) {
709 const QString env_var = Option::sysenv_mod + var;
710 if(!putenv(strdup(QString(env_var + "=" + val).toAscii().data())))
711 envs.append(env_var);
712 }
713 }
714#else
715 Q_UNUSED(values);
716#endif
717 }
718 ~QMakeProjectEnv() {
719#ifdef Q_OS_UNIX
720 for(QStringList::ConstIterator it = envs.begin();it != envs.end(); ++it) {
721 putenv(strdup(QString(*it + "=").toAscii().data()));
722 }
723#endif
724 }
725};
726
727QMakeProject::~QMakeProject()
728{
729 if(own_prop)
730 delete prop;
731 for(QMap<QString, FunctionBlock*>::iterator it = replaceFunctions.begin(); it != replaceFunctions.end(); ++it) {
732 if(!it.value()->deref())
733 delete it.value();
734 }
735 replaceFunctions.clear();
736 for(QMap<QString, FunctionBlock*>::iterator it = testFunctions.begin(); it != testFunctions.end(); ++it) {
737 if(!it.value()->deref())
738 delete it.value();
739 }
740 testFunctions.clear();
741}
742
743
744void
745QMakeProject::init(QMakeProperty *p, const QMap<QString, QStringList> *vars)
746{
747 if(vars)
748 base_vars = *vars;
749 if(!p) {
750 prop = new QMakeProperty;
751 own_prop = true;
752 } else {
753 prop = p;
754 own_prop = false;
755 }
756 reset();
757}
758
759QMakeProject::QMakeProject(QMakeProject *p, const QMap<QString, QStringList> *vars)
760{
761 init(p->properties(), vars ? vars : &p->variables());
762 for(QMap<QString, FunctionBlock*>::iterator it = p->replaceFunctions.begin(); it != p->replaceFunctions.end(); ++it) {
763 it.value()->ref();
764 replaceFunctions.insert(it.key(), it.value());
765 }
766 for(QMap<QString, FunctionBlock*>::iterator it = p->testFunctions.begin(); it != p->testFunctions.end(); ++it) {
767 it.value()->ref();
768 testFunctions.insert(it.key(), it.value());
769 }
770}
771
772void
773QMakeProject::reset()
774{
775 // scope_blocks starts with one non-ignoring entity
776 scope_blocks.clear();
777 scope_blocks.push(ScopeBlock());
778 iterator = 0;
779 function = 0;
780}
781
782bool
783QMakeProject::parse(const QString &t, QMap<QString, QStringList> &place, int numLines)
784{
785 QString s = t.simplified();
786 int hash_mark = s.indexOf("#");
787 if(hash_mark != -1) //good bye comments
788 s = s.left(hash_mark);
789 if(s.isEmpty()) // blank_line
790 return true;
791
792 if(scope_blocks.top().ignore) {
793 bool continue_parsing = false;
794 // adjust scope for each block which appears on a single line
795 for(int i = 0; i < s.length(); i++) {
796 if(s[i] == '{') {
797 scope_blocks.push(ScopeBlock(true));
798 } else if(s[i] == '}') {
799 if(scope_blocks.count() == 1) {
800 fprintf(stderr, "Braces mismatch %s:%d\n", parser.file.toLatin1().constData(), parser.line_no);
801 return false;
802 }
803 ScopeBlock sb = scope_blocks.pop();
804 if(sb.iterate) {
805 sb.iterate->exec(this, place);
806 delete sb.iterate;
807 sb.iterate = 0;
808 }
809 if(!scope_blocks.top().ignore) {
810 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(),
811 parser.line_no, scope_blocks.count()+1);
812 s = s.mid(i+1).trimmed();
813 continue_parsing = !s.isEmpty();
814 break;
815 }
816 }
817 }
818 if(!continue_parsing) {
819 debug_msg(1, "Project Parser: %s:%d : Ignored due to block being false.",
820 parser.file.toLatin1().constData(), parser.line_no);
821 return true;
822 }
823 }
824
825 if(function) {
826 QString append;
827 int d_off = 0;
828 const QChar *d = s.unicode();
829 bool function_finished = false;
830 while(d_off < s.length()) {
831 if(*(d+d_off) == QLatin1Char('}')) {
832 function->scope_level--;
833 if(!function->scope_level) {
834 function_finished = true;
835 break;
836 }
837 } else if(*(d+d_off) == QLatin1Char('{')) {
838 function->scope_level++;
839 }
840 append += *(d+d_off);
841 ++d_off;
842 }
843 if(!append.isEmpty())
844 function->parselist.append(IteratorBlock::Parse(append));
845 if(function_finished) {
846 function = 0;
847 s = QString(d+d_off, s.length()-d_off);
848 } else {
849 return true;
850 }
851 } else if(IteratorBlock *it = scope_blocks.top().iterate) {
852 QString append;
853 int d_off = 0;
854 const QChar *d = s.unicode();
855 bool iterate_finished = false;
856 while(d_off < s.length()) {
857 if(*(d+d_off) == QLatin1Char('}')) {
858 it->scope_level--;
859 if(!it->scope_level) {
860 iterate_finished = true;
861 break;
862 }
863 } else if(*(d+d_off) == QLatin1Char('{')) {
864 it->scope_level++;
865 }
866 append += *(d+d_off);
867 ++d_off;
868 }
869 if(!append.isEmpty())
870 scope_blocks.top().iterate->parselist.append(IteratorBlock::Parse(append));
871 if(iterate_finished) {
872 scope_blocks.top().iterate = 0;
873 bool ret = it->exec(this, place);
874 delete it;
875 if(!ret)
876 return false;
877 s = s.mid(d_off);
878 } else {
879 return true;
880 }
881 }
882
883 QString scope, var, op;
884 QStringList val;
885#define SKIP_WS(d, o, l) while(o < l && (*(d+o) == QLatin1Char(' ') || *(d+o) == QLatin1Char('\t'))) ++o
886 const QChar *d = s.unicode();
887 int d_off = 0;
888 SKIP_WS(d, d_off, s.length());
889 IteratorBlock *iterator = 0;
890 bool scope_failed = false, else_line = false, or_op=false;
891 QChar quote = 0;
892 int parens = 0, scope_count=0, start_block = 0;
893 while(d_off < s.length()) {
894 if(!parens) {
895 if(*(d+d_off) == QLatin1Char('='))
896 break;
897 if(*(d+d_off) == QLatin1Char('+') || *(d+d_off) == QLatin1Char('-') ||
898 *(d+d_off) == QLatin1Char('*') || *(d+d_off) == QLatin1Char('~')) {
899 if(*(d+d_off+1) == QLatin1Char('=')) {
900 break;
901 } else if(*(d+d_off+1) == QLatin1Char(' ')) {
902 const QChar *k = d+d_off+1;
903 int k_off = 0;
904 SKIP_WS(k, k_off, s.length()-d_off);
905 if(*(k+k_off) == QLatin1Char('=')) {
906 QString msg;
907 qmake_error_msg(QString(d+d_off, 1) + "must be followed immediately by =");
908 return false;
909 }
910 }
911 }
912 }
913
914 if(!quote.isNull()) {
915 if(*(d+d_off) == quote)
916 quote = QChar();
917 } else if(*(d+d_off) == '(') {
918 ++parens;
919 } else if(*(d+d_off) == ')') {
920 --parens;
921 } else if(*(d+d_off) == '"' /*|| *(d+d_off) == '\''*/) {
922 quote = *(d+d_off);
923 }
924
925 if(!parens && quote.isNull() &&
926 (*(d+d_off) == QLatin1Char(':') || *(d+d_off) == QLatin1Char('{') ||
927 *(d+d_off) == QLatin1Char(')') || *(d+d_off) == QLatin1Char('|'))) {
928 scope_count++;
929 scope = var.trimmed();
930 if(*(d+d_off) == QLatin1Char(')'))
931 scope += *(d+d_off); // need this
932 var = "";
933
934 bool test = scope_failed;
935 if(scope.isEmpty()) {
936 test = true;
937 } else if(scope.toLower() == "else") { //else is a builtin scope here as it modifies state
938 if(scope_count != 1 || scope_blocks.top().else_status == ScopeBlock::TestNone) {
939 qmake_error_msg(("Unexpected " + scope + " ('" + s + "')").toLatin1());
940 return false;
941 }
942 else_line = true;
943 test = (scope_blocks.top().else_status == ScopeBlock::TestSeek);
944 debug_msg(1, "Project Parser: %s:%d : Else%s %s.", parser.file.toLatin1().constData(), parser.line_no,
945 scope == "else" ? "" : QString(" (" + scope + ")").toLatin1().constData(),
946 test ? "considered" : "excluded");
947 } else {
948 QString comp_scope = scope;
949 bool invert_test = (comp_scope.at(0) == QLatin1Char('!'));
950 if(invert_test)
951 comp_scope = comp_scope.mid(1);
952 int lparen = comp_scope.indexOf('(');
953 if(or_op == scope_failed) {
954 if(lparen != -1) { // if there is an lparen in the scope, it IS a function
955 int rparen = comp_scope.lastIndexOf(')');
956 if(rparen == -1) {
957 qmake_error_msg("Function missing right paren: " + comp_scope);
958 return false;
959 }
960 QString func = comp_scope.left(lparen);
961 QStringList args = split_arg_list(comp_scope.mid(lparen+1, rparen - lparen - 1));
962 if(function) {
963 fprintf(stderr, "%s:%d: No tests can come after a function definition!\n",
964 parser.file.toLatin1().constData(), parser.line_no);
965 return false;
966 } else if(func == "for") { //for is a builtin function here, as it modifies state
967 if(args.count() > 2 || args.count() < 1) {
968 fprintf(stderr, "%s:%d: for(iterate, list) requires two arguments.\n",
969 parser.file.toLatin1().constData(), parser.line_no);
970 return false;
971 } else if(iterator) {
972 fprintf(stderr, "%s:%d unexpected nested for()\n",
973 parser.file.toLatin1().constData(), parser.line_no);
974 return false;
975 }
976
977 iterator = new IteratorBlock;
978 QString it_list;
979 if(args.count() == 1) {
980 doVariableReplace(args[0], place);
981 it_list = args[0];
982 if(args[0] != "ever") {
983 delete iterator;
984 iterator = 0;
985 fprintf(stderr, "%s:%d: for(iterate, list) requires two arguments.\n",
986 parser.file.toLatin1().constData(), parser.line_no);
987 return false;
988 }
989 it_list = "forever";
990 } else if(args.count() == 2) {
991 iterator->variable = args[0];
992 doVariableReplace(args[1], place);
993 it_list = args[1];
994 }
995 QStringList list = place[it_list];
996 if(list.isEmpty()) {
997 if(it_list == "forever") {
998 iterator->loop_forever = true;
999 } else {
1000 int dotdot = it_list.indexOf("..");
1001 if(dotdot != -1) {
1002 bool ok;
1003 int start = it_list.left(dotdot).toInt(&ok);
1004 if(ok) {
1005 int end = it_list.mid(dotdot+2).toInt(&ok);
1006 if(ok) {
1007 if(start < end) {
1008 for(int i = start; i <= end; i++)
1009 list << QString::number(i);
1010 } else {
1011 for(int i = start; i >= end; i--)
1012 list << QString::number(i);
1013 }
1014 }
1015 }
1016 }
1017 }
1018 }
1019 iterator->list = list;
1020 test = !invert_test;
1021 } else if(iterator) {
1022 iterator->test.append(IteratorBlock::Test(func, args, invert_test));
1023 test = !invert_test;
1024 } else if(func == "defineTest" || func == "defineReplace") {
1025 if(!function_blocks.isEmpty()) {
1026 fprintf(stderr,
1027 "%s:%d: cannot define a function within another definition.\n",
1028 parser.file.toLatin1().constData(), parser.line_no);
1029 return false;
1030 }
1031 if(args.count() != 1) {
1032 fprintf(stderr, "%s:%d: %s(function_name) requires one argument.\n",
1033 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
1034 return false;
1035 }
1036 QMap<QString, FunctionBlock*> *map = 0;
1037 if(func == "defineTest")
1038 map = &testFunctions;
1039 else
1040 map = &replaceFunctions;
1041#if 0
1042 if(!map || map->contains(args[0])) {
1043 fprintf(stderr, "%s:%d: Function[%s] multiply defined.\n",
1044 parser.file.toLatin1().constData(), parser.line_no, args[0].toLatin1().constData());
1045 return false;
1046 }
1047#endif
1048 function = new FunctionBlock;
1049 map->insert(args[0], function);
1050 test = true;
1051 } else {
1052 test = doProjectTest(func, args, place);
1053 if(*(d+d_off) == QLatin1Char(')') && d_off == s.length()-1) {
1054 if(invert_test)
1055 test = !test;
1056 scope_blocks.top().else_status =
1057 (test ? ScopeBlock::TestFound : ScopeBlock::TestSeek);
1058 return true; // assume we are done
1059 }
1060 }
1061 } else {
1062 QString cscope = comp_scope.trimmed();
1063 doVariableReplace(cscope, place);
1064 test = isActiveConfig(cscope.trimmed(), true, &place);
1065 }
1066 if(invert_test)
1067 test = !test;
1068 }
1069 }
1070 if(!test && !scope_failed)
1071 debug_msg(1, "Project Parser: %s:%d : Test (%s) failed.", parser.file.toLatin1().constData(),
1072 parser.line_no, scope.toLatin1().constData());
1073 if(test == or_op)
1074 scope_failed = !test;
1075 or_op = (*(d+d_off) == QLatin1Char('|'));
1076
1077 if(*(d+d_off) == QLatin1Char('{')) { // scoping block
1078 start_block++;
1079 if(iterator) {
1080 for(int off = 0, braces = 0; true; ++off) {
1081 if(*(d+d_off+off) == QLatin1Char('{'))
1082 ++braces;
1083 else if(*(d+d_off+off) == QLatin1Char('}') && braces)
1084 --braces;
1085 if(!braces || d_off+off == s.length()) {
1086 iterator->parselist.append(s.mid(d_off, off-1));
1087 if(braces > 1)
1088 iterator->scope_level += braces-1;
1089 d_off += off-1;
1090 break;
1091 }
1092 }
1093 }
1094 }
1095 } else if(!parens && *(d+d_off) == QLatin1Char('}')) {
1096 if(start_block) {
1097 --start_block;
1098 } else if(!scope_blocks.count()) {
1099 warn_msg(WarnParser, "Possible braces mismatch %s:%d", parser.file.toLatin1().constData(), parser.line_no);
1100 } else {
1101 if(scope_blocks.count() == 1) {
1102 fprintf(stderr, "Braces mismatch %s:%d\n", parser.file.toLatin1().constData(), parser.line_no);
1103 return false;
1104 }
1105 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(),
1106 parser.line_no, scope_blocks.count());
1107 ScopeBlock sb = scope_blocks.pop();
1108 if(sb.iterate)
1109 sb.iterate->exec(this, place);
1110 }
1111 } else {
1112 var += *(d+d_off);
1113 }
1114 ++d_off;
1115 }
1116 var = var.trimmed();
1117
1118 if(!else_line || (else_line && !scope_failed))
1119 scope_blocks.top().else_status = (!scope_failed ? ScopeBlock::TestFound : ScopeBlock::TestSeek);
1120 if(start_block) {
1121 ScopeBlock next_block(scope_failed);
1122 next_block.iterate = iterator;
1123 if(iterator)
1124 next_block.else_status = ScopeBlock::TestNone;
1125 else if(scope_failed)
1126 next_block.else_status = ScopeBlock::TestSeek;
1127 else
1128 next_block.else_status = ScopeBlock::TestFound;
1129 scope_blocks.push(next_block);
1130 debug_msg(1, "Project Parser: %s:%d : Entering block %d (%d). [%s]", parser.file.toLatin1().constData(),
1131 parser.line_no, scope_blocks.count(), scope_failed, s.toLatin1().constData());
1132 } else if(iterator) {
1133 iterator->parselist.append(var+s.mid(d_off));
1134 bool ret = iterator->exec(this, place);
1135 delete iterator;
1136 return ret;
1137 }
1138
1139 if((!scope_count && !var.isEmpty()) || (scope_count == 1 && else_line))
1140 scope_blocks.top().else_status = ScopeBlock::TestNone;
1141 if(d_off == s.length()) {
1142 if(!var.trimmed().isEmpty())
1143 qmake_error_msg(("Parse Error ('" + s + "')").toLatin1());
1144 return var.isEmpty(); // allow just a scope
1145 }
1146
1147 SKIP_WS(d, d_off, s.length());
1148 for(; d_off < s.length() && op.indexOf('=') == -1; op += *(d+(d_off++)))
1149 ;
1150 op.replace(QRegExp("\\s"), "");
1151
1152 SKIP_WS(d, d_off, s.length());
1153 QString vals = s.mid(d_off); // vals now contains the space separated list of values
1154 int rbraces = vals.count('}'), lbraces = vals.count('{');
1155 if(scope_blocks.count() > 1 && rbraces - lbraces == 1) {
1156 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(),
1157 parser.line_no, scope_blocks.count());
1158 ScopeBlock sb = scope_blocks.pop();
1159 if(sb.iterate)
1160 sb.iterate->exec(this, place);
1161 vals.truncate(vals.length()-1);
1162 } else if(rbraces != lbraces) {
1163 warn_msg(WarnParser, "Possible braces mismatch {%s} %s:%d",
1164 vals.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no);
1165 }
1166 if(scope_failed)
1167 return true; // oh well
1168#undef SKIP_WS
1169
1170 doVariableReplace(var, place);
1171 var = varMap(var); //backwards compatability
1172 if(!var.isEmpty() && Option::mkfile::do_preprocess) {
1173 static QString last_file("*none*");
1174 if(parser.file != last_file) {
1175 fprintf(stdout, "#file %s:%d\n", parser.file.toLatin1().constData(), parser.line_no);
1176 last_file = parser.file;
1177 }
1178 fprintf(stdout, "%s %s %s\n", var.toLatin1().constData(), op.toLatin1().constData(), vals.toLatin1().constData());
1179 }
1180
1181 if(vals.contains('=') && numLines > 1)
1182 warn_msg(WarnParser, "Detected possible line continuation: {%s} %s:%d",
1183 var.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no);
1184
1185 QStringList &varlist = place[var]; // varlist is the list in the symbol table
1186
1187 if(Option::debug_level >= 1) {
1188 QString tmp_vals = vals;
1189 doVariableReplace(tmp_vals, place);
1190 debug_msg(1, "Project Parser: %s:%d :%s: :%s: (%s)", parser.file.toLatin1().constData(), parser.line_no,
1191 var.toLatin1().constData(), op.toLatin1().constData(), tmp_vals.toLatin1().constData());
1192 }
1193
1194 // now do the operation
1195 if(op == "~=") {
1196 doVariableReplace(vals, place);
1197 if(vals.length() < 4 || vals.at(0) != 's') {
1198 qmake_error_msg(("~= operator only can handle s/// function ('" +
1199 s + "')").toLatin1());
1200 return false;
1201 }
1202 QChar sep = vals.at(1);
1203 QStringList func = vals.split(sep);
1204 if(func.count() < 3 || func.count() > 4) {
1205 qmake_error_msg(("~= operator only can handle s/// function ('" +
1206 s + "')").toLatin1());
1207 return false;
1208 }
1209 bool global = false, case_sense = true, quote = false;
1210 if(func.count() == 4) {
1211 global = func[3].indexOf('g') != -1;
1212 case_sense = func[3].indexOf('i') == -1;
1213 quote = func[3].indexOf('q') != -1;
1214 }
1215 QString from = func[1], to = func[2];
1216 if(quote)
1217 from = QRegExp::escape(from);
1218 QRegExp regexp(from, case_sense ? Qt::CaseSensitive : Qt::CaseInsensitive);
1219 for(QStringList::Iterator varit = varlist.begin(); varit != varlist.end();) {
1220 if((*varit).contains(regexp)) {
1221 (*varit) = (*varit).replace(regexp, to);
1222 if ((*varit).isEmpty())
1223 varit = varlist.erase(varit);
1224 else
1225 ++varit;
1226 if(!global)
1227 break;
1228 } else
1229 ++varit;
1230 }
1231 } else {
1232 QStringList vallist;
1233 {
1234 //doVariableReplace(vals, place);
1235 QStringList tmp = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH"));
1236 for(int i = 0; i < tmp.size(); ++i)
1237 vallist += doVariableReplaceExpand(tmp[i], place);
1238 }
1239
1240 if(op == "=") {
1241 if(!varlist.isEmpty()) {
1242 bool send_warning = false;
1243 if(var != "TEMPLATE" && var != "TARGET") {
1244 QSet<QString> incoming_vals = vallist.toSet();
1245 for(int i = 0; i < varlist.size(); ++i) {
1246 const QString var = varlist.at(i).trimmed();
1247 if(!var.isEmpty() && !incoming_vals.contains(var)) {
1248 send_warning = true;
1249 break;
1250 }
1251 }
1252 }
1253 if(send_warning)
1254 warn_msg(WarnParser, "Operator=(%s) clears variables previously set: %s:%d",
1255 var.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no);
1256 }
1257 varlist.clear();
1258 }
1259 for(QStringList::ConstIterator valit = vallist.begin();
1260 valit != vallist.end(); ++valit) {
1261 if((*valit).isEmpty())
1262 continue;
1263 if((op == "*=" && !varlist.contains((*valit))) ||
1264 op == "=" || op == "+=")
1265 varlist.append((*valit));
1266 else if(op == "-=")
1267 varlist.removeAll((*valit));
1268 }
1269 if(var == "REQUIRES") // special case to get communicated to backends!
1270 doProjectCheckReqs(vallist, place);
1271 }
1272 return true;
1273}
1274
1275bool
1276QMakeProject::read(QTextStream &file, QMap<QString, QStringList> &place)
1277{
1278 int numLines = 0;
1279 bool ret = true;
1280 QString s;
1281 while(!file.atEnd()) {
1282 parser.line_no++;
1283 QString line = file.readLine().trimmed();
1284 int prelen = line.length();
1285
1286 int hash_mark = line.indexOf("#");
1287 if(hash_mark != -1) //good bye comments
1288 line = line.left(hash_mark).trimmed();
1289 if(!line.isEmpty() && line.right(1) == "\\") {
1290 if(!line.startsWith("#")) {
1291 line.truncate(line.length() - 1);
1292 s += line + Option::field_sep;
1293 ++numLines;
1294 }
1295 } else if(!line.isEmpty() || (line.isEmpty() && !prelen)) {
1296 if(s.isEmpty() && line.isEmpty())
1297 continue;
1298 if(!line.isEmpty()) {
1299 s += line;
1300 ++numLines;
1301 }
1302 if(!s.isEmpty()) {
1303 if(!(ret = parse(s, place, numLines))) {
1304 s = "";
1305 numLines = 0;
1306 break;
1307 }
1308 s = "";
1309 numLines = 0;
1310 }
1311 }
1312 }
1313 if (!s.isEmpty())
1314 ret = parse(s, place, numLines);
1315 return ret;
1316}
1317
1318bool
1319QMakeProject::read(const QString &file, QMap<QString, QStringList> &place)
1320{
1321 parser_info pi = parser;
1322 reset();
1323
1324 const QString oldpwd = qmake_getpwd();
1325 QString filename = Option::fixPathToLocalOS(file);
1326 doVariableReplace(filename, place);
1327 bool ret = false, using_stdin = false;
1328 QFile qfile;
1329 if(!strcmp(filename.toLatin1(), "-")) {
1330 qfile.setFileName("");
1331 ret = qfile.open(stdin, QIODevice::ReadOnly);
1332 using_stdin = true;
1333 } else if(QFileInfo(file).isDir()) {
1334 return false;
1335 } else {
1336 qfile.setFileName(filename);
1337 ret = qfile.open(QIODevice::ReadOnly);
1338 qmake_setpwd(QFileInfo(filename).absolutePath());
1339 }
1340 if(ret) {
1341 parser_info pi = parser;
1342 parser.from_file = true;
1343 parser.file = filename;
1344 parser.line_no = 0;
1345 QTextStream t(&qfile);
1346 ret = read(t, place);
1347 if(!using_stdin)
1348 qfile.close();
1349 }
1350 if(scope_blocks.count() != 1) {
1351 qmake_error_msg("Unterminated conditional block at end of file");
1352 ret = false;
1353 }
1354 parser = pi;
1355 qmake_setpwd(oldpwd);
1356 return ret;
1357}
1358
1359bool
1360QMakeProject::read(const QString &project, uchar cmd)
1361{
1362 pfile = QFileInfo(project).absoluteFilePath();
1363 return read(cmd);
1364}
1365
1366bool
1367QMakeProject::read(uchar cmd)
1368{
1369 if(cfile.isEmpty()) {
1370 //find out where qmake (myself) lives
1371 if (!base_vars.contains("QMAKE_QMAKE")) {
1372 if (!Option::qmake_abslocation.isNull())
1373 base_vars["QMAKE_QMAKE"] = QStringList(Option::qmake_abslocation);
1374 else
1375 base_vars["QMAKE_QMAKE"] = QStringList("qmake");
1376 }
1377
1378 // hack to get the Option stuff in there
1379 base_vars["QMAKE_EXT_OBJ"] = QStringList(Option::obj_ext);
1380 base_vars["QMAKE_EXT_CPP"] = Option::cpp_ext;
1381 base_vars["QMAKE_EXT_C"] = Option::c_ext;
1382 base_vars["QMAKE_EXT_H"] = Option::h_ext;
1383 base_vars["QMAKE_SH"] = Option::shellPath;
1384 if(!Option::user_template_prefix.isEmpty())
1385 base_vars["TEMPLATE_PREFIX"] = QStringList(Option::user_template_prefix);
1386
1387 if(cmd & ReadCache && Option::mkfile::do_cache) { // parse the cache
1388 int cache_depth = -1;
1389 QString qmake_cache = Option::mkfile::cachefile;
1390 if(qmake_cache.isEmpty()) { //find it as it has not been specified
1391 QString dir = QDir::toNativeSeparators(Option::output_dir);
1392 while(!QFile::exists((qmake_cache = dir + QDir::separator() + ".qmake.cache"))) {
1393 dir = dir.left(dir.lastIndexOf(QDir::separator()));
1394 if(dir.isEmpty() || dir.indexOf(QDir::separator()) == -1) {
1395 qmake_cache = "";
1396 break;
1397 }
1398 if(cache_depth == -1)
1399 cache_depth = 1;
1400 else
1401 cache_depth++;
1402 }
1403 } else {
1404 QString abs_cache = QFileInfo(Option::mkfile::cachefile).absoluteDir().path();
1405 if(Option::output_dir.startsWith(abs_cache))
1406 cache_depth = Option::output_dir.mid(abs_cache.length()).count('/');
1407 }
1408 if(!qmake_cache.isEmpty()) {
1409 if(read(qmake_cache, cache)) {
1410 Option::mkfile::cachefile_depth = cache_depth;
1411 Option::mkfile::cachefile = qmake_cache;
1412 if(Option::mkfile::qmakespec.isEmpty() && !cache["QMAKESPEC"].isEmpty())
1413 Option::mkfile::qmakespec = cache["QMAKESPEC"].first();
1414 }
1415 }
1416 }
1417 if(cmd & ReadConf) { // parse mkspec
1418 QString qmakespec = fixEnvVariables(Option::mkfile::qmakespec);
1419 QStringList mkspec_roots = qmake_mkspec_paths();
1420 debug_msg(2, "Looking for mkspec %s in (%s)", qmakespec.toLatin1().constData(),
1421 mkspec_roots.join("::").toLatin1().constData());
1422 if(qmakespec.isEmpty()) {
1423 for(QStringList::ConstIterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) {
1424 QString mkspec = (*it) + QDir::separator() + "default";
1425 QFileInfo default_info(mkspec);
1426 if(default_info.exists() && default_info.isDir()) {
1427 qmakespec = mkspec;
1428 break;
1429 }
1430 }
1431 if(qmakespec.isEmpty()) {
1432 fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n");
1433 return false;
1434 }
1435 Option::mkfile::qmakespec = qmakespec;
1436 }
1437
1438 if(QDir::isRelativePath(qmakespec)) {
1439 if (QFile::exists(qmakespec+"/qmake.conf")) {
1440 Option::mkfile::qmakespec = QFileInfo(Option::mkfile::qmakespec).absoluteFilePath();
1441 } else if (QFile::exists(Option::output_dir+"/"+qmakespec+"/qmake.conf")) {
1442 qmakespec = Option::mkfile::qmakespec = QFileInfo(Option::output_dir+"/"+qmakespec).absoluteFilePath();
1443 } else {
1444 bool found_mkspec = false;
1445 for(QStringList::ConstIterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) {
1446 QString mkspec = (*it) + QDir::separator() + qmakespec;
1447 if(QFile::exists(mkspec)) {
1448 found_mkspec = true;
1449 Option::mkfile::qmakespec = qmakespec = mkspec;
1450 break;
1451 }
1452 }
1453 if(!found_mkspec) {
1454 fprintf(stderr, "Could not find mkspecs for your QMAKESPEC(%s) after trying:\n\t%s\n",
1455 qmakespec.toLatin1().constData(), mkspec_roots.join("\n\t").toLatin1().constData());
1456 return false;
1457 }
1458 }
1459 }
1460
1461 // parse qmake configuration
1462 while(qmakespec.endsWith(QString(QChar(QDir::separator()))))
1463 qmakespec.truncate(qmakespec.length()-1);
1464 QString spec = qmakespec + QDir::separator() + "qmake.conf";
1465 if(!QFile::exists(spec) &&
1466 QFile::exists(qmakespec + QDir::separator() + "tmake.conf"))
1467 spec = qmakespec + QDir::separator() + "tmake.conf";
1468 debug_msg(1, "QMAKESPEC conf: reading %s", spec.toLatin1().constData());
1469 if(!read(spec, base_vars)) {
1470 fprintf(stderr, "Failure to read QMAKESPEC conf file %s.\n", spec.toLatin1().constData());
1471 return false;
1472 }
1473
1474 init_symbian(base_vars);
1475
1476 if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) {
1477 debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.toLatin1().constData());
1478 read(Option::mkfile::cachefile, base_vars);
1479 }
1480 }
1481
1482 if(cmd & ReadFeatures) {
1483 debug_msg(1, "Processing default_pre: %s", vars["CONFIG"].join("::").toLatin1().constData());
1484 if(doProjectInclude("default_pre", IncludeFlagFeature, base_vars) == IncludeNoExist)
1485 doProjectInclude("default", IncludeFlagFeature, base_vars);
1486 }
1487 }
1488
1489 vars = base_vars; // start with the base
1490
1491 //get a default
1492 if(pfile != "-" && vars["TARGET"].isEmpty())
1493 vars["TARGET"].append(QFileInfo(pfile).baseName());
1494
1495 //before commandline
1496 if(cmd & ReadCmdLine) {
1497 cfile = pfile;
1498 parser.file = "(internal)";
1499 parser.from_file = false;
1500 parser.line_no = 1; //really arg count now.. duh
1501 reset();
1502 for(QStringList::ConstIterator it = Option::before_user_vars.begin();
1503 it != Option::before_user_vars.end(); ++it) {
1504 if(!parse((*it), vars)) {
1505 fprintf(stderr, "Argument failed to parse: %s\n", (*it).toLatin1().constData());
1506 return false;
1507 }
1508 parser.line_no++;
1509 }
1510 }
1511
1512 //commandline configs
1513 if(cmd & ReadConfigs && !Option::user_configs.isEmpty()) {
1514 parser.file = "(configs)";
1515 parser.from_file = false;
1516 parser.line_no = 1; //really arg count now.. duh
1517 parse("CONFIG += " + Option::user_configs.join(" "), vars);
1518 }
1519
1520 if(cmd & ReadProFile) { // parse project file
1521 debug_msg(1, "Project file: reading %s", pfile.toLatin1().constData());
1522 if(pfile != "-" && !QFile::exists(pfile) && !pfile.endsWith(Option::pro_ext))
1523 pfile += Option::pro_ext;
1524 if(!read(pfile, vars))
1525 return false;
1526 }
1527
1528 if(cmd & ReadPostFiles) { // parse post files
1529 const QStringList l = vars["QMAKE_POST_INCLUDE_FILES"];
1530 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
1531 if(read((*it), vars)) {
1532 if(vars["QMAKE_INTERNAL_INCLUDED_FILES"].indexOf((*it)) == -1)
1533 vars["QMAKE_INTERNAL_INCLUDED_FILES"].append((*it));
1534 }
1535 }
1536 }
1537
1538 if(cmd & ReadCmdLine) {
1539 parser.file = "(internal)";
1540 parser.from_file = false;
1541 parser.line_no = 1; //really arg count now.. duh
1542 reset();
1543 for(QStringList::ConstIterator it = Option::after_user_vars.begin();
1544 it != Option::after_user_vars.end(); ++it) {
1545 if(!parse((*it), vars)) {
1546 fprintf(stderr, "Argument failed to parse: %s\n", (*it).toLatin1().constData());
1547 return false;
1548 }
1549 parser.line_no++;
1550 }
1551 }
1552
1553 //after configs (set in BUILDS)
1554 if(cmd & ReadConfigs && !Option::after_user_configs.isEmpty()) {
1555 parser.file = "(configs)";
1556 parser.from_file = false;
1557 parser.line_no = 1; //really arg count now.. duh
1558 parse("CONFIG += " + Option::after_user_configs.join(" "), vars);
1559 }
1560
1561 if(pfile != "-" && vars["TARGET"].isEmpty())
1562 vars["TARGET"].append(QFileInfo(pfile).baseName());
1563
1564 if(cmd & ReadConfigs && !Option::user_configs.isEmpty()) {
1565 parser.file = "(configs)";
1566 parser.from_file = false;
1567 parser.line_no = 1; //really arg count now.. duh
1568 parse("CONFIG += " + Option::user_configs.join(" "), base_vars);
1569 }
1570
1571 if(cmd & ReadFeatures) {
1572 debug_msg(1, "Processing default_post: %s", vars["CONFIG"].join("::").toLatin1().constData());
1573 doProjectInclude("default_post", IncludeFlagFeature, vars);
1574
1575 QHash<QString, bool> processed;
1576 const QStringList &configs = vars["CONFIG"];
1577 debug_msg(1, "Processing CONFIG features: %s", configs.join("::").toLatin1().constData());
1578 while(1) {
1579 bool finished = true;
1580 for(int i = configs.size()-1; i >= 0; --i) {
1581 const QString config = configs[i].toLower();
1582 if(!processed.contains(config)) {
1583 processed.insert(config, true);
1584 if(doProjectInclude(config, IncludeFlagFeature, vars) == IncludeSuccess) {
1585 finished = false;
1586 break;
1587 }
1588 }
1589 }
1590 if(finished)
1591 break;
1592 }
1593 }
1594 Option::postProcessProject(this); // let Option post-process
1595 return true;
1596}
1597
1598bool
1599QMakeProject::isActiveConfig(const QString &x, bool regex, QMap<QString, QStringList> *place)
1600{
1601 if(x.isEmpty())
1602 return true;
1603
1604 //magic types for easy flipping
1605 if(x == "true")
1606 return true;
1607 else if(x == "false")
1608 return false;
1609
1610 static QString spec;
1611 if(spec.isEmpty())
1612 spec = QFileInfo(Option::mkfile::qmakespec).fileName();
1613
1614 // Symbian is an exception to how scopes are resolved. Since we do not
1615 // have a separate target mode for Symbian, but we expect the scope to resolve
1616 // on other platforms we base it entirely on the mkspec. This means that
1617 // using a mkspec starting with 'symbian*' will resolve both the 'symbian'
1618 // and the 'unix' (because of Open C) scopes to true.
1619 if(isForSymbian() && (x == "symbian" || x == "unix"))
1620 return true;
1621
1622 //mkspecs
1623 if((Option::target_mode == Option::TARG_MACX_MODE ||
1624 Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix")
1625 return !isForSymbian();
1626 else if(Option::target_mode == Option::TARG_MACX_MODE && x == "macx")
1627 return !isForSymbian();
1628 else if(Option::target_mode == Option::TARG_MAC9_MODE && x == "mac9")
1629 return !isForSymbian();
1630 else if((Option::target_mode == Option::TARG_MAC9_MODE || Option::target_mode == Option::TARG_MACX_MODE) &&
1631 x == "mac")
1632 return !isForSymbian();
1633 else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32")
1634 return !isForSymbian();
1635 else if(Option::target_mode == Option::TARG_OS2_MODE && x == "os2")
1636 return true;
1637 QRegExp re(x, Qt::CaseSensitive, QRegExp::Wildcard);
1638 if((regex && re.exactMatch(spec)) || (!regex && spec == x))
1639 return true;
1640#ifdef Q_OS_UNIX
1641 else if(spec == "default") {
1642 static char *buffer = NULL;
1643 if(!buffer) {
1644 buffer = (char *)malloc(1024);
1645 qmakeAddCacheClear(qmakeFreeCacheClear, (void**)&buffer);
1646 }
1647 int l = readlink(Option::mkfile::qmakespec.toLatin1(), buffer, 1024);
1648 if(l != -1) {
1649 buffer[l] = '\0';
1650 QString r = buffer;
1651 if(r.lastIndexOf('/') != -1)
1652 r = r.mid(r.lastIndexOf('/') + 1);
1653 if((regex && re.exactMatch(r)) || (!regex && r == x))
1654 return true;
1655 }
1656 }
1657#elif defined(Q_OS_WIN) || defined(Q_OS_OS2)
1658 else if(spec == "default") {
1659 // We can't resolve symlinks as they do on Unix, so configure.exe puts the source of the
1660 // qmake.conf at the end of the default/qmake.conf in the QMAKESPEC_ORG variable.
1661 const QStringList &spec_org = (place ? (*place)["QMAKESPEC_ORIGINAL"]
1662 : vars["QMAKESPEC_ORIGINAL"]);
1663 if (!spec_org.isEmpty()) {
1664 spec = QFileInfo(spec_org.at(0)).fileName();
1665 if((regex && re.exactMatch(spec)) || (!regex && spec == x))
1666 return true;
1667 }
1668 }
1669#endif
1670
1671 //simple matching
1672 const QStringList &configs = (place ? (*place)["CONFIG"] : vars["CONFIG"]);
1673 for(QStringList::ConstIterator it = configs.begin(); it != configs.end(); ++it) {
1674 if(((regex && re.exactMatch((*it))) || (!regex && (*it) == x)) && re.exactMatch((*it)))
1675 return true;
1676 }
1677 return false;
1678}
1679
1680bool
1681QMakeProject::doProjectTest(QString str, QMap<QString, QStringList> &place)
1682{
1683 QString chk = remove_quotes(str);
1684 if(chk.isEmpty())
1685 return true;
1686 bool invert_test = (chk.left(1) == "!");
1687 if(invert_test)
1688 chk = chk.mid(1);
1689
1690 bool test=false;
1691 int lparen = chk.indexOf('(');
1692 if(lparen != -1) { // if there is an lparen in the chk, it IS a function
1693 int rparen = chk.indexOf(')', lparen);
1694 if(rparen == -1) {
1695 qmake_error_msg("Function missing right paren: " + chk);
1696 } else {
1697 QString func = chk.left(lparen);
1698 test = doProjectTest(func, chk.mid(lparen+1, rparen - lparen - 1), place);
1699 }
1700 } else {
1701 test = isActiveConfig(chk, true, &place);
1702 }
1703 if(invert_test)
1704 return !test;
1705 return test;
1706}
1707
1708bool
1709QMakeProject::doProjectTest(QString func, const QString &params,
1710 QMap<QString, QStringList> &place)
1711{
1712 return doProjectTest(func, split_arg_list(params), place);
1713}
1714
1715QMakeProject::IncludeStatus
1716QMakeProject::doProjectInclude(QString file, uchar flags, QMap<QString, QStringList> &place)
1717{
1718 enum { UnknownFormat, ProFormat, JSFormat } format = UnknownFormat;
1719 if(flags & IncludeFlagFeature) {
1720 if(!file.endsWith(Option::prf_ext))
1721 file += Option::prf_ext;
1722 if(file.indexOf(Option::dir_sep) == -1 || !QFile::exists(file)) {
1723 static QStringList *feature_roots = 0;
1724 if(!feature_roots) {
1725 init_symbian(base_vars);
1726 feature_roots = new QStringList(qmake_feature_paths(prop));
1727 qmakeAddCacheClear(qmakeDeleteCacheClear_QStringList, (void**)&feature_roots);
1728 }
1729 debug_msg(2, "Looking for feature '%s' in (%s)", file.toLatin1().constData(),
1730 feature_roots->join("::").toLatin1().constData());
1731 int start_root = 0;
1732 if(parser.from_file) {
1733 QFileInfo currFile(parser.file), prfFile(file);
1734 if(currFile.fileName() == prfFile.fileName()) {
1735 currFile = QFileInfo(currFile.canonicalFilePath());
1736 for(int root = 0; root < feature_roots->size(); ++root) {
1737 prfFile = QFileInfo(feature_roots->at(root) +
1738 QDir::separator() + file).canonicalFilePath();
1739 if(prfFile == currFile) {
1740 start_root = root+1;
1741 break;
1742 }
1743 }
1744 }
1745 }
1746 for(int root = start_root; root < feature_roots->size(); ++root) {
1747 QString prf(feature_roots->at(root) + QDir::separator() + file);
1748 if(QFile::exists(prf + Option::js_ext)) {
1749 format = JSFormat;
1750 file = prf + Option::js_ext;
1751 break;
1752 } else if(QFile::exists(prf)) {
1753 format = ProFormat;
1754 file = prf;
1755 break;
1756 }
1757 }
1758 if(format == UnknownFormat)
1759 return IncludeNoExist;
1760 if(place["QMAKE_INTERNAL_INCLUDED_FEATURES"].indexOf(file) != -1)
1761 return IncludeFeatureAlreadyLoaded;
1762 place["QMAKE_INTERNAL_INCLUDED_FEATURES"].append(file);
1763 }
1764 }
1765 if(QDir::isRelativePath(file)) {
1766 QStringList include_roots;
1767 if(Option::output_dir != qmake_getpwd())
1768 include_roots << qmake_getpwd();
1769 include_roots << Option::output_dir;
1770 for(int root = 0; root < include_roots.size(); ++root) {
1771 QString testName = QDir::toNativeSeparators(include_roots[root]);
1772 if (!testName.endsWith(QString(QDir::separator())))
1773 testName += QDir::separator();
1774 testName += file;
1775 if(QFile::exists(testName)) {
1776 file = testName;
1777 break;
1778 }
1779 }
1780 }
1781 if(format == UnknownFormat) {
1782 if(QFile::exists(file)) {
1783 if(file.endsWith(Option::js_ext))
1784 format = JSFormat;
1785 else
1786 format = ProFormat;
1787 } else {
1788 return IncludeNoExist;
1789 }
1790 }
1791 if(Option::mkfile::do_preprocess) //nice to see this first..
1792 fprintf(stderr, "#switching file %s(%s) - %s:%d\n", (flags & IncludeFlagFeature) ? "load" : "include",
1793 file.toLatin1().constData(),
1794 parser.file.toLatin1().constData(), parser.line_no);
1795 debug_msg(1, "Project Parser: %s'ing file %s.", (flags & IncludeFlagFeature) ? "load" : "include",
1796 file.toLatin1().constData());
1797
1798 QString orig_file = file;
1799 int di = file.lastIndexOf(QDir::separator());
1800 QString oldpwd = qmake_getpwd();
1801 if(di != -1) {
1802 if(!qmake_setpwd(file.left(file.lastIndexOf(QDir::separator())))) {
1803 fprintf(stderr, "Cannot find directory: %s\n", file.left(di).toLatin1().constData());
1804 return IncludeFailure;
1805 }
1806 file = file.right(file.length() - di - 1);
1807 }
1808 bool parsed = false;
1809 parser_info pi = parser;
1810 if(format == JSFormat) {
1811 warn_msg(WarnParser, "%s:%d: QtScript support disabled for %s.",
1812 pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData());
1813 } else {
1814 QStack<ScopeBlock> sc = scope_blocks;
1815 IteratorBlock *it = iterator;
1816 FunctionBlock *fu = function;
1817 if(flags & (IncludeFlagNewProject|IncludeFlagNewParser)) {
1818 // The "project's variables" are used in other places (eg. export()) so it's not
1819 // possible to use "place" everywhere. Instead just set variables and grab them later
1820 QMakeProject proj(this, &place);
1821 if(flags & IncludeFlagNewParser) {
1822#if 1
1823 if(proj.doProjectInclude("default_pre", IncludeFlagFeature, proj.variables()) == IncludeNoExist)
1824 proj.doProjectInclude("default", IncludeFlagFeature, proj.variables());
1825#endif
1826 parsed = proj.read(file, proj.variables());
1827 } else {
1828 parsed = proj.read(file);
1829 }
1830 place = proj.variables();
1831 } else {
1832 parsed = read(file, place);
1833 }
1834 iterator = it;
1835 function = fu;
1836 scope_blocks = sc;
1837 }
1838 if(parsed) {
1839 if(place["QMAKE_INTERNAL_INCLUDED_FILES"].indexOf(orig_file) == -1)
1840 place["QMAKE_INTERNAL_INCLUDED_FILES"].append(orig_file);
1841 } else {
1842 warn_msg(WarnParser, "%s:%d: Failure to include file %s.",
1843 pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData());
1844 }
1845 parser = pi;
1846 qmake_setpwd(oldpwd);
1847 if(!parsed)
1848 return IncludeParseFailure;
1849 return IncludeSuccess;
1850}
1851
1852QStringList
1853QMakeProject::doProjectExpand(QString func, const QString &params,
1854 QMap<QString, QStringList> &place)
1855{
1856 return doProjectExpand(func, split_arg_list(params), place);
1857}
1858
1859QStringList
1860QMakeProject::doProjectExpand(QString func, QStringList args,
1861 QMap<QString, QStringList> &place)
1862{
1863 QList<QStringList> args_list;
1864 for(int i = 0; i < args.size(); ++i) {
1865 QStringList arg = split_value_list(args[i]), tmp;
1866 for(int i = 0; i < arg.size(); ++i)
1867 tmp += doVariableReplaceExpand(arg[i], place);;
1868 args_list += tmp;
1869 }
1870 return doProjectExpand(func, args_list, place);
1871}
1872
1873// defined in symbian generator
1874extern QString generate_test_uid(const QString& target);
1875
1876QStringList
1877QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
1878 QMap<QString, QStringList> &place)
1879{
1880 func = func.trimmed();
1881 if(replaceFunctions.contains(func)) {
1882 FunctionBlock *defined = replaceFunctions[func];
1883 function_blocks.push(defined);
1884 QStringList ret;
1885 defined->exec(args_list, this, place, ret);
1886 FunctionBlock *popped = function_blocks.pop();
1887 Q_ASSERT(popped == defined);
1888 Q_UNUSED(popped);
1889 return ret;
1890 }
1891
1892 QStringList args; //why don't the builtin functions just use args_list? --Sam
1893 for(int i = 0; i < args_list.size(); ++i)
1894 args += args_list[i].join(QString(Option::field_sep));
1895
1896 ExpandFunc func_t = qmake_expandFunctions().value(func.toLower());
1897 debug_msg(1, "Running project expand: %s(%s) [%d]",
1898 func.toLatin1().constData(), args.join("::").toLatin1().constData(), func_t);
1899
1900 QStringList ret;
1901 switch(func_t) {
1902 case E_MEMBER: {
1903 if(args.count() < 1 || args.count() > 3) {
1904 fprintf(stderr, "%s:%d: member(var, start, end) requires three arguments.\n",
1905 parser.file.toLatin1().constData(), parser.line_no);
1906 } else {
1907 bool ok = true;
1908 const QStringList &var = values(args.first(), place);
1909 int start = 0, end = 0;
1910 if(args.count() >= 2) {
1911 QString start_str = args[1];
1912 start = start_str.toInt(&ok);
1913 if(!ok) {
1914 if(args.count() == 2) {
1915 int dotdot = start_str.indexOf("..");
1916 if(dotdot != -1) {
1917 start = start_str.left(dotdot).toInt(&ok);
1918 if(ok)
1919 end = start_str.mid(dotdot+2).toInt(&ok);
1920 }
1921 }
1922 if(!ok)
1923 fprintf(stderr, "%s:%d: member() argument 2 (start) '%s' invalid.\n",
1924 parser.file.toLatin1().constData(), parser.line_no,
1925 start_str.toLatin1().constData());
1926 } else {
1927 end = start;
1928 if(args.count() == 3)
1929 end = args[2].toInt(&ok);
1930 if(!ok)
1931 fprintf(stderr, "%s:%d: member() argument 3 (end) '%s' invalid.\n",
1932 parser.file.toLatin1().constData(), parser.line_no,
1933 args[2].toLatin1().constData());
1934 }
1935 }
1936 if(ok) {
1937 if(start < 0)
1938 start += var.count();
1939 if(end < 0)
1940 end += var.count();
1941 if(start < 0 || start >= var.count() || end < 0 || end >= var.count()) {
1942 //nothing
1943 } else if(start < end) {
1944 for(int i = start; i <= end && (int)var.count() >= i; i++)
1945 ret += var[i];
1946 } else {
1947 for(int i = start; i >= end && (int)var.count() >= i && i >= 0; i--)
1948 ret += var[i];
1949 }
1950 }
1951 }
1952 break; }
1953 case E_FIRST:
1954 case E_LAST: {
1955 if(args.count() != 1) {
1956 fprintf(stderr, "%s:%d: %s(var) requires one argument.\n",
1957 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
1958 } else {
1959 const QStringList &var = values(args.first(), place);
1960 if(!var.isEmpty()) {
1961 if(func_t == E_FIRST)
1962 ret = QStringList(var[0]);
1963 else
1964 ret = QStringList(var[var.size()-1]);
1965 }
1966 }
1967 break; }
1968 case E_CAT: {
1969 if(args.count() < 1 || args.count() > 2) {
1970 fprintf(stderr, "%s:%d: cat(file) requires one argument.\n",
1971 parser.file.toLatin1().constData(), parser.line_no);
1972 } else {
1973 QString file = args[0];
1974 file = Option::fixPathToLocalOS(file);
1975
1976 bool singleLine = true;
1977 if(args.count() > 1)
1978 singleLine = (args[1].toLower() == "true");
1979
1980 QFile qfile(file);
1981 if(qfile.open(QIODevice::ReadOnly)) {
1982 QTextStream stream(&qfile);
1983 while(!stream.atEnd()) {
1984 ret += split_value_list(stream.readLine().trimmed());
1985 if(!singleLine)
1986 ret += "\n";
1987 }
1988 qfile.close();
1989 }
1990 }
1991 break; }
1992 case E_FROMFILE: {
1993 if(args.count() != 2) {
1994 fprintf(stderr, "%s:%d: fromfile(file, variable) requires two arguments.\n",
1995 parser.file.toLatin1().constData(), parser.line_no);
1996 } else {
1997 QString file = args[0], seek_var = args[1];
1998 file = Option::fixPathToLocalOS(file);
1999
2000 QMap<QString, QStringList> tmp;
2001 if(doProjectInclude(file, IncludeFlagNewParser, tmp) == IncludeSuccess) {
2002 if(tmp.contains("QMAKE_INTERNAL_INCLUDED_FILES")) {
2003 QStringList &out = place["QMAKE_INTERNAL_INCLUDED_FILES"];
2004 const QStringList &in = tmp["QMAKE_INTERNAL_INCLUDED_FILES"];
2005 for(int i = 0; i < in.size(); ++i) {
2006 if(out.indexOf(in[i]) == -1)
2007 out += in[i];
2008 }
2009 }
2010 ret = tmp[seek_var];
2011 }
2012 }
2013 break; }
2014 case E_EVAL: {
2015 if(args.count() < 1 || args.count() > 2) {
2016 fprintf(stderr, "%s:%d: eval(variable) requires one argument.\n",
2017 parser.file.toLatin1().constData(), parser.line_no);
2018
2019 } else {
2020 const QMap<QString, QStringList> *source = &place;
2021 if(args.count() == 2) {
2022 if(args.at(1) == "Global") {
2023 source = &vars;
2024 } else if(args.at(1) == "Local") {
2025 source = &place;
2026 } else {
2027 fprintf(stderr, "%s:%d: unexpected source to eval.\n", parser.file.toLatin1().constData(),
2028 parser.line_no);
2029 }
2030 }
2031 ret += source->value(args.at(0));
2032 }
2033 break; }
2034 case E_LIST: {
2035 static int x = 0;
2036 QString tmp;
2037 tmp.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++);
2038 ret = QStringList(tmp);
2039 QStringList &lst = (*((QMap<QString, QStringList>*)&place))[tmp];
2040 lst.clear();
2041 for(QStringList::ConstIterator arg_it = args.begin();
2042 arg_it != args.end(); ++arg_it)
2043 lst += split_value_list((*arg_it));
2044 break; }
2045 case E_SPRINTF: {
2046 if(args.count() < 1) {
2047 fprintf(stderr, "%s:%d: sprintf(format, ...) requires one argument.\n",
2048 parser.file.toLatin1().constData(), parser.line_no);
2049 } else {
2050 QString tmp = args.at(0);
2051 for(int i = 1; i < args.count(); ++i)
2052 tmp = tmp.arg(args.at(i));
2053 ret = split_value_list(tmp);
2054 }
2055 break; }
2056 case E_JOIN: {
2057 if(args.count() < 1 || args.count() > 4) {
2058 fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four"
2059 "arguments.\n", parser.file.toLatin1().constData(), parser.line_no);
2060 } else {
2061 QString glue, before, after;
2062 if(args.count() >= 2)
2063 glue = args[1];
2064 if(args.count() >= 3)
2065 before = args[2];
2066 if(args.count() == 4)
2067 after = args[3];
2068 const QStringList &var = values(args.first(), place);
2069 if(!var.isEmpty())
2070 ret = split_value_list(before + var.join(glue) + after);
2071 }
2072 break; }
2073 case E_SPLIT: {
2074 if(args.count() < 1 || args.count() > 2) {
2075 fprintf(stderr, "%s:%d split(var, sep) requires one or two arguments\n",
2076 parser.file.toLatin1().constData(), parser.line_no);
2077 } else {
2078 QString sep = QString(Option::field_sep);
2079 if(args.count() >= 2)
2080 sep = args[1];
2081 QStringList var = values(args.first(), place);
2082 for(QStringList::ConstIterator vit = var.begin(); vit != var.end(); ++vit) {
2083 QStringList lst = (*vit).split(sep);
2084 for(QStringList::ConstIterator spltit = lst.begin(); spltit != lst.end(); ++spltit)
2085 ret += (*spltit);
2086 }
2087 }
2088 break; }
2089 case E_BASENAME:
2090 case E_DIRNAME:
2091 case E_SECTION: {
2092 bool regexp = false;
2093 QString sep, var;
2094 int beg=0, end=-1;
2095 if(func_t == E_SECTION) {
2096 if(args.count() != 3 && args.count() != 4) {
2097 fprintf(stderr, "%s:%d section(var, sep, begin, end) requires three argument\n",
2098 parser.file.toLatin1().constData(), parser.line_no);
2099 } else {
2100 var = args[0];
2101 sep = args[1];
2102 beg = args[2].toInt();
2103 if(args.count() == 4)
2104 end = args[3].toInt();
2105 }
2106 } else {
2107 if(args.count() != 1) {
2108 fprintf(stderr, "%s:%d %s(var) requires one argument.\n",
2109 parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData());
2110 } else {
2111 var = args[0];
2112 regexp = true;
2113 sep = "[" + QRegExp::escape(Option::dir_sep) + "/]";
2114 if(func_t == E_DIRNAME)
2115 end = -2;
2116 else
2117 beg = -1;
2118 }
2119 }
2120 if(!var.isNull()) {
2121 const QStringList &l = values(var, place);
2122 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
2123 QString separator = sep;
2124 if(regexp)
2125 ret += (*it).section(QRegExp(separator), beg, end);
2126 else
2127 ret += (*it).section(separator, beg, end);
2128 }
2129 }
2130 break; }
2131 case E_FIND: {
2132 if(args.count() != 2) {
2133 fprintf(stderr, "%s:%d find(var, str) requires two arguments\n",
2134 parser.file.toLatin1().constData(), parser.line_no);
2135 } else {
2136 QRegExp regx(args[1]);
2137 const QStringList &var = values(args.first(), place);
2138 for(QStringList::ConstIterator vit = var.begin();
2139 vit != var.end(); ++vit) {
2140 if(regx.indexIn(*vit) != -1)
2141 ret += (*vit);
2142 }
2143 }
2144 break; }
2145 case E_SYSTEM: {
2146 if(args.count() < 1 || args.count() > 2) {
2147 fprintf(stderr, "%s:%d system(execut) requires one argument.\n",
2148 parser.file.toLatin1().constData(), parser.line_no);
2149 } else {
2150 QMakeProjectEnv env(place);
2151 char buff[256];
2152 bool singleLine = true;
2153 if(args.count() > 1)
2154 singleLine = (args[1].toLower() == "true");
2155 QString output;
2156 FILE *proc = QT_POPEN(args[0].toLatin1(), "r");
2157 while(proc && !feof(proc)) {
2158 int read_in = int(fread(buff, 1, 255, proc));
2159 if(!read_in)
2160 break;
2161 for(int i = 0; i < read_in; i++) {
2162 if((singleLine && buff[i] == '\n') || buff[i] == '\t')
2163 buff[i] = ' ';
2164 }
2165 buff[read_in] = '\0';
2166 output += buff;
2167 }
2168 ret += split_value_list(output);
2169 if(proc)
2170 QT_PCLOSE(proc);
2171 }
2172 break; }
2173 case E_UNIQUE: {
2174 if(args.count() != 1) {
2175 fprintf(stderr, "%s:%d unique(var) requires one argument.\n",
2176 parser.file.toLatin1().constData(), parser.line_no);
2177 } else {
2178 const QStringList &var = values(args.first(), place);
2179 for(int i = 0; i < var.count(); i++) {
2180 if(!ret.contains(var[i]))
2181 ret.append(var[i]);
2182 }
2183 }
2184 break; }
2185 case E_QUOTE:
2186 ret = args;
2187 break;
2188 case E_ESCAPE_EXPAND: {
2189 for(int i = 0; i < args.size(); ++i) {
2190 QChar *i_data = args[i].data();
2191 int i_len = args[i].length();
2192 for(int x = 0; x < i_len; ++x) {
2193 if(*(i_data+x) == '\\' && x < i_len-1) {
2194 if(*(i_data+x+1) == '\\') {
2195 ++x;
2196 } else {
2197 struct {
2198 char in, out;
2199 } mapped_quotes[] = {
2200 { 'n', '\n' },
2201 { 't', '\t' },
2202 { 'r', '\r' },
2203 { 0, 0 }
2204 };
2205 for(int i = 0; mapped_quotes[i].in; ++i) {
2206 if(*(i_data+x+1) == mapped_quotes[i].in) {
2207 *(i_data+x) = mapped_quotes[i].out;
2208 if(x < i_len-2)
2209 memmove(i_data+x+1, i_data+x+2, (i_len-x-2)*sizeof(QChar));
2210 --i_len;
2211 break;
2212 }
2213 }
2214 }
2215 }
2216 }
2217 ret.append(QString(i_data, i_len));
2218 }
2219 break; }
2220 case E_RE_ESCAPE: {
2221 for(int i = 0; i < args.size(); ++i)
2222 ret += QRegExp::escape(args[i]);
2223 break; }
2224 case E_UPPER:
2225 case E_LOWER: {
2226 for(int i = 0; i < args.size(); ++i) {
2227 if(func_t == E_UPPER)
2228 ret += args[i].toUpper();
2229 else
2230 ret += args[i].toLower();
2231 }
2232 break; }
2233 case E_FILES: {
2234 if(args.count() != 1 && args.count() != 2) {
2235 fprintf(stderr, "%s:%d files(pattern) requires one argument.\n",
2236 parser.file.toLatin1().constData(), parser.line_no);
2237 } else {
2238 bool recursive = false;
2239 if(args.count() == 2)
2240 recursive = (args[1].toLower() == "true" || args[1].toInt());
2241 QStringList dirs;
2242 QString r = Option::fixPathToLocalOS(args[0]);
2243 int slash = r.lastIndexOf(QDir::separator());
2244 if(slash != -1) {
2245 dirs.append(r.left(slash));
2246 r = r.mid(slash+1);
2247 } else {
2248 dirs.append("");
2249 }
2250
2251 const QRegExp regex(r, Qt::CaseSensitive, QRegExp::Wildcard);
2252 for(int d = 0; d < dirs.count(); d++) {
2253 QString dir = dirs[d];
2254 if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep))
2255 dir += "/";
2256
2257 QDir qdir(dir);
2258 for(int i = 0; i < (int)qdir.count(); ++i) {
2259 if(qdir[i] == "." || qdir[i] == "..")
2260 continue;
2261 QString fname = dir + qdir[i];
2262 if(QFileInfo(fname).isDir()) {
2263 if(recursive)
2264 dirs.append(fname);
2265 }
2266 if(regex.exactMatch(qdir[i]))
2267 ret += fname;
2268 }
2269 }
2270 }
2271 break; }
2272 case E_PROMPT: {
2273 if(args.count() != 1) {
2274 fprintf(stderr, "%s:%d prompt(question) requires one argument.\n",
2275 parser.file.toLatin1().constData(), parser.line_no);
2276 } else if(projectFile() == "-") {
2277 fprintf(stderr, "%s:%d prompt(question) cannot be used when '-o -' is used.\n",
2278 parser.file.toLatin1().constData(), parser.line_no);
2279 } else {
2280 QString msg = fixEnvVariables(args.first());
2281 if(!msg.endsWith("?"))
2282 msg += "?";
2283 fprintf(stderr, "Project %s: %s ", func.toUpper().toLatin1().constData(),
2284 msg.toLatin1().constData());
2285
2286 QFile qfile;
2287 if(qfile.open(stdin, QIODevice::ReadOnly)) {
2288 QTextStream t(&qfile);
2289 ret = split_value_list(t.readLine());
2290 }
2291 }
2292 break; }
2293 case E_REPLACE: {
2294 if(args.count() != 3 ) {
2295 fprintf(stderr, "%s:%d replace(var, before, after) requires three arguments\n",
2296 parser.file.toLatin1().constData(), parser.line_no);
2297 } else {
2298 const QRegExp before( args[1] );
2299 const QString after( args[2] );
2300 QStringList var = values(args.first(), place);
2301 for(QStringList::Iterator it = var.begin(); it != var.end(); ++it)
2302 ret += it->replace(before, after);
2303 }
2304 break; }
2305 case E_SIZE: {
2306 if(args.count() != 1) {
2307 fprintf(stderr, "%s:%d: size(var) requires one argument.\n",
2308 parser.file.toLatin1().constData(), parser.line_no);
2309 } else {
2310 //QString target = args[0];
2311 int size = values(args[0]).size();
2312 ret += QString::number(size);
2313 }
2314 break; }
2315 case E_GENERATE_UID:
2316 if (args.count() != 1) {
2317 fprintf(stderr, "%s:%d: generate_uid(var) requires one argument.\n",
2318 parser.file.toLatin1().constData(), parser.line_no);
2319 } else {
2320 ret += generate_test_uid(args.first());
2321 }
2322 break;
2323 default: {
2324 fprintf(stderr, "%s:%d: Unknown replace function: %s\n",
2325 parser.file.toLatin1().constData(), parser.line_no,
2326 func.toLatin1().constData());
2327 break; }
2328 }
2329 return ret;
2330}
2331
2332bool
2333QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStringList> &place)
2334{
2335 QList<QStringList> args_list;
2336 for(int i = 0; i < args.size(); ++i) {
2337 QStringList arg = split_value_list(args[i]), tmp;
2338 for(int i = 0; i < arg.size(); ++i)
2339 tmp += doVariableReplaceExpand(arg[i], place);
2340 args_list += tmp;
2341 }
2342 return doProjectTest(func, args_list, place);
2343}
2344
2345bool
2346QMakeProject::doProjectTest(QString func, QList<QStringList> args_list, QMap<QString, QStringList> &place)
2347{
2348 func = func.trimmed();
2349
2350 if(testFunctions.contains(func)) {
2351 FunctionBlock *defined = testFunctions[func];
2352 QStringList ret;
2353 function_blocks.push(defined);
2354 defined->exec(args_list, this, place, ret);
2355 FunctionBlock *popped = function_blocks.pop();
2356 Q_ASSERT(popped == defined);
2357 Q_UNUSED(popped);
2358
2359 if(ret.isEmpty()) {
2360 return true;
2361 } else {
2362 if(ret.first() == "true") {
2363 return true;
2364 } else if(ret.first() == "false") {
2365 return false;
2366 } else {
2367 bool ok;
2368 int val = ret.first().toInt(&ok);
2369 if(ok)
2370 return val;
2371 fprintf(stderr, "%s:%d Unexpected return value from test %s [%s].\n",
2372 parser.file.toLatin1().constData(),
2373 parser.line_no, func.toLatin1().constData(),
2374 ret.join("::").toLatin1().constData());
2375 }
2376 return false;
2377 }
2378 return false;
2379 }
2380
2381 QStringList args; //why don't the builtin functions just use args_list? --Sam
2382 for(int i = 0; i < args_list.size(); ++i)
2383 args += args_list[i].join(QString(Option::field_sep));
2384
2385 TestFunc func_t = qmake_testFunctions().value(func);
2386 debug_msg(1, "Running project test: %s(%s) [%d]",
2387 func.toLatin1().constData(), args.join("::").toLatin1().constData(), func_t);
2388
2389 switch(func_t) {
2390 case T_REQUIRES:
2391 return doProjectCheckReqs(args, place);
2392 case T_LESSTHAN:
2393 case T_GREATERTHAN: {
2394 if(args.count() != 2) {
2395 fprintf(stderr, "%s:%d: %s(variable, value) requires two arguments.\n", parser.file.toLatin1().constData(),
2396 parser.line_no, func.toLatin1().constData());
2397 return false;
2398 }
2399 QString rhs(args[1]), lhs(values(args[0], place).join(QString(Option::field_sep)));
2400 bool ok;
2401 int rhs_int = rhs.toInt(&ok);
2402 if(ok) { // do integer compare
2403 int lhs_int = lhs.toInt(&ok);
2404 if(ok) {
2405 if(func_t == T_GREATERTHAN)
2406 return lhs_int > rhs_int;
2407 return lhs_int < rhs_int;
2408 }
2409 }
2410 if(func_t == T_GREATERTHAN)
2411 return lhs > rhs;
2412 return lhs < rhs; }
2413 case T_IF: {
2414 if(args.count() != 1) {
2415 fprintf(stderr, "%s:%d: if(condition) requires one argument.\n", parser.file.toLatin1().constData(),
2416 parser.line_no);
2417 return false;
2418 }
2419 const QString cond = args.first();
2420 const QChar *d = cond.unicode();
2421 QChar quote = 0;
2422 bool ret = true, or_op = false;
2423 QString test;
2424 for(int d_off = 0, parens = 0, d_len = cond.size(); d_off < d_len; ++d_off) {
2425 if(!quote.isNull()) {
2426 if(*(d+d_off) == quote)
2427 quote = QChar();
2428 } else if(*(d+d_off) == '(') {
2429 ++parens;
2430 } else if(*(d+d_off) == ')') {
2431 --parens;
2432 } else if(*(d+d_off) == '"' /*|| *(d+d_off) == '\''*/) {
2433 quote = *(d+d_off);
2434 }
2435 if(!parens && quote.isNull() && (*(d+d_off) == QLatin1Char(':') || *(d+d_off) == QLatin1Char('|') || d_off == d_len-1)) {
2436 if(d_off == d_len-1)
2437 test += *(d+d_off);
2438 if(!test.isEmpty()) {
2439 const bool success = doProjectTest(test, place);
2440 test = "";
2441 if(or_op)
2442 ret = ret || success;
2443 else
2444 ret = ret && success;
2445 }
2446 if(*(d+d_off) == QLatin1Char(':')) {
2447 or_op = false;
2448 } else if(*(d+d_off) == QLatin1Char('|')) {
2449 or_op = true;
2450 }
2451 } else {
2452 test += *(d+d_off);
2453 }
2454 }
2455 return ret; }
2456 case T_EQUALS:
2457 if(args.count() != 2) {
2458 fprintf(stderr, "%s:%d: %s(variable, value) requires two arguments.\n", parser.file.toLatin1().constData(),
2459 parser.line_no, func.toLatin1().constData());
2460 return false;
2461 }
2462 return values(args[0], place).join(QString(Option::field_sep)) == args[1];
2463 case T_EXISTS: {
2464 if(args.count() != 1) {
2465 fprintf(stderr, "%s:%d: exists(file) requires one argument.\n", parser.file.toLatin1().constData(),
2466 parser.line_no);
2467 return false;
2468 }
2469 QString file = args.first();
2470 file = Option::fixPathToLocalOS(file);
2471
2472 if(QFile::exists(file))
2473 return true;
2474 //regular expression I guess
2475 QString dirstr = qmake_getpwd();
2476 int slsh = file.lastIndexOf(Option::dir_sep);
2477 if(slsh != -1) {
2478 dirstr = file.left(slsh+1);
2479 file = file.right(file.length() - slsh - 1);
2480 }
2481 return QDir(dirstr).entryList(QStringList(file)).count(); }
2482 case T_EXPORT:
2483 if(args.count() != 1) {
2484 fprintf(stderr, "%s:%d: export(variable) requires one argument.\n", parser.file.toLatin1().constData(),
2485 parser.line_no);
2486 return false;
2487 }
2488 for(int i = 0; i < function_blocks.size(); ++i) {
2489 FunctionBlock *f = function_blocks.at(i);
2490 f->vars[args[0]] = values(args[0], place);
2491 if(!i && f->calling_place)
2492 (*f->calling_place)[args[0]] = values(args[0], place);
2493 }
2494 return true;
2495 case T_CLEAR:
2496 if(args.count() != 1) {
2497 fprintf(stderr, "%s:%d: clear(variable) requires one argument.\n", parser.file.toLatin1().constData(),
2498 parser.line_no);
2499 return false;
2500 }
2501 if(!place.contains(args[0]))
2502 return false;
2503 place[args[0]].clear();
2504 return true;
2505 case T_UNSET:
2506 if(args.count() != 1) {
2507 fprintf(stderr, "%s:%d: unset(variable) requires one argument.\n", parser.file.toLatin1().constData(),
2508 parser.line_no);
2509 return false;
2510 }
2511 if(!place.contains(args[0]))
2512 return false;
2513 place.remove(args[0]);
2514 return true;
2515 case T_EVAL: {
2516 if(args.count() < 1 && 0) {
2517 fprintf(stderr, "%s:%d: eval(project) requires one argument.\n", parser.file.toLatin1().constData(),
2518 parser.line_no);
2519 return false;
2520 }
2521 QString project = args.join(" ");
2522 parser_info pi = parser;
2523 parser.from_file = false;
2524 parser.file = "(eval)";
2525 parser.line_no = 0;
2526 QTextStream t(&project, QIODevice::ReadOnly);
2527 bool ret = read(t, place);
2528 parser = pi;
2529 return ret; }
2530 case T_CONFIG: {
2531 if(args.count() < 1 || args.count() > 2) {
2532 fprintf(stderr, "%s:%d: CONFIG(config) requires one argument.\n", parser.file.toLatin1().constData(),
2533 parser.line_no);
2534 return false;
2535 }
2536 if(args.count() == 1)
2537 return isActiveConfig(args[0]);
2538 const QStringList mutuals = args[1].split('|');
2539 const QStringList &configs = values("CONFIG", place);
2540 for(int i = configs.size()-1; i >= 0; i--) {
2541 for(int mut = 0; mut < mutuals.count(); mut++) {
2542 if(configs[i] == mutuals[mut].trimmed())
2543 return (configs[i] == args[0]);
2544 }
2545 }
2546 return false; }
2547 case T_SYSTEM: {
2548 bool setup_env = true;
2549 if(args.count() < 1 || args.count() > 2) {
2550 fprintf(stderr, "%s:%d: system(exec) requires one argument.\n", parser.file.toLatin1().constData(),
2551 parser.line_no);
2552 return false;
2553 }
2554 if(args.count() == 2) {
2555 const QString sarg = args[1];
2556 setup_env = (sarg.toLower() == "true" || sarg.toInt());
2557 }
2558 QMakeProjectEnv env;
2559 if(setup_env)
2560 env.execute(place);
2561 bool ret = system(args[0].toLatin1().constData()) == 0;
2562 return ret; }
2563 case T_RETURN:
2564 if(function_blocks.isEmpty()) {
2565 fprintf(stderr, "%s:%d unexpected return()\n",
2566 parser.file.toLatin1().constData(), parser.line_no);
2567 } else {
2568 FunctionBlock *f = function_blocks.top();
2569 f->cause_return = true;
2570 if(args_list.count() >= 1)
2571 f->return_value += args_list[0];
2572 }
2573 return true;
2574 case T_BREAK:
2575 if(iterator)
2576 iterator->cause_break = true;
2577 else if(!scope_blocks.isEmpty())
2578 scope_blocks.top().ignore = true;
2579 else
2580 fprintf(stderr, "%s:%d unexpected break()\n",
2581 parser.file.toLatin1().constData(), parser.line_no);
2582 return true;
2583 case T_NEXT:
2584 if(iterator)
2585 iterator->cause_next = true;
2586 else
2587 fprintf(stderr, "%s:%d unexpected next()\n",
2588 parser.file.toLatin1().constData(), parser.line_no);
2589 return true;
2590 case T_DEFINED:
2591 if(args.count() < 1 || args.count() > 2) {
2592 fprintf(stderr, "%s:%d: defined(function) requires one argument.\n",
2593 parser.file.toLatin1().constData(), parser.line_no);
2594 } else {
2595 if(args.count() > 1) {
2596 if(args[1] == "test")
2597 return testFunctions.contains(args[0]);
2598 else if(args[1] == "replace")
2599 return replaceFunctions.contains(args[0]);
2600 fprintf(stderr, "%s:%d: defined(function, type): unexpected type [%s].\n",
2601 parser.file.toLatin1().constData(), parser.line_no,
2602 args[1].toLatin1().constData());
2603 } else {
2604 if(replaceFunctions.contains(args[0]) || testFunctions.contains(args[0]))
2605 return true;
2606 }
2607 }
2608 return false;
2609 case T_CONTAINS: {
2610 if(args.count() < 2 || args.count() > 3) {
2611 fprintf(stderr, "%s:%d: contains(var, val) requires at lesat 2 arguments.\n",
2612 parser.file.toLatin1().constData(), parser.line_no);
2613 return false;
2614 }
2615 QRegExp regx(args[1]);
2616 const QStringList &l = values(args[0], place);
2617 if(args.count() == 2) {
2618 for(int i = 0; i < l.size(); ++i) {
2619 const QString val = l[i];
2620 if(regx.exactMatch(val) || val == args[1])
2621 return true;
2622 }
2623 } else {
2624 const QStringList mutuals = args[2].split('|');
2625 for(int i = l.size()-1; i >= 0; i--) {
2626 const QString val = l[i];
2627 for(int mut = 0; mut < mutuals.count(); mut++) {
2628 if(val == mutuals[mut].trimmed())
2629 return (regx.exactMatch(val) || val == args[1]);
2630 }
2631 }
2632 }
2633 return false; }
2634 case T_INFILE: {
2635 if(args.count() < 2 || args.count() > 3) {
2636 fprintf(stderr, "%s:%d: infile(file, var, val) requires at least 2 arguments.\n",
2637 parser.file.toLatin1().constData(), parser.line_no);
2638 return false;
2639 }
2640
2641 bool ret = false;
2642 QMap<QString, QStringList> tmp;
2643 if(doProjectInclude(Option::fixPathToLocalOS(args[0]), IncludeFlagNewParser, tmp) == IncludeSuccess) {
2644 if(tmp.contains("QMAKE_INTERNAL_INCLUDED_FILES")) {
2645 QStringList &out = place["QMAKE_INTERNAL_INCLUDED_FILES"];
2646 const QStringList &in = tmp["QMAKE_INTERNAL_INCLUDED_FILES"];
2647 for(int i = 0; i < in.size(); ++i) {
2648 if(out.indexOf(in[i]) == -1)
2649 out += in[i];
2650 }
2651 }
2652 if(args.count() == 2) {
2653 ret = tmp.contains(args[1]);
2654 } else {
2655 QRegExp regx(args[2]);
2656 const QStringList &l = tmp[args[1]];
2657 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
2658 if(regx.exactMatch((*it)) || (*it) == args[2]) {
2659 ret = true;
2660 break;
2661 }
2662 }
2663 }
2664 }
2665 return ret; }
2666 case T_COUNT:
2667 if(args.count() != 2 && args.count() != 3) {
2668 fprintf(stderr, "%s:%d: count(var, count) requires two arguments.\n", parser.file.toLatin1().constData(),
2669 parser.line_no);
2670 return false;
2671 }
2672 if(args.count() == 3) {
2673 QString comp = args[2];
2674 if(comp == ">" || comp == "greaterThan")
2675 return values(args[0], place).count() > args[1].toInt();
2676 if(comp == ">=")
2677 return values(args[0], place).count() >= args[1].toInt();
2678 if(comp == "<" || comp == "lessThan")
2679 return values(args[0], place).count() < args[1].toInt();
2680 if(comp == "<=")
2681 return values(args[0], place).count() <= args[1].toInt();
2682 if(comp == "equals" || comp == "isEqual" || comp == "=" || comp == "==")
2683 return values(args[0], place).count() == args[1].toInt();
2684 fprintf(stderr, "%s:%d: unexpected modifier to count(%s)\n", parser.file.toLatin1().constData(),
2685 parser.line_no, comp.toLatin1().constData());
2686 return false;
2687 }
2688 return values(args[0], place).count() == args[1].toInt();
2689 case T_ISEMPTY:
2690 if(args.count() != 1) {
2691 fprintf(stderr, "%s:%d: isEmpty(var) requires one argument.\n", parser.file.toLatin1().constData(),
2692 parser.line_no);
2693 return false;
2694 }
2695 return values(args[0], place).isEmpty();
2696 case T_INCLUDE:
2697 case T_LOAD: {
2698 QString parseInto;
2699 const bool include_statement = (func_t == T_INCLUDE);
2700 bool ignore_error = false;
2701 if(args.count() >= 2) {
2702 if(func_t == T_INCLUDE) {
2703 parseInto = args[1];
2704 if (args.count() == 3){
2705 QString sarg = args[2];
2706 if (sarg.toLower() == "true" || sarg.toInt())
2707 ignore_error = true;
2708 }
2709 } else {
2710 QString sarg = args[1];
2711 ignore_error = (sarg.toLower() == "true" || sarg.toInt());
2712 }
2713 } else if(args.count() != 1) {
2714 QString func_desc = "load(feature)";
2715 if(include_statement)
2716 func_desc = "include(file)";
2717 fprintf(stderr, "%s:%d: %s requires one argument.\n", parser.file.toLatin1().constData(),
2718 parser.line_no, func_desc.toLatin1().constData());
2719 return false;
2720 }
2721 QString file = args.first();
2722 file = Option::fixPathToLocalOS(file);
2723 uchar flags = IncludeFlagNone;
2724 if(!include_statement)
2725 flags |= IncludeFlagFeature;
2726 IncludeStatus stat = IncludeFailure;
2727 if(!parseInto.isEmpty()) {
2728 QMap<QString, QStringList> symbols;
2729 stat = doProjectInclude(file, flags|IncludeFlagNewProject, symbols);
2730 if(stat == IncludeSuccess) {
2731 QMap<QString, QStringList> out_place;
2732 for(QMap<QString, QStringList>::ConstIterator it = place.begin(); it != place.end(); ++it) {
2733 const QString var = it.key();
2734 if(var != parseInto && !var.startsWith(parseInto + "."))
2735 out_place.insert(var, it.value());
2736 }
2737 for(QMap<QString, QStringList>::ConstIterator it = symbols.begin(); it != symbols.end(); ++it) {
2738 const QString var = it.key();
2739 if(!var.startsWith("."))
2740 out_place.insert(parseInto + "." + it.key(), it.value());
2741 }
2742 place = out_place;
2743 }
2744 } else {
2745 stat = doProjectInclude(file, flags, place);
2746 }
2747 if(stat == IncludeFeatureAlreadyLoaded) {
2748 warn_msg(WarnParser, "%s:%d: Duplicate of loaded feature %s",
2749 parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData());
2750 } else if(stat == IncludeNoExist && !ignore_error) {
2751 warn_msg(WarnAll, "%s:%d: Unable to find file for inclusion %s",
2752 parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData());
2753 return false;
2754 } else if(stat >= IncludeFailure) {
2755 if(!ignore_error) {
2756 printf("Project LOAD(): Feature %s cannot be found.\n", file.toLatin1().constData());
2757 if (!ignore_error)
2758#if defined(QT_BUILD_QMAKE_LIBRARY)
2759 return false;
2760#else
2761 exit(3);
2762#endif
2763 }
2764 return false;
2765 }
2766 return true; }
2767 case T_DEBUG: {
2768 if(args.count() != 2) {
2769 fprintf(stderr, "%s:%d: debug(level, message) requires one argument.\n", parser.file.toLatin1().constData(),
2770 parser.line_no);
2771 return false;
2772 }
2773 QString msg = fixEnvVariables(args[1]);
2774 debug_msg(args[0].toInt(), "Project DEBUG: %s", msg.toLatin1().constData());
2775 return true; }
2776 case T_ERROR:
2777 case T_MESSAGE:
2778 case T_WARNING: {
2779 if(args.count() != 1) {
2780 fprintf(stderr, "%s:%d: %s(message) requires one argument.\n", parser.file.toLatin1().constData(),
2781 parser.line_no, func.toLatin1().constData());
2782 return false;
2783 }
2784 QString msg = fixEnvVariables(args.first());
2785 fprintf(stderr, "Project %s: %s\n", func.toUpper().toLatin1().constData(), msg.toLatin1().constData());
2786 if(func == "error")
2787#if defined(QT_BUILD_QMAKE_LIBRARY)
2788 return false;
2789#else
2790 exit(2);
2791#endif
2792 return true; }
2793 default:
2794 fprintf(stderr, "%s:%d: Unknown test function: %s\n", parser.file.toLatin1().constData(), parser.line_no,
2795 func.toLatin1().constData());
2796 }
2797 return false;
2798}
2799
2800bool
2801QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringList> &place)
2802{
2803 bool ret = false;
2804 for(QStringList::ConstIterator it = deps.begin(); it != deps.end(); ++it) {
2805 bool test = doProjectTest((*it), place);
2806 if(!test) {
2807 debug_msg(1, "Project Parser: %s:%d Failed test: REQUIRES = %s",
2808 parser.file.toLatin1().constData(), parser.line_no,
2809 (*it).toLatin1().constData());
2810 place["QMAKE_FAILED_REQUIREMENTS"].append((*it));
2811 ret = false;
2812 }
2813 }
2814 return ret;
2815}
2816
2817bool
2818QMakeProject::test(const QString &v)
2819{
2820 QMap<QString, QStringList> tmp = vars;
2821 return doProjectTest(v, tmp);
2822}
2823
2824bool
2825QMakeProject::test(const QString &func, const QList<QStringList> &args)
2826{
2827 QMap<QString, QStringList> tmp = vars;
2828 return doProjectTest(func, args, tmp);
2829}
2830
2831QStringList
2832QMakeProject::expand(const QString &str)
2833{
2834 bool ok;
2835 QMap<QString, QStringList> tmp = vars;
2836 const QStringList ret = doVariableReplaceExpand(str, tmp, &ok);
2837 if(ok)
2838 return ret;
2839 return QStringList();
2840}
2841
2842QStringList
2843QMakeProject::expand(const QString &func, const QList<QStringList> &args)
2844{
2845 QMap<QString, QStringList> tmp = vars;
2846 return doProjectExpand(func, args, tmp);
2847}
2848
2849bool
2850QMakeProject::doVariableReplace(QString &str, QMap<QString, QStringList> &place)
2851{
2852 bool ret;
2853 str = doVariableReplaceExpand(str, place, &ret).join(QString(Option::field_sep));
2854 return ret;
2855}
2856
2857QStringList
2858QMakeProject::doVariableReplaceExpand(const QString &str, QMap<QString, QStringList> &place, bool *ok)
2859{
2860 QStringList ret;
2861 if(ok)
2862 *ok = true;
2863 if(str.isEmpty())
2864 return ret;
2865
2866 const ushort LSQUARE = '[';
2867 const ushort RSQUARE = ']';
2868 const ushort LCURLY = '{';
2869 const ushort RCURLY = '}';
2870 const ushort LPAREN = '(';
2871 const ushort RPAREN = ')';
2872 const ushort DOLLAR = '$';
2873 const ushort SLASH = '\\';
2874 const ushort UNDERSCORE = '_';
2875 const ushort DOT = '.';
2876 const ushort SPACE = ' ';
2877 const ushort TAB = '\t';
2878 const ushort SINGLEQUOTE = '\'';
2879 const ushort DOUBLEQUOTE = '"';
2880
2881 ushort unicode, quote = 0;
2882 const QChar *str_data = str.data();
2883 const int str_len = str.length();
2884
2885 ushort term;
2886 QString var, args;
2887
2888 int replaced = 0;
2889 QString current;
2890 for(int i = 0; i < str_len; ++i) {
2891 unicode = str_data[i].unicode();
2892 const int start_var = i;
2893 if(unicode == DOLLAR && str_len > i+2) {
2894 unicode = str_data[++i].unicode();
2895 if(unicode == DOLLAR) {
2896 term = 0;
2897 var.clear();
2898 args.clear();
2899 enum { VAR, ENVIRON, FUNCTION, PROPERTY } var_type = VAR;
2900 unicode = str_data[++i].unicode();
2901 if(unicode == LSQUARE) {
2902 unicode = str_data[++i].unicode();
2903 term = RSQUARE;
2904 var_type = PROPERTY;
2905 } else if(unicode == LCURLY) {
2906 unicode = str_data[++i].unicode();
2907 var_type = VAR;
2908 term = RCURLY;
2909 } else if(unicode == LPAREN) {
2910 unicode = str_data[++i].unicode();
2911 var_type = ENVIRON;
2912 term = RPAREN;
2913 }
2914 while(1) {
2915 if(!(unicode & (0xFF<<8)) &&
2916 unicode != DOT && unicode != UNDERSCORE &&
2917 //unicode != SINGLEQUOTE && unicode != DOUBLEQUOTE &&
2918 (unicode < 'a' || unicode > 'z') && (unicode < 'A' || unicode > 'Z') &&
2919 (unicode < '0' || unicode > '9'))
2920 break;
2921 var.append(QChar(unicode));
2922 if(++i == str_len)
2923 break;
2924 unicode = str_data[i].unicode();
2925 // at this point, i points to either the 'term' or 'next' character (which is in unicode)
2926 }
2927 if(var_type == VAR && unicode == LPAREN) {
2928 var_type = FUNCTION;
2929 int depth = 0;
2930 while(1) {
2931 if(++i == str_len)
2932 break;
2933 unicode = str_data[i].unicode();
2934 if(unicode == LPAREN) {
2935 depth++;
2936 } else if(unicode == RPAREN) {
2937 if(!depth)
2938 break;
2939 --depth;
2940 }
2941 args.append(QChar(unicode));
2942 }
2943 if(++i < str_len)
2944 unicode = str_data[i].unicode();
2945 else
2946 unicode = 0;
2947 // at this point i is pointing to the 'next' character (which is in unicode)
2948 // this might actually be a term character since you can do $${func()}
2949 }
2950 if(term) {
2951 if(unicode != term) {
2952 qmake_error_msg("Missing " + QString(term) + " terminator [found " + (unicode?QString(unicode):QString("end-of-line")) + "]");
2953 if(ok)
2954 *ok = false;
2955 return QStringList();
2956 }
2957 } else {
2958 // move the 'cursor' back to the last char of the thing we were looking at
2959 --i;
2960 }
2961 // since i never points to the 'next' character, there is no reason for this to be set
2962 unicode = 0;
2963
2964 QStringList replacement;
2965 if(var_type == ENVIRON) {
2966 replacement = split_value_list(QString::fromLocal8Bit(qgetenv(var.toLatin1().constData())));
2967 } else if(var_type == PROPERTY) {
2968 if(prop)
2969 replacement = split_value_list(prop->value(var));
2970 } else if(var_type == FUNCTION) {
2971 replacement = doProjectExpand(var, args, place);
2972 } else if(var_type == VAR) {
2973 replacement = values(var, place);
2974 }
2975 if(!(replaced++) && start_var)
2976 current = str.left(start_var);
2977 if(!replacement.isEmpty()) {
2978 if(quote) {
2979 current += replacement.join(QString(Option::field_sep));
2980 } else {
2981 current += replacement.takeFirst();
2982 if(!replacement.isEmpty()) {
2983 if(!current.isEmpty())
2984 ret.append(current);
2985 current = replacement.takeLast();
2986 if(!replacement.isEmpty())
2987 ret += replacement;
2988 }
2989 }
2990 }
2991 debug_msg(2, "Project Parser [var replace]: %s -> %s",
2992 str.toLatin1().constData(), var.toLatin1().constData(),
2993 replacement.join("::").toLatin1().constData());
2994 } else {
2995 if(replaced)
2996 current.append("$");
2997 }
2998 }
2999 if(quote && unicode == quote) {
3000 unicode = 0;
3001 quote = 0;
3002 } else if(unicode == SLASH) {
3003 bool escape = false;
3004 const char *symbols = "[]{}()$\\'\"";
3005 for(const char *s = symbols; *s; ++s) {
3006 if(str_data[i+1].unicode() == (ushort)*s) {
3007 i++;
3008 escape = true;
3009 if(!(replaced++))
3010 current = str.left(start_var);
3011 current.append(str.at(i));
3012 break;
3013 }
3014 }
3015 if(escape || !replaced)
3016 unicode =0;
3017 } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
3018 quote = unicode;
3019 unicode = 0;
3020 if(!(replaced++) && i)
3021 current = str.left(i);
3022 } else if(!quote && (unicode == SPACE || unicode == TAB)) {
3023 unicode = 0;
3024 if(!current.isEmpty()) {
3025 ret.append(current);
3026 current.clear();
3027 }
3028 }
3029 if(replaced && unicode)
3030 current.append(QChar(unicode));
3031 }
3032 if(!replaced)
3033 ret = QStringList(str);
3034 else if(!current.isEmpty())
3035 ret.append(current);
3036 //qDebug() << "REPLACE" << str << ret;
3037 return ret;
3038}
3039
3040QStringList &QMakeProject::values(const QString &_var, QMap<QString, QStringList> &place)
3041{
3042 QString var = varMap(_var);
3043 if(var == QLatin1String("LITERAL_WHITESPACE")) { //a real space in a token)
3044 var = ".BUILTIN." + var;
3045 place[var] = QStringList(QLatin1String("\t"));
3046 } else if(var == QLatin1String("LITERAL_DOLLAR")) { //a real $
3047 var = ".BUILTIN." + var;
3048 place[var] = QStringList(QLatin1String("$"));
3049 } else if(var == QLatin1String("LITERAL_HASH")) { //a real #
3050 var = ".BUILTIN." + var;
3051 place[var] = QStringList("#");
3052 } else if(var == QLatin1String("OUT_PWD")) { //the out going dir
3053 var = ".BUILTIN." + var;
3054 place[var] = QStringList(Option::output_dir);
3055 } else if(var == QLatin1String("PWD") || //current working dir (of _FILE_)
3056 var == QLatin1String("IN_PWD")) {
3057 var = ".BUILTIN." + var;
3058 place[var] = QStringList(qmake_getpwd());
3059 } else if(var == QLatin1String("DIR_SEPARATOR")) {
3060 var = ".BUILTIN." + var;
3061 place[var] = QStringList(Option::dir_sep);
3062 } else if(var == QLatin1String("DIRLIST_SEPARATOR")) {
3063 var = ".BUILTIN." + var;
3064 place[var] = QStringList(Option::dirlist_sep);
3065 } else if(var == QLatin1String("_LINE_")) { //parser line number
3066 var = ".BUILTIN." + var;
3067 place[var] = QStringList(QString::number(parser.line_no));
3068 } else if(var == QLatin1String("_FILE_")) { //parser file
3069 var = ".BUILTIN." + var;
3070 place[var] = QStringList(parser.file);
3071 } else if(var == QLatin1String("_DATE_")) { //current date/time
3072 var = ".BUILTIN." + var;
3073 place[var] = QStringList(QDateTime::currentDateTime().toString());
3074 } else if(var == QLatin1String("_PRO_FILE_")) {
3075 var = ".BUILTIN." + var;
3076 place[var] = QStringList(pfile);
3077 } else if(var == QLatin1String("_PRO_FILE_PWD_")) {
3078 var = ".BUILTIN." + var;
3079 place[var] = QStringList(pfile.isEmpty() ? qmake_getpwd() : QFileInfo(pfile).absolutePath());
3080 } else if(var == QLatin1String("_QMAKE_CACHE_")) {
3081 var = ".BUILTIN." + var;
3082 if(Option::mkfile::do_cache)
3083 place[var] = QStringList(Option::mkfile::cachefile);
3084 } else if(var == QLatin1String("TEMPLATE")) {
3085 if(!Option::user_template.isEmpty()) {
3086 var = ".BUILTIN.USER." + var;
3087 place[var] = QStringList(Option::user_template);
3088 } else if(!place[var].isEmpty()) {
3089 QString orig_template = place["TEMPLATE"].first(), real_template;
3090 if(!Option::user_template_prefix.isEmpty() && !orig_template.startsWith(Option::user_template_prefix))
3091 real_template = Option::user_template_prefix + orig_template;
3092 if(real_template.endsWith(".t"))
3093 real_template = real_template.left(real_template.length()-2);
3094 if(!real_template.isEmpty()) {
3095 var = ".BUILTIN." + var;
3096 place[var] = QStringList(real_template);
3097 }
3098 } else {
3099 var = ".BUILTIN." + var;
3100 place[var] = QStringList("app");
3101 }
3102 } else if(var.startsWith(QLatin1String("QMAKE_HOST."))) {
3103 QString ret, type = var.mid(11);
3104#if defined(Q_OS_WIN32)
3105 if(type == "os") {
3106 ret = "Windows";
3107 } else if(type == "name") {
3108 DWORD name_length = 1024;
3109 wchar_t name[1024];
3110 if (GetComputerName(name, &name_length))
3111 ret = QString::fromWCharArray(name);
3112 } else if(type == "version" || type == "version_string") {
3113 QSysInfo::WinVersion ver = QSysInfo::WindowsVersion;
3114 if(type == "version")
3115 ret = QString::number(ver);
3116 else if(ver == QSysInfo::WV_Me)
3117 ret = "WinMe";
3118 else if(ver == QSysInfo::WV_95)
3119 ret = "Win95";
3120 else if(ver == QSysInfo::WV_98)
3121 ret = "Win98";
3122 else if(ver == QSysInfo::WV_NT)
3123 ret = "WinNT";
3124 else if(ver == QSysInfo::WV_2000)
3125 ret = "Win2000";
3126 else if(ver == QSysInfo::WV_2000)
3127 ret = "Win2003";
3128 else if(ver == QSysInfo::WV_XP)
3129 ret = "WinXP";
3130 else if(ver == QSysInfo::WV_VISTA)
3131 ret = "WinVista";
3132 else
3133 ret = "Unknown";
3134 } else if(type == "arch") {
3135 SYSTEM_INFO info;
3136 GetSystemInfo(&info);
3137 switch(info.wProcessorArchitecture) {
3138#ifdef PROCESSOR_ARCHITECTURE_AMD64
3139 case PROCESSOR_ARCHITECTURE_AMD64:
3140 ret = "x86_64";
3141 break;
3142#endif
3143 case PROCESSOR_ARCHITECTURE_INTEL:
3144 ret = "x86";
3145 break;
3146 case PROCESSOR_ARCHITECTURE_IA64:
3147#ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
3148 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
3149#endif
3150 ret = "IA64";
3151 break;
3152 default:
3153 ret = "Unknown";
3154 break;
3155 }
3156 }
3157#elif defined(Q_OS_OS2)
3158 if(type == "os") {
3159 ret = "OS2";
3160 } else if(type == "name") {
3161 ret = QString::fromLocal8Bit(qgetenv("HOSTNAME"));
3162 } else if(type == "version" || type == "version_string") {
3163 ULONG buf [3];
3164 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_REVISION,
3165 &buf, sizeof(buf));
3166 if(type == "version")
3167 ret = QString().sprintf("%lu.%lu.%lu", buf[0], buf[1], buf[2]);
3168 else {
3169 /* Warp 3 is reported as 20.30 */
3170 /* Warp 4 is reported as 20.40 */
3171 /* Aurora and eCS are reported as 20.45 */
3172 if (buf[0] == 20 && buf[1] == 30)
3173 ret = "Warp3";
3174 else if (buf[0] == 20 && buf[1] == 40)
3175 ret = "Warp4";
3176 else if (buf[0] == 20 && buf[1] == 45) {
3177 if (QString::fromLocal8Bit(qgetenv("OS")) == "ecs")
3178 ret = "eComStation";
3179 else
3180 ret = "Aurora";
3181 }
3182 else
3183 ret = "Unknown";
3184 }
3185 } else if(type == "arch") {
3186 ret = "x86";
3187 }
3188#elif defined(Q_OS_UNIX)
3189 struct utsname name;
3190 if(!uname(&name)) {
3191 if(type == "os")
3192 ret = name.sysname;
3193 else if(type == "name")
3194 ret = name.nodename;
3195 else if(type == "version")
3196 ret = name.release;
3197 else if(type == "version_string")
3198 ret = name.version;
3199 else if(type == "arch")
3200 ret = name.machine;
3201 }
3202#endif
3203 var = ".BUILTIN.HOST." + type;
3204 place[var] = QStringList(ret);
3205 } else if (var == QLatin1String("QMAKE_DIR_SEP")) {
3206 if (place[var].isEmpty())
3207 return values("DIR_SEPARATOR", place);
3208 } else if (var == QLatin1String("EPOCROOT")) {
3209 if (place[var].isEmpty())
3210 place[var] = QStringList(epocRoot());
3211 }
3212 //qDebug("REPLACE [%s]->[%s]", qPrintable(var), qPrintable(place[var].join("::")));
3213 return place[var];
3214}
3215
3216QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.