summaryrefslogtreecommitdiff
path: root/qmake/generators/projectgenerator.cpp
Unidiff
Diffstat (limited to 'qmake/generators/projectgenerator.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/generators/projectgenerator.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/qmake/generators/projectgenerator.cpp b/qmake/generators/projectgenerator.cpp
index 1515216..1c17379 100644
--- a/qmake/generators/projectgenerator.cpp
+++ b/qmake/generators/projectgenerator.cpp
@@ -1,34 +1,32 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2**
3** 3**
4** Definition of ________ class. 4** Implementation of ProjectGenerator class.
5** 5**
6** Created : 970521 6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** This file is part of qmake.
9**
10** This file is part of the network module of the Qt GUI Toolkit.
11** 9**
12** This file may be distributed under the terms of the Q Public License 10** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 11** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 12** LICENSE.QPL included in the packaging of this file.
15** 13**
16** This file may be distributed and/or modified under the terms of the 14** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 15** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 16** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 17** packaging of this file.
20** 18**
21** Licensees holding valid Qt Enterprise Edition licenses may use this 19** Licensees holding valid Qt Enterprise Edition licenses may use this
22** file in accordance with the Qt Commercial License Agreement provided 20** file in accordance with the Qt Commercial License Agreement provided
23** with the Software. 21** with the Software.
24** 22**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 25**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 27** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 28** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 29** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 30**
33** Contact info@trolltech.com if any conditions of this licensing are 31** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 32** not clear to you.
@@ -136,68 +134,72 @@ ProjectGenerator::init()
136 if(d[i] != "." && d[i] != "..") 134 if(d[i] != "." && d[i] != "..")
137 dirs.append(dir + d[i] + QDir::separator() + regex); 135 dirs.append(dir + d[i] + QDir::separator() + regex);
138 } 136 }
139 } 137 }
140 QDir d(dir, regex); 138 QDir d(dir, regex);
141 for(int i = 0; i < (int)d.count(); i++) { 139 for(int i = 0; i < (int)d.count(); i++) {
142 QString file = dir + d[i]; 140 QString file = dir + d[i];
143 if (addFile(file)) { 141 if (addFile(file)) {
144 add_depend = TRUE; 142 add_depend = TRUE;
145 file_count++; 143 file_count++;
146 } 144 }
147 } 145 }
148 } 146 }
149 if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir)) { 147 if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir)) {
150 QFileInfo fi(dir); 148 QFileInfo fi(dir);
151 if(fi.absFilePath() != QDir::currentDirPath()) 149 if(fi.absFilePath() != QDir::currentDirPath())
152 v["DEPENDPATH"] += fileFixify(dir); 150 v["DEPENDPATH"] += fileFixify(dir);
153 } 151 }
154 } 152 }
155 } 153 }
156 if(!file_count) { //shall we try a subdir? 154 if(!file_count) { //shall we try a subdir?
157 QStringList dirs = Option::projfile::project_dirs; 155 QStringList dirs = Option::projfile::project_dirs;
158 if(Option::projfile::do_pwd) 156 if(Option::projfile::do_pwd)
159 dirs.prepend("."); 157 dirs.prepend(".");
158 const QString out_file = fileFixify(Option::output.name());
160 for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { 159 for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) {
161 if(QFile::exists((*pd))) { 160 if(QFile::exists((*pd))) {
162 QString newdir = (*pd); 161 QString newdir = (*pd);
163 QFileInfo fi(newdir); 162 QFileInfo fi(newdir);
164 if(fi.isDir()) { 163 if(fi.isDir()) {
165 newdir = fileFixify(newdir); 164 newdir = fileFixify(newdir);
166 QStringList &subdirs = v["SUBDIRS"]; 165 QStringList &subdirs = v["SUBDIRS"];
167 if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && 166 if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") &&
168 !subdirs.contains(newdir)) { 167 !subdirs.contains(newdir)) {
169 subdirs.append(newdir); 168 subdirs.append(newdir);
170 } else { 169 } else {
171 QDir d(newdir, "*.pro"); 170 QDir d(newdir, "*.pro");
172 d.setFilter(QDir::Files); 171 d.setFilter(QDir::Files);
173 for(int i = 0; i < (int)d.count(); i++) { 172 for(int i = 0; i < (int)d.count(); i++) {
174 QString nd = newdir + QDir::separator() + d[i]; 173 QString nd = newdir;
174 if(nd == ".")
175 nd = "";
176 else if(!nd.isEmpty() && !nd.endsWith(QString(QChar(QDir::separator()))))
177 nd += QDir::separator();
178 nd += d[i];
175 fileFixify(nd); 179 fileFixify(nd);
176 if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) { 180 if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd) && !out_file.endsWith(nd))
177 if(newdir + d[i] != Option::output_dir + Option::output.name()) 181 subdirs.append(nd);
178 subdirs.append(nd);
179 }
180 } 182 }
181 } 183 }
182 if(Option::projfile::do_recursive) { 184 if(Option::projfile::do_recursive) {
183 QDir d(newdir); 185 QDir d(newdir);
184 d.setFilter(QDir::Dirs); 186 d.setFilter(QDir::Dirs);
185 for(int i = 0; i < (int)d.count(); i++) { 187 for(int i = 0; i < (int)d.count(); i++) {
186 QString nd = fileFixify(newdir + QDir::separator() + d[i]); 188 QString nd = fileFixify(newdir + QDir::separator() + d[i]);
187 if(d[i] != "." && d[i] != ".." && !dirs.contains(nd)) 189 if(d[i] != "." && d[i] != ".." && !dirs.contains(nd))
188 dirs.append(nd); 190 dirs.append(nd);
189 } 191 }
190 } 192 }
191 } 193 }
192 } else { //regexp 194 } else { //regexp
193 QString regx = (*pd), dir; 195 QString regx = (*pd), dir;
194 int s = regx.findRev(Option::dir_sep); 196 int s = regx.findRev(Option::dir_sep);
195 if(s != -1) { 197 if(s != -1) {
196 dir = regx.left(s+1); 198 dir = regx.left(s+1);
197 regx = regx.right(regx.length() - (s+1)); 199 regx = regx.right(regx.length() - (s+1));
198 } 200 }
199 QDir d(dir, regx); 201 QDir d(dir, regx);
200 d.setFilter(QDir::Dirs); 202 d.setFilter(QDir::Dirs);
201 QStringList &subdirs = v["SUBDIRS"]; 203 QStringList &subdirs = v["SUBDIRS"];
202 for(int i = 0; i < (int)d.count(); i++) { 204 for(int i = 0; i < (int)d.count(); i++) {
203 QString newdir(dir + d[i]); 205 QString newdir(dir + d[i]);
@@ -303,49 +305,49 @@ ProjectGenerator::init()
303 } 305 }
304 } 306 }
305 } 307 }
306 if(h.isEmpty()) 308 if(h.isEmpty())
307 addConfig("moc", FALSE); 309 addConfig("moc", FALSE);
308 310
309 //if we find a file that matches an forms it needn't be included in the project 311 //if we find a file that matches an forms it needn't be included in the project
310 QStringList &u = v["INTERFACES"]; 312 QStringList &u = v["INTERFACES"];
311 QString no_ui[] = { "SOURCES", "HEADERS", QString::null }; 313 QString no_ui[] = { "SOURCES", "HEADERS", QString::null };
312 { 314 {
313 for(int i = 0; !no_ui[i].isNull(); i++) { 315 for(int i = 0; !no_ui[i].isNull(); i++) {
314 QStringList &l = v[no_ui[i]]; 316 QStringList &l = v[no_ui[i]];
315 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ) { 317 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ) {
316 bool found = FALSE; 318 bool found = FALSE;
317 for(QStringList::Iterator ui_it = u.begin(); ui_it != u.end(); ++ui_it) { 319 for(QStringList::Iterator ui_it = u.begin(); ui_it != u.end(); ++ui_it) {
318 QString s1 = (*val_it).right((*val_it).length() - ((*val_it).findRev(Option::dir_sep) + 1)); 320 QString s1 = (*val_it).right((*val_it).length() - ((*val_it).findRev(Option::dir_sep) + 1));
319 if(s1.findRev('.') != -1) 321 if(s1.findRev('.') != -1)
320 s1 = s1.left(s1.findRev('.')) + Option::ui_ext; 322 s1 = s1.left(s1.findRev('.')) + Option::ui_ext;
321 QString u1 = (*ui_it).right((*ui_it).length() - ((*ui_it).findRev(Option::dir_sep) + 1)); 323 QString u1 = (*ui_it).right((*ui_it).length() - ((*ui_it).findRev(Option::dir_sep) + 1));
322 if(s1 == u1) { 324 if(s1 == u1) {
323 found = TRUE; 325 found = TRUE;
324 break; 326 break;
325 } 327 }
326 } 328 }
327 if(!found && (*val_it).endsWith(Option::moc_ext)) 329 if(!found && (*val_it).endsWith(Option::cpp_moc_ext))
328 found = TRUE; 330 found = TRUE;
329 if(found) 331 if(found)
330 val_it = l.remove(val_it); 332 val_it = l.remove(val_it);
331 else 333 else
332 ++val_it; 334 ++val_it;
333 } 335 }
334 } 336 }
335 } 337 }
336} 338}
337 339
338 340
339bool 341bool
340ProjectGenerator::writeMakefile(QTextStream &t) 342ProjectGenerator::writeMakefile(QTextStream &t)
341{ 343{
342 t << "######################################################################" << endl; 344 t << "######################################################################" << endl;
343 t << "# Automatically generated by qmake (" << qmake_version() << ") " << QDateTime::currentDateTime().toString() << endl; 345 t << "# Automatically generated by qmake (" << qmake_version() << ") " << QDateTime::currentDateTime().toString() << endl;
344 t << "######################################################################" << endl << endl; 346 t << "######################################################################" << endl << endl;
345 QStringList::Iterator it; 347 QStringList::Iterator it;
346 for(it = Option::before_user_vars.begin(); it != Option::before_user_vars.end(); ++it) 348 for(it = Option::before_user_vars.begin(); it != Option::before_user_vars.end(); ++it)
347 t << (*it) << endl; 349 t << (*it) << endl;
348 t << getWritableVar("TEMPLATE_ASSIGN", FALSE); 350 t << getWritableVar("TEMPLATE_ASSIGN", FALSE);
349 if(project->first("TEMPLATE_ASSIGN") == "subdirs") { 351 if(project->first("TEMPLATE_ASSIGN") == "subdirs") {
350 t << endl << "# Directories" << "\n" 352 t << endl << "# Directories" << "\n"
351 << getWritableVar("SUBDIRS"); 353 << getWritableVar("SUBDIRS");
@@ -370,113 +372,117 @@ ProjectGenerator::writeMakefile(QTextStream &t)
370} 372}
371 373
372bool 374bool
373ProjectGenerator::addConfig(const QString &cfg, bool add) 375ProjectGenerator::addConfig(const QString &cfg, bool add)
374{ 376{
375 QString where = "CONFIG"; 377 QString where = "CONFIG";
376 if(!add) 378 if(!add)
377 where = "CONFIG_REMOVE"; 379 where = "CONFIG_REMOVE";
378 if(!project->variables()[where].contains(cfg)) { 380 if(!project->variables()[where].contains(cfg)) {
379 project->variables()[where] += cfg; 381 project->variables()[where] += cfg;
380 return TRUE; 382 return TRUE;
381 } 383 }
382 return FALSE; 384 return FALSE;
383} 385}
384 386
385 387
386bool 388bool
387ProjectGenerator::addFile(QString file) 389ProjectGenerator::addFile(QString file)
388{ 390{
389 file = fileFixify(file, QDir::currentDirPath()); 391 file = fileFixify(file, QDir::currentDirPath());
390 QString dir; 392 QString dir;
391 int s = file.findRev(Option::dir_sep); 393 int s = file.findRev(Option::dir_sep);
392 if(s != -1) 394 if(s != -1)
393 dir = file.left(s+1); 395 dir = file.left(s+1);
394 if(file.mid(dir.length(), Option::moc_mod.length()) == Option::moc_mod) 396 if(file.mid(dir.length(), Option::h_moc_mod.length()) == Option::h_moc_mod)
395 return FALSE; 397 return FALSE;
396 398
397 QString where; 399 QString where;
398 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) { 400 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) {
399 if(file.endsWith((*cppit))) { 401 if(file.endsWith((*cppit))) {
400 if(QFile::exists(file.left(file.length() - (*cppit).length()) + Option::ui_ext)) 402 if(QFile::exists(file.left(file.length() - (*cppit).length()) + Option::ui_ext))
401 return FALSE; 403 return FALSE;
402 else 404 else
403 where = "SOURCES"; 405 where = "SOURCES";
404 break; 406 break;
405 } 407 }
406 } 408 }
407 if(where.isEmpty()) { 409 if(where.isEmpty()) {
408 for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) { 410 for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) {
409 if(file.endsWith((*hit))) { 411 if(file.endsWith((*hit))) {
410 where = "HEADERS"; 412 where = "HEADERS";
411 break; 413 break;
412 } 414 }
413 } 415 }
414 } 416 }
415 if(where.isEmpty()) { 417 if(where.isEmpty()) {
416 if(file.endsWith(Option::ui_ext)) 418 if(file.endsWith(Option::ui_ext))
417 where = "INTERFACES"; 419 where = "INTERFACES";
418 else if(file.endsWith(".c")) 420 else if(file.endsWith(".c"))
419 where = "SOURCES"; 421 where = "SOURCES";
420 else if(file.endsWith(Option::lex_ext)) 422 else if(file.endsWith(Option::lex_ext))
421 where = "LEXSOURCES"; 423 where = "LEXSOURCES";
422 else if(file.endsWith(Option::yacc_ext)) 424 else if(file.endsWith(Option::yacc_ext))
423 where = "YACCSOURCES"; 425 where = "YACCSOURCES";
424 else if(file.endsWith(".ts")) 426 else if(file.endsWith(".ts"))
425 where = "TRANSLATIONS"; 427 where = "TRANSLATIONS";
426 } 428 }
427 429
428 QString newfile = fileFixify(file); 430 QString newfile = fileFixify(file);
429 if(!where.isEmpty() && !project->variables()[where].contains(file)) { 431 if(!where.isEmpty() && !project->variables()[where].contains(file)) {
430 project->variables()[where] += newfile; 432 project->variables()[where] += newfile;
431 return TRUE; 433 return TRUE;
432 } 434 }
433 return FALSE; 435 return FALSE;
434} 436}
435 437
436 438
437QString 439QString
438ProjectGenerator::getWritableVar(const QString &v, bool /*fixPath*/) 440ProjectGenerator::getWritableVar(const QString &v, bool fixPath)
439{ 441{
440 QStringList &vals = project->variables()[v]; 442 QStringList &vals = project->variables()[v];
441 if(vals.isEmpty()) 443 if(vals.isEmpty())
442 return ""; 444 return "";
443 445
444 QString ret; 446 QString ret;
445 if(v.endsWith("_REMOVE")) 447 if(v.endsWith("_REMOVE"))
446 ret = v.left(v.length() - 7) + " -= "; 448 ret = v.left(v.length() - 7) + " -= ";
447 else if(v.endsWith("_ASSIGN")) 449 else if(v.endsWith("_ASSIGN"))
448 ret = v.left(v.length() - 7) + " = "; 450 ret = v.left(v.length() - 7) + " = ";
449 else 451 else
450 ret = v + " += "; 452 ret = v + " += ";
451 QString join = vals.join(" "); 453 QString join = vals.join(" ");
452 if(ret.length() + join.length() > 80) { 454 if(ret.length() + join.length() > 80) {
453 QString spaces; 455 QString spaces;
454 for(unsigned int i = 0; i < ret.length(); i++) 456 for(unsigned int i = 0; i < ret.length(); i++)
455 spaces += " "; 457 spaces += " ";
456 join = vals.join(" \\\n" + spaces); 458 join = vals.join(" \\\n" + spaces);
457 } 459 }
460#if 0
458 // ### Commented out for now so that project generation works. 461 // ### Commented out for now so that project generation works.
459 // Sam: can you look at why this was needed? 462 // Sam: it had to do with trailing \'s (ie considered continuation lines)
460 /* if(fixPath) 463 if(fixPath)
461 join = join.replace("\\", "/");*/ 464 join = join.replace("\\", "/");
465#else
466 Q_UNUSED(fixPath);
467#endif
462 return ret + join + "\n"; 468 return ret + join + "\n";
463} 469}
464 470
465bool 471bool
466ProjectGenerator::openOutput(QFile &file) const 472ProjectGenerator::openOutput(QFile &file) const
467{ 473{
468 QString outdir; 474 QString outdir;
469 if(!file.name().isEmpty()) { 475 if(!file.name().isEmpty()) {
470 QFileInfo fi(file); 476 QFileInfo fi(file);
471 if(fi.isDir()) 477 if(fi.isDir())
472 outdir = fi.dirPath() + QDir::separator(); 478 outdir = fi.dirPath() + QDir::separator();
473 } 479 }
474 if(!outdir.isEmpty() || file.name().isEmpty()) { 480 if(!outdir.isEmpty() || file.name().isEmpty()) {
475 QString dir = QDir::currentDirPath(); 481 QString dir = QDir::currentDirPath();
476 int s = dir.findRev('/'); 482 int s = dir.findRev('/');
477 if(s != -1) 483 if(s != -1)
478 dir = dir.right(dir.length() - (s + 1)); 484 dir = dir.right(dir.length() - (s + 1));
479 file.setName(outdir + dir + ".pro"); 485 file.setName(outdir + dir + ".pro");
480 } 486 }
481 return MakefileGenerator::openOutput(file); 487 return MakefileGenerator::openOutput(file);
482} 488}