|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the qmake application of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "makefile.h" |
|
43 #include "option.h" |
|
44 #include "cachekeys.h" |
|
45 #include "meta.h" |
|
46 #include <qdir.h> |
|
47 #include <qfile.h> |
|
48 #include <qtextstream.h> |
|
49 #include <qregexp.h> |
|
50 #include <qhash.h> |
|
51 #include <qdebug.h> |
|
52 #include <qbuffer.h> |
|
53 #include <qsettings.h> |
|
54 #include <qdatetime.h> |
|
55 #if defined(Q_OS_UNIX) |
|
56 #include <unistd.h> |
|
57 #else |
|
58 #include <io.h> |
|
59 #endif |
|
60 #include <qdebug.h> |
|
61 #include <stdio.h> |
|
62 #include <stdlib.h> |
|
63 #include <time.h> |
|
64 #include <fcntl.h> |
|
65 #include <sys/types.h> |
|
66 #include <sys/stat.h> |
|
67 |
|
68 QT_BEGIN_NAMESPACE |
|
69 |
|
70 // Well, Windows doesn't have this, so here's the macro |
|
71 #ifndef S_ISDIR |
|
72 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) |
|
73 #endif |
|
74 |
|
75 bool MakefileGenerator::canExecute(const QStringList &cmdline, int *a) const |
|
76 { |
|
77 int argv0 = -1; |
|
78 for(int i = 0; i < cmdline.count(); ++i) { |
|
79 if(!cmdline.at(i).contains('=')) { |
|
80 argv0 = i; |
|
81 break; |
|
82 } |
|
83 } |
|
84 if(a) |
|
85 *a = argv0; |
|
86 if(argv0 != -1) { |
|
87 const QString c = Option::fixPathToLocalOS(cmdline.at(argv0), true); |
|
88 if(exists(c)) |
|
89 return true; |
|
90 } |
|
91 return false; |
|
92 } |
|
93 |
|
94 QString MakefileGenerator::mkdir_p_asstring(const QString &dir, bool escape) const |
|
95 { |
|
96 QString ret = "@$(CHK_DIR_EXISTS) "; |
|
97 if(escape) |
|
98 ret += escapeFilePath(dir); |
|
99 else |
|
100 ret += dir; |
|
101 ret += " "; |
|
102 if(isWindowsShell()) |
|
103 ret += "$(MKDIR)"; |
|
104 else |
|
105 ret += "|| $(MKDIR)"; |
|
106 ret += " "; |
|
107 if(escape) |
|
108 ret += escapeFilePath(dir); |
|
109 else |
|
110 ret += dir; |
|
111 ret += " "; |
|
112 return ret; |
|
113 } |
|
114 |
|
115 bool MakefileGenerator::mkdir(const QString &in_path) const |
|
116 { |
|
117 QString path = Option::fixPathToLocalOS(in_path); |
|
118 if(QFile::exists(path)) |
|
119 return true; |
|
120 |
|
121 QDir d; |
|
122 if(path.startsWith(QDir::separator())) { |
|
123 d.cd(QString(QDir::separator())); |
|
124 path.remove(0, 1); |
|
125 } |
|
126 bool ret = true; |
|
127 #ifdef Q_OS_WIN |
|
128 bool driveExists = true; |
|
129 if(!QDir::isRelativePath(path)) { |
|
130 if(QFile::exists(path.left(3))) { |
|
131 d.cd(path.left(3)); |
|
132 path.remove(0, 3); |
|
133 } else { |
|
134 warn_msg(WarnLogic, "Cannot access drive '%s' (%s)", |
|
135 path.left(3).toLatin1().data(), path.toLatin1().data()); |
|
136 driveExists = false; |
|
137 } |
|
138 } |
|
139 if(driveExists) |
|
140 #endif |
|
141 { |
|
142 QStringList subs = path.split(QDir::separator()); |
|
143 for(QStringList::Iterator subit = subs.begin(); subit != subs.end(); ++subit) { |
|
144 if(!d.cd(*subit)) { |
|
145 d.mkdir((*subit)); |
|
146 if(d.exists((*subit))) { |
|
147 d.cd((*subit)); |
|
148 } else { |
|
149 ret = false; |
|
150 break; |
|
151 } |
|
152 } |
|
153 } |
|
154 } |
|
155 return ret; |
|
156 } |
|
157 |
|
158 // ** base makefile generator |
|
159 MakefileGenerator::MakefileGenerator() : |
|
160 init_opath_already(false), init_already(false), no_io(false), project(0) |
|
161 { |
|
162 } |
|
163 |
|
164 |
|
165 void |
|
166 MakefileGenerator::verifyCompilers() |
|
167 { |
|
168 QMap<QString, QStringList> &v = project->variables(); |
|
169 QStringList &quc = v["QMAKE_EXTRA_COMPILERS"]; |
|
170 for(int i = 0; i < quc.size(); ) { |
|
171 bool error = false; |
|
172 QString comp = quc.at(i); |
|
173 if(v[comp + ".output"].isEmpty()) { |
|
174 if(!v[comp + ".output_function"].isEmpty()) { |
|
175 v[comp + ".output"].append("${QMAKE_FUNC_FILE_IN_" + v[comp + ".output_function"].first() + "}"); |
|
176 } else { |
|
177 error = true; |
|
178 warn_msg(WarnLogic, "Compiler: %s: No output file specified", comp.toLatin1().constData()); |
|
179 } |
|
180 } else if(v[comp + ".input"].isEmpty()) { |
|
181 error = true; |
|
182 warn_msg(WarnLogic, "Compiler: %s: No input variable specified", comp.toLatin1().constData()); |
|
183 } |
|
184 if(error) |
|
185 quc.removeAt(i); |
|
186 else |
|
187 ++i; |
|
188 } |
|
189 } |
|
190 |
|
191 void |
|
192 MakefileGenerator::initOutPaths() |
|
193 { |
|
194 if(init_opath_already) |
|
195 return; |
|
196 verifyCompilers(); |
|
197 init_opath_already = true; |
|
198 QMap<QString, QStringList> &v = project->variables(); |
|
199 //for shadow builds |
|
200 if(!v.contains("QMAKE_ABSOLUTE_SOURCE_PATH")) { |
|
201 if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty() && |
|
202 v.contains("QMAKE_ABSOLUTE_SOURCE_ROOT")) { |
|
203 QString root = v["QMAKE_ABSOLUTE_SOURCE_ROOT"].first(); |
|
204 root = QDir::fromNativeSeparators(root); |
|
205 if(!root.isEmpty()) { |
|
206 QFileInfo fi = fileInfo(Option::mkfile::cachefile); |
|
207 if(!fi.makeAbsolute()) { |
|
208 QString cache_r = fi.path(), pwd = Option::output_dir; |
|
209 if(pwd.startsWith(cache_r) && !pwd.startsWith(root)) { |
|
210 pwd = root + pwd.mid(cache_r.length()); |
|
211 if(exists(pwd)) |
|
212 v.insert("QMAKE_ABSOLUTE_SOURCE_PATH", QStringList(pwd)); |
|
213 } |
|
214 } |
|
215 } |
|
216 } |
|
217 } |
|
218 if(!v["QMAKE_ABSOLUTE_SOURCE_PATH"].isEmpty()) { |
|
219 QString &asp = v["QMAKE_ABSOLUTE_SOURCE_PATH"].first(); |
|
220 asp = QDir::fromNativeSeparators(asp); |
|
221 if(asp.isEmpty() || asp == Option::output_dir) //if they're the same, why bother? |
|
222 v["QMAKE_ABSOLUTE_SOURCE_PATH"].clear(); |
|
223 } |
|
224 |
|
225 QString currentDir = qmake_getpwd(); //just to go back to |
|
226 |
|
227 //some builtin directories |
|
228 if(project->isEmpty("PRECOMPILED_DIR") && !project->isEmpty("OBJECTS_DIR")) |
|
229 v["PRECOMPILED_DIR"] = v["OBJECTS_DIR"]; |
|
230 QString dirs[] = { QString("OBJECTS_DIR"), QString("DESTDIR"), QString("QMAKE_PKGCONFIG_DESTDIR"), |
|
231 QString("SUBLIBS_DIR"), QString("DLLDESTDIR"), QString("QMAKE_LIBTOOL_DESTDIR"), |
|
232 QString("PRECOMPILED_DIR"), QString() }; |
|
233 for(int x = 0; !dirs[x].isEmpty(); x++) { |
|
234 if(v[dirs[x]].isEmpty()) |
|
235 continue; |
|
236 const QString orig_path = v[dirs[x]].first(); |
|
237 |
|
238 QString &pathRef = v[dirs[x]].first(); |
|
239 pathRef = fileFixify(pathRef, Option::output_dir, Option::output_dir); |
|
240 |
|
241 #ifdef Q_OS_WIN |
|
242 // We don't want to add a separator for DLLDESTDIR on Windows (###why?) |
|
243 if(!(dirs[x] == "DLLDESTDIR")) |
|
244 #endif |
|
245 { |
|
246 if(!pathRef.endsWith(Option::dir_sep)) |
|
247 pathRef += Option::dir_sep; |
|
248 } |
|
249 |
|
250 if(noIO()) |
|
251 continue; |
|
252 |
|
253 QString path = project->first(dirs[x]); //not to be changed any further |
|
254 path = fileFixify(path, currentDir, Option::output_dir); |
|
255 debug_msg(3, "Fixed output_dir %s (%s) into %s", dirs[x].toLatin1().constData(), |
|
256 orig_path.toLatin1().constData(), path.toLatin1().constData()); |
|
257 if(!mkdir(path)) |
|
258 warn_msg(WarnLogic, "%s: Cannot access directory '%s'", dirs[x].toLatin1().constData(), |
|
259 path.toLatin1().constData()); |
|
260 } |
|
261 |
|
262 //out paths from the extra compilers |
|
263 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); |
|
264 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { |
|
265 QString tmp_out = project->values((*it) + ".output").first(); |
|
266 if(tmp_out.isEmpty()) |
|
267 continue; |
|
268 const QStringList &tmp = project->values((*it) + ".input"); |
|
269 for(QStringList::ConstIterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) { |
|
270 QStringList &inputs = project->values((*it2)); |
|
271 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) { |
|
272 (*input) = fileFixify((*input), Option::output_dir, Option::output_dir); |
|
273 QString path = unescapeFilePath(replaceExtraCompilerVariables(tmp_out, (*input), QString())); |
|
274 path = Option::fixPathToTargetOS(path); |
|
275 int slash = path.lastIndexOf(Option::dir_sep); |
|
276 if(slash != -1) { |
|
277 path = path.left(slash); |
|
278 // Make out path only if it does not contain makefile variables |
|
279 if(!path.contains("${")) |
|
280 if(path != "." && |
|
281 !mkdir(fileFixify(path, qmake_getpwd(), Option::output_dir))) |
|
282 warn_msg(WarnLogic, "%s: Cannot access directory '%s'", |
|
283 (*it).toLatin1().constData(), path.toLatin1().constData()); |
|
284 } |
|
285 } |
|
286 } |
|
287 } |
|
288 |
|
289 if(!v["DESTDIR"].isEmpty()) { |
|
290 QDir d(v["DESTDIR"].first()); |
|
291 if(Option::fixPathToLocalOS(d.absolutePath()) == Option::fixPathToLocalOS(Option::output_dir)) |
|
292 v.remove("DESTDIR"); |
|
293 } |
|
294 } |
|
295 |
|
296 QMakeProject |
|
297 *MakefileGenerator::projectFile() const |
|
298 { |
|
299 return project; |
|
300 } |
|
301 |
|
302 void |
|
303 MakefileGenerator::setProjectFile(QMakeProject *p) |
|
304 { |
|
305 if(project) |
|
306 return; |
|
307 project = p; |
|
308 init(); |
|
309 usePlatformDir(); |
|
310 findLibraries(); |
|
311 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE && |
|
312 project->isActiveConfig("link_prl")) //load up prl's' |
|
313 processPrlFiles(); |
|
314 } |
|
315 |
|
316 QStringList |
|
317 MakefileGenerator::findFilesInVPATH(QStringList l, uchar flags, const QString &vpath_var) |
|
318 { |
|
319 QStringList vpath; |
|
320 QMap<QString, QStringList> &v = project->variables(); |
|
321 for(int val_it = 0; val_it < l.count(); ) { |
|
322 bool remove_file = false; |
|
323 QString &val = l[val_it]; |
|
324 if(!val.isEmpty()) { |
|
325 QString file = fixEnvVariables(val); |
|
326 if(!(flags & VPATH_NoFixify)) |
|
327 file = fileFixify(file, qmake_getpwd(), Option::output_dir); |
|
328 if (file.at(0) == '\"' && file.at(file.length() - 1) == '\"') |
|
329 file = file.mid(1, file.length() - 2); |
|
330 |
|
331 if(exists(file)) { |
|
332 ++val_it; |
|
333 continue; |
|
334 } |
|
335 bool found = false; |
|
336 if(QDir::isRelativePath(val)) { |
|
337 if(vpath.isEmpty()) { |
|
338 if(!vpath_var.isEmpty()) |
|
339 vpath = v[vpath_var]; |
|
340 vpath += v["VPATH"] + v["QMAKE_ABSOLUTE_SOURCE_PATH"] + v["DEPENDPATH"]; |
|
341 if(Option::output_dir != qmake_getpwd()) |
|
342 vpath += Option::output_dir; |
|
343 } |
|
344 for(QStringList::Iterator vpath_it = vpath.begin(); |
|
345 vpath_it != vpath.end(); ++vpath_it) { |
|
346 QString real_dir = Option::fixPathToLocalOS((*vpath_it)); |
|
347 if(exists(real_dir + QDir::separator() + val)) { |
|
348 QString dir = (*vpath_it); |
|
349 if(!dir.endsWith(Option::dir_sep)) |
|
350 dir += Option::dir_sep; |
|
351 val = dir + val; |
|
352 if(!(flags & VPATH_NoFixify)) |
|
353 val = fileFixify(val); |
|
354 found = true; |
|
355 debug_msg(1, "Found file through vpath %s -> %s", |
|
356 file.toLatin1().constData(), val.toLatin1().constData()); |
|
357 break; |
|
358 } |
|
359 } |
|
360 } |
|
361 if(!found) { |
|
362 QString dir, regex = val, real_dir; |
|
363 if(regex.lastIndexOf(Option::dir_sep) != -1) { |
|
364 dir = regex.left(regex.lastIndexOf(Option::dir_sep) + 1); |
|
365 real_dir = dir; |
|
366 if(!(flags & VPATH_NoFixify)) |
|
367 real_dir = fileFixify(real_dir, qmake_getpwd(), Option::output_dir); |
|
368 regex.remove(0, dir.length()); |
|
369 } |
|
370 if(real_dir.isEmpty() || exists(real_dir)) { |
|
371 QStringList files = QDir(real_dir).entryList(QStringList(regex)); |
|
372 if(files.isEmpty()) { |
|
373 debug_msg(1, "%s:%d Failure to find %s in vpath (%s)", |
|
374 __FILE__, __LINE__, |
|
375 val.toLatin1().constData(), vpath.join("::").toLatin1().constData()); |
|
376 if(flags & VPATH_RemoveMissingFiles) |
|
377 remove_file = true; |
|
378 else if(flags & VPATH_WarnMissingFiles) |
|
379 warn_msg(WarnLogic, "Failure to find: %s", val.toLatin1().constData()); |
|
380 } else { |
|
381 l.removeAt(val_it); |
|
382 QString a; |
|
383 for(int i = (int)files.count()-1; i >= 0; i--) { |
|
384 if(files[i] == "." || files[i] == "..") |
|
385 continue; |
|
386 a = dir + files[i]; |
|
387 if(!(flags & VPATH_NoFixify)) |
|
388 a = fileFixify(a); |
|
389 l.insert(val_it, a); |
|
390 } |
|
391 } |
|
392 } else { |
|
393 debug_msg(1, "%s:%d Cannot match %s%c%s, as %s does not exist.", |
|
394 __FILE__, __LINE__, real_dir.toLatin1().constData(), |
|
395 QDir::separator().toLatin1(), |
|
396 regex.toLatin1().constData(), real_dir.toLatin1().constData()); |
|
397 if(flags & VPATH_RemoveMissingFiles) |
|
398 remove_file = true; |
|
399 else if(flags & VPATH_WarnMissingFiles) |
|
400 warn_msg(WarnLogic, "Failure to find: %s", val.toLatin1().constData()); |
|
401 } |
|
402 } |
|
403 } |
|
404 if(remove_file) |
|
405 l.removeAt(val_it); |
|
406 else |
|
407 ++val_it; |
|
408 } |
|
409 return l; |
|
410 } |
|
411 |
|
412 void |
|
413 MakefileGenerator::initCompiler(const MakefileGenerator::Compiler &comp) |
|
414 { |
|
415 QMap<QString, QStringList> &v = project->variables(); |
|
416 QStringList &l = v[comp.variable_in]; |
|
417 // find all the relevant file inputs |
|
418 if(!init_compiler_already.contains(comp.variable_in)) { |
|
419 init_compiler_already.insert(comp.variable_in, true); |
|
420 if(!noIO()) |
|
421 l = findFilesInVPATH(l, (comp.flags & Compiler::CompilerRemoveNoExist) ? |
|
422 VPATH_RemoveMissingFiles : VPATH_WarnMissingFiles, "VPATH_" + comp.variable_in); |
|
423 } |
|
424 } |
|
425 |
|
426 void |
|
427 MakefileGenerator::init() |
|
428 { |
|
429 initOutPaths(); |
|
430 if(init_already) |
|
431 return; |
|
432 verifyCompilers(); |
|
433 init_already = true; |
|
434 |
|
435 QMap<QString, QStringList> &v = project->variables(); |
|
436 QStringList &quc = v["QMAKE_EXTRA_COMPILERS"]; |
|
437 |
|
438 //make sure the COMPILERS are in the correct input/output chain order |
|
439 for(int comp_out = 0, jump_count = 0; comp_out < quc.size(); ++comp_out) { |
|
440 continue_compiler_chain: |
|
441 if(jump_count > quc.size()) //just to avoid an infinite loop here |
|
442 break; |
|
443 if(project->variables().contains(quc.at(comp_out) + ".variable_out")) { |
|
444 const QStringList &outputs = project->variables().value(quc.at(comp_out) + ".variable_out"); |
|
445 for(int out = 0; out < outputs.size(); ++out) { |
|
446 for(int comp_in = 0; comp_in < quc.size(); ++comp_in) { |
|
447 if(comp_in == comp_out) |
|
448 continue; |
|
449 if(project->variables().contains(quc.at(comp_in) + ".input")) { |
|
450 const QStringList &inputs = project->variables().value(quc.at(comp_in) + ".input"); |
|
451 for(int in = 0; in < inputs.size(); ++in) { |
|
452 if(inputs.at(in) == outputs.at(out) && comp_out > comp_in) { |
|
453 ++jump_count; |
|
454 //move comp_out to comp_in and continue the compiler chain |
|
455 quc.move(comp_out, comp_in); |
|
456 comp_out = comp_in; |
|
457 goto continue_compiler_chain; |
|
458 } |
|
459 } |
|
460 } |
|
461 } |
|
462 } |
|
463 } |
|
464 } |
|
465 |
|
466 if(!project->isEmpty("QMAKE_SUBSTITUTES")) { |
|
467 const QStringList &subs = v["QMAKE_SUBSTITUTES"]; |
|
468 for(int i = 0; i < subs.size(); ++i) { |
|
469 if(!subs.at(i).endsWith(".in")) { |
|
470 warn_msg(WarnLogic, "Substitute '%s' does not end with '.in'", |
|
471 subs.at(i).toLatin1().constData()); |
|
472 continue; |
|
473 } |
|
474 QFile in(fileFixify(subs.at(i))), out(fileInfo(subs.at(i)).fileName()); |
|
475 if(out.fileName().endsWith(".in")) |
|
476 out.setFileName(out.fileName().left(out.fileName().length()-3)); |
|
477 if(in.open(QFile::ReadOnly)) { |
|
478 QString contents; |
|
479 QStack<int> state; |
|
480 enum { IN_CONDITION, MET_CONDITION, PENDING_CONDITION }; |
|
481 for(int count = 1; !in.atEnd(); ++count) { |
|
482 QString line = QString::fromUtf8(in.readLine()); |
|
483 if(line.startsWith("!!IF ")) { |
|
484 if(state.isEmpty() || state.top() == IN_CONDITION) { |
|
485 QString test = line.mid(5, line.length()-(5+1)); |
|
486 if(project->test(test)) |
|
487 state.push(IN_CONDITION); |
|
488 else |
|
489 state.push(PENDING_CONDITION); |
|
490 } else { |
|
491 state.push(MET_CONDITION); |
|
492 } |
|
493 } else if(line.startsWith("!!ELIF ")) { |
|
494 if(state.isEmpty()) { |
|
495 warn_msg(WarnLogic, "(%s:%d): Unexpected else condition", |
|
496 in.fileName().toLatin1().constData(), count); |
|
497 } else if(state.top() == PENDING_CONDITION) { |
|
498 QString test = line.mid(7, line.length()-(7+1)); |
|
499 if(project->test(test)) { |
|
500 state.pop(); |
|
501 state.push(IN_CONDITION); |
|
502 } |
|
503 } else if(state.top() == IN_CONDITION) { |
|
504 state.pop(); |
|
505 state.push(MET_CONDITION); |
|
506 } |
|
507 } else if(line.startsWith("!!ELSE")) { |
|
508 if(state.isEmpty()) { |
|
509 warn_msg(WarnLogic, "(%s:%d): Unexpected else condition", |
|
510 in.fileName().toLatin1().constData(), count); |
|
511 } else if(state.top() == PENDING_CONDITION) { |
|
512 state.pop(); |
|
513 state.push(IN_CONDITION); |
|
514 } else if(state.top() == IN_CONDITION) { |
|
515 state.pop(); |
|
516 state.push(MET_CONDITION); |
|
517 } |
|
518 } else if(line.startsWith("!!ENDIF")) { |
|
519 if(state.isEmpty()) |
|
520 warn_msg(WarnLogic, "(%s:%d): Unexpected endif", |
|
521 in.fileName().toLatin1().constData(), count); |
|
522 else |
|
523 state.pop(); |
|
524 } else if(state.isEmpty() || state.top() == IN_CONDITION) { |
|
525 contents += project->expand(line).join(QString(Option::field_sep)); |
|
526 } |
|
527 } |
|
528 if(out.exists() && out.open(QFile::ReadOnly)) { |
|
529 QString old = QString::fromUtf8(out.readAll()); |
|
530 if(contents == old) { |
|
531 v["QMAKE_INTERNAL_INCLUDED_FILES"].append(subs.at(i)); |
|
532 continue; |
|
533 } |
|
534 out.close(); |
|
535 if(!out.remove()) { |
|
536 warn_msg(WarnLogic, "Cannot clear substitute '%s'", |
|
537 out.fileName().toLatin1().constData()); |
|
538 continue; |
|
539 } |
|
540 } |
|
541 if(out.open(QFile::WriteOnly)) { |
|
542 v["QMAKE_INTERNAL_INCLUDED_FILES"].append(subs.at(i)); |
|
543 out.write(contents.toUtf8()); |
|
544 } else { |
|
545 warn_msg(WarnLogic, "Cannot open substitute for output '%s'", |
|
546 out.fileName().toLatin1().constData()); |
|
547 } |
|
548 } else { |
|
549 warn_msg(WarnLogic, "Cannot open substitute for input '%s'", |
|
550 in.fileName().toLatin1().constData()); |
|
551 } |
|
552 } |
|
553 } |
|
554 |
|
555 int x; |
|
556 |
|
557 //build up a list of compilers |
|
558 QList<Compiler> compilers; |
|
559 { |
|
560 const char *builtins[] = { "OBJECTS", "SOURCES", "PRECOMPILED_HEADER", 0 }; |
|
561 for(x = 0; builtins[x]; ++x) { |
|
562 Compiler compiler; |
|
563 compiler.variable_in = builtins[x]; |
|
564 compiler.flags = Compiler::CompilerBuiltin; |
|
565 compiler.type = QMakeSourceFileInfo::TYPE_C; |
|
566 if(!strcmp(builtins[x], "OBJECTS")) |
|
567 compiler.flags |= Compiler::CompilerNoCheckDeps; |
|
568 compilers.append(compiler); |
|
569 } |
|
570 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { |
|
571 const QStringList &inputs = v[(*it) + ".input"]; |
|
572 for(x = 0; x < inputs.size(); ++x) { |
|
573 Compiler compiler; |
|
574 compiler.variable_in = inputs.at(x); |
|
575 compiler.flags = Compiler::CompilerNoFlags; |
|
576 if(v[(*it) + ".CONFIG"].indexOf("ignore_no_exist") != -1) |
|
577 compiler.flags |= Compiler::CompilerRemoveNoExist; |
|
578 if(v[(*it) + ".CONFIG"].indexOf("no_dependencies") != -1) |
|
579 compiler.flags |= Compiler::CompilerNoCheckDeps; |
|
580 |
|
581 QString dep_type; |
|
582 if(!project->isEmpty((*it) + ".dependency_type")) |
|
583 dep_type = project->first((*it) + ".dependency_type"); |
|
584 if (dep_type.isEmpty()) |
|
585 compiler.type = QMakeSourceFileInfo::TYPE_UNKNOWN; |
|
586 else if(dep_type == "TYPE_UI") |
|
587 compiler.type = QMakeSourceFileInfo::TYPE_UI; |
|
588 else |
|
589 compiler.type = QMakeSourceFileInfo::TYPE_C; |
|
590 compilers.append(compiler); |
|
591 } |
|
592 } |
|
593 } |
|
594 { //do the path fixifying |
|
595 QStringList paths; |
|
596 for(x = 0; x < compilers.count(); ++x) { |
|
597 if(!paths.contains(compilers.at(x).variable_in)) |
|
598 paths << compilers.at(x).variable_in; |
|
599 } |
|
600 paths << "INCLUDEPATH" << "QMAKE_INTERNAL_INCLUDED_FILES" << "PRECOMPILED_HEADER"; |
|
601 for(int y = 0; y < paths.count(); y++) { |
|
602 QStringList &l = v[paths[y]]; |
|
603 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { |
|
604 if((*it).isEmpty()) |
|
605 continue; |
|
606 if(exists((*it))) |
|
607 (*it) = fileFixify((*it)); |
|
608 } |
|
609 } |
|
610 } |
|
611 |
|
612 if(noIO() || !doDepends()) |
|
613 QMakeSourceFileInfo::setDependencyMode(QMakeSourceFileInfo::NonRecursive); |
|
614 for(x = 0; x < compilers.count(); ++x) |
|
615 initCompiler(compilers.at(x)); |
|
616 |
|
617 //merge actual compiler outputs into their variable_out. This is done last so that |
|
618 //files are already properly fixified. |
|
619 for(QStringList::Iterator it = quc.begin(); it != quc.end(); ++it) { |
|
620 QString tmp_out = project->values((*it) + ".output").first(); |
|
621 if(tmp_out.isEmpty()) |
|
622 continue; |
|
623 if(project->values((*it) + ".CONFIG").indexOf("combine") != -1) { |
|
624 QStringList &compilerInputs = project->values((*it) + ".input"); |
|
625 // Don't generate compiler output if it doesn't have input. |
|
626 if (compilerInputs.isEmpty() || project->values(compilerInputs.first()).isEmpty()) |
|
627 continue; |
|
628 if(tmp_out.indexOf("$") == -1) { |
|
629 if(!verifyExtraCompiler((*it), QString())) //verify |
|
630 continue; |
|
631 QString out = fileFixify(tmp_out, Option::output_dir, Option::output_dir); |
|
632 bool pre_dep = (project->values((*it) + ".CONFIG").indexOf("target_predeps") != -1); |
|
633 if(project->variables().contains((*it) + ".variable_out")) { |
|
634 const QStringList &var_out = project->variables().value((*it) + ".variable_out"); |
|
635 for(int i = 0; i < var_out.size(); ++i) { |
|
636 QString v = var_out.at(i); |
|
637 if(v == QLatin1String("SOURCES")) |
|
638 v = "GENERATED_SOURCES"; |
|
639 else if(v == QLatin1String("OBJECTS")) |
|
640 pre_dep = false; |
|
641 QStringList &list = project->values(v); |
|
642 if(!list.contains(out)) |
|
643 list.append(out); |
|
644 } |
|
645 } else if(project->values((*it) + ".CONFIG").indexOf("no_link") == -1) { |
|
646 QStringList &list = project->values("OBJECTS"); |
|
647 pre_dep = false; |
|
648 if(!list.contains(out)) |
|
649 list.append(out); |
|
650 } else { |
|
651 QStringList &list = project->values("UNUSED_SOURCES"); |
|
652 if(!list.contains(out)) |
|
653 list.append(out); |
|
654 } |
|
655 if(pre_dep) { |
|
656 QStringList &list = project->variables()["PRE_TARGETDEPS"]; |
|
657 if(!list.contains(out)) |
|
658 list.append(out); |
|
659 } |
|
660 } |
|
661 } else { |
|
662 QStringList &tmp = project->values((*it) + ".input"); |
|
663 for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) { |
|
664 const QStringList inputs = project->values((*it2)); |
|
665 for(QStringList::ConstIterator input = inputs.constBegin(); input != inputs.constEnd(); ++input) { |
|
666 if((*input).isEmpty()) |
|
667 continue; |
|
668 QString in = Option::fixPathToTargetOS((*input), false); |
|
669 if(!verifyExtraCompiler((*it), in)) //verify |
|
670 continue; |
|
671 QString out = replaceExtraCompilerVariables(tmp_out, (*input), QString()); |
|
672 out = fileFixify(out, Option::output_dir, Option::output_dir); |
|
673 bool pre_dep = (project->values((*it) + ".CONFIG").indexOf("target_predeps") != -1); |
|
674 if(project->variables().contains((*it) + ".variable_out")) { |
|
675 const QStringList &var_out = project->variables().value((*it) + ".variable_out"); |
|
676 for(int i = 0; i < var_out.size(); ++i) { |
|
677 QString v = var_out.at(i); |
|
678 if(v == QLatin1String("SOURCES")) |
|
679 v = "GENERATED_SOURCES"; |
|
680 else if(v == QLatin1String("OBJECTS")) |
|
681 pre_dep = false; |
|
682 QStringList &list = project->values(v); |
|
683 if(!list.contains(out)) |
|
684 list.append(out); |
|
685 } |
|
686 } else if(project->values((*it) + ".CONFIG").indexOf("no_link") == -1) { |
|
687 pre_dep = false; |
|
688 QStringList &list = project->values("OBJECTS"); |
|
689 if(!list.contains(out)) |
|
690 list.append(out); |
|
691 } else { |
|
692 QStringList &list = project->values("UNUSED_SOURCES"); |
|
693 if(!list.contains(out)) |
|
694 list.append(out); |
|
695 } |
|
696 if(pre_dep) { |
|
697 QStringList &list = project->variables()["PRE_TARGETDEPS"]; |
|
698 if(!list.contains(out)) |
|
699 list.append(out); |
|
700 } |
|
701 } |
|
702 } |
|
703 } |
|
704 } |
|
705 |
|
706 //handle dependencies |
|
707 depHeuristicsCache.clear(); |
|
708 if(!noIO()) { |
|
709 // dependency paths |
|
710 QStringList incDirs = v["DEPENDPATH"] + v["QMAKE_ABSOLUTE_SOURCE_PATH"]; |
|
711 if(project->isActiveConfig("depend_includepath")) |
|
712 incDirs += v["INCLUDEPATH"]; |
|
713 if(!project->isActiveConfig("no_include_pwd")) { |
|
714 QString pwd = qmake_getpwd(); |
|
715 if(pwd.isEmpty()) |
|
716 pwd = "."; |
|
717 incDirs += pwd; |
|
718 } |
|
719 QList<QMakeLocalFileName> deplist; |
|
720 for(QStringList::Iterator it = incDirs.begin(); it != incDirs.end(); ++it) |
|
721 deplist.append(QMakeLocalFileName(unescapeFilePath((*it)))); |
|
722 QMakeSourceFileInfo::setDependencyPaths(deplist); |
|
723 debug_msg(1, "Dependency Directories: %s", incDirs.join(" :: ").toLatin1().constData()); |
|
724 //cache info |
|
725 if(project->isActiveConfig("qmake_cache")) { |
|
726 QString cache_file; |
|
727 if(!project->isEmpty("QMAKE_INTERNAL_CACHE_FILE")) { |
|
728 cache_file = QDir::fromNativeSeparators(project->first("QMAKE_INTERNAL_CACHE_FILE")); |
|
729 } else { |
|
730 cache_file = ".qmake.internal.cache"; |
|
731 if(project->isActiveConfig("build_pass")) |
|
732 cache_file += ".BUILD." + project->first("BUILD_PASS"); |
|
733 } |
|
734 if(cache_file.indexOf('/') == -1) |
|
735 cache_file.prepend(Option::output_dir + '/'); |
|
736 QMakeSourceFileInfo::setCacheFile(cache_file); |
|
737 } |
|
738 |
|
739 //add to dependency engine |
|
740 for(x = 0; x < compilers.count(); ++x) { |
|
741 const MakefileGenerator::Compiler &comp = compilers.at(x); |
|
742 if(!(comp.flags & Compiler::CompilerNoCheckDeps)) |
|
743 addSourceFiles(v[comp.variable_in], QMakeSourceFileInfo::SEEK_DEPS, |
|
744 (QMakeSourceFileInfo::SourceFileType)comp.type); |
|
745 } |
|
746 } |
|
747 |
|
748 processSources(); //remove anything in SOURCES which is included (thus it need not be linked in) |
|
749 |
|
750 //all sources and generated sources must be turned into objects at some point (the one builtin compiler) |
|
751 v["OBJECTS"] += createObjectList(v["SOURCES"]) + createObjectList(v["GENERATED_SOURCES"]); |
|
752 |
|
753 //Translation files |
|
754 if(!project->isEmpty("TRANSLATIONS")) { |
|
755 QStringList &trf = project->values("TRANSLATIONS"); |
|
756 for(QStringList::Iterator it = trf.begin(); it != trf.end(); ++it) |
|
757 (*it) = Option::fixPathToLocalOS((*it)); |
|
758 } |
|
759 |
|
760 { //get the output_dir into the pwd |
|
761 if(fileFixify(Option::output_dir) != fileFixify(qmake_getpwd())) |
|
762 project->values("INCLUDEPATH").append(fileFixify(Option::output_dir, |
|
763 Option::output_dir, |
|
764 Option::output_dir)); |
|
765 } |
|
766 |
|
767 //fix up the target deps |
|
768 QString fixpaths[] = { QString("PRE_TARGETDEPS"), QString("POST_TARGETDEPS"), QString() }; |
|
769 for(int path = 0; !fixpaths[path].isNull(); path++) { |
|
770 QStringList &l = v[fixpaths[path]]; |
|
771 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) { |
|
772 if(!(*val_it).isEmpty()) |
|
773 (*val_it) = escapeDependencyPath(Option::fixPathToTargetOS((*val_it), false, false)); |
|
774 } |
|
775 } |
|
776 |
|
777 //extra depends |
|
778 if(!project->isEmpty("DEPENDS")) { |
|
779 QStringList &l = v["DEPENDS"]; |
|
780 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { |
|
781 QStringList files = v[(*it) + ".file"] + v[(*it) + ".files"]; //why do I support such evil things? |
|
782 for(QStringList::Iterator file_it = files.begin(); file_it != files.end(); ++file_it) { |
|
783 QStringList &out_deps = findDependencies(*file_it); |
|
784 QStringList &in_deps = v[(*it) + ".depends"]; //even more evilness.. |
|
785 for(QStringList::Iterator dep_it = in_deps.begin(); dep_it != in_deps.end(); ++dep_it) { |
|
786 if(exists(*dep_it)) { |
|
787 out_deps.append(*dep_it); |
|
788 } else { |
|
789 QString dir, regex = Option::fixPathToLocalOS((*dep_it)); |
|
790 if(regex.lastIndexOf(Option::dir_sep) != -1) { |
|
791 dir = regex.left(regex.lastIndexOf(Option::dir_sep) + 1); |
|
792 regex.remove(0, dir.length()); |
|
793 } |
|
794 QStringList files = QDir(dir).entryList(QStringList(regex)); |
|
795 if(files.isEmpty()) { |
|
796 warn_msg(WarnLogic, "Dependency for [%s]: Not found %s", (*file_it).toLatin1().constData(), |
|
797 (*dep_it).toLatin1().constData()); |
|
798 } else { |
|
799 for(int i = 0; i < files.count(); i++) |
|
800 out_deps.append(dir + files[i]); |
|
801 } |
|
802 } |
|
803 } |
|
804 } |
|
805 } |
|
806 } |
|
807 |
|
808 // escape qmake command |
|
809 if (!project->isEmpty("QMAKE_QMAKE")) { |
|
810 project->values("QMAKE_QMAKE") = escapeFilePaths(project->values("QMAKE_QMAKE")); |
|
811 } |
|
812 } |
|
813 |
|
814 bool |
|
815 MakefileGenerator::processPrlFile(QString &file) |
|
816 { |
|
817 bool ret = false, try_replace_file=false; |
|
818 QString meta_file, orig_file = file; |
|
819 if(QMakeMetaInfo::libExists(file)) { |
|
820 try_replace_file = true; |
|
821 meta_file = file; |
|
822 file = ""; |
|
823 } else { |
|
824 QString tmp = file; |
|
825 int ext = tmp.lastIndexOf('.'); |
|
826 if(ext != -1) |
|
827 tmp = tmp.left(ext); |
|
828 meta_file = tmp; |
|
829 } |
|
830 // meta_file = fileFixify(meta_file); |
|
831 QString real_meta_file = Option::fixPathToLocalOS(meta_file); |
|
832 if(!meta_file.isEmpty()) { |
|
833 QString f = fileFixify(real_meta_file, qmake_getpwd(), Option::output_dir); |
|
834 if(QMakeMetaInfo::libExists(f)) { |
|
835 QMakeMetaInfo libinfo; |
|
836 debug_msg(1, "Processing PRL file: %s", real_meta_file.toLatin1().constData()); |
|
837 if(!libinfo.readLib(f)) { |
|
838 fprintf(stderr, "Error processing meta file: %s\n", real_meta_file.toLatin1().constData()); |
|
839 } else if(project->isActiveConfig("no_read_prl_" + libinfo.type().toLower())) { |
|
840 debug_msg(2, "Ignored meta file %s [%s]", real_meta_file.toLatin1().constData(), libinfo.type().toLatin1().constData()); |
|
841 } else { |
|
842 ret = true; |
|
843 QMap<QString, QStringList> &vars = libinfo.variables(); |
|
844 for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it) |
|
845 processPrlVariable(it.key(), it.value()); |
|
846 if(try_replace_file && !libinfo.isEmpty("QMAKE_PRL_TARGET")) { |
|
847 QString dir; |
|
848 int slsh = real_meta_file.lastIndexOf(Option::dir_sep); |
|
849 if(slsh != -1) |
|
850 dir = real_meta_file.left(slsh+1); |
|
851 file = libinfo.first("QMAKE_PRL_TARGET"); |
|
852 if(QDir::isRelativePath(file)) |
|
853 file.prepend(dir); |
|
854 } |
|
855 } |
|
856 } |
|
857 if(ret) { |
|
858 QString mf = QMakeMetaInfo::findLib(meta_file); |
|
859 if(project->values("QMAKE_PRL_INTERNAL_FILES").indexOf(mf) == -1) |
|
860 project->values("QMAKE_PRL_INTERNAL_FILES").append(mf); |
|
861 if(project->values("QMAKE_INTERNAL_INCLUDED_FILES").indexOf(mf) == -1) |
|
862 project->values("QMAKE_INTERNAL_INCLUDED_FILES").append(mf); |
|
863 } |
|
864 } |
|
865 if(try_replace_file && file.isEmpty()) { |
|
866 #if 0 |
|
867 warn_msg(WarnLogic, "Found prl [%s] file with no target [%s]!", meta_file.toLatin1().constData(), |
|
868 orig_file.toLatin1().constData()); |
|
869 #endif |
|
870 file = orig_file; |
|
871 } |
|
872 return ret; |
|
873 } |
|
874 |
|
875 void |
|
876 MakefileGenerator::filterIncludedFiles(const QString &var) |
|
877 { |
|
878 QStringList &inputs = project->values(var); |
|
879 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ) { |
|
880 if(QMakeSourceFileInfo::included((*input)) > 0) |
|
881 input = inputs.erase(input); |
|
882 else |
|
883 ++input; |
|
884 } |
|
885 } |
|
886 |
|
887 void |
|
888 MakefileGenerator::processPrlVariable(const QString &var, const QStringList &l) |
|
889 { |
|
890 if(var == "QMAKE_PRL_LIBS") { |
|
891 QString where = "QMAKE_LIBS"; |
|
892 if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) |
|
893 where = project->first("QMAKE_INTERNAL_PRL_LIBS"); |
|
894 QStringList &out = project->values(where); |
|
895 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { |
|
896 if(out.indexOf((*it)) == -1) |
|
897 out.append((*it)); |
|
898 } |
|
899 } else if(var == "QMAKE_PRL_DEFINES") { |
|
900 QStringList &out = project->values("DEFINES"); |
|
901 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { |
|
902 if(out.indexOf((*it)) == -1 && |
|
903 project->values("PRL_EXPORT_DEFINES").indexOf((*it)) == -1) |
|
904 out.append((*it)); |
|
905 } |
|
906 } |
|
907 } |
|
908 |
|
909 void |
|
910 MakefileGenerator::processPrlFiles() |
|
911 { |
|
912 QHash<QString, bool> processed; |
|
913 for(bool ret = false; true; ret = false) { |
|
914 //read in any prl files included.. |
|
915 QStringList l_out; |
|
916 QString where = "QMAKE_LIBS"; |
|
917 if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) |
|
918 where = project->first("QMAKE_INTERNAL_PRL_LIBS"); |
|
919 QStringList &l = project->values(where); |
|
920 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { |
|
921 QString file = (*it); |
|
922 if(!processed.contains(file) && processPrlFile(file)) { |
|
923 processed.insert(file, true); |
|
924 ret = true; |
|
925 } |
|
926 if(!file.isEmpty()) |
|
927 l_out.append(file); |
|
928 } |
|
929 if(ret) |
|
930 l = l_out; |
|
931 else |
|
932 break; |
|
933 } |
|
934 } |
|
935 |
|
936 void |
|
937 MakefileGenerator::writePrlFile(QTextStream &t) |
|
938 { |
|
939 QString target = project->first("TARGET"); |
|
940 int slsh = target.lastIndexOf(Option::dir_sep); |
|
941 if(slsh != -1) |
|
942 target.remove(0, slsh + 1); |
|
943 QString bdir = Option::output_dir; |
|
944 if(bdir.isEmpty()) |
|
945 bdir = qmake_getpwd(); |
|
946 t << "QMAKE_PRL_BUILD_DIR = " << bdir << endl; |
|
947 |
|
948 if(!project->projectFile().isEmpty() && project->projectFile() != "-") |
|
949 t << "QMAKE_PRO_INPUT = " << project->projectFile().section('/', -1) << endl; |
|
950 |
|
951 if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH")) |
|
952 t << "QMAKE_PRL_SOURCE_DIR = " << project->first("QMAKE_ABSOLUTE_SOURCE_PATH") << endl; |
|
953 t << "QMAKE_PRL_TARGET = " << target << endl; |
|
954 if(!project->isEmpty("PRL_EXPORT_DEFINES")) |
|
955 t << "QMAKE_PRL_DEFINES = " << project->values("PRL_EXPORT_DEFINES").join(" ") << endl; |
|
956 if(!project->isEmpty("PRL_EXPORT_CFLAGS")) |
|
957 t << "QMAKE_PRL_CFLAGS = " << project->values("PRL_EXPORT_CFLAGS").join(" ") << endl; |
|
958 if(!project->isEmpty("PRL_EXPORT_CXXFLAGS")) |
|
959 t << "QMAKE_PRL_CXXFLAGS = " << project->values("PRL_EXPORT_CXXFLAGS").join(" ") << endl; |
|
960 if(!project->isEmpty("CONFIG")) |
|
961 t << "QMAKE_PRL_CONFIG = " << project->values("CONFIG").join(" ") << endl; |
|
962 if(!project->isEmpty("TARGET_VERSION_EXT")) |
|
963 t << "QMAKE_PRL_VERSION = " << project->first("TARGET_VERSION_EXT") << endl; |
|
964 else if(!project->isEmpty("VERSION")) |
|
965 t << "QMAKE_PRL_VERSION = " << project->first("VERSION") << endl; |
|
966 if(project->isActiveConfig("staticlib") || project->isActiveConfig("explicitlib")) { |
|
967 QStringList libs; |
|
968 if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) |
|
969 libs = project->values("QMAKE_INTERNAL_PRL_LIBS"); |
|
970 else |
|
971 libs << "QMAKE_LIBS"; //obvious one |
|
972 if(project->isActiveConfig("staticlib")) |
|
973 libs << "QMAKE_LIBS_PRIVATE"; |
|
974 t << "QMAKE_PRL_LIBS = "; |
|
975 for(QStringList::Iterator it = libs.begin(); it != libs.end(); ++it) |
|
976 t << project->values((*it)).join(" ") << " "; |
|
977 t << endl; |
|
978 } |
|
979 } |
|
980 |
|
981 bool |
|
982 MakefileGenerator::writeProjectMakefile() |
|
983 { |
|
984 usePlatformDir(); |
|
985 QTextStream t(&Option::output); |
|
986 |
|
987 //header |
|
988 writeHeader(t); |
|
989 |
|
990 QList<SubTarget*> targets; |
|
991 { |
|
992 QStringList builds = project->values("BUILDS"); |
|
993 for(QStringList::Iterator it = builds.begin(); it != builds.end(); ++it) { |
|
994 SubTarget *st = new SubTarget; |
|
995 targets.append(st); |
|
996 st->makefile = "$(MAKEFILE)." + (*it); |
|
997 st->name = (*it); |
|
998 st->target = project->isEmpty((*it) + ".target") ? (*it) : project->first((*it) + ".target"); |
|
999 } |
|
1000 } |
|
1001 if(project->isActiveConfig("build_all")) { |
|
1002 t << "first: all" << endl; |
|
1003 QList<SubTarget*>::Iterator it; |
|
1004 |
|
1005 //install |
|
1006 t << "install: "; |
|
1007 for(it = targets.begin(); it != targets.end(); ++it) |
|
1008 t << (*it)->target << "-install "; |
|
1009 t << endl; |
|
1010 |
|
1011 //uninstall |
|
1012 t << "uninstall: "; |
|
1013 for(it = targets.begin(); it != targets.end(); ++it) |
|
1014 t << (*it)->target << "-uninstall "; |
|
1015 t << endl; |
|
1016 } else { |
|
1017 t << "first: " << targets.first()->target << endl |
|
1018 << "install: " << targets.first()->target << "-install" << endl |
|
1019 << "uninstall: " << targets.first()->target << "-uninstall" << endl; |
|
1020 } |
|
1021 |
|
1022 writeSubTargets(t, targets, SubTargetsNoFlags); |
|
1023 if(!project->isActiveConfig("no_autoqmake")) { |
|
1024 for(QList<SubTarget*>::Iterator it = targets.begin(); it != targets.end(); ++it) |
|
1025 t << (*it)->makefile << ": " << |
|
1026 Option::fixPathToTargetOS(fileFixify(Option::output.fileName())) << endl; |
|
1027 } |
|
1028 qDeleteAll(targets); |
|
1029 return true; |
|
1030 } |
|
1031 |
|
1032 bool |
|
1033 MakefileGenerator::write() |
|
1034 { |
|
1035 if(!project) |
|
1036 return false; |
|
1037 writePrlFile(); |
|
1038 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || //write makefile |
|
1039 Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) { |
|
1040 QTextStream t(&Option::output); |
|
1041 if(!writeMakefile(t)) { |
|
1042 #if 1 |
|
1043 warn_msg(WarnLogic, "Unable to generate output for: %s [TEMPLATE %s]", |
|
1044 Option::output.fileName().toLatin1().constData(), |
|
1045 project->first("TEMPLATE").toLatin1().constData()); |
|
1046 if(Option::output.exists()) |
|
1047 Option::output.remove(); |
|
1048 #endif |
|
1049 } |
|
1050 } |
|
1051 return true; |
|
1052 } |
|
1053 |
|
1054 QString |
|
1055 MakefileGenerator::prlFileName(bool fixify) |
|
1056 { |
|
1057 QString ret = project->first("TARGET_PRL");; |
|
1058 if(ret.isEmpty()) |
|
1059 ret = project->first("TARGET"); |
|
1060 int slsh = ret.lastIndexOf(Option::dir_sep); |
|
1061 if(slsh != -1) |
|
1062 ret.remove(0, slsh); |
|
1063 if(!ret.endsWith(Option::prl_ext)) { |
|
1064 int dot = ret.indexOf('.'); |
|
1065 if(dot != -1) |
|
1066 ret.truncate(dot); |
|
1067 ret += Option::prl_ext; |
|
1068 } |
|
1069 if(!project->isEmpty("QMAKE_BUNDLE")) |
|
1070 ret.prepend(project->first("QMAKE_BUNDLE") + Option::dir_sep); |
|
1071 if(fixify) { |
|
1072 if(!project->isEmpty("DESTDIR")) |
|
1073 ret.prepend(project->first("DESTDIR")); |
|
1074 ret = Option::fixPathToLocalOS(fileFixify(ret, qmake_getpwd(), Option::output_dir)); |
|
1075 } |
|
1076 return ret; |
|
1077 } |
|
1078 |
|
1079 void |
|
1080 MakefileGenerator::writePrlFile() |
|
1081 { |
|
1082 if((Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || |
|
1083 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) |
|
1084 && project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty() |
|
1085 && project->isActiveConfig("create_prl") |
|
1086 && (project->first("TEMPLATE") == "lib" |
|
1087 || project->first("TEMPLATE") == "vclib") |
|
1088 && !project->isActiveConfig("plugin")) { //write prl file |
|
1089 QString local_prl = prlFileName(); |
|
1090 QString prl = fileFixify(local_prl); |
|
1091 mkdir(fileInfo(local_prl).path()); |
|
1092 QFile ft(local_prl); |
|
1093 if(ft.open(QIODevice::WriteOnly)) { |
|
1094 project->values("ALL_DEPS").append(prl); |
|
1095 project->values("QMAKE_INTERNAL_PRL_FILE").append(prl); |
|
1096 QTextStream t(&ft); |
|
1097 writePrlFile(t); |
|
1098 } |
|
1099 } |
|
1100 } |
|
1101 |
|
1102 // Manipulate directories, so it's possible to build |
|
1103 // several cross-platform targets concurrently |
|
1104 void |
|
1105 MakefileGenerator::usePlatformDir() |
|
1106 { |
|
1107 QString pltDir(project->first("QMAKE_PLATFORM_DIR")); |
|
1108 if(pltDir.isEmpty()) |
|
1109 return; |
|
1110 QChar sep = QDir::separator(); |
|
1111 QString slashPltDir = sep + pltDir; |
|
1112 |
|
1113 QString dirs[] = { QString("OBJECTS_DIR"), QString("DESTDIR"), QString("QMAKE_PKGCONFIG_DESTDIR"), |
|
1114 QString("SUBLIBS_DIR"), QString("DLLDESTDIR"), QString("QMAKE_LIBTOOL_DESTDIR"), |
|
1115 QString("PRECOMPILED_DIR"), QString("QMAKE_LIBDIR_QT"), QString() }; |
|
1116 for(int i = 0; !dirs[i].isEmpty(); ++i) { |
|
1117 QString filePath = project->first(dirs[i]); |
|
1118 project->values(dirs[i]) = QStringList(filePath + (filePath.isEmpty() ? pltDir : slashPltDir)); |
|
1119 } |
|
1120 |
|
1121 QString libs[] = { QString("QMAKE_LIBS_QT"), QString("QMAKE_LIBS_QT_THREAD"), QString("QMAKE_LIBS_QT_ENTRY"), QString() }; |
|
1122 for(int i = 0; !libs[i].isEmpty(); ++i) { |
|
1123 QString filePath = project->first(libs[i]); |
|
1124 int fpi = filePath.lastIndexOf(sep); |
|
1125 if(fpi == -1) |
|
1126 project->values(libs[i]).prepend(pltDir + sep); |
|
1127 else |
|
1128 project->values(libs[i]) = QStringList(filePath.left(fpi) + slashPltDir + filePath.mid(fpi)); |
|
1129 } |
|
1130 } |
|
1131 |
|
1132 void |
|
1133 MakefileGenerator::writeObj(QTextStream &t, const QString &src) |
|
1134 { |
|
1135 QStringList &srcl = project->values(src); |
|
1136 QStringList objl = createObjectList(srcl); |
|
1137 |
|
1138 QStringList::Iterator oit = objl.begin(); |
|
1139 QStringList::Iterator sit = srcl.begin(); |
|
1140 QString stringSrc("$src"); |
|
1141 QString stringObj("$obj"); |
|
1142 for(;sit != srcl.end() && oit != objl.end(); ++oit, ++sit) { |
|
1143 if((*sit).isEmpty()) |
|
1144 continue; |
|
1145 |
|
1146 t << escapeDependencyPath((*oit)) << ": " << escapeDependencyPath((*sit)) << " " << escapeDependencyPaths(findDependencies((*sit))).join(" \\\n\t\t"); |
|
1147 |
|
1148 QString comp, cimp; |
|
1149 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) { |
|
1150 if((*sit).endsWith((*cppit))) { |
|
1151 comp = "QMAKE_RUN_CXX"; |
|
1152 cimp = "QMAKE_RUN_CXX_IMP"; |
|
1153 break; |
|
1154 } |
|
1155 } |
|
1156 if(comp.isEmpty()) { |
|
1157 comp = "QMAKE_RUN_CC"; |
|
1158 cimp = "QMAKE_RUN_CC_IMP"; |
|
1159 } |
|
1160 bool use_implicit_rule = !project->isEmpty(cimp); |
|
1161 use_implicit_rule = false; |
|
1162 if(use_implicit_rule) { |
|
1163 if(!project->isEmpty("OBJECTS_DIR")) { |
|
1164 use_implicit_rule = false; |
|
1165 } else { |
|
1166 int dot = (*sit).lastIndexOf('.'); |
|
1167 if(dot == -1 || ((*sit).left(dot) + Option::obj_ext != (*oit))) |
|
1168 use_implicit_rule = false; |
|
1169 } |
|
1170 } |
|
1171 if (!use_implicit_rule && !project->isEmpty(comp)) { |
|
1172 QString p = var(comp), srcf(*sit); |
|
1173 p.replace(stringSrc, escapeFilePath(srcf)); |
|
1174 p.replace(stringObj, escapeFilePath((*oit))); |
|
1175 t << "\n\t" << p; |
|
1176 } |
|
1177 t << endl << endl; |
|
1178 } |
|
1179 } |
|
1180 |
|
1181 QString |
|
1182 MakefileGenerator::filePrefixRoot(const QString &root, const QString &path) |
|
1183 { |
|
1184 QString ret(root + path); |
|
1185 if(path.length() > 2 && path[1] == ':') //c:\foo |
|
1186 ret = QString(path.mid(0, 2) + root + path.mid(2)); |
|
1187 while(ret.endsWith("\\")) |
|
1188 ret = ret.left(ret.length()-1); |
|
1189 return ret; |
|
1190 } |
|
1191 |
|
1192 void |
|
1193 MakefileGenerator::writeInstalls(QTextStream &t, const QString &installs, bool noBuild) |
|
1194 { |
|
1195 QString rm_dir_contents("-$(DEL_FILE)"); |
|
1196 if (!isWindowsShell()) //ick |
|
1197 rm_dir_contents = "-$(DEL_FILE) -r"; |
|
1198 |
|
1199 QString all_installs, all_uninstalls; |
|
1200 QStringList &l = project->values(installs); |
|
1201 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { |
|
1202 QString pvar = (*it) + ".path"; |
|
1203 if(project->values((*it) + ".CONFIG").indexOf("no_path") == -1 && |
|
1204 project->values((*it) + ".CONFIG").indexOf("dummy_install") == -1 && |
|
1205 project->values(pvar).isEmpty()) { |
|
1206 warn_msg(WarnLogic, "%s is not defined: install target not created\n", pvar.toLatin1().constData()); |
|
1207 continue; |
|
1208 } |
|
1209 |
|
1210 bool do_default = true; |
|
1211 const QString root = "$(INSTALL_ROOT)"; |
|
1212 QString target, dst; |
|
1213 if(project->values((*it) + ".CONFIG").indexOf("no_path") == -1 && |
|
1214 project->values((*it) + ".CONFIG").indexOf("dummy_install") == -1) { |
|
1215 dst = fileFixify(unescapeFilePath(project->values(pvar).first()), FileFixifyAbsolute, false); |
|
1216 if(!dst.endsWith(Option::dir_sep)) |
|
1217 dst += Option::dir_sep; |
|
1218 } |
|
1219 dst = escapeFilePath(dst); |
|
1220 |
|
1221 QStringList tmp, uninst = project->values((*it) + ".uninstall"); |
|
1222 //other |
|
1223 tmp = project->values((*it) + ".extra"); |
|
1224 if(tmp.isEmpty()) |
|
1225 tmp = project->values((*it) + ".commands"); //to allow compatible name |
|
1226 if(!tmp.isEmpty()) { |
|
1227 do_default = false; |
|
1228 if(!target.isEmpty()) |
|
1229 target += "\n\t"; |
|
1230 target += tmp.join(" "); |
|
1231 } |
|
1232 //masks |
|
1233 tmp = findFilesInVPATH(project->values((*it) + ".files"), VPATH_NoFixify); |
|
1234 tmp = fileFixify(tmp, FileFixifyAbsolute); |
|
1235 if(!tmp.isEmpty()) { |
|
1236 if(!target.isEmpty()) |
|
1237 target += "\n"; |
|
1238 do_default = false; |
|
1239 for(QStringList::Iterator wild_it = tmp.begin(); wild_it != tmp.end(); ++wild_it) { |
|
1240 QString wild = Option::fixPathToLocalOS((*wild_it), false, false); |
|
1241 QString dirstr = qmake_getpwd(), filestr = wild; |
|
1242 int slsh = filestr.lastIndexOf(Option::dir_sep); |
|
1243 if(slsh != -1) { |
|
1244 dirstr = filestr.left(slsh+1); |
|
1245 filestr.remove(0, slsh+1); |
|
1246 } |
|
1247 if(!dirstr.endsWith(Option::dir_sep)) |
|
1248 dirstr += Option::dir_sep; |
|
1249 if(exists(wild)) { //real file |
|
1250 QString file = wild; |
|
1251 QFileInfo fi(fileInfo(wild)); |
|
1252 if(!target.isEmpty()) |
|
1253 target += "\t"; |
|
1254 QString dst_file = filePrefixRoot(root, dst); |
|
1255 if(fi.isDir() && project->isActiveConfig("copy_dir_files")) { |
|
1256 if(!dst_file.endsWith(Option::dir_sep)) |
|
1257 dst_file += Option::dir_sep; |
|
1258 dst_file += fi.fileName(); |
|
1259 } |
|
1260 QString cmd; |
|
1261 if (fi.isDir()) |
|
1262 cmd = "-$(INSTALL_DIR)"; |
|
1263 else if (fi.isExecutable()) |
|
1264 cmd = "-$(INSTALL_PROGRAM)"; |
|
1265 else |
|
1266 cmd = "-$(INSTALL_FILE)"; |
|
1267 cmd += " " + escapeFilePath(wild) + " " + dst_file + "\n"; |
|
1268 target += cmd; |
|
1269 if(!project->isActiveConfig("debug") && !project->isActiveConfig("nostrip") && |
|
1270 !fi.isDir() && fi.isExecutable() && !project->isEmpty("QMAKE_STRIP")) |
|
1271 target += QString("\t-") + var("QMAKE_STRIP") + " " + |
|
1272 filePrefixRoot(root, fileFixify(dst + filestr, FileFixifyAbsolute, false)) + "\n"; |
|
1273 if(!uninst.isEmpty()) |
|
1274 uninst.append("\n\t"); |
|
1275 uninst.append(rm_dir_contents + " " + filePrefixRoot(root, fileFixify(dst + filestr, FileFixifyAbsolute, false))); |
|
1276 continue; |
|
1277 } |
|
1278 QString local_dirstr = Option::fixPathToLocalOS(dirstr, true); |
|
1279 QStringList files = QDir(local_dirstr).entryList(QStringList(filestr)); |
|
1280 if(project->values((*it) + ".CONFIG").indexOf("no_check_exist") != -1 && files.isEmpty()) { |
|
1281 if(!target.isEmpty()) |
|
1282 target += "\t"; |
|
1283 QString dst_file = filePrefixRoot(root, dst); |
|
1284 QFileInfo fi(fileInfo(wild)); |
|
1285 QString cmd = QString(fi.isExecutable() ? "-$(INSTALL_PROGRAM)" : "-$(INSTALL_FILE)") + " " + |
|
1286 wild + " " + dst_file + "\n"; |
|
1287 target += cmd; |
|
1288 if(!uninst.isEmpty()) |
|
1289 uninst.append("\n\t"); |
|
1290 uninst.append(rm_dir_contents + " " + filePrefixRoot(root, fileFixify(dst + filestr, FileFixifyAbsolute, false))); |
|
1291 } |
|
1292 for(int x = 0; x < files.count(); x++) { |
|
1293 QString file = files[x]; |
|
1294 if(file == "." || file == "..") //blah |
|
1295 continue; |
|
1296 if(!uninst.isEmpty()) |
|
1297 uninst.append("\n\t"); |
|
1298 uninst.append(rm_dir_contents + " " + filePrefixRoot(root, fileFixify(dst + file, FileFixifyAbsolute, false))); |
|
1299 QFileInfo fi(fileInfo(dirstr + file)); |
|
1300 if(!target.isEmpty()) |
|
1301 target += "\t"; |
|
1302 QString dst_file = filePrefixRoot(root, fileFixify(dst, FileFixifyAbsolute, false)); |
|
1303 if(fi.isDir() && project->isActiveConfig("copy_dir_files")) { |
|
1304 if(!dst_file.endsWith(Option::dir_sep)) |
|
1305 dst_file += Option::dir_sep; |
|
1306 dst_file += fi.fileName(); |
|
1307 } |
|
1308 QString cmd = QString(fi.isDir() ? "-$(INSTALL_DIR)" : "-$(INSTALL_FILE)") + " " + |
|
1309 dirstr + file + " " + dst_file + "\n"; |
|
1310 target += cmd; |
|
1311 if(!project->isActiveConfig("debug") && !project->isActiveConfig("nostrip") && |
|
1312 !fi.isDir() && fi.isExecutable() && !project->isEmpty("QMAKE_STRIP")) |
|
1313 target += QString("\t-") + var("QMAKE_STRIP") + " " + |
|
1314 filePrefixRoot(root, fileFixify(dst + file, FileFixifyAbsolute, false)) + |
|
1315 "\n"; |
|
1316 } |
|
1317 } |
|
1318 } |
|
1319 //default? |
|
1320 if(do_default) { |
|
1321 target = defaultInstall((*it)); |
|
1322 uninst = project->values((*it) + ".uninstall"); |
|
1323 } |
|
1324 |
|
1325 if(!target.isEmpty() || project->values((*it) + ".CONFIG").indexOf("dummy_install") != -1) { |
|
1326 if(noBuild || project->values((*it) + ".CONFIG").indexOf("no_build") != -1) |
|
1327 t << "install_" << (*it) << ":"; |
|
1328 else if(project->isActiveConfig("build_all")) |
|
1329 t << "install_" << (*it) << ": all"; |
|
1330 else |
|
1331 t << "install_" << (*it) << ": first"; |
|
1332 const QStringList &deps = project->values((*it) + ".depends"); |
|
1333 if(!deps.isEmpty()) { |
|
1334 for(QStringList::ConstIterator dep_it = deps.begin(); dep_it != deps.end(); ++dep_it) { |
|
1335 QString targ = var((*dep_it) + ".target"); |
|
1336 if(targ.isEmpty()) |
|
1337 targ = (*dep_it); |
|
1338 t << " " << escapeDependencyPath(targ); |
|
1339 } |
|
1340 } |
|
1341 if(project->isEmpty("QMAKE_NOFORCE")) |
|
1342 t << " FORCE"; |
|
1343 t << "\n\t"; |
|
1344 const QStringList &dirs = project->values(pvar); |
|
1345 for(QStringList::ConstIterator pit = dirs.begin(); pit != dirs.end(); ++pit) { |
|
1346 QString tmp_dst = fileFixify((*pit), FileFixifyAbsolute, false); |
|
1347 if (!isWindowsShell() && !tmp_dst.endsWith(Option::dir_sep)) |
|
1348 tmp_dst += Option::dir_sep; |
|
1349 t << mkdir_p_asstring(filePrefixRoot(root, tmp_dst)) << "\n\t"; |
|
1350 } |
|
1351 t << target << endl << endl; |
|
1352 if(!uninst.isEmpty()) { |
|
1353 t << "uninstall_" << (*it) << ": "; |
|
1354 if(project->isEmpty("QMAKE_NOFORCE")) |
|
1355 t << " FORCE"; |
|
1356 t << "\n\t" |
|
1357 << uninst.join(" ") << "\n\t" |
|
1358 << "-$(DEL_DIR) " << filePrefixRoot(root, dst) << " " << endl << endl; |
|
1359 } |
|
1360 t << endl; |
|
1361 |
|
1362 if(project->values((*it) + ".CONFIG").indexOf("no_default_install") == -1) { |
|
1363 all_installs += QString("install_") + (*it) + " "; |
|
1364 if(!uninst.isEmpty()) |
|
1365 all_uninstalls += "uninstall_" + (*it) + " "; |
|
1366 } |
|
1367 } else { |
|
1368 debug_msg(1, "no definition for install %s: install target not created",(*it).toLatin1().constData()); |
|
1369 } |
|
1370 } |
|
1371 t << "install: " << var("INSTALLDEPS") << " " << all_installs; |
|
1372 if(project->isEmpty("QMAKE_NOFORCE")) |
|
1373 t << " FORCE"; |
|
1374 t << "\n\n"; |
|
1375 t << "uninstall: " << all_uninstalls << " " << var("UNINSTALLDEPS"); |
|
1376 if(project->isEmpty("QMAKE_NOFORCE")) |
|
1377 t << " FORCE"; |
|
1378 t << "\n\n"; |
|
1379 } |
|
1380 |
|
1381 QString |
|
1382 MakefileGenerator::var(const QString &var) |
|
1383 { |
|
1384 return val(project->values(var)); |
|
1385 } |
|
1386 |
|
1387 QString |
|
1388 MakefileGenerator::val(const QStringList &varList) |
|
1389 { |
|
1390 return valGlue(varList, "", " ", ""); |
|
1391 } |
|
1392 |
|
1393 QString |
|
1394 MakefileGenerator::varGlue(const QString &var, const QString &before, const QString &glue, const QString &after) |
|
1395 { |
|
1396 return valGlue(project->values(var), before, glue, after); |
|
1397 } |
|
1398 |
|
1399 QString |
|
1400 MakefileGenerator::valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after) |
|
1401 { |
|
1402 QString ret; |
|
1403 for(QStringList::ConstIterator it = varList.begin(); it != varList.end(); ++it) { |
|
1404 if(!(*it).isEmpty()) { |
|
1405 if(!ret.isEmpty()) |
|
1406 ret += glue; |
|
1407 ret += (*it); |
|
1408 } |
|
1409 } |
|
1410 return ret.isEmpty() ? QString("") : before + ret + after; |
|
1411 } |
|
1412 |
|
1413 |
|
1414 QString |
|
1415 MakefileGenerator::varList(const QString &var) |
|
1416 { |
|
1417 return valList(project->values(var)); |
|
1418 } |
|
1419 |
|
1420 QString |
|
1421 MakefileGenerator::valList(const QStringList &varList) |
|
1422 { |
|
1423 return valGlue(varList, "", " \\\n\t\t", ""); |
|
1424 } |
|
1425 |
|
1426 QStringList |
|
1427 MakefileGenerator::createObjectList(const QStringList &sources) |
|
1428 { |
|
1429 QStringList ret; |
|
1430 QString objdir; |
|
1431 if(!project->values("OBJECTS_DIR").isEmpty()) |
|
1432 objdir = project->first("OBJECTS_DIR"); |
|
1433 for(QStringList::ConstIterator it = sources.begin(); it != sources.end(); ++it) { |
|
1434 QFileInfo fi(fileInfo(Option::fixPathToLocalOS((*it)))); |
|
1435 QString dir; |
|
1436 if(objdir.isEmpty() && project->isActiveConfig("object_with_source")) { |
|
1437 QString fName = Option::fixPathToTargetOS((*it), false); |
|
1438 int dl = fName.lastIndexOf(Option::dir_sep); |
|
1439 if(dl != -1) |
|
1440 dir = fName.left(dl + 1); |
|
1441 } else { |
|
1442 dir = objdir; |
|
1443 } |
|
1444 ret.append(dir + fi.completeBaseName() + Option::obj_ext); |
|
1445 } |
|
1446 return ret; |
|
1447 } |
|
1448 |
|
1449 void MakefileGenerator::generatePrint(const QString pathName) |
|
1450 { |
|
1451 QTextStream cout(stdout); |
|
1452 cout << "Generating " << pathName << "\n"; |
|
1453 } |
|
1454 |
|
1455 ReplaceExtraCompilerCacheKey::ReplaceExtraCompilerCacheKey(const QString &v, const QStringList &i, const QStringList &o) |
|
1456 { |
|
1457 hash = 0; |
|
1458 pwd = qmake_getpwd(); |
|
1459 var = v; |
|
1460 { |
|
1461 QStringList il = i; |
|
1462 il.sort(); |
|
1463 in = il.join("::"); |
|
1464 } |
|
1465 { |
|
1466 QStringList ol = o; |
|
1467 ol.sort(); |
|
1468 out = ol.join("::"); |
|
1469 } |
|
1470 } |
|
1471 |
|
1472 bool ReplaceExtraCompilerCacheKey::operator==(const ReplaceExtraCompilerCacheKey &f) const |
|
1473 { |
|
1474 return (hashCode() == f.hashCode() && |
|
1475 f.in == in && |
|
1476 f.out == out && |
|
1477 f.var == var && |
|
1478 f.pwd == pwd); |
|
1479 } |
|
1480 |
|
1481 |
|
1482 QString |
|
1483 MakefileGenerator::replaceExtraCompilerVariables(const QString &orig_var, const QStringList &in, const QStringList &out) |
|
1484 { |
|
1485 //lazy cache |
|
1486 ReplaceExtraCompilerCacheKey cacheKey(orig_var, in, out); |
|
1487 QString cacheVal = extraCompilerVariablesCache.value(cacheKey); |
|
1488 if(!cacheVal.isNull()) |
|
1489 return cacheVal; |
|
1490 |
|
1491 //do the work |
|
1492 QString ret = orig_var; |
|
1493 QRegExp reg_var("\\$\\{.*\\}"); |
|
1494 reg_var.setMinimal(true); |
|
1495 for(int rep = 0; (rep = reg_var.indexIn(ret, rep)) != -1; ) { |
|
1496 QStringList val; |
|
1497 const QString var = ret.mid(rep + 2, reg_var.matchedLength() - 3); |
|
1498 bool filePath = false; |
|
1499 if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_VAR_"))) { |
|
1500 const QString varname = var.mid(10); |
|
1501 val += project->values(varname); |
|
1502 } |
|
1503 if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_VAR_FIRST_"))) { |
|
1504 const QString varname = var.mid(16); |
|
1505 val += project->first(varname); |
|
1506 } |
|
1507 |
|
1508 if(val.isEmpty() && !in.isEmpty()) { |
|
1509 if(var.startsWith(QLatin1String("QMAKE_FUNC_FILE_IN_"))) { |
|
1510 filePath = true; |
|
1511 const QString funcname = var.mid(19); |
|
1512 val += project->expand(funcname, QList<QStringList>() << in); |
|
1513 } else if(var == QLatin1String("QMAKE_FILE_BASE") || var == QLatin1String("QMAKE_FILE_IN_BASE")) { |
|
1514 //filePath = true; |
|
1515 for(int i = 0; i < in.size(); ++i) { |
|
1516 QFileInfo fi(fileInfo(Option::fixPathToLocalOS(in.at(i)))); |
|
1517 QString base = fi.completeBaseName(); |
|
1518 if(base.isNull()) |
|
1519 base = fi.fileName(); |
|
1520 val += base; |
|
1521 } |
|
1522 } else if(var == QLatin1String("QMAKE_FILE_EXT")) { |
|
1523 filePath = true; |
|
1524 for(int i = 0; i < in.size(); ++i) { |
|
1525 QFileInfo fi(fileInfo(Option::fixPathToLocalOS(in.at(i)))); |
|
1526 QString ext; |
|
1527 // Ensure complementarity with QMAKE_FILE_BASE |
|
1528 int baseLen = fi.completeBaseName().length(); |
|
1529 if(baseLen == 0) |
|
1530 ext = fi.fileName(); |
|
1531 else |
|
1532 ext = fi.fileName().remove(0, baseLen); |
|
1533 val += ext; |
|
1534 } |
|
1535 } else if(var == QLatin1String("QMAKE_FILE_PATH") || var == QLatin1String("QMAKE_FILE_IN_PATH")) { |
|
1536 filePath = true; |
|
1537 for(int i = 0; i < in.size(); ++i) |
|
1538 val += fileInfo(Option::fixPathToLocalOS(in.at(i))).path(); |
|
1539 } else if(var == QLatin1String("QMAKE_FILE_NAME") || var == QLatin1String("QMAKE_FILE_IN")) { |
|
1540 filePath = true; |
|
1541 for(int i = 0; i < in.size(); ++i) |
|
1542 val += fileInfo(Option::fixPathToLocalOS(in.at(i))).filePath(); |
|
1543 |
|
1544 } |
|
1545 } |
|
1546 if(val.isEmpty() && !out.isEmpty()) { |
|
1547 if(var.startsWith(QLatin1String("QMAKE_FUNC_FILE_OUT_"))) { |
|
1548 filePath = true; |
|
1549 const QString funcname = var.mid(20); |
|
1550 val += project->expand(funcname, QList<QStringList>() << out); |
|
1551 } else if(var == QLatin1String("QMAKE_FILE_OUT")) { |
|
1552 filePath = true; |
|
1553 for(int i = 0; i < out.size(); ++i) |
|
1554 val += fileInfo(Option::fixPathToLocalOS(out.at(i))).filePath(); |
|
1555 } else if(var == QLatin1String("QMAKE_FILE_OUT_BASE")) { |
|
1556 //filePath = true; |
|
1557 for(int i = 0; i < out.size(); ++i) { |
|
1558 QFileInfo fi(fileInfo(Option::fixPathToLocalOS(out.at(i)))); |
|
1559 QString base = fi.completeBaseName(); |
|
1560 if(base.isNull()) |
|
1561 base = fi.fileName(); |
|
1562 val += base; |
|
1563 } |
|
1564 } |
|
1565 } |
|
1566 if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_FUNC_"))) { |
|
1567 const QString funcname = var.mid(11); |
|
1568 val += project->expand(funcname, QList<QStringList>() << in << out); |
|
1569 } |
|
1570 |
|
1571 if(!val.isEmpty()) { |
|
1572 QString fullVal; |
|
1573 if(filePath) { |
|
1574 for(int i = 0; i < val.size(); ++i) { |
|
1575 const QString file = Option::fixPathToTargetOS(unescapeFilePath(val.at(i)), false); |
|
1576 if(!fullVal.isEmpty()) |
|
1577 fullVal += " "; |
|
1578 fullVal += escapeFilePath(file); |
|
1579 } |
|
1580 } else { |
|
1581 fullVal = val.join(" "); |
|
1582 } |
|
1583 ret.replace(rep, reg_var.matchedLength(), fullVal); |
|
1584 rep += fullVal.length(); |
|
1585 } else { |
|
1586 rep += reg_var.matchedLength(); |
|
1587 } |
|
1588 } |
|
1589 |
|
1590 //cache the value |
|
1591 extraCompilerVariablesCache.insert(cacheKey, ret); |
|
1592 return ret; |
|
1593 } |
|
1594 |
|
1595 bool |
|
1596 MakefileGenerator::verifyExtraCompiler(const QString &comp, const QString &file_unfixed) |
|
1597 { |
|
1598 if(noIO()) |
|
1599 return false; |
|
1600 const QString file = Option::fixPathToLocalOS(file_unfixed); |
|
1601 |
|
1602 if(project->values(comp + ".CONFIG").indexOf("moc_verify") != -1) { |
|
1603 if(!file.isNull()) { |
|
1604 QMakeSourceFileInfo::addSourceFile(file, QMakeSourceFileInfo::SEEK_MOCS); |
|
1605 if(!mocable(file)) { |
|
1606 return false; |
|
1607 } else { |
|
1608 project->values("MOCABLES").append(file); |
|
1609 } |
|
1610 } |
|
1611 } else if(project->values(comp + ".CONFIG").indexOf("function_verify") != -1) { |
|
1612 QString tmp_out = project->values(comp + ".output").first(); |
|
1613 if(tmp_out.isEmpty()) |
|
1614 return false; |
|
1615 QStringList verify_function = project->values(comp + ".verify_function"); |
|
1616 if(verify_function.isEmpty()) |
|
1617 return false; |
|
1618 |
|
1619 for(int i = 0; i < verify_function.size(); ++i) { |
|
1620 bool invert = false; |
|
1621 QString verify = verify_function.at(i); |
|
1622 if(verify.at(0) == QLatin1Char('!')) { |
|
1623 invert = true; |
|
1624 verify = verify.mid(1); |
|
1625 } |
|
1626 |
|
1627 if(project->values(comp + ".CONFIG").indexOf("combine") != -1) { |
|
1628 bool pass = project->test(verify, QList<QStringList>() << QStringList(tmp_out) << QStringList(file)); |
|
1629 if(invert) |
|
1630 pass = !pass; |
|
1631 if(!pass) |
|
1632 return false; |
|
1633 } else { |
|
1634 QStringList &tmp = project->values(comp + ".input"); |
|
1635 for(QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) { |
|
1636 QStringList &inputs = project->values((*it)); |
|
1637 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) { |
|
1638 if((*input).isEmpty()) |
|
1639 continue; |
|
1640 QString in = fileFixify(Option::fixPathToTargetOS((*input), false)); |
|
1641 if(in == file) { |
|
1642 bool pass = project->test(verify, |
|
1643 QList<QStringList>() << QStringList(replaceExtraCompilerVariables(tmp_out, (*input), QString())) << |
|
1644 QStringList(file)); |
|
1645 if(invert) |
|
1646 pass = !pass; |
|
1647 if(!pass) |
|
1648 return false; |
|
1649 break; |
|
1650 } |
|
1651 } |
|
1652 } |
|
1653 } |
|
1654 } |
|
1655 } else if(project->values(comp + ".CONFIG").indexOf("verify") != -1) { |
|
1656 QString tmp_out = project->values(comp + ".output").first(); |
|
1657 if(tmp_out.isEmpty()) |
|
1658 return false; |
|
1659 QString tmp_cmd; |
|
1660 if(!project->isEmpty(comp + ".commands")) { |
|
1661 int argv0 = -1; |
|
1662 QStringList cmdline = project->values(comp + ".commands"); |
|
1663 for(int i = 0; i < cmdline.count(); ++i) { |
|
1664 if(!cmdline.at(i).contains('=')) { |
|
1665 argv0 = i; |
|
1666 break; |
|
1667 } |
|
1668 } |
|
1669 if(argv0 != -1) { |
|
1670 cmdline[argv0] = Option::fixPathToTargetOS(cmdline.at(argv0), false); |
|
1671 tmp_cmd = cmdline.join(" "); |
|
1672 } |
|
1673 } |
|
1674 |
|
1675 if(project->values(comp + ".CONFIG").indexOf("combine") != -1) { |
|
1676 QString cmd = replaceExtraCompilerVariables(tmp_cmd, QString(), tmp_out); |
|
1677 if(system(cmd.toLatin1().constData())) |
|
1678 return false; |
|
1679 } else { |
|
1680 QStringList &tmp = project->values(comp + ".input"); |
|
1681 for(QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) { |
|
1682 QStringList &inputs = project->values((*it)); |
|
1683 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) { |
|
1684 if((*input).isEmpty()) |
|
1685 continue; |
|
1686 QString in = fileFixify(Option::fixPathToTargetOS((*input), false)); |
|
1687 if(in == file) { |
|
1688 QString out = replaceExtraCompilerVariables(tmp_out, (*input), QString()); |
|
1689 QString cmd = replaceExtraCompilerVariables(tmp_cmd, in, out); |
|
1690 if(system(cmd.toLatin1().constData())) |
|
1691 return false; |
|
1692 break; |
|
1693 } |
|
1694 } |
|
1695 } |
|
1696 } |
|
1697 } |
|
1698 return true; |
|
1699 } |
|
1700 |
|
1701 void |
|
1702 MakefileGenerator::writeExtraTargets(QTextStream &t) |
|
1703 { |
|
1704 QStringList &qut = project->values("QMAKE_EXTRA_TARGETS"); |
|
1705 for(QStringList::Iterator it = qut.begin(); it != qut.end(); ++it) { |
|
1706 QString targ = var((*it) + ".target"), |
|
1707 cmd = var((*it) + ".commands"), deps; |
|
1708 if(targ.isEmpty()) |
|
1709 targ = (*it); |
|
1710 QStringList &deplist = project->values((*it) + ".depends"); |
|
1711 for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) { |
|
1712 QString dep = var((*dep_it) + ".target"); |
|
1713 if(dep.isEmpty()) |
|
1714 dep = (*dep_it); |
|
1715 deps += " " + escapeDependencyPath(dep); |
|
1716 } |
|
1717 if(project->values((*it) + ".CONFIG").indexOf("fix_target") != -1) |
|
1718 targ = fileFixify(targ); |
|
1719 if(project->isEmpty("QMAKE_NOFORCE") && |
|
1720 project->values((*it) + ".CONFIG").indexOf("phony") != -1) |
|
1721 deps += QString(" ") + "FORCE"; |
|
1722 t << escapeDependencyPath(targ) << ":" << deps; |
|
1723 if(!cmd.isEmpty()) |
|
1724 t << "\n\t" << cmd; |
|
1725 t << endl << endl; |
|
1726 |
|
1727 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it)) << escapeDependencyPath(targ); |
|
1728 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(targ)) << deps.split(" ", QString::SkipEmptyParts); |
|
1729 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it) + escapeDependencyPath(targ)) << cmd; |
|
1730 } |
|
1731 } |
|
1732 |
|
1733 void |
|
1734 MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) |
|
1735 { |
|
1736 QString clean_targets; |
|
1737 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); |
|
1738 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { |
|
1739 QString tmp_out = fileFixify(project->values((*it) + ".output").first(), |
|
1740 Option::output_dir, Option::output_dir); |
|
1741 QString tmp_cmd; |
|
1742 if(!project->isEmpty((*it) + ".commands")) { |
|
1743 QStringList cmdline = project->values((*it) + ".commands"); |
|
1744 int argv0 = findExecutable(cmdline); |
|
1745 if(argv0 != -1) { |
|
1746 cmdline[argv0] = escapeFilePath(Option::fixPathToTargetOS(cmdline.at(argv0), false)); |
|
1747 tmp_cmd = cmdline.join(" "); |
|
1748 } |
|
1749 } |
|
1750 QStringList tmp_dep = project->values((*it) + ".depends"); |
|
1751 QString tmp_dep_cmd; |
|
1752 if(!project->isEmpty((*it) + ".depend_command")) { |
|
1753 int argv0 = -1; |
|
1754 QStringList cmdline = project->values((*it) + ".depend_command"); |
|
1755 for(int i = 0; i < cmdline.count(); ++i) { |
|
1756 if(!cmdline.at(i).contains('=')) { |
|
1757 argv0 = i; |
|
1758 break; |
|
1759 } |
|
1760 } |
|
1761 if(argv0 != -1) { |
|
1762 const QString c = Option::fixPathToLocalOS(cmdline.at(argv0), true); |
|
1763 if(exists(c)) { |
|
1764 cmdline[argv0] = escapeFilePath(Option::fixPathToLocalOS(cmdline.at(argv0), false)); |
|
1765 tmp_dep_cmd = cmdline.join(" "); |
|
1766 } else { |
|
1767 cmdline[argv0] = escapeFilePath(cmdline.at(argv0)); |
|
1768 } |
|
1769 } |
|
1770 } |
|
1771 QStringList &vars = project->values((*it) + ".variables"); |
|
1772 if(tmp_out.isEmpty() || tmp_cmd.isEmpty()) |
|
1773 continue; |
|
1774 QStringList tmp_inputs; |
|
1775 { |
|
1776 const QStringList &comp_inputs = project->values((*it) + ".input"); |
|
1777 for(QStringList::ConstIterator it2 = comp_inputs.begin(); it2 != comp_inputs.end(); ++it2) { |
|
1778 const QStringList &tmp = project->values((*it2)); |
|
1779 for(QStringList::ConstIterator input = tmp.begin(); input != tmp.end(); ++input) { |
|
1780 QString in = Option::fixPathToTargetOS((*input), false); |
|
1781 if(verifyExtraCompiler((*it), in)) |
|
1782 tmp_inputs.append((*input)); |
|
1783 } |
|
1784 } |
|
1785 } |
|
1786 |
|
1787 t << "compiler_" << (*it) << "_make_all:"; |
|
1788 if(project->values((*it) + ".CONFIG").indexOf("combine") != -1) { |
|
1789 // compilers with a combined input only have one output |
|
1790 QString input = project->values((*it) + ".output").first(); |
|
1791 t << " " << escapeDependencyPath(replaceExtraCompilerVariables(tmp_out, input, QString())); |
|
1792 } else { |
|
1793 for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) { |
|
1794 QString in = Option::fixPathToTargetOS((*input), false); |
|
1795 t << " " << escapeDependencyPath(replaceExtraCompilerVariables(tmp_out, (*input), QString())); |
|
1796 } |
|
1797 } |
|
1798 t << endl; |
|
1799 |
|
1800 if(project->values((*it) + ".CONFIG").indexOf("no_clean") == -1) { |
|
1801 QString tmp_clean = project->values((*it) + ".clean").join(" "); |
|
1802 QString tmp_clean_cmds = project->values((*it) + ".clean_commands").join(" "); |
|
1803 if(!tmp_inputs.isEmpty()) |
|
1804 clean_targets += QString("compiler_" + (*it) + "_clean "); |
|
1805 t << "compiler_" << (*it) << "_clean:"; |
|
1806 bool wrote_clean_cmds = false, wrote_clean = false; |
|
1807 if(tmp_clean_cmds.isEmpty()) { |
|
1808 wrote_clean_cmds = true; |
|
1809 } else if(tmp_clean_cmds.indexOf("${QMAKE_") == -1) { |
|
1810 t << "\n\t" << tmp_clean_cmds; |
|
1811 wrote_clean_cmds = true; |
|
1812 } |
|
1813 if(tmp_clean.isEmpty()) |
|
1814 tmp_clean = tmp_out; |
|
1815 if(tmp_clean.indexOf("${QMAKE_") == -1) { |
|
1816 t << "\n\t" << "-$(DEL_FILE) " << tmp_clean; |
|
1817 if (isForSymbian()) |
|
1818 t << " 2> NUL"; // Eliminate unnecessary warnings |
|
1819 wrote_clean = true; |
|
1820 } |
|
1821 if(!wrote_clean_cmds || !wrote_clean) { |
|
1822 QStringList cleans; |
|
1823 const QString del_statement("-$(DEL_FILE)"); |
|
1824 if(!wrote_clean) { |
|
1825 if(project->isActiveConfig("no_delete_multiple_files")) { |
|
1826 for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) |
|
1827 cleans.append(" " + replaceExtraCompilerVariables(tmp_clean, (*input), |
|
1828 replaceExtraCompilerVariables(tmp_out, (*input), QString()))); |
|
1829 } else { |
|
1830 QString files, file; |
|
1831 const int commandlineLimit = 2047; // NT limit, expanded |
|
1832 for(int input = 0; input < tmp_inputs.size(); ++input) { |
|
1833 file = " " + replaceExtraCompilerVariables(tmp_clean, tmp_inputs.at(input), |
|
1834 replaceExtraCompilerVariables(tmp_out, tmp_inputs.at(input), QString())); |
|
1835 if(del_statement.length() + files.length() + |
|
1836 qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) { |
|
1837 cleans.append(files); |
|
1838 files.clear(); |
|
1839 } |
|
1840 files += file; |
|
1841 } |
|
1842 if(!files.isEmpty()) |
|
1843 cleans.append(files); |
|
1844 } |
|
1845 } |
|
1846 if(!cleans.isEmpty()) { |
|
1847 if (isForSymbian()) |
|
1848 t << valGlue(cleans, "\n\t" + del_statement, " 2> NUL\n\t" + del_statement, " 2> NUL"); |
|
1849 else |
|
1850 t << valGlue(cleans, "\n\t" + del_statement, "\n\t" + del_statement, ""); |
|
1851 } |
|
1852 if(!wrote_clean_cmds) { |
|
1853 for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) { |
|
1854 t << "\n\t" << replaceExtraCompilerVariables(tmp_clean_cmds, (*input), |
|
1855 replaceExtraCompilerVariables(tmp_out, (*input), QString())); |
|
1856 } |
|
1857 } |
|
1858 } |
|
1859 t << endl; |
|
1860 } |
|
1861 if(project->values((*it) + ".CONFIG").indexOf("combine") != -1) { |
|
1862 if(tmp_out.indexOf("${QMAKE_") != -1) { |
|
1863 warn_msg(WarnLogic, "QMAKE_EXTRA_COMPILERS(%s) with combine has variable output.", |
|
1864 (*it).toLatin1().constData()); |
|
1865 continue; |
|
1866 } |
|
1867 QStringList deps, inputs; |
|
1868 if(!tmp_dep.isEmpty()) |
|
1869 deps += fileFixify(tmp_dep, Option::output_dir, Option::output_dir); |
|
1870 for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) { |
|
1871 deps += findDependencies((*input)); |
|
1872 inputs += Option::fixPathToTargetOS((*input), false); |
|
1873 if(!tmp_dep_cmd.isEmpty() && doDepends()) { |
|
1874 char buff[256]; |
|
1875 QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, (*input), |
|
1876 tmp_out); |
|
1877 dep_cmd = fixEnvVariables(dep_cmd); |
|
1878 if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) { |
|
1879 QString indeps; |
|
1880 while(!feof(proc)) { |
|
1881 int read_in = (int)fread(buff, 1, 255, proc); |
|
1882 if(!read_in) |
|
1883 break; |
|
1884 indeps += QByteArray(buff, read_in); |
|
1885 } |
|
1886 QT_PCLOSE(proc); |
|
1887 if(!indeps.isEmpty()) { |
|
1888 QStringList dep_cmd_deps = indeps.replace('\n', ' ').simplified().split(' '); |
|
1889 for(int i = 0; i < dep_cmd_deps.count(); ++i) { |
|
1890 QString &file = dep_cmd_deps[i]; |
|
1891 if(!exists(file)) { |
|
1892 QString localFile; |
|
1893 QList<QMakeLocalFileName> depdirs = QMakeSourceFileInfo::dependencyPaths(); |
|
1894 for(QList<QMakeLocalFileName>::Iterator it = depdirs.begin(); |
|
1895 it != depdirs.end(); ++it) { |
|
1896 if(exists((*it).real() + Option::dir_sep + file)) { |
|
1897 localFile = (*it).local() + Option::dir_sep + file; |
|
1898 break; |
|
1899 } |
|
1900 } |
|
1901 file = localFile; |
|
1902 } |
|
1903 if(!file.isEmpty()) |
|
1904 file = fileFixify(file); |
|
1905 } |
|
1906 deps += dep_cmd_deps; |
|
1907 } |
|
1908 } |
|
1909 } |
|
1910 } |
|
1911 for(int i = 0; i < inputs.size(); ) { |
|
1912 if(tmp_out == inputs.at(i)) |
|
1913 inputs.removeAt(i); |
|
1914 else |
|
1915 ++i; |
|
1916 } |
|
1917 for(int i = 0; i < deps.size(); ) { |
|
1918 if(tmp_out == deps.at(i)) |
|
1919 deps.removeAt(i); |
|
1920 else |
|
1921 ++i; |
|
1922 } |
|
1923 if (inputs.isEmpty()) |
|
1924 continue; |
|
1925 |
|
1926 QString cmd; |
|
1927 if (isForSymbianSbsv2()) { |
|
1928 // In sbsv2 the command inputs and outputs need to use absolute paths |
|
1929 cmd = replaceExtraCompilerVariables(tmp_cmd, |
|
1930 fileFixify(escapeFilePaths(inputs), FileFixifyAbsolute), |
|
1931 fileFixify(QStringList(tmp_out), FileFixifyAbsolute)); |
|
1932 } else { |
|
1933 cmd = replaceExtraCompilerVariables(tmp_cmd, escapeFilePaths(inputs), QStringList(tmp_out)); |
|
1934 } |
|
1935 |
|
1936 t << escapeDependencyPath(tmp_out) << ":"; |
|
1937 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it)) << escapeDependencyPath(tmp_out); |
|
1938 // compiler.CONFIG+=explicit_dependencies means that ONLY compiler.depends gets to cause Makefile dependencies |
|
1939 if(project->values((*it) + ".CONFIG").indexOf("explicit_dependencies") != -1) { |
|
1940 t << " " << valList(escapeDependencyPaths(fileFixify(tmp_dep, Option::output_dir, Option::output_dir))); |
|
1941 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(tmp_out)) << tmp_dep; |
|
1942 } else { |
|
1943 t << " " << valList(escapeDependencyPaths(inputs)) << " " << valList(escapeDependencyPaths(deps)); |
|
1944 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(tmp_out)) << inputs << deps; |
|
1945 } |
|
1946 t << "\n\t" << cmd << endl << endl; |
|
1947 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it) + escapeDependencyPath(tmp_out)) << cmd; |
|
1948 continue; |
|
1949 } |
|
1950 for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) { |
|
1951 QString in = Option::fixPathToTargetOS((*input), false); |
|
1952 QStringList deps = findDependencies((*input)); |
|
1953 deps += escapeDependencyPath(in); |
|
1954 QString out = replaceExtraCompilerVariables(tmp_out, (*input), QString()); |
|
1955 if(!tmp_dep.isEmpty()) { |
|
1956 QStringList pre_deps = fileFixify(tmp_dep, Option::output_dir, Option::output_dir); |
|
1957 for(int i = 0; i < pre_deps.size(); ++i) |
|
1958 deps += replaceExtraCompilerVariables(pre_deps.at(i), (*input), out); |
|
1959 } |
|
1960 QString cmd = replaceExtraCompilerVariables(tmp_cmd, (*input), out); |
|
1961 // NOTE: The var -> QMAKE_COMP_var replace feature is unsupported, do not use! |
|
1962 if (isForSymbianSbsv2()) { |
|
1963 // In sbsv2 the command inputs and outputs need to use absolute paths |
|
1964 cmd = replaceExtraCompilerVariables(tmp_cmd, |
|
1965 fileFixify((*input), FileFixifyAbsolute), |
|
1966 fileFixify(out, FileFixifyAbsolute)); |
|
1967 } else { |
|
1968 cmd = replaceExtraCompilerVariables(tmp_cmd, (*input), out); |
|
1969 } |
|
1970 for(QStringList::ConstIterator it3 = vars.constBegin(); it3 != vars.constEnd(); ++it3) |
|
1971 cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")"); |
|
1972 if(!tmp_dep_cmd.isEmpty() && doDepends()) { |
|
1973 char buff[256]; |
|
1974 QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, (*input), out); |
|
1975 dep_cmd = fixEnvVariables(dep_cmd); |
|
1976 if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) { |
|
1977 QString indeps; |
|
1978 while(!feof(proc)) { |
|
1979 int read_in = (int)fread(buff, 1, 255, proc); |
|
1980 if(!read_in) |
|
1981 break; |
|
1982 indeps += QByteArray(buff, read_in); |
|
1983 } |
|
1984 QT_PCLOSE(proc); |
|
1985 if(!indeps.isEmpty()) { |
|
1986 QStringList dep_cmd_deps = indeps.replace('\n', ' ').simplified().split(' '); |
|
1987 for(int i = 0; i < dep_cmd_deps.count(); ++i) { |
|
1988 QString &file = dep_cmd_deps[i]; |
|
1989 if(!exists(file)) { |
|
1990 QString localFile; |
|
1991 QList<QMakeLocalFileName> depdirs = QMakeSourceFileInfo::dependencyPaths(); |
|
1992 for(QList<QMakeLocalFileName>::Iterator it = depdirs.begin(); |
|
1993 it != depdirs.end(); ++it) { |
|
1994 if(exists((*it).real() + Option::dir_sep + file)) { |
|
1995 localFile = (*it).local() + Option::dir_sep + file; |
|
1996 break; |
|
1997 } |
|
1998 } |
|
1999 file = localFile; |
|
2000 } |
|
2001 if(!file.isEmpty()) |
|
2002 file = fileFixify(file); |
|
2003 } |
|
2004 deps += dep_cmd_deps; |
|
2005 } |
|
2006 } |
|
2007 //use the depend system to find includes of these included files |
|
2008 QStringList inc_deps; |
|
2009 for(int i = 0; i < deps.size(); ++i) { |
|
2010 const QString dep = deps.at(i); |
|
2011 if(QFile::exists(dep)) { |
|
2012 SourceFileType type = TYPE_UNKNOWN; |
|
2013 if(type == TYPE_UNKNOWN) { |
|
2014 for(QStringList::Iterator cit = Option::c_ext.begin(); |
|
2015 cit != Option::c_ext.end(); ++cit) { |
|
2016 if(dep.endsWith((*cit))) { |
|
2017 type = TYPE_C; |
|
2018 break; |
|
2019 } |
|
2020 } |
|
2021 } |
|
2022 if(type == TYPE_UNKNOWN) { |
|
2023 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); |
|
2024 cppit != Option::cpp_ext.end(); ++cppit) { |
|
2025 if(dep.endsWith((*cppit))) { |
|
2026 type = TYPE_C; |
|
2027 break; |
|
2028 } |
|
2029 } |
|
2030 } |
|
2031 if(type == TYPE_UNKNOWN) { |
|
2032 for(QStringList::Iterator hit = Option::h_ext.begin(); |
|
2033 type == TYPE_UNKNOWN && hit != Option::h_ext.end(); ++hit) { |
|
2034 if(dep.endsWith((*hit))) { |
|
2035 type = TYPE_C; |
|
2036 break; |
|
2037 } |
|
2038 } |
|
2039 } |
|
2040 if(type != TYPE_UNKNOWN) { |
|
2041 if(!QMakeSourceFileInfo::containsSourceFile(dep, type)) |
|
2042 QMakeSourceFileInfo::addSourceFile(dep, type); |
|
2043 inc_deps += QMakeSourceFileInfo::dependencies(dep); |
|
2044 } |
|
2045 } |
|
2046 } |
|
2047 deps += inc_deps; |
|
2048 } |
|
2049 for(int i = 0; i < deps.size(); ) { |
|
2050 QString &dep = deps[i]; |
|
2051 dep = Option::fixPathToTargetOS(unescapeFilePath(dep), false); |
|
2052 if(out == dep) |
|
2053 deps.removeAt(i); |
|
2054 else |
|
2055 ++i; |
|
2056 } |
|
2057 t << escapeDependencyPath(out) << ": " << valList(escapeDependencyPaths(deps)) << "\n\t" |
|
2058 << cmd << endl << endl; |
|
2059 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it)) << escapeDependencyPath(out); |
|
2060 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(out)) << deps; |
|
2061 project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it) + escapeDependencyPath(out)) << cmd; |
|
2062 } |
|
2063 } |
|
2064 t << "compiler_clean: " << clean_targets << endl << endl; |
|
2065 } |
|
2066 |
|
2067 void |
|
2068 MakefileGenerator::writeExtraCompilerVariables(QTextStream &t) |
|
2069 { |
|
2070 bool first = true; |
|
2071 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); |
|
2072 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { |
|
2073 const QStringList &vars = project->values((*it) + ".variables"); |
|
2074 for(QStringList::ConstIterator varit = vars.begin(); varit != vars.end(); ++varit) { |
|
2075 if(first) { |
|
2076 t << "\n####### Custom Compiler Variables" << endl; |
|
2077 first = false; |
|
2078 } |
|
2079 t << "QMAKE_COMP_" << (*varit) << " = " |
|
2080 << valList(project->values((*varit))) << endl; |
|
2081 } |
|
2082 } |
|
2083 if(!first) |
|
2084 t << endl; |
|
2085 } |
|
2086 |
|
2087 void |
|
2088 MakefileGenerator::writeExtraVariables(QTextStream &t) |
|
2089 { |
|
2090 bool first = true; |
|
2091 QMap<QString, QStringList> &vars = project->variables(); |
|
2092 QStringList &exports = project->values("QMAKE_EXTRA_VARIABLES"); |
|
2093 for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it) { |
|
2094 for(QStringList::Iterator exp_it = exports.begin(); exp_it != exports.end(); ++exp_it) { |
|
2095 QRegExp rx((*exp_it), Qt::CaseInsensitive, QRegExp::Wildcard); |
|
2096 if(rx.exactMatch(it.key())) { |
|
2097 if(first) { |
|
2098 t << "\n####### Custom Variables" << endl; |
|
2099 first = false; |
|
2100 } |
|
2101 t << "EXPORT_" << it.key() << " = " << it.value().join(" ") << endl; |
|
2102 } |
|
2103 } |
|
2104 } |
|
2105 if(!first) |
|
2106 t << endl; |
|
2107 } |
|
2108 |
|
2109 bool |
|
2110 MakefileGenerator::writeStubMakefile(QTextStream &t) |
|
2111 { |
|
2112 t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE")) << endl; |
|
2113 QStringList &qut = project->values("QMAKE_EXTRA_TARGETS"); |
|
2114 for(QStringList::ConstIterator it = qut.begin(); it != qut.end(); ++it) |
|
2115 t << *it << " "; |
|
2116 //const QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName())); |
|
2117 t << "first all clean install distclean uninstall: " << "qmake" << endl |
|
2118 << "qmake_all:" << endl; |
|
2119 writeMakeQmake(t); |
|
2120 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2121 t << "FORCE:" << endl << endl; |
|
2122 return true; |
|
2123 } |
|
2124 |
|
2125 bool |
|
2126 MakefileGenerator::writeMakefile(QTextStream &t) |
|
2127 { |
|
2128 t << "####### Compile" << endl << endl; |
|
2129 writeObj(t, "SOURCES"); |
|
2130 writeObj(t, "GENERATED_SOURCES"); |
|
2131 |
|
2132 t << "####### Install" << endl << endl; |
|
2133 writeInstalls(t, "INSTALLS"); |
|
2134 |
|
2135 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2136 t << "FORCE:" << endl << endl; |
|
2137 return true; |
|
2138 } |
|
2139 |
|
2140 QString MakefileGenerator::buildArgs(const QString &outdir) |
|
2141 { |
|
2142 QString ret; |
|
2143 //special variables |
|
2144 if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH")) |
|
2145 ret += " QMAKE_ABSOLUTE_SOURCE_PATH=" + escapeFilePath(project->first("QMAKE_ABSOLUTE_SOURCE_PATH")); |
|
2146 |
|
2147 //warnings |
|
2148 else if(Option::warn_level == WarnNone) |
|
2149 ret += " -Wnone"; |
|
2150 else if(Option::warn_level == WarnAll) |
|
2151 ret += " -Wall"; |
|
2152 else if(Option::warn_level & WarnParser) |
|
2153 ret += " -Wparser"; |
|
2154 //other options |
|
2155 if(!Option::user_template.isEmpty()) |
|
2156 ret += " -t " + Option::user_template; |
|
2157 if(!Option::user_template_prefix.isEmpty()) |
|
2158 ret += " -tp " + Option::user_template_prefix; |
|
2159 if(!Option::mkfile::do_cache) |
|
2160 ret += " -nocache"; |
|
2161 if(!Option::mkfile::do_deps) |
|
2162 ret += " -nodepend"; |
|
2163 if(!Option::mkfile::do_dep_heuristics) |
|
2164 ret += " -nodependheuristics"; |
|
2165 if(!Option::mkfile::qmakespec_commandline.isEmpty()) |
|
2166 ret += " -spec " + specdir(outdir); |
|
2167 if(Option::target_mode == Option::TARG_MAC9_MODE) |
|
2168 ret += " -mac9"; |
|
2169 else if(Option::target_mode == Option::TARG_MACX_MODE) |
|
2170 ret += " -macx"; |
|
2171 else if(Option::target_mode == Option::TARG_UNIX_MODE) |
|
2172 ret += " -unix"; |
|
2173 else if(Option::target_mode == Option::TARG_WIN_MODE) |
|
2174 ret += " -win32"; |
|
2175 |
|
2176 //configs |
|
2177 for(QStringList::Iterator it = Option::user_configs.begin(); |
|
2178 it != Option::user_configs.end(); ++it) |
|
2179 ret += " -config " + (*it); |
|
2180 //arguments |
|
2181 for(QStringList::Iterator it = Option::before_user_vars.begin(); |
|
2182 it != Option::before_user_vars.end(); ++it) { |
|
2183 if((*it).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH") |
|
2184 ret += " " + escapeFilePath((*it)); |
|
2185 } |
|
2186 if(Option::after_user_vars.count()) { |
|
2187 ret += " -after "; |
|
2188 for(QStringList::Iterator it = Option::after_user_vars.begin(); |
|
2189 it != Option::after_user_vars.end(); ++it) { |
|
2190 if((*it).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH") |
|
2191 ret += " " + escapeFilePath((*it)); |
|
2192 } |
|
2193 } |
|
2194 return ret; |
|
2195 } |
|
2196 |
|
2197 //could get stored argv, but then it would have more options than are |
|
2198 //probably necesary this will try to guess the bare minimum.. |
|
2199 QString MakefileGenerator::build_args(const QString &outdir) |
|
2200 { |
|
2201 QString ret = "$(QMAKE)"; |
|
2202 |
|
2203 // general options and arguments |
|
2204 ret += buildArgs(outdir); |
|
2205 |
|
2206 //output |
|
2207 QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName())); |
|
2208 if(!ofile.isEmpty() && ofile != project->first("QMAKE_MAKEFILE")) |
|
2209 ret += " -o " + escapeFilePath(ofile); |
|
2210 |
|
2211 //inputs |
|
2212 ret += " " + escapeFilePath(fileFixify(project->projectFile(), outdir)); |
|
2213 |
|
2214 return ret; |
|
2215 } |
|
2216 |
|
2217 void |
|
2218 MakefileGenerator::writeHeader(QTextStream &t) |
|
2219 { |
|
2220 t << "#############################################################################" << endl; |
|
2221 t << "# Makefile for building: " << escapeFilePath(var("TARGET")) << endl; |
|
2222 t << "# Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; |
|
2223 t << QDateTime::currentDateTime().toString() << endl; |
|
2224 t << "# Project: " << fileFixify(project->projectFile()) << endl; |
|
2225 t << "# Template: " << var("TEMPLATE") << endl; |
|
2226 if(!project->isActiveConfig("build_pass")) |
|
2227 t << "# Command: " << build_args().replace("$(QMAKE)", |
|
2228 (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE"))) << endl; |
|
2229 t << "#############################################################################" << endl; |
|
2230 t << endl; |
|
2231 } |
|
2232 |
|
2233 QList<MakefileGenerator::SubTarget*> |
|
2234 MakefileGenerator::findSubDirsSubTargets() const |
|
2235 { |
|
2236 QList<SubTarget*> targets; |
|
2237 { |
|
2238 const QStringList subdirs = project->values("SUBDIRS"); |
|
2239 for(int subdir = 0; subdir < subdirs.size(); ++subdir) { |
|
2240 QString fixedSubdir = subdirs[subdir]; |
|
2241 fixedSubdir = fixedSubdir.replace(QRegExp("[^a-zA-Z0-9_]"),"-"); |
|
2242 |
|
2243 SubTarget *st = new SubTarget; |
|
2244 st->name = subdirs[subdir]; |
|
2245 targets.append(st); |
|
2246 |
|
2247 bool fromFile = false; |
|
2248 QString file = subdirs[subdir]; |
|
2249 if(!project->isEmpty(fixedSubdir + ".file")) { |
|
2250 if(!project->isEmpty(fixedSubdir + ".subdir")) |
|
2251 warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s", |
|
2252 subdirs[subdir].toLatin1().constData()); |
|
2253 file = project->first(fixedSubdir + ".file"); |
|
2254 fromFile = true; |
|
2255 } else if(!project->isEmpty(fixedSubdir + ".subdir")) { |
|
2256 file = project->first(fixedSubdir + ".subdir"); |
|
2257 fromFile = false; |
|
2258 } else { |
|
2259 fromFile = file.endsWith(Option::pro_ext); |
|
2260 } |
|
2261 file = Option::fixPathToTargetOS(file); |
|
2262 |
|
2263 if(fromFile) { |
|
2264 int slsh = file.lastIndexOf(Option::dir_sep); |
|
2265 if(slsh != -1) { |
|
2266 st->in_directory = file.left(slsh+1); |
|
2267 st->profile = file.mid(slsh+1); |
|
2268 } else { |
|
2269 st->profile = file; |
|
2270 } |
|
2271 } else { |
|
2272 if(!file.isEmpty() && !project->isActiveConfig("subdir_first_pro")) |
|
2273 st->profile = file.section(Option::dir_sep, -1) + Option::pro_ext; |
|
2274 st->in_directory = file; |
|
2275 } |
|
2276 while(st->in_directory.endsWith(Option::dir_sep)) |
|
2277 st->in_directory.chop(1); |
|
2278 if(fileInfo(st->in_directory).isRelative()) |
|
2279 st->out_directory = st->in_directory; |
|
2280 else |
|
2281 st->out_directory = fileFixify(st->in_directory, qmake_getpwd(), Option::output_dir); |
|
2282 if(!project->isEmpty(fixedSubdir + ".makefile")) { |
|
2283 st->makefile = project->first(fixedSubdir + ".makefile"); |
|
2284 } else { |
|
2285 st->makefile = "$(MAKEFILE)"; |
|
2286 if(!st->profile.isEmpty()) { |
|
2287 QString basename = st->in_directory; |
|
2288 int new_slsh = basename.lastIndexOf(Option::dir_sep); |
|
2289 if(new_slsh != -1) |
|
2290 basename = basename.mid(new_slsh+1); |
|
2291 if(st->profile != basename + Option::pro_ext) |
|
2292 st->makefile += "." + st->profile.left(st->profile.length() - Option::pro_ext.length()); |
|
2293 } |
|
2294 } |
|
2295 if(!project->isEmpty(fixedSubdir + ".depends")) { |
|
2296 const QStringList depends = project->values(fixedSubdir + ".depends"); |
|
2297 for(int depend = 0; depend < depends.size(); ++depend) { |
|
2298 bool found = false; |
|
2299 for(int subDep = 0; subDep < subdirs.size(); ++subDep) { |
|
2300 if(subdirs[subDep] == depends.at(depend)) { |
|
2301 QString fixedSubDep = subdirs[subDep]; |
|
2302 fixedSubDep = fixedSubDep.replace(QRegExp("[^a-zA-Z0-9_]"),"-"); |
|
2303 if(!project->isEmpty(fixedSubDep + ".target")) { |
|
2304 st->depends += project->first(fixedSubDep + ".target"); |
|
2305 } else { |
|
2306 QString d = Option::fixPathToLocalOS(subdirs[subDep]); |
|
2307 if(!project->isEmpty(fixedSubDep + ".file")) |
|
2308 d = project->first(fixedSubDep + ".file"); |
|
2309 else if(!project->isEmpty(fixedSubDep + ".subdir")) |
|
2310 d = project->first(fixedSubDep + ".subdir"); |
|
2311 st->depends += "sub-" + d.replace(QRegExp("[^a-zA-Z0-9_]"),"-"); |
|
2312 } |
|
2313 found = true; |
|
2314 break; |
|
2315 } |
|
2316 } |
|
2317 if(!found) { |
|
2318 QString depend_str = depends.at(depend); |
|
2319 st->depends += depend_str.replace(QRegExp("[^a-zA-Z0-9_]"),"-"); |
|
2320 } |
|
2321 } |
|
2322 } |
|
2323 if(!project->isEmpty(fixedSubdir + ".target")) { |
|
2324 st->target = project->first(fixedSubdir + ".target"); |
|
2325 } else { |
|
2326 st->target = "sub-" + file; |
|
2327 st->target = st->target.replace(QRegExp("[^a-zA-Z0-9_]"),"-"); |
|
2328 } |
|
2329 } |
|
2330 } |
|
2331 return targets; |
|
2332 } |
|
2333 |
|
2334 void |
|
2335 MakefileGenerator::writeSubDirs(QTextStream &t) |
|
2336 { |
|
2337 QList<SubTarget*> targets = findSubDirsSubTargets(); |
|
2338 t << "first: make_default" << endl; |
|
2339 int flags = SubTargetInstalls; |
|
2340 if(project->isActiveConfig("ordered")) |
|
2341 flags |= SubTargetOrdered; |
|
2342 writeSubTargets(t, targets, flags); |
|
2343 qDeleteAll(targets); |
|
2344 } |
|
2345 |
|
2346 void |
|
2347 MakefileGenerator::writeSubTargets(QTextStream &t, QList<MakefileGenerator::SubTarget*> targets, int flags) |
|
2348 { |
|
2349 // blasted includes |
|
2350 QStringList &qeui = project->values("QMAKE_EXTRA_INCLUDES"); |
|
2351 for(QStringList::Iterator qeui_it = qeui.begin(); qeui_it != qeui.end(); ++qeui_it) |
|
2352 t << "include " << (*qeui_it) << endl; |
|
2353 |
|
2354 if (!(flags & SubTargetSkipDefaultVariables)) { |
|
2355 QString ofile = Option::fixPathToTargetOS(Option::output.fileName()); |
|
2356 if(ofile.lastIndexOf(Option::dir_sep) != -1) |
|
2357 ofile.remove(0, ofile.lastIndexOf(Option::dir_sep) +1); |
|
2358 t << "MAKEFILE = " << ofile << endl; |
|
2359 /* Calling Option::fixPathToTargetOS() is necessary for MinGW/MSYS, which requires |
|
2360 * back-slashes to be turned into slashes. */ |
|
2361 t << "QMAKE = " << Option::fixPathToTargetOS(var("QMAKE_QMAKE")) << endl; |
|
2362 t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl; |
|
2363 t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl; |
|
2364 t << "MKDIR = " << var("QMAKE_MKDIR") << endl; |
|
2365 t << "COPY = " << var("QMAKE_COPY") << endl; |
|
2366 t << "COPY_FILE = " << var("QMAKE_COPY_FILE") << endl; |
|
2367 t << "COPY_DIR = " << var("QMAKE_COPY_DIR") << endl; |
|
2368 t << "INSTALL_FILE = " << var("QMAKE_INSTALL_FILE") << endl; |
|
2369 t << "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl; |
|
2370 t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl; |
|
2371 t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl; |
|
2372 t << "SYMLINK = " << var("QMAKE_SYMBOLIC_LINK") << endl; |
|
2373 t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl; |
|
2374 t << "MOVE = " << var("QMAKE_MOVE") << endl; |
|
2375 t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl; |
|
2376 t << "MKDIR = " << var("QMAKE_MKDIR") << endl; |
|
2377 t << "SUBTARGETS = "; // subtargets are sub-directory |
|
2378 for(int target = 0; target < targets.size(); ++target) |
|
2379 t << " \\\n\t\t" << targets.at(target)->target; |
|
2380 t << endl << endl; |
|
2381 } |
|
2382 writeExtraVariables(t); |
|
2383 |
|
2384 QStringList targetSuffixes; |
|
2385 const QString abs_source_path = project->first("QMAKE_ABSOLUTE_SOURCE_PATH"); |
|
2386 if (!(flags & SubTargetSkipDefaultTargets)) { |
|
2387 targetSuffixes << "make_default" << "make_first" << "all" << "clean" << "distclean" |
|
2388 << QString((flags & SubTargetInstalls) ? "install_subtargets" : "install") |
|
2389 << QString((flags & SubTargetInstalls) ? "uninstall_subtargets" : "uninstall"); |
|
2390 } |
|
2391 |
|
2392 // generate target rules |
|
2393 for(int target = 0; target < targets.size(); ++target) { |
|
2394 SubTarget *subtarget = targets.at(target); |
|
2395 QString in_directory = subtarget->in_directory; |
|
2396 if(!in_directory.isEmpty() && !in_directory.endsWith(Option::dir_sep)) |
|
2397 in_directory += Option::dir_sep; |
|
2398 QString out_directory = subtarget->out_directory; |
|
2399 if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep)) |
|
2400 out_directory += Option::dir_sep; |
|
2401 if(!abs_source_path.isEmpty() && out_directory.startsWith(abs_source_path)) |
|
2402 out_directory = Option::output_dir + out_directory.mid(abs_source_path.length()); |
|
2403 |
|
2404 QString mkfile = subtarget->makefile; |
|
2405 if(!in_directory.isEmpty()) |
|
2406 mkfile.prepend(out_directory); |
|
2407 |
|
2408 QString in_directory_cdin, in_directory_cdout, out_directory_cdin, out_directory_cdout; |
|
2409 #define MAKE_CD_IN_AND_OUT(directory) \ |
|
2410 if(!directory.isEmpty()) { \ |
|
2411 if(project->isActiveConfig("cd_change_global")) { \ |
|
2412 directory ## _cdin = "\n\tcd " + directory + "\n\t"; \ |
|
2413 QDir pwd(Option::output_dir); \ |
|
2414 QStringList in = directory.split(Option::dir_sep), out; \ |
|
2415 for(int i = 0; i < in.size(); i++) { \ |
|
2416 if(in.at(i) == "..") \ |
|
2417 out.prepend(fileInfo(pwd.path()).fileName()); \ |
|
2418 else if(in.at(i) != ".") \ |
|
2419 out.prepend(".."); \ |
|
2420 pwd.cd(in.at(i)); \ |
|
2421 } \ |
|
2422 directory ## _cdout = "\n\t@cd " + out.join(Option::dir_sep); \ |
|
2423 } else { \ |
|
2424 directory ## _cdin = "\n\tcd " + directory + " && "; \ |
|
2425 } \ |
|
2426 } else { \ |
|
2427 directory ## _cdin = "\n\t"; \ |
|
2428 } |
|
2429 MAKE_CD_IN_AND_OUT(in_directory); |
|
2430 MAKE_CD_IN_AND_OUT(out_directory); |
|
2431 |
|
2432 //qmake it |
|
2433 if(!subtarget->profile.isEmpty()) { |
|
2434 QString out = subtarget->makefile; |
|
2435 QString in = fileFixify(in_directory + subtarget->profile, out_directory, QString(), FileFixifyAbsolute); |
|
2436 if(out.startsWith(in_directory)) |
|
2437 out = out.mid(in_directory.length()); |
|
2438 t << mkfile << ": " << "\n\t"; |
|
2439 if(!in_directory.isEmpty()) { |
|
2440 t << mkdir_p_asstring(out_directory) |
|
2441 << out_directory_cdin |
|
2442 << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out |
|
2443 << in_directory_cdout << endl; |
|
2444 } else { |
|
2445 t << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out << endl; |
|
2446 } |
|
2447 t << subtarget->target << "-qmake_all: "; |
|
2448 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2449 t << " FORCE"; |
|
2450 t << "\n\t"; |
|
2451 if(!in_directory.isEmpty()) { |
|
2452 t << mkdir_p_asstring(out_directory) |
|
2453 << out_directory_cdin |
|
2454 << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out |
|
2455 << in_directory_cdout << endl; |
|
2456 } else { |
|
2457 t << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out << endl; |
|
2458 } |
|
2459 } |
|
2460 |
|
2461 QString makefilein = " -f " + subtarget->makefile; |
|
2462 |
|
2463 { //actually compile |
|
2464 t << subtarget->target << ": " << mkfile; |
|
2465 if(!subtarget->depends.isEmpty()) |
|
2466 t << " " << valList(subtarget->depends); |
|
2467 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2468 t << " FORCE"; |
|
2469 t << out_directory_cdin |
|
2470 << "$(MAKE)" << makefilein |
|
2471 << out_directory_cdout << endl; |
|
2472 } |
|
2473 |
|
2474 for(int suffix = 0; suffix < targetSuffixes.size(); ++suffix) { |
|
2475 QString s = targetSuffixes.at(suffix); |
|
2476 if(s == "install_subtargets") |
|
2477 s = "install"; |
|
2478 else if(s == "uninstall_subtargets") |
|
2479 s = "uninstall"; |
|
2480 else if(s == "make_first") |
|
2481 s = "first"; |
|
2482 else if(s == "make_default") |
|
2483 s = QString(); |
|
2484 |
|
2485 if(flags & SubTargetOrdered) { |
|
2486 t << subtarget->target << "-" << targetSuffixes.at(suffix) << "-ordered: " << mkfile; |
|
2487 if(target) |
|
2488 t << " " << targets.at(target-1)->target << "-" << targetSuffixes.at(suffix) << "-ordered "; |
|
2489 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2490 t << " FORCE"; |
|
2491 t << out_directory_cdin |
|
2492 << "$(MAKE)" << makefilein << " " << s |
|
2493 << out_directory_cdout << endl; |
|
2494 } |
|
2495 t << subtarget->target << "-" << targetSuffixes.at(suffix) << ": " << mkfile; |
|
2496 if(!subtarget->depends.isEmpty()) |
|
2497 t << " " << valGlue(subtarget->depends, QString(), "-" + targetSuffixes.at(suffix) + " ", |
|
2498 "-"+targetSuffixes.at(suffix)); |
|
2499 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2500 t << " FORCE"; |
|
2501 t << out_directory_cdin |
|
2502 << "$(MAKE)" << makefilein << " " << s |
|
2503 << out_directory_cdout << endl; |
|
2504 } |
|
2505 } |
|
2506 t << endl; |
|
2507 |
|
2508 if (!(flags & SubTargetSkipDefaultTargets)) { |
|
2509 if(project->values("QMAKE_INTERNAL_QMAKE_DEPS").indexOf("qmake_all") == -1) |
|
2510 project->values("QMAKE_INTERNAL_QMAKE_DEPS").append("qmake_all"); |
|
2511 |
|
2512 writeMakeQmake(t); |
|
2513 |
|
2514 t << "qmake_all:"; |
|
2515 if(!targets.isEmpty()) { |
|
2516 for(QList<SubTarget*>::Iterator it = targets.begin(); it != targets.end(); ++it) { |
|
2517 if(!(*it)->profile.isEmpty()) |
|
2518 t << " " << (*it)->target << "-" << "qmake_all"; |
|
2519 } |
|
2520 } |
|
2521 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2522 t << " FORCE"; |
|
2523 if(project->isActiveConfig("no_empty_targets")) |
|
2524 t << "\n\t" << "@cd ."; |
|
2525 t << endl << endl; |
|
2526 } |
|
2527 |
|
2528 for(int s = 0; s < targetSuffixes.size(); ++s) { |
|
2529 QString suffix = targetSuffixes.at(s); |
|
2530 if(!(flags & SubTargetInstalls) && suffix.endsWith("install")) |
|
2531 continue; |
|
2532 |
|
2533 t << suffix << ":"; |
|
2534 for(int target = 0; target < targets.size(); ++target) { |
|
2535 SubTarget *subTarget = targets.at(target); |
|
2536 if((suffix == "make_first" || suffix == "make_default") |
|
2537 && project->values(subTarget->name + ".CONFIG").indexOf("no_default_target") != -1) { |
|
2538 continue; |
|
2539 } |
|
2540 QString targetRule = subTarget->target + "-" + suffix; |
|
2541 if(flags & SubTargetOrdered) |
|
2542 targetRule += "-ordered"; |
|
2543 t << " " << targetRule; |
|
2544 } |
|
2545 if(suffix == "all" || suffix == "make_first") |
|
2546 t << varGlue("ALL_DEPS"," "," ",""); |
|
2547 if(suffix == "clean") |
|
2548 t << varGlue("CLEAN_DEPS"," "," ",""); |
|
2549 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2550 t << " FORCE"; |
|
2551 t << endl; |
|
2552 if(suffix == "clean") { |
|
2553 t << varGlue("QMAKE_CLEAN","\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ", "\n"); |
|
2554 } else if(suffix == "distclean") { |
|
2555 QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName())); |
|
2556 if(!ofile.isEmpty()) |
|
2557 t << "\t-$(DEL_FILE) " << ofile << endl; |
|
2558 t << varGlue("QMAKE_DISTCLEAN","\t-$(DEL_FILE) "," ","\n"); |
|
2559 } else if(project->isActiveConfig("no_empty_targets")) { |
|
2560 t << "\t" << "@cd ." << endl; |
|
2561 } |
|
2562 } |
|
2563 |
|
2564 // user defined targets |
|
2565 QStringList &qut = project->values("QMAKE_EXTRA_TARGETS"); |
|
2566 for(QStringList::Iterator qut_it = qut.begin(); qut_it != qut.end(); ++qut_it) { |
|
2567 QString targ = var((*qut_it) + ".target"), |
|
2568 cmd = var((*qut_it) + ".commands"), deps; |
|
2569 if(targ.isEmpty()) |
|
2570 targ = (*qut_it); |
|
2571 t << endl; |
|
2572 |
|
2573 QStringList &deplist = project->values((*qut_it) + ".depends"); |
|
2574 for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) { |
|
2575 QString dep = var((*dep_it) + ".target"); |
|
2576 if(dep.isEmpty()) |
|
2577 dep = Option::fixPathToTargetOS(*dep_it, false); |
|
2578 deps += " " + dep; |
|
2579 } |
|
2580 if(project->values((*qut_it) + ".CONFIG").indexOf("recursive") != -1) { |
|
2581 QSet<QString> recurse; |
|
2582 if(project->isSet((*qut_it) + ".recurse")) { |
|
2583 recurse = project->values((*qut_it) + ".recurse").toSet(); |
|
2584 } else { |
|
2585 for(int target = 0; target < targets.size(); ++target) |
|
2586 recurse.insert(targets.at(target)->name); |
|
2587 } |
|
2588 for(int target = 0; target < targets.size(); ++target) { |
|
2589 SubTarget *subtarget = targets.at(target); |
|
2590 QString in_directory = subtarget->in_directory; |
|
2591 if(!in_directory.isEmpty() && !in_directory.endsWith(Option::dir_sep)) |
|
2592 in_directory += Option::dir_sep; |
|
2593 QString out_directory = subtarget->out_directory; |
|
2594 if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep)) |
|
2595 out_directory += Option::dir_sep; |
|
2596 if(!abs_source_path.isEmpty() && out_directory.startsWith(abs_source_path)) |
|
2597 out_directory = Option::output_dir + out_directory.mid(abs_source_path.length()); |
|
2598 |
|
2599 if(!recurse.contains(subtarget->name)) |
|
2600 continue; |
|
2601 QString mkfile = subtarget->makefile; |
|
2602 if(!in_directory.isEmpty()) { |
|
2603 if(!out_directory.endsWith(Option::dir_sep)) |
|
2604 mkfile.prepend(out_directory + Option::dir_sep); |
|
2605 else |
|
2606 mkfile.prepend(out_directory); |
|
2607 } |
|
2608 QString out_directory_cdin, out_directory_cdout; |
|
2609 MAKE_CD_IN_AND_OUT(out_directory); |
|
2610 |
|
2611 //don't need the makefile arg if it isn't changed |
|
2612 QString makefilein; |
|
2613 if(subtarget->makefile != "$(MAKEFILE)") |
|
2614 makefilein = " -f " + subtarget->makefile; |
|
2615 |
|
2616 //write the rule/depends |
|
2617 if(flags & SubTargetOrdered) { |
|
2618 const QString dep = subtarget->target + "-" + (*qut_it) + "_ordered"; |
|
2619 t << dep << ": " << mkfile; |
|
2620 if(target) |
|
2621 t << " " << targets.at(target-1)->target << "-" << (*qut_it) << "_ordered "; |
|
2622 deps += " " + dep; |
|
2623 } else { |
|
2624 const QString dep = subtarget->target + "-" + (*qut_it); |
|
2625 t << dep << ": " << mkfile; |
|
2626 if(!subtarget->depends.isEmpty()) |
|
2627 t << " " << valGlue(subtarget->depends, QString(), "-" + (*qut_it) + " ", "-" + (*qut_it)); |
|
2628 deps += " " + dep; |
|
2629 } |
|
2630 |
|
2631 QString sub_targ = targ; |
|
2632 if(project->isSet((*qut_it) + ".recurse_target")) |
|
2633 sub_targ = project->first((*qut_it) + ".recurse_target"); |
|
2634 |
|
2635 //write the commands |
|
2636 if(!out_directory.isEmpty()) { |
|
2637 t << out_directory_cdin |
|
2638 << "$(MAKE)" << makefilein << " " << sub_targ |
|
2639 << out_directory_cdout << endl; |
|
2640 } else { |
|
2641 t << "\n\t" |
|
2642 << "$(MAKE)" << makefilein << " " << sub_targ << endl; |
|
2643 } |
|
2644 } |
|
2645 } |
|
2646 if(project->isEmpty("QMAKE_NOFORCE") && |
|
2647 project->values((*qut_it) + ".CONFIG").indexOf("phony") != -1) |
|
2648 deps += " FORCE"; |
|
2649 t << targ << ":" << deps << "\n"; |
|
2650 if(!cmd.isEmpty()) |
|
2651 t << "\t" << cmd << endl; |
|
2652 } |
|
2653 |
|
2654 if(flags & SubTargetInstalls) { |
|
2655 project->values("INSTALLDEPS") += "install_subtargets"; |
|
2656 project->values("UNINSTALLDEPS") += "uninstall_subtargets"; |
|
2657 writeInstalls(t, "INSTALLS", true); |
|
2658 } |
|
2659 |
|
2660 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2661 t << "FORCE:" << endl << endl; |
|
2662 } |
|
2663 |
|
2664 void |
|
2665 MakefileGenerator::writeMakeQmake(QTextStream &t) |
|
2666 { |
|
2667 QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName())); |
|
2668 if(project->isEmpty("QMAKE_FAILED_REQUIREMENTS") && !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) { |
|
2669 QStringList files = fileFixify(Option::mkfile::project_files); |
|
2670 t << escapeDependencyPath(project->first("QMAKE_INTERNAL_PRL_FILE")) << ": " << "\n\t" |
|
2671 << "@$(QMAKE) -prl " << buildArgs() << " " << files.join(" ") << endl; |
|
2672 } |
|
2673 |
|
2674 QString pfile = project->projectFile(); |
|
2675 if(pfile != "(stdin)") { |
|
2676 QString qmake = build_args(); |
|
2677 if(!ofile.isEmpty() && !project->isActiveConfig("no_autoqmake")) { |
|
2678 t << escapeFilePath(ofile) << ": " << escapeDependencyPath(fileFixify(pfile)) << " "; |
|
2679 if(Option::mkfile::do_cache) |
|
2680 t << escapeDependencyPath(fileFixify(Option::mkfile::cachefile)) << " "; |
|
2681 if(!specdir().isEmpty()) { |
|
2682 if(exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"qmake.conf"))) |
|
2683 t << escapeDependencyPath(specdir() + Option::dir_sep + "qmake.conf") << " "; |
|
2684 else if(exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"tmake.conf"))) |
|
2685 t << escapeDependencyPath(specdir() + Option::dir_sep + "tmake.conf") << " "; |
|
2686 } |
|
2687 const QStringList &included = project->values("QMAKE_INTERNAL_INCLUDED_FILES"); |
|
2688 t << escapeDependencyPaths(included).join(" \\\n\t\t") << "\n\t" |
|
2689 << qmake << endl; |
|
2690 for(int include = 0; include < included.size(); ++include) { |
|
2691 const QString i(included.at(include)); |
|
2692 if(!i.isEmpty()) |
|
2693 t << i << ":" << endl; |
|
2694 } |
|
2695 } |
|
2696 if(project->first("QMAKE_ORIG_TARGET") != "qmake") { |
|
2697 t << "qmake: " << |
|
2698 project->values("QMAKE_INTERNAL_QMAKE_DEPS").join(" \\\n\t\t"); |
|
2699 if(project->isEmpty("QMAKE_NOFORCE")) |
|
2700 t << " FORCE"; |
|
2701 t << "\n\t" << "@" << qmake << endl << endl; |
|
2702 } |
|
2703 } |
|
2704 } |
|
2705 |
|
2706 QFileInfo |
|
2707 MakefileGenerator::fileInfo(QString file) const |
|
2708 { |
|
2709 static QHash<FileInfoCacheKey, QFileInfo> *cache = 0; |
|
2710 static QFileInfo noInfo = QFileInfo(); |
|
2711 if(!cache) { |
|
2712 cache = new QHash<FileInfoCacheKey, QFileInfo>; |
|
2713 qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFileInfoCacheKeyQFileInfo, (void**)&cache); |
|
2714 } |
|
2715 FileInfoCacheKey cacheKey(file); |
|
2716 QFileInfo value = cache->value(cacheKey, noInfo); |
|
2717 if (value != noInfo) |
|
2718 return value; |
|
2719 |
|
2720 QFileInfo fi(file); |
|
2721 if (fi.exists()) |
|
2722 cache->insert(cacheKey, fi); |
|
2723 return fi; |
|
2724 } |
|
2725 |
|
2726 QString |
|
2727 MakefileGenerator::unescapeFilePath(const QString &path) const |
|
2728 { |
|
2729 QString ret = path; |
|
2730 if(!ret.isEmpty()) { |
|
2731 if(ret.contains(QLatin1String("\\ "))) |
|
2732 ret.replace(QLatin1String("\\ "), QLatin1String(" ")); |
|
2733 if(ret.contains(QLatin1Char('\"'))) |
|
2734 ret.remove(QLatin1Char('\"')); |
|
2735 } |
|
2736 return ret; |
|
2737 } |
|
2738 |
|
2739 QStringList |
|
2740 MakefileGenerator::escapeFilePaths(const QStringList &paths) const |
|
2741 { |
|
2742 QStringList ret; |
|
2743 for(int i = 0; i < paths.size(); ++i) |
|
2744 ret.append(escapeFilePath(paths.at(i))); |
|
2745 return ret; |
|
2746 } |
|
2747 |
|
2748 QStringList |
|
2749 MakefileGenerator::escapeDependencyPaths(const QStringList &paths) const |
|
2750 { |
|
2751 QStringList ret; |
|
2752 for(int i = 0; i < paths.size(); ++i) |
|
2753 ret.append(escapeDependencyPath(paths.at(i))); |
|
2754 return ret; |
|
2755 } |
|
2756 |
|
2757 QStringList |
|
2758 MakefileGenerator::unescapeFilePaths(const QStringList &paths) const |
|
2759 { |
|
2760 QStringList ret; |
|
2761 for(int i = 0; i < paths.size(); ++i) |
|
2762 ret.append(unescapeFilePath(paths.at(i))); |
|
2763 return ret; |
|
2764 } |
|
2765 |
|
2766 QStringList |
|
2767 MakefileGenerator::fileFixify(const QStringList& files, const QString &out_dir, const QString &in_dir, |
|
2768 FileFixifyType fix, bool canon) const |
|
2769 { |
|
2770 if(files.isEmpty()) |
|
2771 return files; |
|
2772 QStringList ret; |
|
2773 for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it) { |
|
2774 if(!(*it).isEmpty()) |
|
2775 ret << fileFixify((*it), out_dir, in_dir, fix, canon); |
|
2776 } |
|
2777 return ret; |
|
2778 } |
|
2779 |
|
2780 QString |
|
2781 MakefileGenerator::fileFixify(const QString& file, const QString &out_d, const QString &in_d, |
|
2782 FileFixifyType fix, bool canon) const |
|
2783 { |
|
2784 if(file.isEmpty()) |
|
2785 return file; |
|
2786 QString ret = unescapeFilePath(file); |
|
2787 |
|
2788 //setup the cache |
|
2789 static QHash<FileFixifyCacheKey, QString> *cache = 0; |
|
2790 if(!cache) { |
|
2791 cache = new QHash<FileFixifyCacheKey, QString>; |
|
2792 qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFileFixifyCacheKeyQString, (void**)&cache); |
|
2793 } |
|
2794 FileFixifyCacheKey cacheKey(ret, out_d, in_d, fix, canon); |
|
2795 QString cacheVal = cache->value(cacheKey); |
|
2796 if(!cacheVal.isNull()) |
|
2797 return cacheVal; |
|
2798 |
|
2799 //do the fixin' |
|
2800 QString pwd = qmake_getpwd(); |
|
2801 if (!pwd.endsWith('/')) |
|
2802 pwd += '/'; |
|
2803 QString orig_file = ret; |
|
2804 if(ret.startsWith(QLatin1Char('~'))) { |
|
2805 if(ret.startsWith(QLatin1String("~/"))) |
|
2806 ret = QDir::homePath() + ret.mid(1); |
|
2807 else |
|
2808 warn_msg(WarnLogic, "Unable to expand ~ in %s", ret.toLatin1().constData()); |
|
2809 } |
|
2810 if(fix == FileFixifyAbsolute || (fix == FileFixifyDefault && project->isActiveConfig("no_fixpath"))) { |
|
2811 if(fix == FileFixifyAbsolute && QDir::isRelativePath(ret)) //already absolute |
|
2812 ret.prepend(pwd); |
|
2813 ret = Option::fixPathToTargetOS(ret, false, canon); |
|
2814 } else { //fix it.. |
|
2815 QString out_dir = QDir(Option::output_dir).absoluteFilePath(out_d); |
|
2816 QString in_dir = QDir(pwd).absoluteFilePath(in_d); |
|
2817 { |
|
2818 QFileInfo in_fi(fileInfo(in_dir)); |
|
2819 if(in_fi.exists()) |
|
2820 in_dir = in_fi.canonicalFilePath(); |
|
2821 QFileInfo out_fi(fileInfo(out_dir)); |
|
2822 if(out_fi.exists()) |
|
2823 out_dir = out_fi.canonicalFilePath(); |
|
2824 } |
|
2825 |
|
2826 QString qfile(Option::fixPathToLocalOS(ret, true, canon)); |
|
2827 QFileInfo qfileinfo(fileInfo(qfile)); |
|
2828 if(out_dir != in_dir || !qfileinfo.isRelative()) { |
|
2829 if(qfileinfo.isRelative()) { |
|
2830 ret = in_dir + "/" + qfile; |
|
2831 qfileinfo.setFile(ret); |
|
2832 } |
|
2833 ret = Option::fixPathToTargetOS(ret, false, canon); |
|
2834 if(canon && qfileinfo.exists() && |
|
2835 file == Option::fixPathToTargetOS(ret, true, canon)) |
|
2836 ret = Option::fixPathToTargetOS(qfileinfo.canonicalFilePath()); |
|
2837 QString match_dir = Option::fixPathToTargetOS(out_dir, false, canon); |
|
2838 if(ret == match_dir) { |
|
2839 ret = ""; |
|
2840 } else if(ret.startsWith(match_dir + Option::dir_sep)) { |
|
2841 ret = ret.mid(match_dir.length() + Option::dir_sep.length()); |
|
2842 } else { |
|
2843 //figure out the depth |
|
2844 int depth = 4; |
|
2845 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || |
|
2846 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { |
|
2847 if(project && !project->isEmpty("QMAKE_PROJECT_DEPTH")) |
|
2848 depth = project->first("QMAKE_PROJECT_DEPTH").toInt(); |
|
2849 else if(Option::mkfile::cachefile_depth != -1) |
|
2850 depth = Option::mkfile::cachefile_depth; |
|
2851 } |
|
2852 //calculate how much can be removed |
|
2853 QString dot_prefix; |
|
2854 for(int i = 1; i <= depth; i++) { |
|
2855 int sl = match_dir.lastIndexOf(Option::dir_sep); |
|
2856 if(sl == -1) |
|
2857 break; |
|
2858 match_dir = match_dir.left(sl); |
|
2859 if(match_dir.isEmpty()) |
|
2860 break; |
|
2861 if(ret.startsWith(match_dir + Option::dir_sep)) { |
|
2862 //concat |
|
2863 int remlen = ret.length() - (match_dir.length() + 1); |
|
2864 if(remlen < 0) |
|
2865 remlen = 0; |
|
2866 ret = ret.right(remlen); |
|
2867 //prepend |
|
2868 for(int o = 0; o < i; o++) |
|
2869 dot_prefix += ".." + Option::dir_sep; |
|
2870 } |
|
2871 } |
|
2872 ret.prepend(dot_prefix); |
|
2873 } |
|
2874 } else { |
|
2875 ret = Option::fixPathToTargetOS(ret, false, canon); |
|
2876 } |
|
2877 } |
|
2878 if(ret.isEmpty()) |
|
2879 ret = "."; |
|
2880 debug_msg(3, "Fixed[%d,%d] %s :: to :: %s [%s::%s] [%s::%s]", fix, canon, orig_file.toLatin1().constData(), |
|
2881 ret.toLatin1().constData(), in_d.toLatin1().constData(), out_d.toLatin1().constData(), |
|
2882 pwd.toLatin1().constData(), Option::output_dir.toLatin1().constData()); |
|
2883 cache->insert(cacheKey, ret); |
|
2884 return ret; |
|
2885 } |
|
2886 |
|
2887 void |
|
2888 MakefileGenerator::checkMultipleDefinition(const QString &f, const QString &w) |
|
2889 { |
|
2890 if(!(Option::warn_level & WarnLogic)) |
|
2891 return; |
|
2892 QString file = f; |
|
2893 int slsh = f.lastIndexOf(Option::dir_sep); |
|
2894 if(slsh != -1) |
|
2895 file.remove(0, slsh + 1); |
|
2896 QStringList &l = project->values(w); |
|
2897 for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) { |
|
2898 QString file2((*val_it)); |
|
2899 slsh = file2.lastIndexOf(Option::dir_sep); |
|
2900 if(slsh != -1) |
|
2901 file2.remove(0, slsh + 1); |
|
2902 if(file2 == file) { |
|
2903 warn_msg(WarnLogic, "Found potential symbol conflict of %s (%s) in %s", |
|
2904 file.toLatin1().constData(), (*val_it).toLatin1().constData(), w.toLatin1().constData()); |
|
2905 break; |
|
2906 } |
|
2907 } |
|
2908 } |
|
2909 |
|
2910 QMakeLocalFileName |
|
2911 MakefileGenerator::fixPathForFile(const QMakeLocalFileName &file, bool forOpen) |
|
2912 { |
|
2913 if(forOpen) |
|
2914 return QMakeLocalFileName(fileFixify(file.real(), qmake_getpwd(), Option::output_dir)); |
|
2915 return QMakeLocalFileName(fileFixify(file.real())); |
|
2916 } |
|
2917 |
|
2918 QFileInfo |
|
2919 MakefileGenerator::findFileInfo(const QMakeLocalFileName &file) |
|
2920 { |
|
2921 return fileInfo(file.local()); |
|
2922 } |
|
2923 |
|
2924 QMakeLocalFileName |
|
2925 MakefileGenerator::findFileForDep(const QMakeLocalFileName &dep, const QMakeLocalFileName &file) |
|
2926 { |
|
2927 QMakeLocalFileName ret; |
|
2928 if(!project->isEmpty("SKIP_DEPENDS")) { |
|
2929 bool found = false; |
|
2930 QStringList &nodeplist = project->values("SKIP_DEPENDS"); |
|
2931 for(QStringList::Iterator it = nodeplist.begin(); |
|
2932 it != nodeplist.end(); ++it) { |
|
2933 QRegExp regx((*it)); |
|
2934 if(regx.indexIn(dep.local()) != -1) { |
|
2935 found = true; |
|
2936 break; |
|
2937 } |
|
2938 } |
|
2939 if(found) |
|
2940 return ret; |
|
2941 } |
|
2942 |
|
2943 ret = QMakeSourceFileInfo::findFileForDep(dep, file); |
|
2944 if(!ret.isNull()) |
|
2945 return ret; |
|
2946 |
|
2947 //these are some "hacky" heuristics it will try to do on an include |
|
2948 //however these can be turned off at runtime, I'm not sure how |
|
2949 //reliable these will be, most likely when problems arise turn it off |
|
2950 //and see if they go away.. |
|
2951 if(Option::mkfile::do_dep_heuristics) { |
|
2952 if(depHeuristicsCache.contains(dep.real())) |
|
2953 return depHeuristicsCache[dep.real()]; |
|
2954 |
|
2955 if(Option::output_dir != qmake_getpwd() |
|
2956 && QDir::isRelativePath(dep.real())) { //is it from the shadow tree |
|
2957 QList<QMakeLocalFileName> depdirs = QMakeSourceFileInfo::dependencyPaths(); |
|
2958 depdirs.prepend(fileInfo(file.real()).absoluteDir().path()); |
|
2959 QString pwd = qmake_getpwd(); |
|
2960 if(pwd.at(pwd.length()-1) != '/') |
|
2961 pwd += '/'; |
|
2962 for(int i = 0; i < depdirs.count(); i++) { |
|
2963 QString dir = depdirs.at(i).real(); |
|
2964 if(!QDir::isRelativePath(dir) && dir.startsWith(pwd)) |
|
2965 dir = dir.mid(pwd.length()); |
|
2966 if(QDir::isRelativePath(dir)) { |
|
2967 if(!dir.endsWith(Option::dir_sep)) |
|
2968 dir += Option::dir_sep; |
|
2969 QString shadow = fileFixify(dir + dep.local(), pwd, Option::output_dir); |
|
2970 if(exists(shadow)) { |
|
2971 ret = QMakeLocalFileName(shadow); |
|
2972 goto found_dep_from_heuristic; |
|
2973 } |
|
2974 } |
|
2975 } |
|
2976 } |
|
2977 { //is it from an EXTRA_TARGET |
|
2978 const QString dep_basename = dep.local().section(Option::dir_sep, -1); |
|
2979 QStringList &qut = project->values("QMAKE_EXTRA_TARGETS"); |
|
2980 for(QStringList::Iterator it = qut.begin(); it != qut.end(); ++it) { |
|
2981 QString targ = var((*it) + ".target"); |
|
2982 if(targ.isEmpty()) |
|
2983 targ = (*it); |
|
2984 QString out = Option::fixPathToTargetOS(targ); |
|
2985 if(out == dep.real() || out.section(Option::dir_sep, -1) == dep_basename) { |
|
2986 ret = QMakeLocalFileName(out); |
|
2987 goto found_dep_from_heuristic; |
|
2988 } |
|
2989 } |
|
2990 } |
|
2991 { //is it from an EXTRA_COMPILER |
|
2992 const QString dep_basename = dep.local().section(Option::dir_sep, -1); |
|
2993 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); |
|
2994 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { |
|
2995 QString tmp_out = project->values((*it) + ".output").first(); |
|
2996 if(tmp_out.isEmpty()) |
|
2997 continue; |
|
2998 QStringList &tmp = project->values((*it) + ".input"); |
|
2999 for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) { |
|
3000 QStringList &inputs = project->values((*it2)); |
|
3001 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) { |
|
3002 QString out = Option::fixPathToTargetOS(unescapeFilePath(replaceExtraCompilerVariables(tmp_out, (*input), QString()))); |
|
3003 if(out == dep.real() || out.section(Option::dir_sep, -1) == dep_basename) { |
|
3004 ret = QMakeLocalFileName(fileFixify(out, qmake_getpwd(), Option::output_dir)); |
|
3005 goto found_dep_from_heuristic; |
|
3006 } |
|
3007 } |
|
3008 } |
|
3009 } |
|
3010 } |
|
3011 found_dep_from_heuristic: |
|
3012 depHeuristicsCache.insert(dep.real(), ret); |
|
3013 } |
|
3014 return ret; |
|
3015 } |
|
3016 |
|
3017 QStringList |
|
3018 &MakefileGenerator::findDependencies(const QString &file) |
|
3019 { |
|
3020 const QString fixedFile = fileFixify(file); |
|
3021 if(!dependsCache.contains(fixedFile)) { |
|
3022 #if 1 |
|
3023 QStringList deps = QMakeSourceFileInfo::dependencies(file); |
|
3024 if(file != fixedFile) |
|
3025 deps += QMakeSourceFileInfo::dependencies(fixedFile); |
|
3026 #else |
|
3027 QStringList deps = QMakeSourceFileInfo::dependencies(fixedFile); |
|
3028 #endif |
|
3029 dependsCache.insert(fixedFile, deps); |
|
3030 } |
|
3031 return dependsCache[fixedFile]; |
|
3032 } |
|
3033 |
|
3034 QString |
|
3035 MakefileGenerator::specdir(const QString &outdir) |
|
3036 { |
|
3037 #if 0 |
|
3038 if(!spec.isEmpty()) |
|
3039 return spec; |
|
3040 #endif |
|
3041 spec = fileFixify(Option::mkfile::qmakespec, outdir); |
|
3042 return spec; |
|
3043 } |
|
3044 |
|
3045 bool |
|
3046 MakefileGenerator::openOutput(QFile &file, const QString &build) const |
|
3047 { |
|
3048 { |
|
3049 QString outdir; |
|
3050 if(!file.fileName().isEmpty()) { |
|
3051 if(QDir::isRelativePath(file.fileName())) |
|
3052 file.setFileName(Option::output_dir + "/" + file.fileName()); //pwd when qmake was run |
|
3053 QFileInfo fi(fileInfo(file.fileName())); |
|
3054 if(fi.isDir()) |
|
3055 outdir = file.fileName() + '/'; |
|
3056 } |
|
3057 if(!outdir.isEmpty() || file.fileName().isEmpty()) { |
|
3058 QString fname = "Makefile"; |
|
3059 if(!project->isEmpty("MAKEFILE")) |
|
3060 fname = project->first("MAKEFILE"); |
|
3061 file.setFileName(outdir + fname); |
|
3062 } |
|
3063 } |
|
3064 if(QDir::isRelativePath(file.fileName())) { |
|
3065 QString fname = Option::output_dir; //pwd when qmake was run |
|
3066 if(!fname.endsWith("/")) |
|
3067 fname += "/"; |
|
3068 fname += file.fileName(); |
|
3069 file.setFileName(fname); |
|
3070 } |
|
3071 if(!build.isEmpty()) |
|
3072 file.setFileName(file.fileName() + "." + build); |
|
3073 if(project->isEmpty("QMAKE_MAKEFILE")) |
|
3074 project->values("QMAKE_MAKEFILE").append(file.fileName()); |
|
3075 int slsh = file.fileName().lastIndexOf('/'); |
|
3076 if(slsh != -1) |
|
3077 mkdir(file.fileName().left(slsh)); |
|
3078 if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { |
|
3079 QFileInfo fi(fileInfo(Option::output.fileName())); |
|
3080 QString od; |
|
3081 if(fi.isSymLink()) |
|
3082 od = fileInfo(fi.readLink()).absolutePath(); |
|
3083 else |
|
3084 od = fi.path(); |
|
3085 od = QDir::fromNativeSeparators(od); |
|
3086 if(QDir::isRelativePath(od)) { |
|
3087 QString dir = Option::output_dir; |
|
3088 if (!dir.endsWith('/') && !od.isEmpty()) |
|
3089 dir += '/'; |
|
3090 od.prepend(dir); |
|
3091 } |
|
3092 Option::output_dir = od; |
|
3093 return true; |
|
3094 } |
|
3095 return false; |
|
3096 } |
|
3097 |
|
3098 QT_END_NAMESPACE |