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