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.cpp64
1 files changed, 42 insertions, 22 deletions
diff --git a/qmake/generators/projectgenerator.cpp b/qmake/generators/projectgenerator.cpp
index 5ff6250..1515216 100644
--- a/qmake/generators/projectgenerator.cpp
+++ b/qmake/generators/projectgenerator.cpp
@@ -1,193 +1,200 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Definition of ________ class. 4** Definition of ________ class.
5** 5**
6** Created : 970521 6** Created : 970521
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the network module of the Qt GUI Toolkit. 10** This file is part of the network module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** 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 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** 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 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition licenses may use this 21** Licensees holding valid Qt Enterprise Edition licenses may use this
22** file in accordance with the Qt Commercial License Agreement provided 22** file in accordance with the Qt Commercial License Agreement provided
23** with the Software. 23** with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** 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. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "projectgenerator.h" 38#include "projectgenerator.h"
39#include "option.h" 39#include "option.h"
40#include <qdir.h> 40#include <qdir.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45QString project_builtin_regx() //calculate the builtin regular expression..
46{
47 QString ret;
48 QStringList builtin_exts(".c");
49 builtin_exts << Option::ui_ext << Option::yacc_ext << Option::lex_ext << ".ts";
50 builtin_exts += Option::h_ext + Option::cpp_ext;
51 for(QStringList::Iterator ext_it = builtin_exts.begin();
52 ext_it != builtin_exts.end(); ++ext_it) {
53 if(!ret.isEmpty())
54 ret += "; ";
55 ret += QString("*") + (*ext_it);
56 }
57 return ret;
58}
59
60
45 61
46ProjectGenerator::ProjectGenerator(QMakeProject *p) : MakefileGenerator(p), init_flag(FALSE) 62ProjectGenerator::ProjectGenerator(QMakeProject *p) : MakefileGenerator(p), init_flag(FALSE)
47{ 63{
48} 64}
49 65
50void 66void
51ProjectGenerator::init() 67ProjectGenerator::init()
52{ 68{
53 if(init_flag) 69 if(init_flag)
54 return; 70 return;
55 int file_count = 0; 71 int file_count = 0;
56 init_flag = TRUE; 72 init_flag = TRUE;
57 73
58 QMap<QString, QStringList> &v = project->variables(); 74 QMap<QString, QStringList> &v = project->variables();
59 QString templ = Option::user_template.isEmpty() ? QString("app") : Option::user_template; 75 QString templ = Option::user_template.isEmpty() ? QString("app") : Option::user_template;
60 if(!Option::user_template_prefix.isEmpty()) 76 if(!Option::user_template_prefix.isEmpty())
61 templ.prepend(Option::user_template_prefix); 77 templ.prepend(Option::user_template_prefix);
62 v["TEMPLATE_ASSIGN"] += templ; 78 v["TEMPLATE_ASSIGN"] += templ;
63 79
64 //figure out target 80 //figure out target
65 if(Option::output.name() == "-" || Option::output.name().isEmpty()) 81 if(Option::output.name() == "-" || Option::output.name().isEmpty())
66 v["TARGET"] = QStringList("unknown"); 82 v["TARGET"] = QStringList("unknown");
67 83
68 //the scary stuff 84 //the scary stuff
69 if(project->first("TEMPLATE_ASSIGN") != "subdirs") { 85 if(project->first("TEMPLATE_ASSIGN") != "subdirs") {
70 QString builtin_regex; 86 QString builtin_regex = project_builtin_regx();
71 { //calculate the builtin regular expression..
72 QStringList builtin_exts(".c");
73 builtin_exts << Option::ui_ext << Option::yacc_ext << Option::lex_ext;
74 builtin_exts += Option::h_ext + Option::cpp_ext;
75 for(QStringList::Iterator ext_it = builtin_exts.begin();
76 ext_it != builtin_exts.end(); ++ext_it) {
77 if(!builtin_regex.isEmpty())
78 builtin_regex += "; ";
79 builtin_regex += QString("*") + (*ext_it);
80 }
81 }
82 QStringList dirs = Option::projfile::project_dirs; 87 QStringList dirs = Option::projfile::project_dirs;
83 if(Option::projfile::do_pwd) 88 if(Option::projfile::do_pwd) {
89 if(!v["INCLUDEPATH"].contains("."))
90 v["INCLUDEPATH"] += ".";
84 dirs.prepend(QDir::currentDirPath()); 91 dirs.prepend(QDir::currentDirPath());
92 }
85 93
86 for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { 94 for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) {
87 QString dir, regex; 95 QString dir, regex;
88 bool add_depend = FALSE; 96 bool add_depend = FALSE;
89 if(QFile::exists((*pd))) { 97 if(QFile::exists((*pd))) {
90 QFileInfo fi((*pd)); 98 QFileInfo fi((*pd));
91 if(fi.isDir()) { 99 if(fi.isDir()) {
92 dir = (*pd); 100 dir = (*pd);
93 add_depend = TRUE; 101 add_depend = TRUE;
94 if(dir.right(1) != Option::dir_sep) 102 if(dir.right(1) != Option::dir_sep)
95 dir += Option::dir_sep; 103 dir += Option::dir_sep;
96 if(Option::projfile::do_recursive) { 104 if(Option::projfile::do_recursive) {
97 QDir d(dir); 105 QDir d(dir);
98 d.setFilter(QDir::Dirs); 106 d.setFilter(QDir::Dirs);
99 for(int i = 0; i < (int)d.count(); i++) { 107 for(int i = 0; i < (int)d.count(); i++) {
100 if(d[i] != "." && d[i] != "..") 108 if(d[i] != "." && d[i] != "..")
101 dirs.append(dir + d[i] + QDir::separator() + builtin_regex); 109 dirs.append(dir + d[i] + QDir::separator() + builtin_regex);
102 } 110 }
103 } 111 }
104 regex = builtin_regex; 112 regex = builtin_regex;
105 } else { 113 } else {
106 QString file = (*pd); 114 QString file = (*pd);
107 int s = file.findRev(Option::dir_sep); 115 int s = file.findRev(Option::dir_sep);
108 if(s != -1) 116 if(s != -1)
109 dir = file.left(s+1); 117 dir = file.left(s+1);
110 if(addFile(file)) { 118 if(addFile(file)) {
111 add_depend = TRUE; 119 add_depend = TRUE;
112 file_count++; 120 file_count++;
113 } 121 }
114 } 122 }
115 } else { //regexp 123 } else { //regexp
116 regex = (*pd); 124 regex = (*pd);
117 } 125 }
118 if(!regex.isEmpty()) { 126 if(!regex.isEmpty()) {
119 int s = regex.findRev(Option::dir_sep); 127 int s = regex.findRev(Option::dir_sep);
120 if(s != -1) { 128 if(s != -1) {
121 dir = regex.left(s+1); 129 dir = regex.left(s+1);
122 regex = regex.right(regex.length() - (s+1)); 130 regex = regex.right(regex.length() - (s+1));
123 } 131 }
124 if(Option::projfile::do_recursive) { 132 if(Option::projfile::do_recursive) {
125 QDir d(dir); 133 QDir d(dir);
126 d.setFilter(QDir::Dirs); 134 d.setFilter(QDir::Dirs);
127 for(int i = 0; i < (int)d.count(); i++) { 135 for(int i = 0; i < (int)d.count(); i++) {
128 if(d[i] != "." && d[i] != "..") 136 if(d[i] != "." && d[i] != "..")
129 dirs.append(dir + d[i] + QDir::separator() + regex); 137 dirs.append(dir + d[i] + QDir::separator() + regex);
130 } 138 }
131 } 139 }
132 QDir d(dir, regex); 140 QDir d(dir, regex);
133 for(int i = 0; i < (int)d.count(); i++) { 141 for(int i = 0; i < (int)d.count(); i++) {
134 QString file = dir + d[i]; 142 QString file = dir + d[i];
135 if (addFile(file)) { 143 if (addFile(file)) {
136 add_depend = TRUE; 144 add_depend = TRUE;
137 file_count++; 145 file_count++;
138 } 146 }
139 } 147 }
140 } 148 }
141 if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir)) { 149 if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir)) {
142 QFileInfo fi(dir); 150 QFileInfo fi(dir);
143 if(fi.absFilePath() != QDir::currentDirPath()) { 151 if(fi.absFilePath() != QDir::currentDirPath())
144 v["DEPENDPATH"] += fileFixify(dir); 152 v["DEPENDPATH"] += fileFixify(dir);
145 }
146 } 153 }
147 } 154 }
148 } 155 }
149 if(!file_count) { //shall we try a subdir? 156 if(!file_count) { //shall we try a subdir?
150 QStringList dirs = Option::projfile::project_dirs; 157 QStringList dirs = Option::projfile::project_dirs;
151 if(Option::projfile::do_pwd) 158 if(Option::projfile::do_pwd)
152 dirs.prepend("."); 159 dirs.prepend(".");
153 for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { 160 for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) {
154 if(QFile::exists((*pd))) { 161 if(QFile::exists((*pd))) {
155 QString newdir = (*pd); 162 QString newdir = (*pd);
156 QFileInfo fi(newdir); 163 QFileInfo fi(newdir);
157 if(fi.isDir()) { 164 if(fi.isDir()) {
158 newdir = fileFixify(newdir); 165 newdir = fileFixify(newdir);
159 QStringList &subdirs = v["SUBDIRS"]; 166 QStringList &subdirs = v["SUBDIRS"];
160 if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && 167 if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") &&
161 !subdirs.contains(newdir)) { 168 !subdirs.contains(newdir)) {
162 subdirs.append(newdir); 169 subdirs.append(newdir);
163 } else { 170 } else {
164 QDir d(newdir, "*.pro"); 171 QDir d(newdir, "*.pro");
165 d.setFilter(QDir::Files); 172 d.setFilter(QDir::Files);
166 for(int i = 0; i < (int)d.count(); i++) { 173 for(int i = 0; i < (int)d.count(); i++) {
167 QString nd = newdir + QDir::separator() + d[i]; 174 QString nd = newdir + QDir::separator() + d[i];
168 fileFixify(nd); 175 fileFixify(nd);
169 if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) { 176 if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) {
170 if(newdir + d[i] != Option::output_dir + Option::output.name()) 177 if(newdir + d[i] != Option::output_dir + Option::output.name())
171 subdirs.append(nd); 178 subdirs.append(nd);
172 } 179 }
173 } 180 }
174 } 181 }
175 if(Option::projfile::do_recursive) { 182 if(Option::projfile::do_recursive) {
176 QDir d(newdir); 183 QDir d(newdir);
177 d.setFilter(QDir::Dirs); 184 d.setFilter(QDir::Dirs);
178 for(int i = 0; i < (int)d.count(); i++) { 185 for(int i = 0; i < (int)d.count(); i++) {
179 QString nd = fileFixify(newdir + QDir::separator() + d[i]); 186 QString nd = fileFixify(newdir + QDir::separator() + d[i]);
180 if(d[i] != "." && d[i] != ".." && !dirs.contains(nd)) 187 if(d[i] != "." && d[i] != ".." && !dirs.contains(nd))
181 dirs.append(nd); 188 dirs.append(nd);
182 } 189 }
183 } 190 }
184 } 191 }
185 } else { //regexp 192 } else { //regexp
186 QString regx = (*pd), dir; 193 QString regx = (*pd), dir;
187 int s = regx.findRev(Option::dir_sep); 194 int s = regx.findRev(Option::dir_sep);
188 if(s != -1) { 195 if(s != -1) {
189 dir = regx.left(s+1); 196 dir = regx.left(s+1);
190 regx = regx.right(regx.length() - (s+1)); 197 regx = regx.right(regx.length() - (s+1));
191 } 198 }
192 QDir d(dir, regx); 199 QDir d(dir, regx);
193 d.setFilter(QDir::Dirs); 200 d.setFilter(QDir::Dirs);
@@ -196,258 +203,271 @@ ProjectGenerator::init()
196 QString newdir(dir + d[i]); 203 QString newdir(dir + d[i]);
197 QFileInfo fi(newdir); 204 QFileInfo fi(newdir);
198 if(fi.fileName() != "." && fi.fileName() != "..") { 205 if(fi.fileName() != "." && fi.fileName() != "..") {
199 newdir = fileFixify(newdir); 206 newdir = fileFixify(newdir);
200 if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && 207 if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") &&
201 !subdirs.contains(newdir)) { 208 !subdirs.contains(newdir)) {
202 subdirs.append(newdir); 209 subdirs.append(newdir);
203 } else { 210 } else {
204 QDir d(newdir, "*.pro"); 211 QDir d(newdir, "*.pro");
205 d.setFilter(QDir::Files); 212 d.setFilter(QDir::Files);
206 for(int i = 0; i < (int)d.count(); i++) { 213 for(int i = 0; i < (int)d.count(); i++) {
207 QString nd = newdir + QDir::separator() + d[i]; 214 QString nd = newdir + QDir::separator() + d[i];
208 fileFixify(nd); 215 fileFixify(nd);
209 if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) { 216 if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) {
210 if(newdir + d[i] != Option::output_dir + Option::output.name()) 217 if(newdir + d[i] != Option::output_dir + Option::output.name())
211 subdirs.append(nd); 218 subdirs.append(nd);
212 } 219 }
213 } 220 }
214 } 221 }
215 if(Option::projfile::do_recursive && !dirs.contains(newdir)) 222 if(Option::projfile::do_recursive && !dirs.contains(newdir))
216 dirs.append(newdir); 223 dirs.append(newdir);
217 } 224 }
218 } 225 }
219 } 226 }
220 } 227 }
221 v["TEMPLATE_ASSIGN"] = "subdirs"; 228 v["TEMPLATE_ASSIGN"] = "subdirs";
222 return; 229 return;
223 } 230 }
224 231
225 QPtrList<MakefileDependDir> deplist; 232 QPtrList<MakefileDependDir> deplist;
226 deplist.setAutoDelete(TRUE); 233 deplist.setAutoDelete(TRUE);
227 { 234 {
228 QStringList &d = v["DEPENDPATH"]; 235 QStringList &d = v["DEPENDPATH"];
229 for(QStringList::Iterator it = d.begin(); it != d.end(); ++it) { 236 for(QStringList::Iterator it = d.begin(); it != d.end(); ++it) {
230 QString r = (*it), l = Option::fixPathToLocalOS((*it)); 237 QString r = (*it), l = Option::fixPathToLocalOS((*it));
231 deplist.append(new MakefileDependDir(r, l)); 238 deplist.append(new MakefileDependDir(r, l));
232 } 239 }
233 } 240 }
234 QStringList &h = v["HEADERS"]; 241 QStringList &h = v["HEADERS"];
235 bool no_qt_files = TRUE; 242 bool no_qt_files = TRUE;
236 QString srcs[] = { "SOURCES", "YACCSOURCES", "LEXSOURCES", "INTERFACES", QString::null }; 243 QString srcs[] = { "SOURCES", "YACCSOURCES", "LEXSOURCES", "INTERFACES", QString::null };
237 for(int i = 0; !srcs[i].isNull(); i++) { 244 for(int i = 0; !srcs[i].isNull(); i++) {
238 QStringList &l = v[srcs[i]]; 245 QStringList &l = v[srcs[i]];
239 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) { 246 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
240 if(generateDependencies(deplist, (*val_it), TRUE)) { 247 if(generateDependencies(deplist, (*val_it), TRUE)) {
241 QStringList &tmp = findDependencies((*val_it)); 248 QStringList &tmp = findDependencies((*val_it));
242 if(!tmp.isEmpty()) { 249 if(!tmp.isEmpty()) {
243 for(QStringList::Iterator dep_it = tmp.begin(); dep_it != tmp.end(); ++dep_it) { 250 for(QStringList::Iterator dep_it = tmp.begin(); dep_it != tmp.end(); ++dep_it) {
244 QString file_no_path = (*dep_it).right( 251 QString file_dir = (*dep_it).section(Option::dir_sep, 0, -2),
245 (*dep_it).length() - ((*dep_it).findRev(Option::dir_sep)+1)); 252 file_no_path = (*dep_it).section(Option::dir_sep, -1);
253 if(!file_dir.isEmpty()) {
254 for(MakefileDependDir *mdd = deplist.first(); mdd; mdd = deplist.next()) {
255 if(mdd->local_dir == file_dir && !v["INCLUDEPATH"].contains(mdd->real_dir))
256 v["INCLUDEPATH"] += mdd->real_dir;
257 }
258 }
246 if(no_qt_files && file_no_path.find(QRegExp("^q[a-z_0-9].h$")) != -1) 259 if(no_qt_files && file_no_path.find(QRegExp("^q[a-z_0-9].h$")) != -1)
247 no_qt_files = FALSE; 260 no_qt_files = FALSE;
248 QString h_ext; 261 QString h_ext;
249 for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) { 262 for(QStringList::Iterator hit = Option::h_ext.begin();
263 hit != Option::h_ext.end(); ++hit) {
250 if((*dep_it).endsWith((*hit))) { 264 if((*dep_it).endsWith((*hit))) {
251 h_ext = (*hit); 265 h_ext = (*hit);
252 break; 266 break;
253 } 267 }
254 } 268 }
255 if(!h_ext.isEmpty()) { 269 if(!h_ext.isEmpty()) {
256 if((*dep_it).left(1).lower() == "q") { 270 if((*dep_it).left(1).lower() == "q") {
257 QString qhdr = (*dep_it).lower(); 271 QString qhdr = (*dep_it).lower();
258 if(file_no_path == "qthread.h") 272 if(file_no_path == "qthread.h")
259 addConfig("thread"); 273 addConfig("thread");
260 } 274 }
261 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); 275 for(QStringList::Iterator cppit = Option::cpp_ext.begin();
262 cppit != Option::cpp_ext.end(); ++cppit) { 276 cppit != Option::cpp_ext.end(); ++cppit) {
263 QString src((*dep_it).left((*dep_it).length() - h_ext.length()) + (*cppit)); 277 QString src((*dep_it).left((*dep_it).length() - h_ext.length()) +
278 (*cppit));
264 if(QFile::exists(src)) { 279 if(QFile::exists(src)) {
265 bool exists = FALSE; 280 bool exists = FALSE;
266 QStringList &srcl = v["SOURCES"]; 281 QStringList &srcl = v["SOURCES"];
267 for(QStringList::Iterator src_it = srcl.begin(); src_it != srcl.end(); ++src_it) { 282 for(QStringList::Iterator src_it = srcl.begin();
283 src_it != srcl.end(); ++src_it) {
268 if((*src_it).lower() == src.lower()) { 284 if((*src_it).lower() == src.lower()) {
269 exists = TRUE; 285 exists = TRUE;
270 break; 286 break;
271 } 287 }
272 } 288 }
273 if(!exists) 289 if(!exists)
274 srcl.append(src); 290 srcl.append(src);
275 } 291 }
276 } 292 }
277 } else if((*dep_it).endsWith(Option::lex_ext) && 293 } else if((*dep_it).endsWith(Option::lex_ext) &&
278 file_no_path.startsWith(Option::lex_mod)) { 294 file_no_path.startsWith(Option::lex_mod)) {
279 addConfig("lex_included"); 295 addConfig("lex_included");
280 } 296 }
281 if(!h.contains((*dep_it))) { 297 if(!h.contains((*dep_it))) {
282 if(generateMocList((*dep_it)) && !findMocDestination((*dep_it)).isEmpty()) 298 if(generateMocList((*dep_it)) && !findMocDestination((*dep_it)).isEmpty())
283 h += (*dep_it); 299 h += (*dep_it);
284 } 300 }
285 } 301 }
286 } 302 }
287 } 303 }
288 } 304 }
289 } 305 }
290 if(h.isEmpty()) 306 if(h.isEmpty())
291 addConfig("moc", FALSE); 307 addConfig("moc", FALSE);
292 308
293 //if we find a file that matches an forms it needn't be included in the project 309 //if we find a file that matches an forms it needn't be included in the project
294 QStringList &u = v["INTERFACES"]; 310 QStringList &u = v["INTERFACES"];
295 QString no_ui[] = { "SOURCES", "HEADERS", QString::null }; 311 QString no_ui[] = { "SOURCES", "HEADERS", QString::null };
296 { 312 {
297 for(int i = 0; !no_ui[i].isNull(); i++) { 313 for(int i = 0; !no_ui[i].isNull(); i++) {
298 QStringList &l = v[no_ui[i]]; 314 QStringList &l = v[no_ui[i]];
299 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ) { 315 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ) {
300 bool found = FALSE; 316 bool found = FALSE;
301 for(QStringList::Iterator ui_it = u.begin(); ui_it != u.end(); ++ui_it) { 317 for(QStringList::Iterator ui_it = u.begin(); ui_it != u.end(); ++ui_it) {
302 QString s1 = (*val_it).right((*val_it).length() - ((*val_it).findRev(Option::dir_sep) + 1)); 318 QString s1 = (*val_it).right((*val_it).length() - ((*val_it).findRev(Option::dir_sep) + 1));
303 if(s1.findRev('.') != -1) 319 if(s1.findRev('.') != -1)
304 s1 = s1.left(s1.findRev('.')) + Option::ui_ext; 320 s1 = s1.left(s1.findRev('.')) + Option::ui_ext;
305 QString u1 = (*ui_it).right((*ui_it).length() - ((*ui_it).findRev(Option::dir_sep) + 1)); 321 QString u1 = (*ui_it).right((*ui_it).length() - ((*ui_it).findRev(Option::dir_sep) + 1));
306 if(s1 == u1) { 322 if(s1 == u1) {
307 found = TRUE; 323 found = TRUE;
308 break; 324 break;
309 } 325 }
310 } 326 }
311 if(!found && (*val_it).endsWith(Option::moc_ext)) 327 if(!found && (*val_it).endsWith(Option::moc_ext))
312 found = TRUE; 328 found = TRUE;
313 if(found) 329 if(found)
314 val_it = l.remove(val_it); 330 val_it = l.remove(val_it);
315 else 331 else
316 ++val_it; 332 ++val_it;
317 } 333 }
318 } 334 }
319 } 335 }
320} 336}
321 337
322 338
323bool 339bool
324ProjectGenerator::writeMakefile(QTextStream &t) 340ProjectGenerator::writeMakefile(QTextStream &t)
325{ 341{
326 t << "######################################################################" << endl; 342 t << "######################################################################" << endl;
327 t << "# Automatically generated by qmake (" << qmake_version() << ") " << QDateTime::currentDateTime().toString() << endl; 343 t << "# Automatically generated by qmake (" << qmake_version() << ") " << QDateTime::currentDateTime().toString() << endl;
328 t << "######################################################################" << endl << endl; 344 t << "######################################################################" << endl << endl;
329 QStringList::Iterator it; 345 QStringList::Iterator it;
330 for(it = Option::before_user_vars.begin(); it != Option::before_user_vars.end(); ++it) 346 for(it = Option::before_user_vars.begin(); it != Option::before_user_vars.end(); ++it)
331 t << (*it) << endl; 347 t << (*it) << endl;
332 t << getWritableVar("TEMPLATE_ASSIGN", FALSE); 348 t << getWritableVar("TEMPLATE_ASSIGN", FALSE);
333 if(project->first("TEMPLATE_ASSIGN") == "subdirs") { 349 if(project->first("TEMPLATE_ASSIGN") == "subdirs") {
334 t << endl << "# Directories" << "\n" 350 t << endl << "# Directories" << "\n"
335 << getWritableVar("SUBDIRS"); 351 << getWritableVar("SUBDIRS");
336 } else { 352 } else {
337 t << getWritableVar("TARGET") 353 t << getWritableVar("TARGET")
338 << getWritableVar("CONFIG", FALSE) 354 << getWritableVar("CONFIG", FALSE)
339 << getWritableVar("CONFIG_REMOVE", FALSE) 355 << getWritableVar("CONFIG_REMOVE", FALSE)
340 << getWritableVar("DEPENDPATH") << endl; 356 << getWritableVar("DEPENDPATH")
357 << getWritableVar("INCLUDEPATH") << endl;
341 358
342 t << "# Input" << "\n"; 359 t << "# Input" << "\n";
343 t << getWritableVar("HEADERS") 360 t << getWritableVar("HEADERS")
344 << getWritableVar("INTERFACES") 361 << getWritableVar("INTERFACES")
345 << getWritableVar("LEXSOURCES") 362 << getWritableVar("LEXSOURCES")
346 << getWritableVar("YACCSOURCES") 363 << getWritableVar("YACCSOURCES")
347 << getWritableVar("SOURCES"); 364 << getWritableVar("SOURCES")
365 << getWritableVar("TRANSLATIONS");
348 } 366 }
349 for(it = Option::after_user_vars.begin(); it != Option::after_user_vars.end(); ++it) 367 for(it = Option::after_user_vars.begin(); it != Option::after_user_vars.end(); ++it)
350 t << (*it) << endl; 368 t << (*it) << endl;
351 return TRUE; 369 return TRUE;
352} 370}
353 371
354bool 372bool
355ProjectGenerator::addConfig(const QString &cfg, bool add) 373ProjectGenerator::addConfig(const QString &cfg, bool add)
356{ 374{
357 QString where = "CONFIG"; 375 QString where = "CONFIG";
358 if(!add) 376 if(!add)
359 where = "CONFIG_REMOVE"; 377 where = "CONFIG_REMOVE";
360 if(!project->variables()[where].contains(cfg)) { 378 if(!project->variables()[where].contains(cfg)) {
361 project->variables()[where] += cfg; 379 project->variables()[where] += cfg;
362 return TRUE; 380 return TRUE;
363 } 381 }
364 return FALSE; 382 return FALSE;
365} 383}
366 384
367 385
368bool 386bool
369ProjectGenerator::addFile(QString file) 387ProjectGenerator::addFile(QString file)
370{ 388{
371 file = fileFixify(file, QDir::currentDirPath()); 389 file = fileFixify(file, QDir::currentDirPath());
372 QString dir; 390 QString dir;
373 int s = file.findRev(Option::dir_sep); 391 int s = file.findRev(Option::dir_sep);
374 if(s != -1) 392 if(s != -1)
375 dir = file.left(s+1); 393 dir = file.left(s+1);
376 if(file.mid(dir.length(), Option::moc_mod.length()) == Option::moc_mod) 394 if(file.mid(dir.length(), Option::moc_mod.length()) == Option::moc_mod)
377 return FALSE; 395 return FALSE;
378 396
379 QString where; 397 QString where;
380 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) { 398 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) {
381 if(file.endsWith((*cppit))) { 399 if(file.endsWith((*cppit))) {
382 if(QFile::exists(file.left(file.length() - (*cppit).length()) + Option::ui_ext)) 400 if(QFile::exists(file.left(file.length() - (*cppit).length()) + Option::ui_ext))
383 return FALSE; 401 return FALSE;
384 else 402 else
385 where = "SOURCES"; 403 where = "SOURCES";
386 break; 404 break;
387 } 405 }
388 } 406 }
389 if(where.isEmpty()) { 407 if(where.isEmpty()) {
390 for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) { 408 for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) {
391 if(file.endsWith((*hit))) { 409 if(file.endsWith((*hit))) {
392 where = "HEADERS"; 410 where = "HEADERS";
393 break; 411 break;
394 } 412 }
395 } 413 }
396 } 414 }
397 if(where.isEmpty()) { 415 if(where.isEmpty()) {
398 if(file.endsWith(Option::ui_ext)) 416 if(file.endsWith(Option::ui_ext))
399 where = "INTERFACES"; 417 where = "INTERFACES";
400 else if(file.endsWith(".c")) 418 else if(file.endsWith(".c"))
401 where = "SOURCES"; 419 where = "SOURCES";
402 else if(file.endsWith(Option::lex_ext)) 420 else if(file.endsWith(Option::lex_ext))
403 where = "LEXSOURCES"; 421 where = "LEXSOURCES";
404 else if(file.endsWith(Option::yacc_ext)) 422 else if(file.endsWith(Option::yacc_ext))
405 where = "YACCSOURCES"; 423 where = "YACCSOURCES";
424 else if(file.endsWith(".ts"))
425 where = "TRANSLATIONS";
406 } 426 }
407 427
408 QString newfile = fileFixify(file); 428 QString newfile = fileFixify(file);
409 if(!where.isEmpty() && !project->variables()[where].contains(file)) { 429 if(!where.isEmpty() && !project->variables()[where].contains(file)) {
410 project->variables()[where] += newfile; 430 project->variables()[where] += newfile;
411 return TRUE; 431 return TRUE;
412 } 432 }
413 return FALSE; 433 return FALSE;
414} 434}
415 435
416 436
417QString 437QString
418ProjectGenerator::getWritableVar(const QString &v, bool /*fixPath*/) 438ProjectGenerator::getWritableVar(const QString &v, bool /*fixPath*/)
419{ 439{
420 QStringList &vals = project->variables()[v]; 440 QStringList &vals = project->variables()[v];
421 if(vals.isEmpty()) 441 if(vals.isEmpty())
422 return ""; 442 return "";
423 443
424 QString ret; 444 QString ret;
425 if(v.endsWith("_REMOVE")) 445 if(v.endsWith("_REMOVE"))
426 ret = v.left(v.length() - 7) + " -= "; 446 ret = v.left(v.length() - 7) + " -= ";
427 else if(v.endsWith("_ASSIGN")) 447 else if(v.endsWith("_ASSIGN"))
428 ret = v.left(v.length() - 7) + " = "; 448 ret = v.left(v.length() - 7) + " = ";
429 else 449 else
430 ret = v + " += "; 450 ret = v + " += ";
431 QString join = vals.join(" "); 451 QString join = vals.join(" ");
432 if(ret.length() + join.length() > 80) { 452 if(ret.length() + join.length() > 80) {
433 QString spaces; 453 QString spaces;
434 for(unsigned int i = 0; i < ret.length(); i++) 454 for(unsigned int i = 0; i < ret.length(); i++)
435 spaces += " "; 455 spaces += " ";
436 join = vals.join(" \\\n" + spaces); 456 join = vals.join(" \\\n" + spaces);
437 } 457 }
438 // ### Commented out for now so that project generation works. 458 // ### Commented out for now so that project generation works.
439 // Sam: can you look at why this was needed? 459 // Sam: can you look at why this was needed?
440 /* if(fixPath) 460 /* if(fixPath)
441 join = join.replace("\\", "/");*/ 461 join = join.replace("\\", "/");*/
442 return ret + join + "\n"; 462 return ret + join + "\n";
443} 463}
444 464
445bool 465bool
446ProjectGenerator::openOutput(QFile &file) const 466ProjectGenerator::openOutput(QFile &file) const
447{ 467{
448 QString outdir; 468 QString outdir;
449 if(!file.name().isEmpty()) { 469 if(!file.name().isEmpty()) {
450 QFileInfo fi(file); 470 QFileInfo fi(file);
451 if(fi.isDir()) 471 if(fi.isDir())
452 outdir = fi.dirPath() + QDir::separator(); 472 outdir = fi.dirPath() + QDir::separator();
453 } 473 }