source: trunk/qmake/project.cpp@ 16

Last change on this file since 16 was 8, checked in by dmik, 20 years ago

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

  • Property svn:keywords set to Id
File size: 45.3 KB
RevLine 
[2]1/****************************************************************************
2** $Id: project.cpp 8 2005-11-16 19:36:46Z dmik $
3**
4** Implementation of QMakeProject class.
5**
6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
7**
8** This file is part of qmake.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition licenses may use this
20** file in accordance with the Qt Commercial License Agreement provided
21** with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36#include "project.h"
37#include "property.h"
38#include "option.h"
39#include <qfile.h>
40#include <qdir.h>
41#include <qregexp.h>
42#include <qtextstream.h>
43#include <qvaluestack.h>
44#ifdef Q_OS_UNIX
45# include <unistd.h>
46#endif
47#include <stdio.h>
48#include <stdlib.h>
49
50#ifdef Q_OS_WIN32
51#define QT_POPEN _popen
52#else
53#define QT_POPEN popen
54#endif
55
56struct parser_info {
57 QString file;
58 int line_no;
59} parser;
60
61static void qmake_error_msg(const char *msg)
62{
63 fprintf(stderr, "%s:%d: %s\n", parser.file.latin1(), parser.line_no, msg);
64}
65
66QStringList qmake_mkspec_paths()
67{
68 QStringList ret;
69 const QString concat = QDir::separator() + QString("mkspecs");
70 if(const char *qmakepath = getenv("QMAKEPATH")) {
[8]71#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
[2]72 QStringList lst = QStringList::split(';', qmakepath);
73 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) {
74 QStringList lst2 = QStringList::split(':', (*it));
75 for(QStringList::Iterator it2 = lst2.begin(); it2 != lst2.end(); ++it2)
76 ret << ((*it2) + concat);
77 }
78#else
79 QStringList lst = QStringList::split(':', qmakepath);
80 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
81 ret << ((*it) + concat);
82#endif
83 }
84 if(const char *qtdir = getenv("QTDIR"))
85 ret << (QString(qtdir) + concat);
86#ifdef QT_INSTALL_PREFIX
87 ret << (QT_INSTALL_PREFIX + concat);
88#endif
89#if defined(HAVE_QCONFIG_CPP)
90 ret << (qInstallPath() + concat);
91#endif
92#ifdef QT_INSTALL_DATA
93 ret << (QT_INSTALL_DATA + concat);
94#endif
95#if defined(HAVE_QCONFIG_CPP)
96 ret << (qInstallPathData() + concat);
97#endif
98
99 /* prefer $QTDIR if it is set */
100 if (getenv("QTDIR"))
101 ret << getenv("QTDIR");
102 ret << qInstallPathData();
103 return ret;
104}
105
106static QString varMap(const QString &x)
107{
108 QString ret(x);
109 if(ret.startsWith("TMAKE")) //tmake no more!
110 ret = "QMAKE" + ret.mid(5);
111 else if(ret == "INTERFACES")
112 ret = "FORMS";
113 else if(ret == "QMAKE_POST_BUILD")
114 ret = "QMAKE_POST_LINK";
115 else if(ret == "TARGETDEPS")
116 ret = "POST_TARGETDEPS";
117 else if(ret == "LIBPATH")
118 ret = "QMAKE_LIBDIR";
119 else if(ret == "QMAKE_EXT_MOC")
120 ret = "QMAKE_EXT_CPP_MOC";
121 else if(ret == "QMAKE_MOD_MOC")
122 ret = "QMAKE_H_MOD_MOC";
123 else if(ret == "QMAKE_LFLAGS_SHAPP")
124 ret = "QMAKE_LFLAGS_APP";
125 else if(ret == "PRECOMPH")
126 ret = "PRECOMPILED_HEADER";
127 else if(ret == "PRECOMPCPP")
128 ret = "PRECOMPILED_SOURCE";
129 else if(ret == "INCPATH")
130 ret = "INCLUDEPATH";
131 return ret;
132}
133
134static QStringList split_arg_list(const QString &params)
135{
136 QChar quote = 0;
137 QStringList args;
138 for(int x = 0, last = 0, parens = 0; x <= (int)params.length(); x++) {
139 if(x == (int)params.length()) {
140 QString mid = params.mid(last, x - last).stripWhiteSpace();
141 if(mid[(int)mid.length()-1] == quote)
142 mid.truncate(1);
143 args << mid;
144 } else if(params[x] == ')') {
145 parens--;
146 } else if(params[x] == '(') {
147 parens++;
148 } else if(params[x] == quote) {
149 quote = 0;
150 } else if(params[x] == '\'' || params[x] == '"') {
151 quote = params[x];
152 } else if(!parens && !quote && params[x] == ',') {
153 args << params.mid(last, x - last).stripWhiteSpace();
154 last = x+1;
155 }
156 }
157 return args;
158}
159
160static QStringList split_value_list(const QString &vals, bool do_semicolon=FALSE)
161{
162 QString build;
163 QStringList ret;
164 QValueStack<QChar> quote;
165 for(int x = 0; x < (int)vals.length(); x++) {
166 if(x != (int)vals.length()-1 && vals[x] == '\\' && (vals[x+1] == '\'' || vals[x+1] == '"'))
167 build += vals[x++]; //get that 'escape'
168 else if(!quote.isEmpty() && vals[x] == quote.top())
169 quote.pop();
170 else if(vals[x] == '\'' || vals[x] == '"')
171 quote.push(vals[x]);
172
173 if(quote.isEmpty() && ((do_semicolon && vals[x] == ';') || vals[x] == ' ')) {
174 ret << build;
175 build = "";
176 } else {
177 build += vals[x];
178 }
179 }
180 if(!build.isEmpty())
181 ret << build;
182 return ret;
183}
184
185QMakeProject::QMakeProject()
186{
187 prop = NULL;
188}
189
190QMakeProject::QMakeProject(QMakeProperty *p)
191{
192 prop = p;
193}
194
195void
196QMakeProject::reset()
197{
198 /* scope blocks start at true */
199 test_status = TestNone;
200 scope_flag = 0x01;
201 scope_block = 0;
202}
203
204bool
205QMakeProject::parse(const QString &t, QMap<QString, QStringList> &place)
206{
207 QString s = t.simplifyWhiteSpace();
208 int hash_mark = s.find("#");
209 if(hash_mark != -1) //good bye comments
210 s = s.left(hash_mark);
211 if(s.isEmpty()) /* blank_line */
212 return TRUE;
213
214 if(s.stripWhiteSpace().left(1) == "}") {
215 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.latin1(),
216 parser.line_no, scope_block);
217 test_status = ((scope_flag & (0x01 << scope_block)) ? TestFound : TestSeek);
218 scope_block--;
219 s = s.mid(1).stripWhiteSpace();
220 if(s.isEmpty())
221 return TRUE;
222 }
223 if(!(scope_flag & (0x01 << scope_block))) {
224 /* adjust scope for each block which appears on a single line */
225 for(int i = (s.contains('{')-s.contains('}')); i>0; i--)
226 scope_flag &= ~(0x01 << (++scope_block));
227 debug_msg(1, "Project Parser: %s:%d : Ignored due to block being false.",
228 parser.file.latin1(), parser.line_no);
229 return TRUE;
230 }
231
232 QString scope, var, op;
233 QStringList val;
234#define SKIP_WS(d) while(*d && (*d == ' ' || *d == '\t')) d++
235 const char *d = s.latin1();
236 SKIP_WS(d);
237 bool scope_failed = FALSE, else_line = FALSE, or_op=FALSE;
238 int parens = 0, scope_count=0;
239 while(*d) {
240 if(!parens) {
241 if(*d == '=')
242 break;
243 if(*d == '+' || *d == '-' || *d == '*' || *d == '~') {
244 if(*(d+1) == '=') {
245 break;
246 } else if(*(d+1) == ' ') {
247 const char *k = d + 1;
248 SKIP_WS(k);
249 if(*k == '=') {
250 QString msg;
251 qmake_error_msg(*d + "must be followed immediately by =");
252 return FALSE;
253 }
254 }
255 }
256 }
257
258 if ( *d == '(' )
259 ++parens;
260 else if ( *d == ')' )
261 --parens;
262
263 if(!parens && (*d == ':' || *d == '{' || *d == ')' || *d == '|')) {
264 scope_count++;
265 scope = var.stripWhiteSpace();
266 if ( *d == ')' )
267 scope += *d; /* need this */
268 var = "";
269
270 bool test = scope_failed;
271 if(scope.lower() == "else") {
272 if(scope_count != 1 || test_status == TestNone) {
273 qmake_error_msg("Unexpected " + scope + " ('" + s + "')");
274 return FALSE;
275 }
276 else_line = TRUE;
277 test = (test_status == TestSeek);
278 debug_msg(1, "Project Parser: %s:%d : Else%s %s.", parser.file.latin1(), parser.line_no,
279 scope == "else" ? "" : QString(" (" + scope + ")").latin1(),
280 test ? "considered" : "excluded");
281 } else {
282 QString comp_scope = scope;
283 bool invert_test = (comp_scope.left(1) == "!");
284 if(invert_test)
285 comp_scope = comp_scope.right(comp_scope.length()-1);
286 int lparen = comp_scope.find('(');
287 if(or_op || !scope_failed) {
288 if(lparen != -1) { /* if there is an lparen in the scope, it IS a function */
289 int rparen = comp_scope.findRev(')');
290 if(rparen == -1) {
291 QCString error;
292 error.sprintf("Function missing right paren: %s ('%s')",
293 comp_scope.latin1(), s.latin1());
294 qmake_error_msg(error);
295 return FALSE;
296 }
297 QString func = comp_scope.left(lparen);
298 test = doProjectTest(func, comp_scope.mid(lparen+1, rparen - lparen - 1), place);
299 if ( *d == ')' && !*(d+1) ) {
300 if(invert_test)
301 test = !test;
302 test_status = (test ? TestFound : TestSeek);
303 return TRUE; /* assume we are done */
304 }
305 } else {
306 test = isActiveConfig(comp_scope.stripWhiteSpace(), TRUE, &place);
307 }
308 if(invert_test)
309 test = !test;
310 }
311 }
312 if(!test && !scope_failed)
313 debug_msg(1, "Project Parser: %s:%d : Test (%s) failed.", parser.file.latin1(),
314 parser.line_no, scope.latin1());
315 if(test == or_op)
316 scope_failed = !test;
317 or_op = (*d == '|');
318 if(*d == '{') { /* scoping block */
319 if(!scope_failed)
320 scope_flag |= (0x01 << (++scope_block));
321 else
322 scope_flag &= ~(0x01 << (++scope_block));
323 debug_msg(1, "Project Parser: %s:%d : Entering block %d (%d).", parser.file.latin1(),
324 parser.line_no, scope_block, !scope_failed);
325 }
326 } else if(!parens && *d == '}') {
327 if(!scope_block) {
328 warn_msg(WarnParser, "Possible braces mismatch %s:%d", parser.file.latin1(), parser.line_no);
329 } else {
330 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.latin1(),
331 parser.line_no, scope_block);
332 --scope_block;
333 }
334 } else {
335 var += *d;
336 }
337 d++;
338 }
339 var = var.stripWhiteSpace();
340 if(!scope_count || (scope_count == 1 && else_line))
341 test_status = TestNone;
342 else if(!else_line || test_status != TestFound)
343 test_status = (scope_failed ? TestSeek : TestFound);
344 if(scope_failed)
345 return TRUE; /* oh well */
346 if(!*d) {
347 if(!var.stripWhiteSpace().isEmpty())
348 qmake_error_msg("Parse Error ('" + s + "')");
349 return var.isEmpty(); /* allow just a scope */
350 }
351
352 SKIP_WS(d);
353 for( ; *d && op.find('=') == -1; op += *(d++))
354 ;
355 op.replace(QRegExp("\\s"), "");
356
357 SKIP_WS(d);
358 QString vals(d); /* vals now contains the space separated list of values */
359 int rbraces = vals.contains('}'), lbraces = vals.contains('{');
360 if(scope_block && rbraces - lbraces == 1) {
361 debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.latin1(),
362 parser.line_no, scope_block);
363 test_status = ((scope_flag & (0x01 << scope_block)) ? TestFound : TestSeek);
364 scope_block--;
365 vals.truncate(vals.length()-1);
366 } else if(rbraces != lbraces) {
367 warn_msg(WarnParser, "Possible braces mismatch {%s} %s:%d",
368 vals.latin1(), parser.file.latin1(), parser.line_no);
369 }
370 doVariableReplace(vals, place);
371
372#undef SKIP_WS
373
374 if(!var.isEmpty() && Option::mkfile::do_preprocess) {
375 static QString last_file("*none*");
376 if(parser.file != last_file) {
377 fprintf(stdout, "#file %s:%d\n", parser.file.latin1(), parser.line_no);
378 last_file = parser.file;
379 }
380 fprintf(stdout, "%s %s %s\n", var.latin1(), op.latin1(), vals.latin1());
381 }
382 var = varMap(var); //backwards compatability
383
384 /* vallist is the broken up list of values */
385 QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH"));
386 if(!vallist.grep("=").isEmpty())
387 warn_msg(WarnParser, "Detected possible line continuation: {%s} %s:%d",
388 var.latin1(), parser.file.latin1(), parser.line_no);
389
390 QStringList &varlist = place[var]; /* varlist is the list in the symbol table */
391 debug_msg(1, "Project Parser: %s:%d :%s: :%s: (%s)", parser.file.latin1(), parser.line_no,
392 var.latin1(), op.latin1(), vallist.isEmpty() ? "" : vallist.join(" :: ").latin1());
393
394 /* now do the operation */
395 if(op == "~=") {
396 if(vallist.count() != 1) {
397 qmake_error_msg("~= operator only accepts one right hand paramater ('" +
398 s + "')");
399 return FALSE;
400 }
401 QString val(vallist.first());
402 if(val.length() < 4 || val.at(0) != 's') {
403 qmake_error_msg("~= operator only can handle s/// function ('" +
404 s + "')");
405 return FALSE;
406 }
407 QChar sep = val.at(1);
408 QStringList func = QStringList::split(sep, val, TRUE);
409 if(func.count() < 3 || func.count() > 4) {
410 qmake_error_msg("~= operator only can handle s/// function ('" +
411 s + "')");
412 return FALSE;
413 }
414 bool global = FALSE, case_sense = TRUE;
415 if(func.count() == 4) {
416 global = func[3].find('g') != -1;
417 case_sense = func[3].find('i') == -1;
418 }
419 QRegExp regexp(func[1], case_sense);
420 for(QStringList::Iterator varit = varlist.begin();
421 varit != varlist.end(); ++varit) {
422 if((*varit).contains(regexp)) {
423 (*varit) = (*varit).replace(regexp, func[2]);
424 if(!global)
425 break;
426 }
427 }
428 } else {
429 if(op == "=") {
430 if(!varlist.isEmpty())
431 warn_msg(WarnParser, "Operator=(%s) clears variables previously set: %s:%d",
432 var.latin1(), parser.file.latin1(), parser.line_no);
433 varlist.clear();
434 }
435 for(QStringList::Iterator valit = vallist.begin();
436 valit != vallist.end(); ++valit) {
437 if((*valit).isEmpty())
438 continue;
439 if((op == "*=" && !(*varlist.find((*valit)))) ||
440 op == "=" || op == "+=")
441 varlist.append((*valit));
442 else if(op == "-=")
443 varlist.remove((*valit));
444 }
445 }
446 if(var == "REQUIRES") /* special case to get communicated to backends! */
447 doProjectCheckReqs(vallist, place);
448
449 return TRUE;
450}
451
452bool
453QMakeProject::read(const QString &file, QMap<QString, QStringList> &place)
454{
455 parser_info pi = parser;
456 reset();
457
458 QString filename = Option::fixPathToLocalOS(file);
459 doVariableReplace(filename, place);
460 bool ret = FALSE, using_stdin = FALSE;
461 QFile qfile;
462 if(!strcmp(filename, "-")) {
463 qfile.setName("");
464 ret = qfile.open(IO_ReadOnly, stdin);
465 using_stdin = TRUE;
466 } else {
467 qfile.setName(filename);
468 ret = qfile.open(IO_ReadOnly);
469 }
470 if ( ret ) {
471 QTextStream t( &qfile );
472 QString s, line;
473 parser.file = filename;
474 parser.line_no = 0;
475 while ( !t.eof() ) {
476 parser.line_no++;
477 line = t.readLine().stripWhiteSpace();
478 int prelen = line.length();
479
480 int hash_mark = line.find("#");
481 if(hash_mark != -1) //good bye comments
482 line = line.left(hash_mark);
483 if(!line.isEmpty() && line.right(1) == "\\") {
484 if (!line.startsWith("#")) {
485 line.truncate(line.length() - 1);
486 s += line + " ";
487 }
488 } else if(!line.isEmpty() || (line.isEmpty() && !prelen)) {
489 if(s.isEmpty() && line.isEmpty())
490 continue;
491 if(!line.isEmpty())
492 s += line;
493 if(!s.isEmpty()) {
494 if(!(ret = parse(s, place)))
495 break;
496 s = "";
497 }
498 }
499 }
500 if(!using_stdin)
501 qfile.close();
502 }
503 parser = pi;
504 if(scope_block != 0)
505 warn_msg(WarnParser, "%s: Unterminated conditional at end of file.",
506 file.latin1());
507 return ret;
508}
509
510bool
511QMakeProject::read(const QString &project, const QString &, uchar cmd)
512{
513 pfile = project;
514 return read(cmd);
515}
516
517bool
518QMakeProject::read(uchar cmd)
519{
520 if(cfile.isEmpty()) {
521 // hack to get the Option stuff in there
522 base_vars["QMAKE_EXT_CPP"] = Option::cpp_ext;
523 base_vars["QMAKE_EXT_H"] = Option::h_ext;
524 if(!Option::user_template_prefix.isEmpty())
525 base_vars["TEMPLATE_PREFIX"] = Option::user_template_prefix;
526
527 if(cmd & ReadCache && Option::mkfile::do_cache) { /* parse the cache */
528 if(Option::mkfile::cachefile.isEmpty()) { //find it as it has not been specified
529 QString dir = QDir::convertSeparators(Option::output_dir);
530 while(!QFile::exists((Option::mkfile::cachefile = dir +
531 QDir::separator() + ".qmake.cache"))) {
532 dir = dir.left(dir.findRev(QDir::separator()));
533 if(dir.isEmpty() || dir.find(QDir::separator()) == -1) {
534 Option::mkfile::cachefile = "";
535 break;
536 }
537 if(Option::mkfile::cachefile_depth == -1)
538 Option::mkfile::cachefile_depth = 1;
539 else
540 Option::mkfile::cachefile_depth++;
541 }
542 }
543 if(!Option::mkfile::cachefile.isEmpty()) {
544 read(Option::mkfile::cachefile, cache);
545 if(Option::mkfile::qmakespec.isEmpty() && !cache["QMAKESPEC"].isEmpty())
546 Option::mkfile::qmakespec = cache["QMAKESPEC"].first();
547 }
548 }
549 if(cmd & ReadConf) { /* parse mkspec */
550 QStringList mkspec_roots = qmake_mkspec_paths();
551 if(Option::mkfile::qmakespec.isEmpty()) {
552 for(QStringList::Iterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) {
553 QString mkspec = (*it) + QDir::separator() + "default";
554 if(QFile::exists(mkspec)) {
555 Option::mkfile::qmakespec = mkspec;
556 break;
557 }
558 }
559 if(Option::mkfile::qmakespec.isEmpty()) {
560 fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n");
561 return FALSE;
562 }
563 }
564
565 if(QDir::isRelativePath(Option::mkfile::qmakespec)) {
566 bool found_mkspec = FALSE;
567 for(QStringList::Iterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) {
568 QString mkspec = (*it) + QDir::separator() + Option::mkfile::qmakespec;
569 if(QFile::exists(mkspec)) {
570 found_mkspec = TRUE;
571 Option::mkfile::qmakespec = mkspec;
572 break;
573 }
574 }
575 if(!found_mkspec) {
576 fprintf(stderr, "Could not find mkspecs for your QMAKESPEC after trying:\n\t%s\n",
577 mkspec_roots.join("\n\t").latin1());
578 return FALSE;
579 }
580 }
581
582 /* parse qmake configuration */
583 while(Option::mkfile::qmakespec.endsWith(QString(QChar(QDir::separator()))))
584 Option::mkfile::qmakespec.truncate(Option::mkfile::qmakespec.length()-1);
585 QString spec = Option::mkfile::qmakespec + QDir::separator() + "qmake.conf";
586 if(!QFile::exists(spec) &&
587 QFile::exists(Option::mkfile::qmakespec + QDir::separator() + "tmake.conf"))
588 spec = Option::mkfile::qmakespec + QDir::separator() + "tmake.conf";
589 debug_msg(1, "QMAKESPEC conf: reading %s", spec.latin1());
590 if(!read(spec, base_vars)) {
591 fprintf(stderr, "Failure to read QMAKESPEC conf file %s.\n", spec.latin1());
592 return FALSE;
593 }
594 if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) {
595 debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.latin1());
596 read(Option::mkfile::cachefile, base_vars);
597 }
598 }
599 if(cmd & ReadCmdLine) {
600 /* commandline */
601 cfile = pfile;
602 parser.line_no = 1; //really arg count now.. duh
603 parser.file = "(internal)";
604 reset();
605 for(QStringList::Iterator it = Option::before_user_vars.begin();
606 it != Option::before_user_vars.end(); ++it) {
607 if(!parse((*it), base_vars)) {
608 fprintf(stderr, "Argument failed to parse: %s\n", (*it).latin1());
609 return FALSE;
610 }
611 parser.line_no++;
612 }
613 }
614 }
615
616 vars = base_vars; /* start with the base */
617
618 if(cmd & ReadProFile) { /* parse project file */
619 debug_msg(1, "Project file: reading %s", pfile.latin1());
620 if(pfile != "-" && !QFile::exists(pfile) && !pfile.endsWith(".pro"))
621 pfile += ".pro";
622 if(!read(pfile, vars))
623 return FALSE;
624 }
625
626 if(cmd & ReadPostFiles) { /* parse post files */
627 const QStringList l = vars["QMAKE_POST_INCLUDE_FILES"];
628 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
629 read((*it), vars);
630 }
631
632 if(cmd & ReadCmdLine) {
633 parser.line_no = 1; //really arg count now.. duh
634 parser.file = "(internal)";
635 reset();
636 for(QStringList::Iterator it = Option::after_user_vars.begin();
637 it != Option::after_user_vars.end(); ++it) {
638 if(!parse((*it), vars)) {
639 fprintf(stderr, "Argument failed to parse: %s\n", (*it).latin1());
640 return FALSE;
641 }
642 parser.line_no++;
643 }
644 }
645
646 /* now let the user override the template from an option.. */
647 if(!Option::user_template.isEmpty()) {
648 debug_msg(1, "Overriding TEMPLATE (%s) with: %s", vars["TEMPLATE"].first().latin1(),
649 Option::user_template.latin1());
650 vars["TEMPLATE"].clear();
651 vars["TEMPLATE"].append(Option::user_template);
652 }
653
654 QStringList &templ = vars["TEMPLATE"];
655 if(templ.isEmpty())
656 templ.append(QString("app"));
657 else if(vars["TEMPLATE"].first().endsWith(".t"))
658 templ = QStringList(templ.first().left(templ.first().length() - 2));
659 if ( !Option::user_template_prefix.isEmpty() )
660 templ.first().prepend(Option::user_template_prefix);
661
662 if(vars["TARGET"].isEmpty()) {
663 // ### why not simply use:
664 // QFileInfo fi(pfile);
665 // fi.baseName();
666 QString tmp = pfile;
667 if(tmp.findRev('/') != -1)
668 tmp = tmp.right( tmp.length() - tmp.findRev('/') - 1 );
669 if(tmp.findRev('.') != -1)
670 tmp = tmp.left(tmp.findRev('.'));
671 vars["TARGET"].append(tmp);
672 }
673
674 QString test_version = getenv("QTESTVERSION");
675 if (!test_version.isEmpty()) {
676 QString s = vars["TARGET"].first();
677 if (s == "qt" || s == "qt-mt" || s == "qte" || s == "qte-mt") {
678 QString &ver = vars["VERSION"].first();
679// fprintf(stderr,"Current QT version number: " + ver + "\n");
680 if (ver != "" && ver != test_version) {
681 ver = test_version;
682 fprintf(stderr,"Changed QT version number to " + test_version + "!\n");
683 }
684 }
685 }
686 return TRUE;
687}
688
689bool
690QMakeProject::isActiveConfig(const QString &x, bool regex, QMap<QString, QStringList> *place)
691{
692 if(x.isEmpty())
693 return TRUE;
694
695 if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE ||
696 Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix")
697 return TRUE;
698 else if(Option::target_mode == Option::TARG_MACX_MODE && x == "macx")
699 return TRUE;
700 else if(Option::target_mode == Option::TARG_QNX6_MODE && x == "qnx6")
701 return TRUE;
702 else if(Option::target_mode == Option::TARG_MAC9_MODE && x == "mac9")
703 return TRUE;
704 else if((Option::target_mode == Option::TARG_MAC9_MODE || Option::target_mode == Option::TARG_MACX_MODE) &&
705 x == "mac")
706 return TRUE;
707 else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32")
708 return TRUE;
[8]709 else if(Option::target_mode == Option::TARG_OS2_MODE && x == "os2")
710 return TRUE;
[2]711
712
713 QRegExp re(x, FALSE, TRUE);
714 QString spec = Option::mkfile::qmakespec.right(Option::mkfile::qmakespec.length() -
715 (Option::mkfile::qmakespec.findRev(QDir::separator())+1));
716 if((regex && re.exactMatch(spec)) || (!regex && spec == x))
717 return TRUE;
718#ifdef Q_OS_UNIX
719 else if(spec == "default") {
720 static char *buffer = NULL;
721 if(!buffer)
722 buffer = (char *)malloc(1024);
723 int l = readlink(Option::mkfile::qmakespec, buffer, 1024);
724 if(l != -1) {
725 buffer[l] = '\0';
726 QString r = buffer;
727 if(r.findRev('/') != -1)
728 r = r.mid(r.findRev('/') + 1);
729 if((regex && re.exactMatch(r)) || (!regex && r == x))
730 return TRUE;
731 }
732 }
733#endif
734
735
736 QStringList &configs = (place ? (*place)["CONFIG"] : vars["CONFIG"]);
737 for(QStringList::Iterator it = configs.begin(); it != configs.end(); ++it) {
738 if((regex && re.exactMatch((*it))) || (!regex && (*it) == x))
739 if(re.exactMatch((*it)))
740 return TRUE;
741 }
742 return FALSE;
743}
744
745bool
746QMakeProject::doProjectTest(const QString& func, const QString &params, QMap<QString, QStringList> &place)
747{
748 QStringList args = split_arg_list(params);
749 for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) {
750 QString tmp = (*arit).stripWhiteSpace();
751 if((tmp[0] == '\'' || tmp[0] == '"') && tmp.right(1) == tmp.left(1))
752 tmp = tmp.mid(1, tmp.length() - 2);
753 }
754 return doProjectTest(func.stripWhiteSpace(), args, place);
755}
756
757bool
758QMakeProject::doProjectTest(const QString& func, QStringList args, QMap<QString, QStringList> &place)
759{
760 for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) {
761 (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space
762 doVariableReplace((*arit), place);
763 }
764 debug_msg(1, "Running project test: %s( %s )", func.latin1(), args.join("::").latin1());
765
766 if(func == "requires") {
767 return doProjectCheckReqs(args, place);
768 } else if(func == "equals") {
769 if(args.count() != 2) {
770 fprintf(stderr, "%s:%d: equals(variable, value) requires two arguments.\n", parser.file.latin1(),
771 parser.line_no);
772 return FALSE;
773 }
774 QString value = args[1];
775 if((value.left(1) == "\"" || value.left(1) == "'") && value.right(1) == value.left(1))
776 value = value.mid(1, value.length()-2);
777 return vars[args[0]].join(" ") == value;
778 } else if(func == "exists") {
779 if(args.count() != 1) {
780 fprintf(stderr, "%s:%d: exists(file) requires one argument.\n", parser.file.latin1(),
781 parser.line_no);
782 return FALSE;
783 }
784 QString file = args.first();
785 file = Option::fixPathToLocalOS(file);
786 doVariableReplace(file, place);
787
788 if(QFile::exists(file))
789 return TRUE;
790 //regular expression I guess
791 QString dirstr = QDir::currentDirPath();
792 int slsh = file.findRev(Option::dir_sep);
793 if(slsh != -1) {
794 dirstr = file.left(slsh+1);
795 file = file.right(file.length() - slsh - 1);
796 }
797 QDir dir(dirstr, file);
798 return dir.count() != 0;
799 } else if(func == "system") {
800 if(args.count() != 1) {
801 fprintf(stderr, "%s:%d: system(exec) requires one argument.\n", parser.file.latin1(),
802 parser.line_no);
803 return FALSE;
804 }
805 return system(args.first().latin1()) == 0;
806 } else if(func == "contains") {
807 if(args.count() != 2) {
808 fprintf(stderr, "%s:%d: contains(var, val) requires two arguments.\n", parser.file.latin1(),
809 parser.line_no);
810 return FALSE;
811 }
812 QRegExp regx(args[1]);
813 QStringList &l = place[args[0]];
814 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
815 if(regx.exactMatch((*it)))
816 return TRUE;
817 }
818 return FALSE;
819 } else if(func == "infile") {
820 if(args.count() < 2 || args.count() > 3) {
821 fprintf(stderr, "%s:%d: infile(file, var, val) requires at least 2 arguments.\n",
822 parser.file.latin1(), parser.line_no);
823 return FALSE;
824 }
825 QMakeProject proj;
826 QString file = args[0];
827 doVariableReplace(file, place);
828 fixEnvVariables(file);
829 int di = file.findRev(Option::dir_sep);
830 QDir sunworkshop42workaround = QDir::current();
831 QString oldpwd = sunworkshop42workaround.currentDirPath();
832 if(di != -1) {
833 if(!QDir::setCurrent(file.left(file.findRev(Option::dir_sep)))) {
834 fprintf(stderr, "Cannot find directory: %s\n", file.left(di).latin1());
835 return FALSE;
836 }
837 file = file.right(file.length() - di - 1);
838 }
839 parser_info pi = parser;
840 bool ret = !proj.read(file, oldpwd);
841 parser = pi;
842 if(ret) {
843 fprintf(stderr, "Error processing project file: %s\n", file.latin1());
844 QDir::setCurrent(oldpwd);
845 return FALSE;
846 }
847 if(args.count() == 2) {
848 ret = !proj.isEmpty(args[1]);
849 } else {
850 QRegExp regx(args[2]);
851 QStringList &l = proj.values(args[1]);
852 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
853 if(regx.exactMatch((*it))) {
854 ret = TRUE;
855 break;
856 }
857 }
858 }
859 QDir::setCurrent(oldpwd);
860 return ret;
861 } else if(func == "count") {
862 if(args.count() != 2) {
863 fprintf(stderr, "%s:%d: count(var, count) requires two arguments.\n", parser.file.latin1(),
864 parser.line_no);
865 return FALSE;
866 }
867 return vars[args[0]].count() == args[1].toUInt();
868 } else if(func == "isEmpty") {
869 if(args.count() != 1) {
870 fprintf(stderr, "%s:%d: isEmpty(var) requires one argument.\n", parser.file.latin1(),
871 parser.line_no);
872 return FALSE;
873 }
874 return vars[args[0]].isEmpty();
875 } else if(func == "include" || func == "load") {
876 QString seek_var;
877 if(args.count() == 2 && func == "include") {
878 seek_var = args[1];
879 } else if(args.count() != 1) {
880 QString func_desc = "include(file)";
881 if(func == "load")
882 func_desc = "load(feature)";
883 fprintf(stderr, "%s:%d: %s requires one argument.\n", parser.file.latin1(),
884 parser.line_no, func_desc.latin1());
885 return FALSE;
886 }
887
888 QString file = args.first();
889 file = Option::fixPathToLocalOS(file);
890 file.replace("\"", "");
891 doVariableReplace(file, place);
892 if(func == "load") {
893 if(!file.endsWith(Option::prf_ext))
894 file += Option::prf_ext;
895 if(file.find(Option::dir_sep) == -1 || !QFile::exists(file)) {
896 bool found = FALSE;
897 const QString concat = QDir::separator() + QString("mkspecs") +
898 QDir::separator() + QString("features");
899 QStringList feature_roots;
900 if(const char *mkspec_path = getenv("QMAKEFEATURES")) {
[8]901#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
[2]902 QStringList lst = QStringList::split(';', mkspec_path);
903 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
904 feature_roots += QStringList::split(':', (*it));
905#else
906 feature_roots += QStringList::split(':', mkspec_path);
907#endif
908 }
909 if(const char *qmakepath = getenv("QMAKEPATH")) {
[8]910#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
[2]911 QStringList lst = QStringList::split(';', qmakepath);
912 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) {
913 QStringList lst2 = QStringList::split(':', (*it));
914 for(QStringList::Iterator it2 = lst2.begin(); it2 != lst2.end(); ++it2)
915 feature_roots << ((*it2) + concat);
916 }
917#else
918 QStringList lst = QStringList::split(':', qmakepath);
919 for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
920 feature_roots << ((*it) + concat);
921#endif
922 }
923 feature_roots << Option::mkfile::qmakespec;
924 if(const char *qtdir = getenv("QTDIR"))
925 feature_roots << (qtdir + concat);
926#ifdef QT_INSTALL_PREFIX
927 feature_roots << (QT_INSTALL_PREFIX + concat);
928#endif
929#if defined(HAVE_QCONFIG_CPP)
930 feature_roots << (qInstallPath() + concat);
931#endif
932#ifdef QT_INSTALL_DATA
933 feature_roots << (QT_INSTALL_DATA + concat);
934#endif
935#if defined(HAVE_QCONFIG_CPP)
936 feature_roots << (qInstallPathData() + concat);
937#endif
938 for(QStringList::Iterator it = feature_roots.begin(); it != feature_roots.end(); ++it) {
939 QString prf = (*it) + QDir::separator() + file;
940 if(QFile::exists(prf)) {
941 found = TRUE;
942 file = prf;
943 break;
944 }
945 }
946 if(!found) {
947 printf("Project LOAD(): Feature %s cannot be found.\n", args.first().latin1());
948 exit(3);
949 }
950 }
951 }
952 if(QDir::isRelativePath(file)) {
953 QStringList include_roots;
954 include_roots << Option::output_dir;
955 QString pfilewd = QFileInfo(parser.file).dirPath();
956 if(pfilewd.isEmpty())
957 include_roots << pfilewd;
958 if(Option::output_dir != QDir::currentDirPath())
959 include_roots << QDir::currentDirPath();
960 for(QStringList::Iterator it = include_roots.begin(); it != include_roots.end(); ++it) {
961 if(QFile::exists((*it) + QDir::separator() + file)) {
962 file = (*it) + QDir::separator() + file;
963 break;
964 }
965 }
966 }
967
968 if(Option::mkfile::do_preprocess) //nice to see this first..
969 fprintf(stderr, "#switching file %s(%s) - %s:%d\n", func.latin1(), file.latin1(),
970 parser.file.latin1(), parser.line_no);
971 debug_msg(1, "Project Parser: %s'ing file %s.", func.latin1(), file.latin1());
972 QString orig_file = file;
973 int di = file.findRev(Option::dir_sep);
974 QDir sunworkshop42workaround = QDir::current();
975 QString oldpwd = sunworkshop42workaround.currentDirPath();
976 if(di != -1) {
977 if(!QDir::setCurrent(file.left(file.findRev(Option::dir_sep)))) {
978 fprintf(stderr, "Cannot find directory: %s\n", file.left(di).latin1());
979 return FALSE;
980 }
981 file = file.right(file.length() - di - 1);
982 }
983 parser_info pi = parser;
984 int sb = scope_block;
985 int sf = scope_flag;
986 TestStatus sc = test_status;
987 bool r = FALSE;
988 if(!seek_var.isNull()) {
989 QMap<QString, QStringList> tmp;
990 if((r = read(file.latin1(), tmp)))
991 place[seek_var] += tmp[seek_var];
992 } else {
993 r = read(file.latin1(), place);
994 }
995 if(r)
996 vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(orig_file);
997 else
998 warn_msg(WarnParser, "%s:%d: Failure to include file %s.",
999 pi.file.latin1(), pi.line_no, orig_file.latin1());
1000 parser = pi;
1001 test_status = sc;
1002 scope_flag = sf;
1003 scope_block = sb;
1004 QDir::setCurrent(oldpwd);
1005 return r;
1006 } else if(func == "error" || func == "message") {
1007 if(args.count() != 1) {
1008 fprintf(stderr, "%s:%d: %s(message) requires one argument.\n", parser.file.latin1(),
1009 parser.line_no, func.latin1());
1010 return FALSE;
1011 }
1012 QString msg = args.first();
1013 if((msg.startsWith("\"") || msg.startsWith("'")) && msg.endsWith(msg.left(1)))
1014 msg = msg.mid(1, msg.length()-2);
1015 msg.replace(QString("${QMAKE_FILE}"), parser.file.latin1());
1016 msg.replace(QString("${QMAKE_LINE_NUMBER}"), QString::number(parser.line_no));
1017 msg.replace(QString("${QMAKE_DATE}"), QDateTime::currentDateTime().toString());
1018 doVariableReplace(msg, place);
1019 fixEnvVariables(msg);
1020 fprintf(stderr, "Project %s: %s\n", func.upper().latin1(), msg.latin1());
1021 if(func == "message")
1022 return TRUE;
1023 exit(2);
1024 } else {
1025 fprintf(stderr, "%s:%d: Unknown test function: %s\n", parser.file.latin1(), parser.line_no,
1026 func.latin1());
1027 }
1028 return FALSE;
1029}
1030
1031bool
1032QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringList> &place)
1033{
1034 bool ret = FALSE;
1035 for(QStringList::ConstIterator it = deps.begin(); it != deps.end(); ++it) {
1036 QString chk = (*it);
1037 if(chk.isEmpty())
1038 continue;
1039 bool invert_test = (chk.left(1) == "!");
1040 if(invert_test)
1041 chk = chk.right(chk.length() - 1);
1042
1043 bool test;
1044 int lparen = chk.find('(');
1045 if(lparen != -1) { /* if there is an lparen in the chk, it IS a function */
1046 int rparen = chk.findRev(')');
1047 if(rparen == -1) {
1048 QCString error;
1049 error.sprintf("Function (in REQUIRES) missing right paren: %s", chk.latin1());
1050 qmake_error_msg(error);
1051 } else {
1052 QString func = chk.left(lparen);
1053 test = doProjectTest(func, chk.mid(lparen+1, rparen - lparen - 1), place);
1054 }
1055 } else {
1056 test = isActiveConfig(chk, TRUE, &place);
1057 }
1058 if(invert_test) {
1059 chk.prepend("!");
1060 test = !test;
1061 }
1062 if(!test) {
1063 debug_msg(1, "Project Parser: %s:%d Failed test: REQUIRES = %s",
1064 parser.file.latin1(), parser.line_no, chk.latin1());
1065 place["QMAKE_FAILED_REQUIREMENTS"].append(chk);
1066 ret = FALSE;
1067 }
1068 }
1069 return ret;
1070}
1071
1072
1073QString
1074QMakeProject::doVariableReplace(QString &str, const QMap<QString, QStringList> &place)
1075{
1076 for(int var_begin, var_last=0; (var_begin = str.find("$$", var_last)) != -1; var_last = var_begin) {
1077 if(var_begin >= (int)str.length() + 2) {
1078 break;
1079 } else if(var_begin != 0 && str[var_begin-1] == '\\') {
1080 str.replace(var_begin-1, 1, "");
1081 var_begin += 1;
1082 continue;
1083 }
1084
1085 int var_incr = var_begin + 2;
1086 bool in_braces = FALSE, as_env = FALSE, as_prop = FALSE;
1087 if(str[var_incr] == '{') {
1088 in_braces = TRUE;
1089 var_incr++;
1090 while(var_incr < (int)str.length() &&
1091 (str[var_incr] == ' ' || str[var_incr] == '\t' || str[var_incr] == '\n'))
1092 var_incr++;
1093 }
1094 if(str[var_incr] == '(') {
1095 as_env = TRUE;
1096 var_incr++;
1097 } else if(str[var_incr] == '[') {
1098 as_prop = TRUE;
1099 var_incr++;
1100 }
1101 QString val, args;
1102 while(var_incr < (int)str.length() &&
1103 (str[var_incr].isLetter() || str[var_incr].isNumber() || str[var_incr] == '.' || str[var_incr] == '_'))
1104 val += str[var_incr++];
1105 if(as_env) {
1106 if(str[var_incr] != ')') {
1107 var_incr++;
1108 warn_msg(WarnParser, "%s:%d: Unterminated env-variable replacement '%s' (%s)",
1109 parser.file.latin1(), parser.line_no,
1110 str.mid(var_begin, QMAX(var_incr - var_begin,
1111 (int)str.length())).latin1(), str.latin1());
1112 var_begin += var_incr;
1113 continue;
1114 }
1115 var_incr++;
1116 } else if(as_prop) {
1117 if(str[var_incr] != ']') {
1118 var_incr++;
1119 warn_msg(WarnParser, "%s:%d: Unterminated prop-variable replacement '%s' (%s)",
1120 parser.file.latin1(), parser.line_no,
1121 str.mid(var_begin, QMAX(var_incr - var_begin, int(str.length()))).latin1(), str.latin1());
1122 var_begin += var_incr;
1123 continue;
1124 }
1125 var_incr++;
1126 } else if(str[var_incr] == '(') { //args
1127 for(int parens = 0; var_incr < (int)str.length(); var_incr++) {
1128 if(str[var_incr] == '(') {
1129 parens++;
1130 if(parens == 1)
1131 continue;
1132 } else if(str[var_incr] == ')') {
1133 parens--;
1134 if(!parens) {
1135 var_incr++;
1136 break;
1137 }
1138 }
1139 args += str[var_incr];
1140 }
1141 }
1142 if(var_incr > (int)str.length() || (in_braces && str[var_incr] != '}')) {
1143 var_incr++;
1144 warn_msg(WarnParser, "%s:%d: Unterminated variable replacement '%s' (%s)",
1145 parser.file.latin1(), parser.line_no,
1146 str.mid(var_begin, QMAX(var_incr - var_begin,
1147 (int)str.length())).latin1(), str.latin1());
1148 var_begin += var_incr;
1149 continue;
1150 } else if(in_braces) {
1151 var_incr++;
1152 }
1153
1154 QString replacement;
1155 if(as_env) {
1156 replacement = getenv(val);
1157 } else if(as_prop) {
1158 if(prop)
1159 replacement = prop->value(val);
1160 } else if(args.isEmpty()) {
1161 if(val.left(1) == ".")
1162 replacement = "";
1163 else if(val == "LITERAL_WHITESPACE")
1164 replacement = "\t";
1165 else if(val == "LITERAL_DOLLAR")
1166 replacement = "$";
1167 else if(val == "LITERAL_HASH")
1168 replacement = "#";
1169 else if(val == "PWD")
1170 replacement = QDir::currentDirPath();
1171 else if(val == "DIR_SEPARATOR")
1172 replacement = Option::dir_sep;
1173 else
1174 replacement = place[varMap(val)].join(" ");
1175 } else {
1176 QStringList arg_list = split_arg_list(doVariableReplace(args, place));
1177 debug_msg(1, "Running function: %s( %s )", val.latin1(), arg_list.join("::").latin1());
1178 if(val.lower() == "member") {
1179 if(arg_list.count() < 1 || arg_list.count() > 3) {
1180 fprintf(stderr, "%s:%d: member(var, start, end) requires three arguments.\n",
1181 parser.file.latin1(), parser.line_no);
1182 } else {
1183 const QStringList &var = place[varMap(arg_list.first())];
1184 int start = 0;
1185 if(arg_list.count() >= 2)
1186 start = arg_list[1].toInt();
1187 if(start < 0)
1188 start += var.count();
1189 int end = start;
1190 if(arg_list.count() == 3)
1191 end = arg_list[2].toInt();
1192 if(end < 0)
1193 end += var.count();
1194 if(end < start)
1195 end = start;
1196 for(int i = start; i <= end && (int)var.count() >= i; i++) {
1197 if(!replacement.isEmpty())
1198 replacement += " ";
1199 replacement += var[i];
1200 }
1201 }
1202 } else if(val.lower() == "fromfile") {
1203 if(arg_list.count() != 2) {
1204 fprintf(stderr, "%s:%d: fromfile(file, variable) requires two arguments.\n",
1205 parser.file.latin1(), parser.line_no);
1206 } else {
1207 QString file = arg_list[0];
1208 file = Option::fixPathToLocalOS(file);
1209 file.replace("\"", "");
1210
1211 if(QDir::isRelativePath(file)) {
1212 QStringList include_roots;
1213 include_roots << Option::output_dir;
1214 QString pfilewd = QFileInfo(parser.file).dirPath();
1215 if(pfilewd.isEmpty())
1216 include_roots << pfilewd;
1217 if(Option::output_dir != QDir::currentDirPath())
1218 include_roots << QDir::currentDirPath();
1219 for(QStringList::Iterator it = include_roots.begin(); it != include_roots.end(); ++it) {
1220 if(QFile::exists((*it) + QDir::separator() + file)) {
1221 file = (*it) + QDir::separator() + file;
1222 break;
1223 }
1224 }
1225 }
1226 QString orig_file = file;
1227 int di = file.findRev(Option::dir_sep);
1228 QDir sunworkshop42workaround = QDir::current();
1229 QString oldpwd = sunworkshop42workaround.currentDirPath();
1230 if(di != -1 && QDir::setCurrent(file.left(file.findRev(Option::dir_sep))))
1231 file = file.right(file.length() - di - 1);
1232 parser_info pi = parser;
1233 int sb = scope_block;
1234 int sf = scope_flag;
1235 TestStatus sc = test_status;
1236 QMap<QString, QStringList> tmp;
1237 bool r = read(file.latin1(), tmp);
1238 if(r) {
1239 replacement = tmp[arg_list[1]].join(" ");
1240 vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(orig_file);
1241 } else {
1242 warn_msg(WarnParser, "%s:%d: Failure to include file %s.",
1243 pi.file.latin1(), pi.line_no, orig_file.latin1());
1244 }
1245 parser = pi;
1246 test_status = sc;
1247 scope_flag = sf;
1248 scope_block = sb;
1249 QDir::setCurrent(oldpwd);
1250 }
1251 } else if(val.lower() == "eval") {
1252 for(QStringList::ConstIterator arg_it = arg_list.begin();
1253 arg_it != arg_list.end(); ++arg_it) {
1254 if(!replacement.isEmpty())
1255 replacement += " ";
1256 replacement += place[(*arg_it)].join(" ");
1257 }
1258 } else if(val.lower() == "list") {
1259 static int x = 0;
1260 replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++);
1261 QStringList &lst = (*((QMap<QString, QStringList>*)&place))[replacement];
1262 lst.clear();
1263 for(QStringList::ConstIterator arg_it = arg_list.begin();
1264 arg_it != arg_list.end(); ++arg_it)
1265 lst += split_value_list((*arg_it));
1266 } else if(val.lower() == "join") {
1267 if(arg_list.count() < 1 || arg_list.count() > 4) {
1268 fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four"
1269 "arguments.\n", parser.file.latin1(), parser.line_no);
1270 } else {
1271 QString glue, before, after;
1272 if(arg_list.count() >= 2)
1273 glue = arg_list[1].replace("\"", "" );
1274 if(arg_list.count() >= 3)
1275 before = arg_list[2].replace("\"", "" );
1276 if(arg_list.count() == 4)
1277 after = arg_list[3].replace("\"", "" );
1278 const QStringList &var = place[varMap(arg_list.first())];
1279 if(!var.isEmpty())
1280 replacement = before + var.join(glue) + after;
1281 }
1282 } else if(val.lower() == "split") {
1283 if(arg_list.count() < 2 || arg_list.count() > 3) {
1284 fprintf(stderr, "%s:%d split(var, sep, join) requires three arguments\n",
1285 parser.file.latin1(), parser.line_no);
1286 } else {
1287 QString sep = arg_list[1], join = " ";
1288 if(arg_list.count() == 3)
1289 join = arg_list[2];
1290 QStringList var = place[varMap(arg_list.first())];
1291 for(QStringList::Iterator vit = var.begin(); vit != var.end(); ++vit) {
1292 QStringList lst = QStringList::split(sep, (*vit));
1293 for(QStringList::Iterator spltit = lst.begin(); spltit != lst.end(); ++spltit) {
1294 if(!replacement.isEmpty())
1295 replacement += join;
1296 replacement += (*spltit);
1297 }
1298 }
1299 }
1300 } else if(val.lower() == "find") {
1301 if(arg_list.count() != 2) {
1302 fprintf(stderr, "%s:%d find(var, str) requires two arguments\n",
1303 parser.file.latin1(), parser.line_no);
1304 } else {
1305 QRegExp regx(arg_list[1]);
1306 const QStringList &var = place[varMap(arg_list.first())];
1307 for(QStringList::ConstIterator vit = var.begin();
1308 vit != var.end(); ++vit) {
1309 if(regx.search(*vit) != -1) {
1310 if(!replacement.isEmpty())
1311 replacement += " ";
1312 replacement += (*vit);
1313 }
1314 }
1315 }
1316 } else if(val.lower() == "system") {
1317 if(arg_list.count() != 1) {
1318 fprintf(stderr, "%s:%d system(execut) requires one argument\n",
1319 parser.file.latin1(), parser.line_no);
1320 } else {
1321 char buff[256];
1322 FILE *proc = QT_POPEN(arg_list.join(" ").latin1(), "r");
1323 while(proc && !feof(proc)) {
1324 int read_in = fread(buff, 1, 255, proc);
1325 if(!read_in)
1326 break;
1327 for(int i = 0; i < read_in; i++) {
1328 if(buff[i] == '\n' || buff[i] == '\t')
1329 buff[i] = ' ';
1330 }
1331 buff[read_in] = '\0';
1332 replacement += buff;
1333 }
1334 }
1335 } else if(val.lower() == "files") {
1336 if(arg_list.count() != 1) {
1337 fprintf(stderr, "%s:%d files(pattern) requires one argument\n",
1338 parser.file.latin1(), parser.line_no);
1339 } else {
1340 QString dir, regex = arg_list[0];
1341 regex = Option::fixPathToLocalOS(regex);
1342 regex.replace("\"", "");
1343 if(regex.findRev(QDir::separator()) != -1) {
1344 dir = regex.left(regex.findRev(QDir::separator()) + 1);
1345 regex = regex.right(regex.length() - dir.length());
1346 }
1347 QDir d(dir, regex);
1348 for(int i = 0; i < (int)d.count(); i++) {
1349 if(!replacement.isEmpty())
1350 replacement += " ";
1351 replacement += dir + d[i];
1352 }
1353 }
1354 } else if(val.lower() == "prompt") {
1355 if(arg_list.count() != 1) {
1356 fprintf(stderr, "%s:%d prompt(question) requires one argument\n",
1357 parser.file.latin1(), parser.line_no);
1358 } else if(projectFile() == "-") {
1359 fprintf(stderr, "%s:%d prompt(question) cannot be used when '-o -' is used.\n",
1360 parser.file.latin1(), parser.line_no);
1361 } else {
1362 QString msg = arg_list.first();
1363 if((msg.startsWith("\"") || msg.startsWith("'")) && msg.endsWith(msg.left(1)))
1364 msg = msg.mid(1, msg.length()-2);
1365 msg.replace(QString("${QMAKE_FILE}"), parser.file.latin1());
1366 msg.replace(QString("${QMAKE_LINE_NUMBER}"), QString::number(parser.line_no));
1367 msg.replace(QString("${QMAKE_DATE}"), QDateTime::currentDateTime().toString());
1368 doVariableReplace(msg, place);
1369 fixEnvVariables(msg);
1370 if(!msg.endsWith("?"))
1371 msg += "?";
1372 fprintf(stderr, "Project %s: %s ", val.upper().latin1(), msg.latin1());
1373
1374 QFile qfile;
1375 if(qfile.open(IO_ReadOnly, stdin)) {
1376 QTextStream t(&qfile);
1377 replacement = t.readLine();
1378 }
1379 }
1380 } else {
1381 fprintf(stderr, "%s:%d: Unknown replace function: %s\n",
1382 parser.file.latin1(), parser.line_no, val.latin1());
1383 }
1384 }
1385 //actually do replacement now..
1386 int mlen = var_incr - var_begin;
1387 debug_msg(2, "Project Parser [var replace]: '%s' :: %s -> %s", str.latin1(),
1388 str.mid(var_begin, mlen).latin1(), replacement.latin1());
1389 str.replace(var_begin, mlen, replacement);
1390 var_begin += replacement.length();
1391 }
1392 return str;
1393}
Note: See TracBrowser for help on using the repository browser.