1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the qmake application of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include "cachekeys.h"
48 #include <qtextstream.h>
53 #include <qsettings.h>
54 #include <qdatetime.h>
55 #if defined(Q_OS_UNIX)
65 #include <sys/types.h>
70 // Well, Windows doesn't have this, so here's the macro
72 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
75 bool MakefileGenerator::canExecute(const QStringList
&cmdline
, int *a
) const
78 for(int i
= 0; i
< cmdline
.count(); ++i
) {
79 if(!cmdline
.at(i
).contains('=')) {
87 const QString c
= Option::fixPathToLocalOS(cmdline
.at(argv0
), true);
94 QString
MakefileGenerator::mkdir_p_asstring(const QString
&dir
, bool escape
) const
96 QString ret
= "@$(CHK_DIR_EXISTS) ";
98 ret
+= escapeFilePath(dir
);
105 ret
+= "|| $(MKDIR)";
108 ret
+= escapeFilePath(dir
);
115 bool MakefileGenerator::mkdir(const QString
&in_path
) const
117 QString path
= Option::fixPathToLocalOS(in_path
);
118 if(QFile::exists(path
))
122 if(path
.startsWith(QDir::separator())) {
123 d
.cd(QString(QDir::separator()));
128 bool driveExists
= true;
129 if(!QDir::isRelativePath(path
)) {
130 if(QFile::exists(path
.left(3))) {
134 warn_msg(WarnLogic
, "Cannot access drive '%s' (%s)",
135 path
.left(3).toLatin1().data(), path
.toLatin1().data());
142 QStringList subs
= path
.split(QDir::separator());
143 for(QStringList::Iterator subit
= subs
.begin(); subit
!= subs
.end(); ++subit
) {
146 if(d
.exists((*subit
))) {
158 // ** base makefile generator
159 MakefileGenerator::MakefileGenerator() :
160 init_opath_already(false), init_already(false), no_io(false), project(0)
166 MakefileGenerator::verifyCompilers()
168 QMap
<QString
, QStringList
> &v
= project
->variables();
169 QStringList
&quc
= v
["QMAKE_EXTRA_COMPILERS"];
170 for(int i
= 0; i
< quc
.size(); ) {
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() + "}");
178 warn_msg(WarnLogic
, "Compiler: %s: No output file specified", comp
.toLatin1().constData());
180 } else if(v
[comp
+ ".input"].isEmpty()) {
182 warn_msg(WarnLogic
, "Compiler: %s: No input variable specified", comp
.toLatin1().constData());
192 MakefileGenerator::initOutPaths()
194 if(init_opath_already
)
197 init_opath_already
= true;
198 QMap
<QString
, QStringList
> &v
= project
->variables();
200 if(!v
.contains("QMAKE_ABSOLUTE_SOURCE_PATH")) {
201 if(Option::mkfile::do_cache
&& !Option::mkfile::cachefile
.isEmpty() &&
202 v
.contains("QMAKE_ABSOLUTE_SOURCE_ROOT")) {
203 QString root
= v
["QMAKE_ABSOLUTE_SOURCE_ROOT"].first();
204 root
= QDir::fromNativeSeparators(root
);
205 if(!root
.isEmpty()) {
206 QFileInfo fi
= fileInfo(Option::mkfile::cachefile
);
207 if(!fi
.makeAbsolute()) {
208 QString cache_r
= fi
.path(), pwd
= Option::output_dir
;
209 if(pwd
.startsWith(cache_r
) && !pwd
.startsWith(root
)) {
210 pwd
= root
+ pwd
.mid(cache_r
.length());
212 v
.insert("QMAKE_ABSOLUTE_SOURCE_PATH", QStringList(pwd
));
218 if(!v
["QMAKE_ABSOLUTE_SOURCE_PATH"].isEmpty()) {
219 QString
&asp
= v
["QMAKE_ABSOLUTE_SOURCE_PATH"].first();
220 asp
= QDir::fromNativeSeparators(asp
);
221 if(asp
.isEmpty() || asp
== Option::output_dir
) //if they're the same, why bother?
222 v
["QMAKE_ABSOLUTE_SOURCE_PATH"].clear();
225 QString currentDir
= qmake_getpwd(); //just to go back to
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())
236 const QString orig_path
= v
[dirs
[x
]].first();
238 QString
&pathRef
= v
[dirs
[x
]].first();
239 pathRef
= fileFixify(pathRef
, Option::output_dir
, Option::output_dir
);
242 // We don't want to add a separator for DLLDESTDIR on Windows (###why?)
243 if(!(dirs
[x
] == "DLLDESTDIR"))
246 if(!pathRef
.endsWith(Option::dir_sep
))
247 pathRef
+= Option::dir_sep
;
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());
258 warn_msg(WarnLogic
, "%s: Cannot access directory '%s'", dirs
[x
].toLatin1().constData(),
259 path
.toLatin1().constData());
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())
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
);
277 path
= path
.left(slash
);
278 // Make out path only if it does not contain makefile variables
279 if(!path
.contains("${"))
281 !mkdir(fileFixify(path
, qmake_getpwd(), Option::output_dir
)))
282 warn_msg(WarnLogic
, "%s: Cannot access directory '%s'",
283 (*it
).toLatin1().constData(), path
.toLatin1().constData());
289 if(!v
["DESTDIR"].isEmpty()) {
290 QDir
d(v
["DESTDIR"].first());
291 if(Option::fixPathToLocalOS(d
.absolutePath()) == Option::fixPathToLocalOS(Option::output_dir
))
297 *MakefileGenerator::projectFile() const
303 MakefileGenerator::setProjectFile(QMakeProject
*p
)
311 if(Option::qmake_mode
== Option::QMAKE_GENERATE_MAKEFILE
&&
312 project
->isActiveConfig("link_prl")) //load up prl's'
317 MakefileGenerator::findFilesInVPATH(QStringList l
, uchar flags
, const QString
&vpath_var
)
320 QMap
<QString
, QStringList
> &v
= project
->variables();
321 for(int val_it
= 0; val_it
< l
.count(); ) {
322 bool remove_file
= false;
323 QString
&val
= l
[val_it
];
325 QString file
= fixEnvVariables(val
);
326 if(!(flags
& VPATH_NoFixify
))
327 file
= fileFixify(file
, qmake_getpwd(), Option::output_dir
);
328 if (file
.at(0) == '\"' && file
.at(file
.length() - 1) == '\"')
329 file
= file
.mid(1, file
.length() - 2);
336 if(QDir::isRelativePath(val
)) {
337 if(vpath
.isEmpty()) {
338 if(!vpath_var
.isEmpty())
339 vpath
= v
[vpath_var
];
340 vpath
+= v
["VPATH"] + v
["QMAKE_ABSOLUTE_SOURCE_PATH"] + v
["DEPENDPATH"];
341 if(Option::output_dir
!= qmake_getpwd())
342 vpath
+= Option::output_dir
;
344 for(QStringList::Iterator vpath_it
= vpath
.begin();
345 vpath_it
!= vpath
.end(); ++vpath_it
) {
346 QString real_dir
= Option::fixPathToLocalOS((*vpath_it
));
347 if(exists(real_dir
+ QDir::separator() + val
)) {
348 QString dir
= (*vpath_it
);
349 if(!dir
.endsWith(Option::dir_sep
))
350 dir
+= Option::dir_sep
;
352 if(!(flags
& VPATH_NoFixify
))
353 val
= fileFixify(val
);
355 debug_msg(1, "Found file through vpath %s -> %s",
356 file
.toLatin1().constData(), val
.toLatin1().constData());
362 QString dir
, regex
= val
, real_dir
;
363 if(regex
.lastIndexOf(Option::dir_sep
) != -1) {
364 dir
= regex
.left(regex
.lastIndexOf(Option::dir_sep
) + 1);
366 if(!(flags
& VPATH_NoFixify
))
367 real_dir
= fileFixify(real_dir
, qmake_getpwd(), Option::output_dir
);
368 regex
.remove(0, dir
.length());
370 if(real_dir
.isEmpty() || exists(real_dir
)) {
371 QStringList files
= QDir(real_dir
).entryList(QStringList(regex
));
372 if(files
.isEmpty()) {
373 debug_msg(1, "%s:%d Failure to find %s in vpath (%s)",
375 val
.toLatin1().constData(), vpath
.join("::").toLatin1().constData());
376 if(flags
& VPATH_RemoveMissingFiles
)
378 else if(flags
& VPATH_WarnMissingFiles
)
379 warn_msg(WarnLogic
, "Failure to find: %s", val
.toLatin1().constData());
383 for(int i
= (int)files
.count()-1; i
>= 0; i
--) {
384 if(files
[i
] == "." || files
[i
] == "..")
387 if(!(flags
& VPATH_NoFixify
))
393 debug_msg(1, "%s:%d Cannot match %s%c%s, as %s does not exist.",
394 __FILE__
, __LINE__
, real_dir
.toLatin1().constData(),
395 QDir::separator().toLatin1(),
396 regex
.toLatin1().constData(), real_dir
.toLatin1().constData());
397 if(flags
& VPATH_RemoveMissingFiles
)
399 else if(flags
& VPATH_WarnMissingFiles
)
400 warn_msg(WarnLogic
, "Failure to find: %s", val
.toLatin1().constData());
413 MakefileGenerator::initCompiler(const MakefileGenerator::Compiler
&comp
)
415 QMap
<QString
, QStringList
> &v
= project
->variables();
416 QStringList
&l
= v
[comp
.variable_in
];
417 // find all the relevant file inputs
418 if(!init_compiler_already
.contains(comp
.variable_in
)) {
419 init_compiler_already
.insert(comp
.variable_in
, true);
421 l
= findFilesInVPATH(l
, (comp
.flags
& Compiler::CompilerRemoveNoExist
) ?
422 VPATH_RemoveMissingFiles
: VPATH_WarnMissingFiles
, "VPATH_" + comp
.variable_in
);
427 MakefileGenerator::init()
435 QMap
<QString
, QStringList
> &v
= project
->variables();
436 QStringList
&quc
= v
["QMAKE_EXTRA_COMPILERS"];
438 //make sure the COMPILERS are in the correct input/output chain order
439 for(int comp_out
= 0, jump_count
= 0; comp_out
< quc
.size(); ++comp_out
) {
440 continue_compiler_chain
:
441 if(jump_count
> quc
.size()) //just to avoid an infinite loop here
443 if(project
->variables().contains(quc
.at(comp_out
) + ".variable_out")) {
444 const QStringList
&outputs
= project
->variables().value(quc
.at(comp_out
) + ".variable_out");
445 for(int out
= 0; out
< outputs
.size(); ++out
) {
446 for(int comp_in
= 0; comp_in
< quc
.size(); ++comp_in
) {
447 if(comp_in
== comp_out
)
449 if(project
->variables().contains(quc
.at(comp_in
) + ".input")) {
450 const QStringList
&inputs
= project
->variables().value(quc
.at(comp_in
) + ".input");
451 for(int in
= 0; in
< inputs
.size(); ++in
) {
452 if(inputs
.at(in
) == outputs
.at(out
) && comp_out
> comp_in
) {
454 //move comp_out to comp_in and continue the compiler chain
455 quc
.move(comp_out
, comp_in
);
457 goto continue_compiler_chain
;
466 if(!project
->isEmpty("QMAKE_SUBSTITUTES")) {
467 const QStringList
&subs
= v
["QMAKE_SUBSTITUTES"];
468 for(int i
= 0; i
< subs
.size(); ++i
) {
469 if(!subs
.at(i
).endsWith(".in")) {
470 warn_msg(WarnLogic
, "Substitute '%s' does not end with '.in'",
471 subs
.at(i
).toLatin1().constData());
474 QFile
in(fileFixify(subs
.at(i
))), out(fileInfo(subs
.at(i
)).fileName());
475 if(out
.fileName().endsWith(".in"))
476 out
.setFileName(out
.fileName().left(out
.fileName().length()-3));
477 if(in
.open(QFile::ReadOnly
)) {
480 enum { IN_CONDITION
, MET_CONDITION
, PENDING_CONDITION
};
481 for(int count
= 1; !in
.atEnd(); ++count
) {
482 QString line
= QString::fromUtf8(in
.readLine());
483 if(line
.startsWith("!!IF ")) {
484 if(state
.isEmpty() || state
.top() == IN_CONDITION
) {
485 QString test
= line
.mid(5, line
.length()-(5+1));
486 if(project
->test(test
))
487 state
.push(IN_CONDITION
);
489 state
.push(PENDING_CONDITION
);
491 state
.push(MET_CONDITION
);
493 } else if(line
.startsWith("!!ELIF ")) {
494 if(state
.isEmpty()) {
495 warn_msg(WarnLogic
, "(%s:%d): Unexpected else condition",
496 in
.fileName().toLatin1().constData(), count
);
497 } else if(state
.top() == PENDING_CONDITION
) {
498 QString test
= line
.mid(7, line
.length()-(7+1));
499 if(project
->test(test
)) {
501 state
.push(IN_CONDITION
);
503 } else if(state
.top() == IN_CONDITION
) {
505 state
.push(MET_CONDITION
);
507 } else if(line
.startsWith("!!ELSE")) {
508 if(state
.isEmpty()) {
509 warn_msg(WarnLogic
, "(%s:%d): Unexpected else condition",
510 in
.fileName().toLatin1().constData(), count
);
511 } else if(state
.top() == PENDING_CONDITION
) {
513 state
.push(IN_CONDITION
);
514 } else if(state
.top() == IN_CONDITION
) {
516 state
.push(MET_CONDITION
);
518 } else if(line
.startsWith("!!ENDIF")) {
520 warn_msg(WarnLogic
, "(%s:%d): Unexpected endif",
521 in
.fileName().toLatin1().constData(), count
);
524 } else if(state
.isEmpty() || state
.top() == IN_CONDITION
) {
525 contents
+= project
->expand(line
).join(QString(Option::field_sep
));
528 if(out
.exists() && out
.open(QFile::ReadOnly
)) {
529 QString old
= QString::fromUtf8(out
.readAll());
530 if(contents
== old
) {
531 v
["QMAKE_INTERNAL_INCLUDED_FILES"].append(subs
.at(i
));
536 warn_msg(WarnLogic
, "Cannot clear substitute '%s'",
537 out
.fileName().toLatin1().constData());
541 if(out
.open(QFile::WriteOnly
)) {
542 v
["QMAKE_INTERNAL_INCLUDED_FILES"].append(subs
.at(i
));
543 out
.write(contents
.toUtf8());
545 warn_msg(WarnLogic
, "Cannot open substitute for output '%s'",
546 out
.fileName().toLatin1().constData());
549 warn_msg(WarnLogic
, "Cannot open substitute for input '%s'",
550 in
.fileName().toLatin1().constData());
557 //build up a list of compilers
558 QList
<Compiler
> compilers
;
560 const char *builtins
[] = { "OBJECTS", "SOURCES", "PRECOMPILED_HEADER", 0 };
561 for(x
= 0; builtins
[x
]; ++x
) {
563 compiler
.variable_in
= builtins
[x
];
564 compiler
.flags
= Compiler::CompilerBuiltin
;
565 compiler
.type
= QMakeSourceFileInfo::TYPE_C
;
566 if(!strcmp(builtins
[x
], "OBJECTS"))
567 compiler
.flags
|= Compiler::CompilerNoCheckDeps
;
568 compilers
.append(compiler
);
570 for(QStringList::ConstIterator it
= quc
.begin(); it
!= quc
.end(); ++it
) {
571 const QStringList
&inputs
= v
[(*it
) + ".input"];
572 for(x
= 0; x
< inputs
.size(); ++x
) {
574 compiler
.variable_in
= inputs
.at(x
);
575 compiler
.flags
= Compiler::CompilerNoFlags
;
576 if(v
[(*it
) + ".CONFIG"].indexOf("ignore_no_exist") != -1)
577 compiler
.flags
|= Compiler::CompilerRemoveNoExist
;
578 if(v
[(*it
) + ".CONFIG"].indexOf("no_dependencies") != -1)
579 compiler
.flags
|= Compiler::CompilerNoCheckDeps
;
582 if(!project
->isEmpty((*it
) + ".dependency_type"))
583 dep_type
= project
->first((*it
) + ".dependency_type");
584 if (dep_type
.isEmpty())
585 compiler
.type
= QMakeSourceFileInfo::TYPE_UNKNOWN
;
586 else if(dep_type
== "TYPE_UI")
587 compiler
.type
= QMakeSourceFileInfo::TYPE_UI
;
589 compiler
.type
= QMakeSourceFileInfo::TYPE_C
;
590 compilers
.append(compiler
);
594 { //do the path fixifying
596 for(x
= 0; x
< compilers
.count(); ++x
) {
597 if(!paths
.contains(compilers
.at(x
).variable_in
))
598 paths
<< compilers
.at(x
).variable_in
;
600 paths
<< "INCLUDEPATH" << "QMAKE_INTERNAL_INCLUDED_FILES" << "PRECOMPILED_HEADER";
601 for(int y
= 0; y
< paths
.count(); y
++) {
602 QStringList
&l
= v
[paths
[y
]];
603 for(QStringList::Iterator it
= l
.begin(); it
!= l
.end(); ++it
) {
607 (*it
) = fileFixify((*it
));
612 if(noIO() || !doDepends())
613 QMakeSourceFileInfo::setDependencyMode(QMakeSourceFileInfo::NonRecursive
);
614 for(x
= 0; x
< compilers
.count(); ++x
)
615 initCompiler(compilers
.at(x
));
617 //merge actual compiler outputs into their variable_out. This is done last so that
618 //files are already properly fixified.
619 for(QStringList::Iterator it
= quc
.begin(); it
!= quc
.end(); ++it
) {
620 QString tmp_out
= project
->values((*it
) + ".output").first();
621 if(tmp_out
.isEmpty())
623 if(project
->values((*it
) + ".CONFIG").indexOf("combine") != -1) {
624 QStringList
&compilerInputs
= project
->values((*it
) + ".input");
625 // Don't generate compiler output if it doesn't have input.
626 if (compilerInputs
.isEmpty() || project
->values(compilerInputs
.first()).isEmpty())
628 if(tmp_out
.indexOf("$") == -1) {
629 if(!verifyExtraCompiler((*it
), QString())) //verify
631 QString out
= fileFixify(tmp_out
, Option::output_dir
, Option::output_dir
);
632 bool pre_dep
= (project
->values((*it
) + ".CONFIG").indexOf("target_predeps") != -1);
633 if(project
->variables().contains((*it
) + ".variable_out")) {
634 const QStringList
&var_out
= project
->variables().value((*it
) + ".variable_out");
635 for(int i
= 0; i
< var_out
.size(); ++i
) {
636 QString v
= var_out
.at(i
);
637 if(v
== QLatin1String("SOURCES"))
638 v
= "GENERATED_SOURCES";
639 else if(v
== QLatin1String("OBJECTS"))
641 QStringList
&list
= project
->values(v
);
642 if(!list
.contains(out
))
645 } else if(project
->values((*it
) + ".CONFIG").indexOf("no_link") == -1) {
646 QStringList
&list
= project
->values("OBJECTS");
648 if(!list
.contains(out
))
651 QStringList
&list
= project
->values("UNUSED_SOURCES");
652 if(!list
.contains(out
))
656 QStringList
&list
= project
->variables()["PRE_TARGETDEPS"];
657 if(!list
.contains(out
))
662 QStringList
&tmp
= project
->values((*it
) + ".input");
663 for(QStringList::Iterator it2
= tmp
.begin(); it2
!= tmp
.end(); ++it2
) {
664 const QStringList inputs
= project
->values((*it2
));
665 for(QStringList::ConstIterator input
= inputs
.constBegin(); input
!= inputs
.constEnd(); ++input
) {
666 if((*input
).isEmpty())
668 QString in
= Option::fixPathToTargetOS((*input
), false);
669 if(!verifyExtraCompiler((*it
), in
)) //verify
671 QString out
= replaceExtraCompilerVariables(tmp_out
, (*input
), QString());
672 out
= fileFixify(out
, Option::output_dir
, Option::output_dir
);
673 bool pre_dep
= (project
->values((*it
) + ".CONFIG").indexOf("target_predeps") != -1);
674 if(project
->variables().contains((*it
) + ".variable_out")) {
675 const QStringList
&var_out
= project
->variables().value((*it
) + ".variable_out");
676 for(int i
= 0; i
< var_out
.size(); ++i
) {
677 QString v
= var_out
.at(i
);
678 if(v
== QLatin1String("SOURCES"))
679 v
= "GENERATED_SOURCES";
680 else if(v
== QLatin1String("OBJECTS"))
682 QStringList
&list
= project
->values(v
);
683 if(!list
.contains(out
))
686 } else if(project
->values((*it
) + ".CONFIG").indexOf("no_link") == -1) {
688 QStringList
&list
= project
->values("OBJECTS");
689 if(!list
.contains(out
))
692 QStringList
&list
= project
->values("UNUSED_SOURCES");
693 if(!list
.contains(out
))
697 QStringList
&list
= project
->variables()["PRE_TARGETDEPS"];
698 if(!list
.contains(out
))
706 //handle dependencies
707 depHeuristicsCache
.clear();
710 QStringList incDirs
= v
["DEPENDPATH"] + v
["QMAKE_ABSOLUTE_SOURCE_PATH"];
711 if(project
->isActiveConfig("depend_includepath"))
712 incDirs
+= v
["INCLUDEPATH"];
713 if(!project
->isActiveConfig("no_include_pwd")) {
714 QString pwd
= qmake_getpwd();
719 QList
<QMakeLocalFileName
> deplist
;
720 for(QStringList::Iterator it
= incDirs
.begin(); it
!= incDirs
.end(); ++it
)
721 deplist
.append(QMakeLocalFileName(unescapeFilePath((*it
))));
722 QMakeSourceFileInfo::setDependencyPaths(deplist
);
723 debug_msg(1, "Dependency Directories: %s", incDirs
.join(" :: ").toLatin1().constData());
725 if(project
->isActiveConfig("qmake_cache")) {
727 if(!project
->isEmpty("QMAKE_INTERNAL_CACHE_FILE")) {
728 cache_file
= QDir::fromNativeSeparators(project
->first("QMAKE_INTERNAL_CACHE_FILE"));
730 cache_file
= ".qmake.internal.cache";
731 if(project
->isActiveConfig("build_pass"))
732 cache_file
+= ".BUILD." + project
->first("BUILD_PASS");
734 if(cache_file
.indexOf('/') == -1)
735 cache_file
.prepend(Option::output_dir
+ '/');
736 QMakeSourceFileInfo::setCacheFile(cache_file
);
739 //add to dependency engine
740 for(x
= 0; x
< compilers
.count(); ++x
) {
741 const MakefileGenerator::Compiler
&comp
= compilers
.at(x
);
742 if(!(comp
.flags
& Compiler::CompilerNoCheckDeps
))
743 addSourceFiles(v
[comp
.variable_in
], QMakeSourceFileInfo::SEEK_DEPS
,
744 (QMakeSourceFileInfo::SourceFileType
)comp
.type
);
748 processSources(); //remove anything in SOURCES which is included (thus it need not be linked in)
750 //all sources and generated sources must be turned into objects at some point (the one builtin compiler)
751 v
["OBJECTS"] += createObjectList(v
["SOURCES"]) + createObjectList(v
["GENERATED_SOURCES"]);
754 if(!project
->isEmpty("TRANSLATIONS")) {
755 QStringList
&trf
= project
->values("TRANSLATIONS");
756 for(QStringList::Iterator it
= trf
.begin(); it
!= trf
.end(); ++it
)
757 (*it
) = Option::fixPathToLocalOS((*it
));
760 { //get the output_dir into the pwd
761 if(fileFixify(Option::output_dir
) != fileFixify(qmake_getpwd()))
762 project
->values("INCLUDEPATH").append(fileFixify(Option::output_dir
,
764 Option::output_dir
));
767 //fix up the target deps
768 QString fixpaths
[] = { QString("PRE_TARGETDEPS"), QString("POST_TARGETDEPS"), QString() };
769 for(int path
= 0; !fixpaths
[path
].isNull(); path
++) {
770 QStringList
&l
= v
[fixpaths
[path
]];
771 for(QStringList::Iterator val_it
= l
.begin(); val_it
!= l
.end(); ++val_it
) {
772 if(!(*val_it
).isEmpty())
773 (*val_it
) = escapeDependencyPath(Option::fixPathToTargetOS((*val_it
), false, false));
778 if(!project
->isEmpty("DEPENDS")) {
779 QStringList
&l
= v
["DEPENDS"];
780 for(QStringList::Iterator it
= l
.begin(); it
!= l
.end(); ++it
) {
781 QStringList files
= v
[(*it
) + ".file"] + v
[(*it
) + ".files"]; //why do I support such evil things?
782 for(QStringList::Iterator file_it
= files
.begin(); file_it
!= files
.end(); ++file_it
) {
783 QStringList
&out_deps
= findDependencies(*file_it
);
784 QStringList
&in_deps
= v
[(*it
) + ".depends"]; //even more evilness..
785 for(QStringList::Iterator dep_it
= in_deps
.begin(); dep_it
!= in_deps
.end(); ++dep_it
) {
786 if(exists(*dep_it
)) {
787 out_deps
.append(*dep_it
);
789 QString dir
, regex
= Option::fixPathToLocalOS((*dep_it
));
790 if(regex
.lastIndexOf(Option::dir_sep
) != -1) {
791 dir
= regex
.left(regex
.lastIndexOf(Option::dir_sep
) + 1);
792 regex
.remove(0, dir
.length());
794 QStringList files
= QDir(dir
).entryList(QStringList(regex
));
795 if(files
.isEmpty()) {
796 warn_msg(WarnLogic
, "Dependency for [%s]: Not found %s", (*file_it
).toLatin1().constData(),
797 (*dep_it
).toLatin1().constData());
799 for(int i
= 0; i
< files
.count(); i
++)
800 out_deps
.append(dir
+ files
[i
]);
808 // escape qmake command
809 if (!project
->isEmpty("QMAKE_QMAKE")) {
810 project
->values("QMAKE_QMAKE") = escapeFilePaths(project
->values("QMAKE_QMAKE"));
815 MakefileGenerator::processPrlFile(QString
&file
)
817 bool ret
= false, try_replace_file
=false;
818 QString meta_file
, orig_file
= file
;
819 if(QMakeMetaInfo::libExists(file
)) {
820 try_replace_file
= true;
825 int ext
= tmp
.lastIndexOf('.');
830 // meta_file = fileFixify(meta_file);
831 QString real_meta_file
= Option::fixPathToLocalOS(meta_file
);
832 if(!meta_file
.isEmpty()) {
833 QString f
= fileFixify(real_meta_file
, qmake_getpwd(), Option::output_dir
);
834 if(QMakeMetaInfo::libExists(f
)) {
835 QMakeMetaInfo libinfo
;
836 debug_msg(1, "Processing PRL file: %s", real_meta_file
.toLatin1().constData());
837 if(!libinfo
.readLib(f
)) {
838 fprintf(stderr
, "Error processing meta file: %s\n", real_meta_file
.toLatin1().constData());
839 } else if(project
->isActiveConfig("no_read_prl_" + libinfo
.type().toLower())) {
840 debug_msg(2, "Ignored meta file %s [%s]", real_meta_file
.toLatin1().constData(), libinfo
.type().toLatin1().constData());
843 QMap
<QString
, QStringList
> &vars
= libinfo
.variables();
844 for(QMap
<QString
, QStringList
>::Iterator it
= vars
.begin(); it
!= vars
.end(); ++it
)
845 processPrlVariable(it
.key(), it
.value());
846 if(try_replace_file
&& !libinfo
.isEmpty("QMAKE_PRL_TARGET")) {
848 int slsh
= real_meta_file
.lastIndexOf(Option::dir_sep
);
850 dir
= real_meta_file
.left(slsh
+1);
851 file
= libinfo
.first("QMAKE_PRL_TARGET");
852 if(QDir::isRelativePath(file
))
858 QString mf
= QMakeMetaInfo::findLib(meta_file
);
859 if(project
->values("QMAKE_PRL_INTERNAL_FILES").indexOf(mf
) == -1)
860 project
->values("QMAKE_PRL_INTERNAL_FILES").append(mf
);
861 if(project
->values("QMAKE_INTERNAL_INCLUDED_FILES").indexOf(mf
) == -1)
862 project
->values("QMAKE_INTERNAL_INCLUDED_FILES").append(mf
);
865 if(try_replace_file
&& file
.isEmpty()) {
867 warn_msg(WarnLogic
, "Found prl [%s] file with no target [%s]!", meta_file
.toLatin1().constData(),
868 orig_file
.toLatin1().constData());
876 MakefileGenerator::filterIncludedFiles(const QString
&var
)
878 QStringList
&inputs
= project
->values(var
);
879 for(QStringList::Iterator input
= inputs
.begin(); input
!= inputs
.end(); ) {
880 if(QMakeSourceFileInfo::included((*input
)) > 0)
881 input
= inputs
.erase(input
);
888 MakefileGenerator::processPrlVariable(const QString
&var
, const QStringList
&l
)
890 if(var
== "QMAKE_PRL_LIBS") {
891 QString where
= "QMAKE_LIBS";
892 if(!project
->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
893 where
= project
->first("QMAKE_INTERNAL_PRL_LIBS");
894 QStringList
&out
= project
->values(where
);
895 for(QStringList::ConstIterator it
= l
.begin(); it
!= l
.end(); ++it
) {
896 if(out
.indexOf((*it
)) == -1)
899 } else if(var
== "QMAKE_PRL_DEFINES") {
900 QStringList
&out
= project
->values("DEFINES");
901 for(QStringList::ConstIterator it
= l
.begin(); it
!= l
.end(); ++it
) {
902 if(out
.indexOf((*it
)) == -1 &&
903 project
->values("PRL_EXPORT_DEFINES").indexOf((*it
)) == -1)
910 MakefileGenerator::processPrlFiles()
912 QHash
<QString
, bool> processed
;
913 for(bool ret
= false; true; ret
= false) {
914 //read in any prl files included..
916 QString where
= "QMAKE_LIBS";
917 if(!project
->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
918 where
= project
->first("QMAKE_INTERNAL_PRL_LIBS");
919 QStringList
&l
= project
->values(where
);
920 for(QStringList::Iterator it
= l
.begin(); it
!= l
.end(); ++it
) {
921 QString file
= (*it
);
922 if(!processed
.contains(file
) && processPrlFile(file
)) {
923 processed
.insert(file
, true);
937 MakefileGenerator::writePrlFile(QTextStream
&t
)
939 QString target
= project
->first("TARGET");
940 int slsh
= target
.lastIndexOf(Option::dir_sep
);
942 target
.remove(0, slsh
+ 1);
943 QString bdir
= Option::output_dir
;
945 bdir
= qmake_getpwd();
946 t
<< "QMAKE_PRL_BUILD_DIR = " << bdir
<< endl
;
948 if(!project
->projectFile().isEmpty() && project
->projectFile() != "-")
949 t
<< "QMAKE_PRO_INPUT = " << project
->projectFile().section('/', -1) << endl
;
951 if(!project
->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
952 t
<< "QMAKE_PRL_SOURCE_DIR = " << project
->first("QMAKE_ABSOLUTE_SOURCE_PATH") << endl
;
953 t
<< "QMAKE_PRL_TARGET = " << target
<< endl
;
954 if(!project
->isEmpty("PRL_EXPORT_DEFINES"))
955 t
<< "QMAKE_PRL_DEFINES = " << project
->values("PRL_EXPORT_DEFINES").join(" ") << endl
;
956 if(!project
->isEmpty("PRL_EXPORT_CFLAGS"))
957 t
<< "QMAKE_PRL_CFLAGS = " << project
->values("PRL_EXPORT_CFLAGS").join(" ") << endl
;
958 if(!project
->isEmpty("PRL_EXPORT_CXXFLAGS"))
959 t
<< "QMAKE_PRL_CXXFLAGS = " << project
->values("PRL_EXPORT_CXXFLAGS").join(" ") << endl
;
960 if(!project
->isEmpty("CONFIG"))
961 t
<< "QMAKE_PRL_CONFIG = " << project
->values("CONFIG").join(" ") << endl
;
962 if(!project
->isEmpty("TARGET_VERSION_EXT"))
963 t
<< "QMAKE_PRL_VERSION = " << project
->first("TARGET_VERSION_EXT") << endl
;
964 else if(!project
->isEmpty("VERSION"))
965 t
<< "QMAKE_PRL_VERSION = " << project
->first("VERSION") << endl
;
966 if(project
->isActiveConfig("staticlib") || project
->isActiveConfig("explicitlib")) {
968 if(!project
->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
969 libs
= project
->values("QMAKE_INTERNAL_PRL_LIBS");
971 libs
<< "QMAKE_LIBS"; //obvious one
972 if(project
->isActiveConfig("staticlib"))
973 libs
<< "QMAKE_LIBS_PRIVATE";
974 t
<< "QMAKE_PRL_LIBS = ";
975 for(QStringList::Iterator it
= libs
.begin(); it
!= libs
.end(); ++it
)
976 t
<< project
->values((*it
)).join(" ") << " ";
982 MakefileGenerator::writeProjectMakefile()
985 QTextStream
t(&Option::output
);
990 QList
<SubTarget
*> targets
;
992 QStringList builds
= project
->values("BUILDS");
993 for(QStringList::Iterator it
= builds
.begin(); it
!= builds
.end(); ++it
) {
994 SubTarget
*st
= new SubTarget
;
996 st
->makefile
= "$(MAKEFILE)." + (*it
);
998 st
->target
= project
->isEmpty((*it
) + ".target") ? (*it
) : project
->first((*it
) + ".target");
1001 if(project
->isActiveConfig("build_all")) {
1002 t
<< "first: all" << endl
;
1003 QList
<SubTarget
*>::Iterator it
;
1007 for(it
= targets
.begin(); it
!= targets
.end(); ++it
)
1008 t
<< (*it
)->target
<< "-install ";
1013 for(it
= targets
.begin(); it
!= targets
.end(); ++it
)
1014 t
<< (*it
)->target
<< "-uninstall ";
1017 t
<< "first: " << targets
.first()->target
<< endl
1018 << "install: " << targets
.first()->target
<< "-install" << endl
1019 << "uninstall: " << targets
.first()->target
<< "-uninstall" << endl
;
1022 writeSubTargets(t
, targets
, SubTargetsNoFlags
);
1023 if(!project
->isActiveConfig("no_autoqmake")) {
1024 for(QList
<SubTarget
*>::Iterator it
= targets
.begin(); it
!= targets
.end(); ++it
)
1025 t
<< (*it
)->makefile
<< ": " <<
1026 Option::fixPathToTargetOS(fileFixify(Option::output
.fileName())) << endl
;
1028 qDeleteAll(targets
);
1033 MakefileGenerator::write()
1038 if(Option::qmake_mode
== Option::QMAKE_GENERATE_MAKEFILE
|| //write makefile
1039 Option::qmake_mode
== Option::QMAKE_GENERATE_PROJECT
) {
1040 QTextStream
t(&Option::output
);
1041 if(!writeMakefile(t
)) {
1043 warn_msg(WarnLogic
, "Unable to generate output for: %s [TEMPLATE %s]",
1044 Option::output
.fileName().toLatin1().constData(),
1045 project
->first("TEMPLATE").toLatin1().constData());
1046 if(Option::output
.exists())
1047 Option::output
.remove();
1055 MakefileGenerator::prlFileName(bool fixify
)
1057 QString ret
= project
->first("TARGET_PRL");;
1059 ret
= project
->first("TARGET");
1060 int slsh
= ret
.lastIndexOf(Option::dir_sep
);
1062 ret
.remove(0, slsh
);
1063 if(!ret
.endsWith(Option::prl_ext
)) {
1064 int dot
= ret
.indexOf('.');
1067 ret
+= Option::prl_ext
;
1069 if(!project
->isEmpty("QMAKE_BUNDLE"))
1070 ret
.prepend(project
->first("QMAKE_BUNDLE") + Option::dir_sep
);
1072 if(!project
->isEmpty("DESTDIR"))
1073 ret
.prepend(project
->first("DESTDIR"));
1074 ret
= Option::fixPathToLocalOS(fileFixify(ret
, qmake_getpwd(), Option::output_dir
));
1080 MakefileGenerator::writePrlFile()
1082 if((Option::qmake_mode
== Option::QMAKE_GENERATE_MAKEFILE
||
1083 Option::qmake_mode
== Option::QMAKE_GENERATE_PRL
)
1084 && project
->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()
1085 && project
->isActiveConfig("create_prl")
1086 && (project
->first("TEMPLATE") == "lib"
1087 || project
->first("TEMPLATE") == "vclib")
1088 && !project
->isActiveConfig("plugin")) { //write prl file
1089 QString local_prl
= prlFileName();
1090 QString prl
= fileFixify(local_prl
);
1091 mkdir(fileInfo(local_prl
).path());
1092 QFile
ft(local_prl
);
1093 if(ft
.open(QIODevice::WriteOnly
)) {
1094 project
->values("ALL_DEPS").append(prl
);
1095 project
->values("QMAKE_INTERNAL_PRL_FILE").append(prl
);
1102 // Manipulate directories, so it's possible to build
1103 // several cross-platform targets concurrently
1105 MakefileGenerator::usePlatformDir()
1107 QString
pltDir(project
->first("QMAKE_PLATFORM_DIR"));
1108 if(pltDir
.isEmpty())
1110 QChar sep
= QDir::separator();
1111 QString slashPltDir
= sep
+ pltDir
;
1113 QString dirs
[] = { QString("OBJECTS_DIR"), QString("DESTDIR"), QString("QMAKE_PKGCONFIG_DESTDIR"),
1114 QString("SUBLIBS_DIR"), QString("DLLDESTDIR"), QString("QMAKE_LIBTOOL_DESTDIR"),
1115 QString("PRECOMPILED_DIR"), QString("QMAKE_LIBDIR_QT"), QString() };
1116 for(int i
= 0; !dirs
[i
].isEmpty(); ++i
) {
1117 QString filePath
= project
->first(dirs
[i
]);
1118 project
->values(dirs
[i
]) = QStringList(filePath
+ (filePath
.isEmpty() ? pltDir
: slashPltDir
));
1121 QString libs
[] = { QString("QMAKE_LIBS_QT"), QString("QMAKE_LIBS_QT_THREAD"), QString("QMAKE_LIBS_QT_ENTRY"), QString() };
1122 for(int i
= 0; !libs
[i
].isEmpty(); ++i
) {
1123 QString filePath
= project
->first(libs
[i
]);
1124 int fpi
= filePath
.lastIndexOf(sep
);
1126 project
->values(libs
[i
]).prepend(pltDir
+ sep
);
1128 project
->values(libs
[i
]) = QStringList(filePath
.left(fpi
) + slashPltDir
+ filePath
.mid(fpi
));
1133 MakefileGenerator::writeObj(QTextStream
&t
, const QString
&src
)
1135 QStringList
&srcl
= project
->values(src
);
1136 QStringList objl
= createObjectList(srcl
);
1138 QStringList::Iterator oit
= objl
.begin();
1139 QStringList::Iterator sit
= srcl
.begin();
1140 QString
stringSrc("$src");
1141 QString
stringObj("$obj");
1142 for(;sit
!= srcl
.end() && oit
!= objl
.end(); ++oit
, ++sit
) {
1143 if((*sit
).isEmpty())
1146 t
<< escapeDependencyPath((*oit
)) << ": " << escapeDependencyPath((*sit
)) << " " << escapeDependencyPaths(findDependencies((*sit
))).join(" \\\n\t\t");
1149 for(QStringList::Iterator cppit
= Option::cpp_ext
.begin(); cppit
!= Option::cpp_ext
.end(); ++cppit
) {
1150 if((*sit
).endsWith((*cppit
))) {
1151 comp
= "QMAKE_RUN_CXX";
1152 cimp
= "QMAKE_RUN_CXX_IMP";
1156 if(comp
.isEmpty()) {
1157 comp
= "QMAKE_RUN_CC";
1158 cimp
= "QMAKE_RUN_CC_IMP";
1160 bool use_implicit_rule
= !project
->isEmpty(cimp
);
1161 use_implicit_rule
= false;
1162 if(use_implicit_rule
) {
1163 if(!project
->isEmpty("OBJECTS_DIR")) {
1164 use_implicit_rule
= false;
1166 int dot
= (*sit
).lastIndexOf('.');
1167 if(dot
== -1 || ((*sit
).left(dot
) + Option::obj_ext
!= (*oit
)))
1168 use_implicit_rule
= false;
1171 if (!use_implicit_rule
&& !project
->isEmpty(comp
)) {
1172 QString p
= var(comp
), srcf(*sit
);
1173 p
.replace(stringSrc
, escapeFilePath(srcf
));
1174 p
.replace(stringObj
, escapeFilePath((*oit
)));
1182 MakefileGenerator::filePrefixRoot(const QString
&root
, const QString
&path
)
1184 QString
ret(root
+ path
);
1185 if(path
.length() > 2 && path
[1] == ':') //c:\foo
1186 ret
= QString(path
.mid(0, 2) + root
+ path
.mid(2));
1187 while(ret
.endsWith("\\"))
1188 ret
= ret
.left(ret
.length()-1);
1193 MakefileGenerator::writeInstalls(QTextStream
&t
, const QString
&installs
, bool noBuild
)
1195 QString
rm_dir_contents("-$(DEL_FILE)");
1196 if (!isWindowsShell()) //ick
1197 rm_dir_contents
= "-$(DEL_FILE) -r";
1199 QString all_installs
, all_uninstalls
;
1200 QStringList
&l
= project
->values(installs
);
1201 for(QStringList::Iterator it
= l
.begin(); it
!= l
.end(); ++it
) {
1202 QString pvar
= (*it
) + ".path";
1203 if(project
->values((*it
) + ".CONFIG").indexOf("no_path") == -1 &&
1204 project
->values((*it
) + ".CONFIG").indexOf("dummy_install") == -1 &&
1205 project
->values(pvar
).isEmpty()) {
1206 warn_msg(WarnLogic
, "%s is not defined: install target not created\n", pvar
.toLatin1().constData());
1210 bool do_default
= true;
1211 const QString root
= "$(INSTALL_ROOT)";
1212 QString target
, dst
;
1213 if(project
->values((*it
) + ".CONFIG").indexOf("no_path") == -1 &&
1214 project
->values((*it
) + ".CONFIG").indexOf("dummy_install") == -1) {
1215 dst
= fileFixify(unescapeFilePath(project
->values(pvar
).first()), FileFixifyAbsolute
, false);
1216 if(!dst
.endsWith(Option::dir_sep
))
1217 dst
+= Option::dir_sep
;
1219 dst
= escapeFilePath(dst
);
1221 QStringList tmp
, uninst
= project
->values((*it
) + ".uninstall");
1223 tmp
= project
->values((*it
) + ".extra");
1225 tmp
= project
->values((*it
) + ".commands"); //to allow compatible name
1226 if(!tmp
.isEmpty()) {
1228 if(!target
.isEmpty())
1230 target
+= tmp
.join(" ");
1233 tmp
= findFilesInVPATH(project
->values((*it
) + ".files"), VPATH_NoFixify
);
1234 tmp
= fileFixify(tmp
, FileFixifyAbsolute
);
1235 if(!tmp
.isEmpty()) {
1236 if(!target
.isEmpty())
1239 for(QStringList::Iterator wild_it
= tmp
.begin(); wild_it
!= tmp
.end(); ++wild_it
) {
1240 QString wild
= Option::fixPathToLocalOS((*wild_it
), false, false);
1241 QString dirstr
= qmake_getpwd(), filestr
= wild
;
1242 int slsh
= filestr
.lastIndexOf(Option::dir_sep
);
1244 dirstr
= filestr
.left(slsh
+1);
1245 filestr
.remove(0, slsh
+1);
1247 if(!dirstr
.endsWith(Option::dir_sep
))
1248 dirstr
+= Option::dir_sep
;
1249 if(exists(wild
)) { //real file
1250 QString file
= wild
;
1251 QFileInfo
fi(fileInfo(wild
));
1252 if(!target
.isEmpty())
1254 QString dst_file
= filePrefixRoot(root
, dst
);
1255 if(fi
.isDir() && project
->isActiveConfig("copy_dir_files")) {
1256 if(!dst_file
.endsWith(Option::dir_sep
))
1257 dst_file
+= Option::dir_sep
;
1258 dst_file
+= fi
.fileName();
1262 cmd
= "-$(INSTALL_DIR)";
1263 else if (fi
.isExecutable())
1264 cmd
= "-$(INSTALL_PROGRAM)";
1266 cmd
= "-$(INSTALL_FILE)";
1267 cmd
+= " " + escapeFilePath(wild
) + " " + dst_file
+ "\n";
1269 if(!project
->isActiveConfig("debug") && !project
->isActiveConfig("nostrip") &&
1270 !fi
.isDir() && fi
.isExecutable() && !project
->isEmpty("QMAKE_STRIP"))
1271 target
+= QString("\t-") + var("QMAKE_STRIP") + " " +
1272 filePrefixRoot(root
, fileFixify(dst
+ filestr
, FileFixifyAbsolute
, false)) + "\n";
1273 if(!uninst
.isEmpty())
1274 uninst
.append("\n\t");
1275 uninst
.append(rm_dir_contents
+ " " + filePrefixRoot(root
, fileFixify(dst
+ filestr
, FileFixifyAbsolute
, false)));
1278 QString local_dirstr
= Option::fixPathToLocalOS(dirstr
, true);
1279 QStringList files
= QDir(local_dirstr
).entryList(QStringList(filestr
));
1280 if(project
->values((*it
) + ".CONFIG").indexOf("no_check_exist") != -1 && files
.isEmpty()) {
1281 if(!target
.isEmpty())
1283 QString dst_file
= filePrefixRoot(root
, dst
);
1284 QFileInfo
fi(fileInfo(wild
));
1285 QString cmd
= QString(fi
.isExecutable() ? "-$(INSTALL_PROGRAM)" : "-$(INSTALL_FILE)") + " " +
1286 wild
+ " " + dst_file
+ "\n";
1288 if(!uninst
.isEmpty())
1289 uninst
.append("\n\t");
1290 uninst
.append(rm_dir_contents
+ " " + filePrefixRoot(root
, fileFixify(dst
+ filestr
, FileFixifyAbsolute
, false)));
1292 for(int x
= 0; x
< files
.count(); x
++) {
1293 QString file
= files
[x
];
1294 if(file
== "." || file
== "..") //blah
1296 if(!uninst
.isEmpty())
1297 uninst
.append("\n\t");
1298 uninst
.append(rm_dir_contents
+ " " + filePrefixRoot(root
, fileFixify(dst
+ file
, FileFixifyAbsolute
, false)));
1299 QFileInfo
fi(fileInfo(dirstr
+ file
));
1300 if(!target
.isEmpty())
1302 QString dst_file
= filePrefixRoot(root
, fileFixify(dst
, FileFixifyAbsolute
, false));
1303 if(fi
.isDir() && project
->isActiveConfig("copy_dir_files")) {
1304 if(!dst_file
.endsWith(Option::dir_sep
))
1305 dst_file
+= Option::dir_sep
;
1306 dst_file
+= fi
.fileName();
1308 QString cmd
= QString(fi
.isDir() ? "-$(INSTALL_DIR)" : "-$(INSTALL_FILE)") + " " +
1309 dirstr
+ file
+ " " + dst_file
+ "\n";
1311 if(!project
->isActiveConfig("debug") && !project
->isActiveConfig("nostrip") &&
1312 !fi
.isDir() && fi
.isExecutable() && !project
->isEmpty("QMAKE_STRIP"))
1313 target
+= QString("\t-") + var("QMAKE_STRIP") + " " +
1314 filePrefixRoot(root
, fileFixify(dst
+ file
, FileFixifyAbsolute
, false)) +
1321 target
= defaultInstall((*it
));
1322 uninst
= project
->values((*it
) + ".uninstall");
1325 if(!target
.isEmpty() || project
->values((*it
) + ".CONFIG").indexOf("dummy_install") != -1) {
1326 if(noBuild
|| project
->values((*it
) + ".CONFIG").indexOf("no_build") != -1)
1327 t
<< "install_" << (*it
) << ":";
1328 else if(project
->isActiveConfig("build_all"))
1329 t
<< "install_" << (*it
) << ": all";
1331 t
<< "install_" << (*it
) << ": first";
1332 const QStringList
&deps
= project
->values((*it
) + ".depends");
1333 if(!deps
.isEmpty()) {
1334 for(QStringList::ConstIterator dep_it
= deps
.begin(); dep_it
!= deps
.end(); ++dep_it
) {
1335 QString targ
= var((*dep_it
) + ".target");
1338 t
<< " " << escapeDependencyPath(targ
);
1341 if(project
->isEmpty("QMAKE_NOFORCE"))
1344 const QStringList
&dirs
= project
->values(pvar
);
1345 for(QStringList::ConstIterator pit
= dirs
.begin(); pit
!= dirs
.end(); ++pit
) {
1346 QString tmp_dst
= fileFixify((*pit
), FileFixifyAbsolute
, false);
1347 if (!isWindowsShell() && !tmp_dst
.endsWith(Option::dir_sep
))
1348 tmp_dst
+= Option::dir_sep
;
1349 t
<< mkdir_p_asstring(filePrefixRoot(root
, tmp_dst
)) << "\n\t";
1351 t
<< target
<< endl
<< endl
;
1352 if(!uninst
.isEmpty()) {
1353 t
<< "uninstall_" << (*it
) << ": ";
1354 if(project
->isEmpty("QMAKE_NOFORCE"))
1357 << uninst
.join(" ") << "\n\t"
1358 << "-$(DEL_DIR) " << filePrefixRoot(root
, dst
) << " " << endl
<< endl
;
1362 if(project
->values((*it
) + ".CONFIG").indexOf("no_default_install") == -1) {
1363 all_installs
+= QString("install_") + (*it
) + " ";
1364 if(!uninst
.isEmpty())
1365 all_uninstalls
+= "uninstall_" + (*it
) + " ";
1368 debug_msg(1, "no definition for install %s: install target not created",(*it
).toLatin1().constData());
1371 t
<< "install: " << var("INSTALLDEPS") << " " << all_installs
;
1372 if(project
->isEmpty("QMAKE_NOFORCE"))
1375 t
<< "uninstall: " << all_uninstalls
<< " " << var("UNINSTALLDEPS");
1376 if(project
->isEmpty("QMAKE_NOFORCE"))
1382 MakefileGenerator::var(const QString
&var
)
1384 return val(project
->values(var
));
1388 MakefileGenerator::val(const QStringList
&varList
)
1390 return valGlue(varList
, "", " ", "");
1394 MakefileGenerator::varGlue(const QString
&var
, const QString
&before
, const QString
&glue
, const QString
&after
)
1396 return valGlue(project
->values(var
), before
, glue
, after
);
1400 MakefileGenerator::valGlue(const QStringList
&varList
, const QString
&before
, const QString
&glue
, const QString
&after
)
1403 for(QStringList::ConstIterator it
= varList
.begin(); it
!= varList
.end(); ++it
) {
1404 if(!(*it
).isEmpty()) {
1410 return ret
.isEmpty() ? QString("") : before
+ ret
+ after
;
1415 MakefileGenerator::varList(const QString
&var
)
1417 return valList(project
->values(var
));
1421 MakefileGenerator::valList(const QStringList
&varList
)
1423 return valGlue(varList
, "", " \\\n\t\t", "");
1427 MakefileGenerator::createObjectList(const QStringList
&sources
)
1431 if(!project
->values("OBJECTS_DIR").isEmpty())
1432 objdir
= project
->first("OBJECTS_DIR");
1433 for(QStringList::ConstIterator it
= sources
.begin(); it
!= sources
.end(); ++it
) {
1434 QFileInfo
fi(fileInfo(Option::fixPathToLocalOS((*it
))));
1436 if(objdir
.isEmpty() && project
->isActiveConfig("object_with_source")) {
1437 QString fName
= Option::fixPathToTargetOS((*it
), false);
1438 int dl
= fName
.lastIndexOf(Option::dir_sep
);
1440 dir
= fName
.left(dl
+ 1);
1444 ret
.append(dir
+ fi
.completeBaseName() + Option::obj_ext
);
1449 ReplaceExtraCompilerCacheKey::ReplaceExtraCompilerCacheKey(const QString
&v
, const QStringList
&i
, const QStringList
&o
)
1452 pwd
= qmake_getpwd();
1462 out
= ol
.join("::");
1466 bool ReplaceExtraCompilerCacheKey::operator==(const ReplaceExtraCompilerCacheKey
&f
) const
1468 return (hashCode() == f
.hashCode() &&
1477 MakefileGenerator::replaceExtraCompilerVariables(const QString
&orig_var
, const QStringList
&in
, const QStringList
&out
)
1480 ReplaceExtraCompilerCacheKey
cacheKey(orig_var
, in
, out
);
1481 QString cacheVal
= extraCompilerVariablesCache
.value(cacheKey
);
1482 if(!cacheVal
.isNull())
1486 QString ret
= orig_var
;
1487 QRegExp
reg_var("\\$\\{.*\\}");
1488 reg_var
.setMinimal(true);
1489 for(int rep
= 0; (rep
= reg_var
.indexIn(ret
, rep
)) != -1; ) {
1491 const QString var
= ret
.mid(rep
+ 2, reg_var
.matchedLength() - 3);
1492 bool filePath
= false;
1493 if(val
.isEmpty() && var
.startsWith(QLatin1String("QMAKE_VAR_"))) {
1494 const QString varname
= var
.mid(10);
1495 val
+= project
->values(varname
);
1497 if(val
.isEmpty() && var
.startsWith(QLatin1String("QMAKE_VAR_FIRST_"))) {
1498 const QString varname
= var
.mid(16);
1499 val
+= project
->first(varname
);
1502 if(val
.isEmpty() && !in
.isEmpty()) {
1503 if(var
.startsWith(QLatin1String("QMAKE_FUNC_FILE_IN_"))) {
1505 const QString funcname
= var
.mid(19);
1506 val
+= project
->expand(funcname
, QList
<QStringList
>() << in
);
1507 } else if(var
== QLatin1String("QMAKE_FILE_BASE") || var
== QLatin1String("QMAKE_FILE_IN_BASE")) {
1509 for(int i
= 0; i
< in
.size(); ++i
) {
1510 QFileInfo
fi(fileInfo(Option::fixPathToLocalOS(in
.at(i
))));
1511 QString base
= fi
.completeBaseName();
1513 base
= fi
.fileName();
1516 } else if(var
== QLatin1String("QMAKE_FILE_PATH") || var
== QLatin1String("QMAKE_FILE_IN_PATH")) {
1518 for(int i
= 0; i
< in
.size(); ++i
)
1519 val
+= fileInfo(Option::fixPathToLocalOS(in
.at(i
))).path();
1520 } else if(var
== QLatin1String("QMAKE_FILE_NAME") || var
== QLatin1String("QMAKE_FILE_IN")) {
1522 for(int i
= 0; i
< in
.size(); ++i
)
1523 val
+= fileInfo(Option::fixPathToLocalOS(in
.at(i
))).filePath();
1527 if(val
.isEmpty() && !out
.isEmpty()) {
1528 if(var
.startsWith(QLatin1String("QMAKE_FUNC_FILE_OUT_"))) {
1530 const QString funcname
= var
.mid(20);
1531 val
+= project
->expand(funcname
, QList
<QStringList
>() << out
);
1532 } else if(var
== QLatin1String("QMAKE_FILE_OUT")) {
1534 for(int i
= 0; i
< out
.size(); ++i
)
1535 val
+= fileInfo(Option::fixPathToLocalOS(out
.at(i
))).filePath();
1536 } else if(var
== QLatin1String("QMAKE_FILE_OUT_BASE")) {
1538 for(int i
= 0; i
< out
.size(); ++i
) {
1539 QFileInfo
fi(fileInfo(Option::fixPathToLocalOS(out
.at(i
))));
1540 QString base
= fi
.completeBaseName();
1542 base
= fi
.fileName();
1547 if(val
.isEmpty() && var
.startsWith(QLatin1String("QMAKE_FUNC_"))) {
1548 const QString funcname
= var
.mid(11);
1549 val
+= project
->expand(funcname
, QList
<QStringList
>() << in
<< out
);
1552 if(!val
.isEmpty()) {
1555 for(int i
= 0; i
< val
.size(); ++i
) {
1556 const QString file
= Option::fixPathToTargetOS(unescapeFilePath(val
.at(i
)), false);
1557 if(!fullVal
.isEmpty())
1559 fullVal
+= escapeFilePath(file
);
1562 fullVal
= val
.join(" ");
1564 ret
.replace(rep
, reg_var
.matchedLength(), fullVal
);
1565 rep
+= fullVal
.length();
1567 rep
+= reg_var
.matchedLength();
1572 extraCompilerVariablesCache
.insert(cacheKey
, ret
);
1577 MakefileGenerator::verifyExtraCompiler(const QString
&comp
, const QString
&file_unfixed
)
1581 const QString file
= Option::fixPathToLocalOS(file_unfixed
);
1583 if(project
->values(comp
+ ".CONFIG").indexOf("moc_verify") != -1) {
1584 if(!file
.isNull()) {
1585 QMakeSourceFileInfo::addSourceFile(file
, QMakeSourceFileInfo::SEEK_MOCS
);
1586 if(!mocable(file
)) {
1589 project
->values("MOCABLES").append(file
);
1592 } else if(project
->values(comp
+ ".CONFIG").indexOf("function_verify") != -1) {
1593 QString tmp_out
= project
->values(comp
+ ".output").first();
1594 if(tmp_out
.isEmpty())
1596 QStringList verify_function
= project
->values(comp
+ ".verify_function");
1597 if(verify_function
.isEmpty())
1600 for(int i
= 0; i
< verify_function
.size(); ++i
) {
1601 bool invert
= false;
1602 QString verify
= verify_function
.at(i
);
1603 if(verify
.at(0) == QLatin1Char('!')) {
1605 verify
= verify
.mid(1);
1608 if(project
->values(comp
+ ".CONFIG").indexOf("combine") != -1) {
1609 bool pass
= project
->test(verify
, QList
<QStringList
>() << QStringList(tmp_out
) << QStringList(file
));
1615 QStringList
&tmp
= project
->values(comp
+ ".input");
1616 for(QStringList::Iterator it
= tmp
.begin(); it
!= tmp
.end(); ++it
) {
1617 QStringList
&inputs
= project
->values((*it
));
1618 for(QStringList::Iterator input
= inputs
.begin(); input
!= inputs
.end(); ++input
) {
1619 if((*input
).isEmpty())
1621 QString in
= fileFixify(Option::fixPathToTargetOS((*input
), false));
1623 bool pass
= project
->test(verify
,
1624 QList
<QStringList
>() << QStringList(replaceExtraCompilerVariables(tmp_out
, (*input
), QString())) <<
1636 } else if(project
->values(comp
+ ".CONFIG").indexOf("verify") != -1) {
1637 QString tmp_out
= project
->values(comp
+ ".output").first();
1638 if(tmp_out
.isEmpty())
1641 if(!project
->isEmpty(comp
+ ".commands")) {
1643 QStringList cmdline
= project
->values(comp
+ ".commands");
1644 for(int i
= 0; i
< cmdline
.count(); ++i
) {
1645 if(!cmdline
.at(i
).contains('=')) {
1651 cmdline
[argv0
] = Option::fixPathToTargetOS(cmdline
.at(argv0
), false);
1652 tmp_cmd
= cmdline
.join(" ");
1656 if(project
->values(comp
+ ".CONFIG").indexOf("combine") != -1) {
1657 QString cmd
= replaceExtraCompilerVariables(tmp_cmd
, QString(), tmp_out
);
1658 if(system(cmd
.toLatin1().constData()))
1661 QStringList
&tmp
= project
->values(comp
+ ".input");
1662 for(QStringList::Iterator it
= tmp
.begin(); it
!= tmp
.end(); ++it
) {
1663 QStringList
&inputs
= project
->values((*it
));
1664 for(QStringList::Iterator input
= inputs
.begin(); input
!= inputs
.end(); ++input
) {
1665 if((*input
).isEmpty())
1667 QString in
= fileFixify(Option::fixPathToTargetOS((*input
), false));
1669 QString out
= replaceExtraCompilerVariables(tmp_out
, (*input
), QString());
1670 QString cmd
= replaceExtraCompilerVariables(tmp_cmd
, in
, out
);
1671 if(system(cmd
.toLatin1().constData()))
1683 MakefileGenerator::writeExtraTargets(QTextStream
&t
)
1685 QStringList
&qut
= project
->values("QMAKE_EXTRA_TARGETS");
1686 for(QStringList::Iterator it
= qut
.begin(); it
!= qut
.end(); ++it
) {
1687 QString targ
= var((*it
) + ".target"),
1688 cmd
= var((*it
) + ".commands"), deps
;
1691 QStringList
&deplist
= project
->values((*it
) + ".depends");
1692 for(QStringList::Iterator dep_it
= deplist
.begin(); dep_it
!= deplist
.end(); ++dep_it
) {
1693 QString dep
= var((*dep_it
) + ".target");
1696 deps
+= " " + escapeDependencyPath(dep
);
1698 if(project
->values((*it
) + ".CONFIG").indexOf("fix_target") != -1)
1699 targ
= fileFixify(targ
);
1700 if(project
->isEmpty("QMAKE_NOFORCE") &&
1701 project
->values((*it
) + ".CONFIG").indexOf("phony") != -1)
1702 deps
+= QString(" ") + "FORCE";
1703 t
<< escapeDependencyPath(targ
) << ":" << deps
;
1708 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it
)) << escapeDependencyPath(targ
);
1709 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it
) + escapeDependencyPath(targ
)) << deps
.split(" ", QString::SkipEmptyParts
);
1710 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it
) + escapeDependencyPath(targ
)) << cmd
;
1715 MakefileGenerator::writeExtraCompilerTargets(QTextStream
&t
)
1717 QString clean_targets
;
1718 const QStringList
&quc
= project
->values("QMAKE_EXTRA_COMPILERS");
1719 for(QStringList::ConstIterator it
= quc
.begin(); it
!= quc
.end(); ++it
) {
1720 QString tmp_out
= fileFixify(project
->values((*it
) + ".output").first(),
1721 Option::output_dir
, Option::output_dir
);
1723 if(!project
->isEmpty((*it
) + ".commands")) {
1724 QStringList cmdline
= project
->values((*it
) + ".commands");
1725 int argv0
= findExecutable(cmdline
);
1727 cmdline
[argv0
] = escapeFilePath(Option::fixPathToTargetOS(cmdline
.at(argv0
), false));
1728 tmp_cmd
= cmdline
.join(" ");
1731 QStringList tmp_dep
= project
->values((*it
) + ".depends");
1732 QString tmp_dep_cmd
;
1733 if(!project
->isEmpty((*it
) + ".depend_command")) {
1735 QStringList cmdline
= project
->values((*it
) + ".depend_command");
1736 for(int i
= 0; i
< cmdline
.count(); ++i
) {
1737 if(!cmdline
.at(i
).contains('=')) {
1743 const QString c
= Option::fixPathToLocalOS(cmdline
.at(argv0
), true);
1745 cmdline
[argv0
] = escapeFilePath(Option::fixPathToLocalOS(cmdline
.at(argv0
), false));
1746 tmp_dep_cmd
= cmdline
.join(" ");
1748 cmdline
[argv0
] = escapeFilePath(cmdline
.at(argv0
));
1752 QStringList
&vars
= project
->values((*it
) + ".variables");
1753 if(tmp_out
.isEmpty() || tmp_cmd
.isEmpty())
1755 QStringList tmp_inputs
;
1757 const QStringList
&comp_inputs
= project
->values((*it
) + ".input");
1758 for(QStringList::ConstIterator it2
= comp_inputs
.begin(); it2
!= comp_inputs
.end(); ++it2
) {
1759 const QStringList
&tmp
= project
->values((*it2
));
1760 for(QStringList::ConstIterator input
= tmp
.begin(); input
!= tmp
.end(); ++input
) {
1761 QString in
= Option::fixPathToTargetOS((*input
), false);
1762 if(verifyExtraCompiler((*it
), in
))
1763 tmp_inputs
.append((*input
));
1768 t
<< "compiler_" << (*it
) << "_make_all:";
1769 if(project
->values((*it
) + ".CONFIG").indexOf("combine") != -1) {
1770 // compilers with a combined input only have one output
1771 QString input
= project
->values((*it
) + ".output").first();
1772 t
<< " " << escapeDependencyPath(replaceExtraCompilerVariables(tmp_out
, input
, QString()));
1774 for(QStringList::ConstIterator input
= tmp_inputs
.begin(); input
!= tmp_inputs
.end(); ++input
) {
1775 QString in
= Option::fixPathToTargetOS((*input
), false);
1776 t
<< " " << escapeDependencyPath(replaceExtraCompilerVariables(tmp_out
, (*input
), QString()));
1781 if(project
->values((*it
) + ".CONFIG").indexOf("no_clean") == -1) {
1782 QString tmp_clean
= project
->values((*it
) + ".clean").join(" ");
1783 QString tmp_clean_cmds
= project
->values((*it
) + ".clean_commands").join(" ");
1784 if(!tmp_inputs
.isEmpty())
1785 clean_targets
+= QString("compiler_" + (*it
) + "_clean ");
1786 t
<< "compiler_" << (*it
) << "_clean:";
1787 bool wrote_clean_cmds
= false, wrote_clean
= false;
1788 if(tmp_clean_cmds
.isEmpty()) {
1789 wrote_clean_cmds
= true;
1790 } else if(tmp_clean_cmds
.indexOf("${QMAKE_") == -1) {
1791 t
<< "\n\t" << tmp_clean_cmds
;
1792 wrote_clean_cmds
= true;
1794 if(tmp_clean
.isEmpty())
1795 tmp_clean
= tmp_out
;
1796 if(tmp_clean
.indexOf("${QMAKE_") == -1) {
1797 t
<< "\n\t" << "-$(DEL_FILE) " << tmp_clean
;
1799 t
<< " 2> NUL"; // Eliminate unnecessary warnings
1802 if(!wrote_clean_cmds
|| !wrote_clean
) {
1804 const QString
del_statement("-$(DEL_FILE)");
1806 if(project
->isActiveConfig("no_delete_multiple_files")) {
1807 for(QStringList::ConstIterator input
= tmp_inputs
.begin(); input
!= tmp_inputs
.end(); ++input
)
1808 cleans
.append(" " + replaceExtraCompilerVariables(tmp_clean
, (*input
),
1809 replaceExtraCompilerVariables(tmp_out
, (*input
), QString())));
1811 QString files
, file
;
1812 const int commandlineLimit
= 2047; // NT limit, expanded
1813 for(int input
= 0; input
< tmp_inputs
.size(); ++input
) {
1814 file
= " " + replaceExtraCompilerVariables(tmp_clean
, tmp_inputs
.at(input
),
1815 replaceExtraCompilerVariables(tmp_out
, tmp_inputs
.at(input
), QString()));
1816 if(del_statement
.length() + files
.length() +
1817 qMax(fixEnvVariables(file
).length(), file
.length()) > commandlineLimit
) {
1818 cleans
.append(files
);
1823 if(!files
.isEmpty())
1824 cleans
.append(files
);
1827 if(!cleans
.isEmpty())
1829 t
<< valGlue(cleans
, "\n\t" + del_statement
, " 2> NUL\n\t" + del_statement
, " 2> NUL");
1831 t
<< valGlue(cleans
, "\n\t" + del_statement
, "\n\t" + del_statement
, "");
1832 if(!wrote_clean_cmds
) {
1833 for(QStringList::ConstIterator input
= tmp_inputs
.begin(); input
!= tmp_inputs
.end(); ++input
) {
1834 t
<< "\n\t" << replaceExtraCompilerVariables(tmp_clean_cmds
, (*input
),
1835 replaceExtraCompilerVariables(tmp_out
, (*input
), QString()));
1841 if(project
->values((*it
) + ".CONFIG").indexOf("combine") != -1) {
1842 if(tmp_out
.indexOf("${QMAKE_") != -1) {
1843 warn_msg(WarnLogic
, "QMAKE_EXTRA_COMPILERS(%s) with combine has variable output.",
1844 (*it
).toLatin1().constData());
1847 QStringList deps
, inputs
;
1848 if(!tmp_dep
.isEmpty())
1849 deps
+= fileFixify(tmp_dep
, Option::output_dir
, Option::output_dir
);
1850 for(QStringList::ConstIterator input
= tmp_inputs
.begin(); input
!= tmp_inputs
.end(); ++input
) {
1851 deps
+= findDependencies((*input
));
1852 inputs
+= Option::fixPathToTargetOS((*input
), false);
1853 if(!tmp_dep_cmd
.isEmpty() && doDepends()) {
1855 QString dep_cmd
= replaceExtraCompilerVariables(tmp_dep_cmd
, (*input
),
1857 dep_cmd
= fixEnvVariables(dep_cmd
);
1858 if(FILE *proc
= QT_POPEN(dep_cmd
.toLatin1().constData(), "r")) {
1860 while(!feof(proc
)) {
1861 int read_in
= (int)fread(buff
, 1, 255, proc
);
1864 indeps
+= QByteArray(buff
, read_in
);
1867 if(!indeps
.isEmpty()) {
1868 QStringList dep_cmd_deps
= indeps
.replace('\n', ' ').simplified().split(' ');
1869 for(int i
= 0; i
< dep_cmd_deps
.count(); ++i
) {
1870 QString
&file
= dep_cmd_deps
[i
];
1873 QList
<QMakeLocalFileName
> depdirs
= QMakeSourceFileInfo::dependencyPaths();
1874 for(QList
<QMakeLocalFileName
>::Iterator it
= depdirs
.begin();
1875 it
!= depdirs
.end(); ++it
) {
1876 if(exists((*it
).real() + Option::dir_sep
+ file
)) {
1877 localFile
= (*it
).local() + Option::dir_sep
+ file
;
1884 file
= fileFixify(file
);
1886 deps
+= dep_cmd_deps
;
1891 for(int i
= 0; i
< inputs
.size(); ) {
1892 if(tmp_out
== inputs
.at(i
))
1897 for(int i
= 0; i
< deps
.size(); ) {
1898 if(tmp_out
== deps
.at(i
))
1903 if (inputs
.isEmpty())
1907 if (isForSymbianSbsv2()) {
1908 // In sbsv2 the command inputs and outputs need to use absolute paths
1909 cmd
= replaceExtraCompilerVariables(tmp_cmd
,
1910 fileFixify(escapeFilePaths(inputs
), FileFixifyAbsolute
),
1911 fileFixify(QStringList(tmp_out
), FileFixifyAbsolute
));
1913 cmd
= replaceExtraCompilerVariables(tmp_cmd
, escapeFilePaths(inputs
), QStringList(tmp_out
));
1916 t
<< escapeDependencyPath(tmp_out
) << ":";
1917 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it
)) << escapeDependencyPath(tmp_out
);
1918 // compiler.CONFIG+=explicit_dependencies means that ONLY compiler.depends gets to cause Makefile dependencies
1919 if(project
->values((*it
) + ".CONFIG").indexOf("explicit_dependencies") != -1) {
1920 t
<< " " << valList(escapeDependencyPaths(fileFixify(tmp_dep
, Option::output_dir
, Option::output_dir
)));
1921 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it
) + escapeDependencyPath(tmp_out
)) << tmp_dep
;
1923 t
<< " " << valList(escapeDependencyPaths(inputs
)) << " " << valList(escapeDependencyPaths(deps
));
1924 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it
) + escapeDependencyPath(tmp_out
)) << inputs
<< deps
;
1926 t
<< "\n\t" << cmd
<< endl
<< endl
;
1927 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it
) + escapeDependencyPath(tmp_out
)) << cmd
;
1930 for(QStringList::ConstIterator input
= tmp_inputs
.begin(); input
!= tmp_inputs
.end(); ++input
) {
1931 QString in
= Option::fixPathToTargetOS((*input
), false);
1932 QStringList deps
= findDependencies((*input
));
1933 deps
+= escapeDependencyPath(in
);
1934 QString out
= replaceExtraCompilerVariables(tmp_out
, (*input
), QString());
1935 if(!tmp_dep
.isEmpty()) {
1936 QStringList pre_deps
= fileFixify(tmp_dep
, Option::output_dir
, Option::output_dir
);
1937 for(int i
= 0; i
< pre_deps
.size(); ++i
)
1938 deps
+= replaceExtraCompilerVariables(pre_deps
.at(i
), (*input
), out
);
1940 QString cmd
= replaceExtraCompilerVariables(tmp_cmd
, (*input
), out
);
1941 // NOTE: The var -> QMAKE_COMP_var replace feature is unsupported, do not use!
1942 if (isForSymbianSbsv2()) {
1943 // In sbsv2 the command inputs and outputs need to use absolute paths
1944 cmd
= replaceExtraCompilerVariables(tmp_cmd
,
1945 fileFixify((*input
), FileFixifyAbsolute
),
1946 fileFixify(out
, FileFixifyAbsolute
));
1948 cmd
= replaceExtraCompilerVariables(tmp_cmd
, (*input
), out
);
1950 for(QStringList::ConstIterator it3
= vars
.constBegin(); it3
!= vars
.constEnd(); ++it3
)
1951 cmd
.replace("$(" + (*it3
) + ")", "$(QMAKE_COMP_" + (*it3
)+")");
1952 if(!tmp_dep_cmd
.isEmpty() && doDepends()) {
1954 QString dep_cmd
= replaceExtraCompilerVariables(tmp_dep_cmd
, (*input
), out
);
1955 dep_cmd
= fixEnvVariables(dep_cmd
);
1956 if(FILE *proc
= QT_POPEN(dep_cmd
.toLatin1().constData(), "r")) {
1958 while(!feof(proc
)) {
1959 int read_in
= (int)fread(buff
, 1, 255, proc
);
1962 indeps
+= QByteArray(buff
, read_in
);
1965 if(!indeps
.isEmpty()) {
1966 QStringList dep_cmd_deps
= indeps
.replace('\n', ' ').simplified().split(' ');
1967 for(int i
= 0; i
< dep_cmd_deps
.count(); ++i
) {
1968 QString
&file
= dep_cmd_deps
[i
];
1971 QList
<QMakeLocalFileName
> depdirs
= QMakeSourceFileInfo::dependencyPaths();
1972 for(QList
<QMakeLocalFileName
>::Iterator it
= depdirs
.begin();
1973 it
!= depdirs
.end(); ++it
) {
1974 if(exists((*it
).real() + Option::dir_sep
+ file
)) {
1975 localFile
= (*it
).local() + Option::dir_sep
+ file
;
1982 file
= fileFixify(file
);
1984 deps
+= dep_cmd_deps
;
1987 //use the depend system to find includes of these included files
1988 QStringList inc_deps
;
1989 for(int i
= 0; i
< deps
.size(); ++i
) {
1990 const QString dep
= deps
.at(i
);
1991 if(QFile::exists(dep
)) {
1992 SourceFileType type
= TYPE_UNKNOWN
;
1993 if(type
== TYPE_UNKNOWN
) {
1994 for(QStringList::Iterator cit
= Option::c_ext
.begin();
1995 cit
!= Option::c_ext
.end(); ++cit
) {
1996 if(dep
.endsWith((*cit
))) {
2002 if(type
== TYPE_UNKNOWN
) {
2003 for(QStringList::Iterator cppit
= Option::cpp_ext
.begin();
2004 cppit
!= Option::cpp_ext
.end(); ++cppit
) {
2005 if(dep
.endsWith((*cppit
))) {
2011 if(type
== TYPE_UNKNOWN
) {
2012 for(QStringList::Iterator hit
= Option::h_ext
.begin();
2013 type
== TYPE_UNKNOWN
&& hit
!= Option::h_ext
.end(); ++hit
) {
2014 if(dep
.endsWith((*hit
))) {
2020 if(type
!= TYPE_UNKNOWN
) {
2021 if(!QMakeSourceFileInfo::containsSourceFile(dep
, type
))
2022 QMakeSourceFileInfo::addSourceFile(dep
, type
);
2023 inc_deps
+= QMakeSourceFileInfo::dependencies(dep
);
2029 for(int i
= 0; i
< deps
.size(); ) {
2030 QString
&dep
= deps
[i
];
2031 dep
= Option::fixPathToTargetOS(unescapeFilePath(dep
), false);
2037 t
<< escapeDependencyPath(out
) << ": " << valList(escapeDependencyPaths(deps
)) << "\n\t"
2038 << cmd
<< endl
<< endl
;
2039 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it
)) << escapeDependencyPath(out
);
2040 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it
) + escapeDependencyPath(out
)) << deps
;
2041 project
->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it
) + escapeDependencyPath(out
)) << cmd
;
2044 t
<< "compiler_clean: " << clean_targets
<< endl
<< endl
;
2048 MakefileGenerator::writeExtraCompilerVariables(QTextStream
&t
)
2051 const QStringList
&quc
= project
->values("QMAKE_EXTRA_COMPILERS");
2052 for(QStringList::ConstIterator it
= quc
.begin(); it
!= quc
.end(); ++it
) {
2053 const QStringList
&vars
= project
->values((*it
) + ".variables");
2054 for(QStringList::ConstIterator varit
= vars
.begin(); varit
!= vars
.end(); ++varit
) {
2056 t
<< "\n####### Custom Compiler Variables" << endl
;
2059 t
<< "QMAKE_COMP_" << (*varit
) << " = "
2060 << valList(project
->values((*varit
))) << endl
;
2068 MakefileGenerator::writeExtraVariables(QTextStream
&t
)
2071 QMap
<QString
, QStringList
> &vars
= project
->variables();
2072 QStringList
&exports
= project
->values("QMAKE_EXTRA_VARIABLES");
2073 for(QMap
<QString
, QStringList
>::Iterator it
= vars
.begin(); it
!= vars
.end(); ++it
) {
2074 for(QStringList::Iterator exp_it
= exports
.begin(); exp_it
!= exports
.end(); ++exp_it
) {
2075 QRegExp
rx((*exp_it
), Qt::CaseInsensitive
, QRegExp::Wildcard
);
2076 if(rx
.exactMatch(it
.key())) {
2078 t
<< "\n####### Custom Variables" << endl
;
2081 t
<< "EXPORT_" << it
.key() << " = " << it
.value().join(" ") << endl
;
2090 MakefileGenerator::writeStubMakefile(QTextStream
&t
)
2092 t
<< "QMAKE = " << (project
->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE")) << endl
;
2093 QStringList
&qut
= project
->values("QMAKE_EXTRA_TARGETS");
2094 for(QStringList::ConstIterator it
= qut
.begin(); it
!= qut
.end(); ++it
)
2096 //const QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
2097 t
<< "first all clean install distclean uninstall: " << "qmake" << endl
2098 << "qmake_all:" << endl
;
2100 if(project
->isEmpty("QMAKE_NOFORCE"))
2101 t
<< "FORCE:" << endl
<< endl
;
2106 MakefileGenerator::writeMakefile(QTextStream
&t
)
2108 t
<< "####### Compile" << endl
<< endl
;
2109 writeObj(t
, "SOURCES");
2110 writeObj(t
, "GENERATED_SOURCES");
2112 t
<< "####### Install" << endl
<< endl
;
2113 writeInstalls(t
, "INSTALLS");
2115 if(project
->isEmpty("QMAKE_NOFORCE"))
2116 t
<< "FORCE:" << endl
<< endl
;
2120 QString
MakefileGenerator::buildArgs(const QString
&outdir
)
2124 if(!project
->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
2125 ret
+= " QMAKE_ABSOLUTE_SOURCE_PATH=" + escapeFilePath(project
->first("QMAKE_ABSOLUTE_SOURCE_PATH"));
2128 else if(Option::warn_level
== WarnNone
)
2130 else if(Option::warn_level
== WarnAll
)
2132 else if(Option::warn_level
& WarnParser
)
2135 if(!Option::user_template
.isEmpty())
2136 ret
+= " -t " + Option::user_template
;
2137 if(!Option::user_template_prefix
.isEmpty())
2138 ret
+= " -tp " + Option::user_template_prefix
;
2139 if(!Option::mkfile::do_cache
)
2141 if(!Option::mkfile::do_deps
)
2142 ret
+= " -nodepend";
2143 if(!Option::mkfile::do_dep_heuristics
)
2144 ret
+= " -nodependheuristics";
2145 if(!Option::mkfile::qmakespec_commandline
.isEmpty())
2146 ret
+= " -spec " + specdir(outdir
);
2147 if(Option::target_mode
== Option::TARG_MAC9_MODE
)
2149 else if(Option::target_mode
== Option::TARG_MACX_MODE
)
2151 else if(Option::target_mode
== Option::TARG_UNIX_MODE
)
2153 else if(Option::target_mode
== Option::TARG_WIN_MODE
)
2157 for(QStringList::Iterator it
= Option::user_configs
.begin();
2158 it
!= Option::user_configs
.end(); ++it
)
2159 ret
+= " -config " + (*it
);
2161 for(QStringList::Iterator it
= Option::before_user_vars
.begin();
2162 it
!= Option::before_user_vars
.end(); ++it
) {
2163 if((*it
).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH")
2164 ret
+= " " + escapeFilePath((*it
));
2166 if(Option::after_user_vars
.count()) {
2168 for(QStringList::Iterator it
= Option::after_user_vars
.begin();
2169 it
!= Option::after_user_vars
.end(); ++it
) {
2170 if((*it
).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH")
2171 ret
+= " " + escapeFilePath((*it
));
2177 //could get stored argv, but then it would have more options than are
2178 //probably necesary this will try to guess the bare minimum..
2179 QString
MakefileGenerator::build_args(const QString
&outdir
)
2181 QString ret
= "$(QMAKE)";
2183 // general options and arguments
2184 ret
+= buildArgs(outdir
);
2187 QString ofile
= Option::fixPathToTargetOS(fileFixify(Option::output
.fileName()));
2188 if(!ofile
.isEmpty() && ofile
!= project
->first("QMAKE_MAKEFILE"))
2189 ret
+= " -o " + escapeFilePath(ofile
);
2192 ret
+= " " + escapeFilePath(fileFixify(project
->projectFile(), outdir
));
2198 MakefileGenerator::writeHeader(QTextStream
&t
)
2200 t
<< "#############################################################################" << endl
;
2201 t
<< "# Makefile for building: " << escapeFilePath(var("TARGET")) << endl
;
2202 t
<< "# Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR
<< ") on: ";
2203 t
<< QDateTime::currentDateTime().toString() << endl
;
2204 t
<< "# Project: " << fileFixify(project
->projectFile()) << endl
;
2205 t
<< "# Template: " << var("TEMPLATE") << endl
;
2206 if(!project
->isActiveConfig("build_pass"))
2207 t
<< "# Command: " << build_args().replace("$(QMAKE)",
2208 (project
->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE"))) << endl
;
2209 t
<< "#############################################################################" << endl
;
2213 QList
<MakefileGenerator::SubTarget
*>
2214 MakefileGenerator::findSubDirsSubTargets() const
2216 QList
<SubTarget
*> targets
;
2218 const QStringList subdirs
= project
->values("SUBDIRS");
2219 for(int subdir
= 0; subdir
< subdirs
.size(); ++subdir
) {
2220 QString fixedSubdir
= subdirs
[subdir
];
2221 fixedSubdir
= fixedSubdir
.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
2223 SubTarget
*st
= new SubTarget
;
2224 st
->name
= subdirs
[subdir
];
2227 bool fromFile
= false;
2228 QString file
= subdirs
[subdir
];
2229 if(!project
->isEmpty(fixedSubdir
+ ".file")) {
2230 if(!project
->isEmpty(fixedSubdir
+ ".subdir"))
2231 warn_msg(WarnLogic
, "Cannot assign both file and subdir for subdir %s",
2232 subdirs
[subdir
].toLatin1().constData());
2233 file
= project
->first(fixedSubdir
+ ".file");
2235 } else if(!project
->isEmpty(fixedSubdir
+ ".subdir")) {
2236 file
= project
->first(fixedSubdir
+ ".subdir");
2239 fromFile
= file
.endsWith(Option::pro_ext
);
2241 file
= Option::fixPathToTargetOS(file
);
2244 int slsh
= file
.lastIndexOf(Option::dir_sep
);
2246 st
->in_directory
= file
.left(slsh
+1);
2247 st
->profile
= file
.mid(slsh
+1);
2252 if(!file
.isEmpty() && !project
->isActiveConfig("subdir_first_pro"))
2253 st
->profile
= file
.section(Option::dir_sep
, -1) + Option::pro_ext
;
2254 st
->in_directory
= file
;
2256 while(st
->in_directory
.endsWith(Option::dir_sep
))
2257 st
->in_directory
.chop(1);
2258 if(fileInfo(st
->in_directory
).isRelative())
2259 st
->out_directory
= st
->in_directory
;
2261 st
->out_directory
= fileFixify(st
->in_directory
, qmake_getpwd(), Option::output_dir
);
2262 if(!project
->isEmpty(fixedSubdir
+ ".makefile")) {
2263 st
->makefile
= project
->first(fixedSubdir
+ ".makefile");
2265 st
->makefile
= "$(MAKEFILE)";
2266 if(!st
->profile
.isEmpty()) {
2267 QString basename
= st
->in_directory
;
2268 int new_slsh
= basename
.lastIndexOf(Option::dir_sep
);
2270 basename
= basename
.mid(new_slsh
+1);
2271 if(st
->profile
!= basename
+ Option::pro_ext
)
2272 st
->makefile
+= "." + st
->profile
.left(st
->profile
.length() - Option::pro_ext
.length());
2275 if(!project
->isEmpty(fixedSubdir
+ ".depends")) {
2276 const QStringList depends
= project
->values(fixedSubdir
+ ".depends");
2277 for(int depend
= 0; depend
< depends
.size(); ++depend
) {
2279 for(int subDep
= 0; subDep
< subdirs
.size(); ++subDep
) {
2280 if(subdirs
[subDep
] == depends
.at(depend
)) {
2281 QString fixedSubDep
= subdirs
[subDep
];
2282 fixedSubDep
= fixedSubDep
.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
2283 if(!project
->isEmpty(fixedSubDep
+ ".target")) {
2284 st
->depends
+= project
->first(fixedSubDep
+ ".target");
2286 QString d
= Option::fixPathToLocalOS(subdirs
[subDep
]);
2287 if(!project
->isEmpty(fixedSubDep
+ ".file"))
2288 d
= project
->first(fixedSubDep
+ ".file");
2289 else if(!project
->isEmpty(fixedSubDep
+ ".subdir"))
2290 d
= project
->first(fixedSubDep
+ ".subdir");
2291 st
->depends
+= "sub-" + d
.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
2298 QString depend_str
= depends
.at(depend
);
2299 st
->depends
+= depend_str
.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
2303 if(!project
->isEmpty(fixedSubdir
+ ".target")) {
2304 st
->target
= project
->first(fixedSubdir
+ ".target");
2306 st
->target
= "sub-" + file
;
2307 st
->target
= st
->target
.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
2315 MakefileGenerator::writeSubDirs(QTextStream
&t
)
2317 QList
<SubTarget
*> targets
= findSubDirsSubTargets();
2318 t
<< "first: make_default" << endl
;
2319 int flags
= SubTargetInstalls
;
2320 if(project
->isActiveConfig("ordered"))
2321 flags
|= SubTargetOrdered
;
2322 writeSubTargets(t
, targets
, flags
);
2323 qDeleteAll(targets
);
2327 MakefileGenerator::writeSubTargets(QTextStream
&t
, QList
<MakefileGenerator::SubTarget
*> targets
, int flags
)
2330 QStringList
&qeui
= project
->values("QMAKE_EXTRA_INCLUDES");
2331 for(QStringList::Iterator qeui_it
= qeui
.begin(); qeui_it
!= qeui
.end(); ++qeui_it
)
2332 t
<< "include " << (*qeui_it
) << endl
;
2334 if (!(flags
& SubTargetSkipDefaultVariables
)) {
2335 QString ofile
= Option::fixPathToTargetOS(Option::output
.fileName());
2336 if(ofile
.lastIndexOf(Option::dir_sep
) != -1)
2337 ofile
.remove(0, ofile
.lastIndexOf(Option::dir_sep
) +1);
2338 t
<< "MAKEFILE = " << ofile
<< endl
;
2339 /* Calling Option::fixPathToTargetOS() is necessary for MinGW/MSYS, which requires
2340 * back-slashes to be turned into slashes. */
2341 t
<< "QMAKE = " << Option::fixPathToTargetOS(var("QMAKE_QMAKE")) << endl
;
2342 t
<< "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl
;
2343 t
<< "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl
;
2344 t
<< "MKDIR = " << var("QMAKE_MKDIR") << endl
;
2345 t
<< "COPY = " << var("QMAKE_COPY") << endl
;
2346 t
<< "COPY_FILE = " << var("QMAKE_COPY_FILE") << endl
;
2347 t
<< "COPY_DIR = " << var("QMAKE_COPY_DIR") << endl
;
2348 t
<< "INSTALL_FILE = " << var("QMAKE_INSTALL_FILE") << endl
;
2349 t
<< "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl
;
2350 t
<< "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl
;
2351 t
<< "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl
;
2352 t
<< "SYMLINK = " << var("QMAKE_SYMBOLIC_LINK") << endl
;
2353 t
<< "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl
;
2354 t
<< "MOVE = " << var("QMAKE_MOVE") << endl
;
2355 t
<< "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl
;
2356 t
<< "MKDIR = " << var("QMAKE_MKDIR") << endl
;
2357 t
<< "SUBTARGETS = "; // subtargets are sub-directory
2358 for(int target
= 0; target
< targets
.size(); ++target
)
2359 t
<< " \\\n\t\t" << targets
.at(target
)->target
;
2362 writeExtraVariables(t
);
2364 QStringList targetSuffixes
;
2365 const QString abs_source_path
= project
->first("QMAKE_ABSOLUTE_SOURCE_PATH");
2366 if (!(flags
& SubTargetSkipDefaultTargets
)) {
2367 targetSuffixes
<< "make_default" << "make_first" << "all" << "clean" << "distclean"
2368 << QString((flags
& SubTargetInstalls
) ? "install_subtargets" : "install")
2369 << QString((flags
& SubTargetInstalls
) ? "uninstall_subtargets" : "uninstall");
2372 // generate target rules
2373 for(int target
= 0; target
< targets
.size(); ++target
) {
2374 SubTarget
*subtarget
= targets
.at(target
);
2375 QString in_directory
= subtarget
->in_directory
;
2376 if(!in_directory
.isEmpty() && !in_directory
.endsWith(Option::dir_sep
))
2377 in_directory
+= Option::dir_sep
;
2378 QString out_directory
= subtarget
->out_directory
;
2379 if(!out_directory
.isEmpty() && !out_directory
.endsWith(Option::dir_sep
))
2380 out_directory
+= Option::dir_sep
;
2381 if(!abs_source_path
.isEmpty() && out_directory
.startsWith(abs_source_path
))
2382 out_directory
= Option::output_dir
+ out_directory
.mid(abs_source_path
.length());
2384 QString mkfile
= subtarget
->makefile
;
2385 if(!in_directory
.isEmpty())
2386 mkfile
.prepend(out_directory
);
2388 QString in_directory_cdin
, in_directory_cdout
, out_directory_cdin
, out_directory_cdout
;
2389 #define MAKE_CD_IN_AND_OUT(directory) \
2390 if(!directory.isEmpty()) { \
2391 if(project->isActiveConfig("cd_change_global")) { \
2392 directory ## _cdin = "\n\tcd " + directory + "\n\t"; \
2393 QDir pwd(Option::output_dir); \
2394 QStringList in = directory.split(Option::dir_sep), out; \
2395 for(int i = 0; i < in.size(); i++) { \
2396 if(in.at(i) == "..") \
2397 out.prepend(fileInfo(pwd.path()).fileName()); \
2398 else if(in.at(i) != ".") \
2399 out.prepend(".."); \
2402 directory ## _cdout = "\n\t@cd " + out.join(Option::dir_sep); \
2404 directory ## _cdin = "\n\tcd " + directory + " && "; \
2407 directory ## _cdin = "\n\t"; \
2409 MAKE_CD_IN_AND_OUT(in_directory
);
2410 MAKE_CD_IN_AND_OUT(out_directory
);
2413 if(!subtarget
->profile
.isEmpty()) {
2414 QString out
= out_directory
+ subtarget
->makefile
,
2415 in
= fileFixify(in_directory
+ subtarget
->profile
, in_directory
);
2416 if(in
.startsWith(in_directory
))
2417 in
= in
.mid(in_directory
.length());
2418 if(out
.startsWith(in_directory
))
2419 out
= out
.mid(in_directory
.length());
2420 t
<< mkfile
<< ": " << "\n\t";
2421 if(!in_directory
.isEmpty()) {
2422 t
<< mkdir_p_asstring(in_directory
)
2423 << in_directory_cdin
2424 << "$(QMAKE) " << in
<< buildArgs(in_directory
) << " -o " << out
2425 << in_directory_cdout
<< endl
;
2427 t
<< "$(QMAKE) " << in
<< buildArgs(in_directory
) << " -o " << out
<< endl
;
2429 t
<< subtarget
->target
<< "-qmake_all: ";
2430 if(project
->isEmpty("QMAKE_NOFORCE"))
2433 if(!in_directory
.isEmpty()) {
2434 t
<< mkdir_p_asstring(in_directory
)
2435 << in_directory_cdin
2436 << "$(QMAKE) " << in
<< buildArgs(in_directory
) << " -o " << out
2437 << in_directory_cdout
<< endl
;
2439 t
<< "$(QMAKE) " << in
<< buildArgs(in_directory
) << " -o " << out
<< endl
;
2443 QString makefilein
= " -f " + subtarget
->makefile
;
2445 { //actually compile
2446 t
<< subtarget
->target
<< ": " << mkfile
;
2447 if(!subtarget
->depends
.isEmpty())
2448 t
<< " " << valList(subtarget
->depends
);
2449 if(project
->isEmpty("QMAKE_NOFORCE"))
2451 t
<< out_directory_cdin
2452 << "$(MAKE)" << makefilein
2453 << out_directory_cdout
<< endl
;
2456 for(int suffix
= 0; suffix
< targetSuffixes
.size(); ++suffix
) {
2457 QString s
= targetSuffixes
.at(suffix
);
2458 if(s
== "install_subtargets")
2460 else if(s
== "uninstall_subtargets")
2462 else if(s
== "make_first")
2464 else if(s
== "make_default")
2467 if(flags
& SubTargetOrdered
) {
2468 t
<< subtarget
->target
<< "-" << targetSuffixes
.at(suffix
) << "-ordered: " << mkfile
;
2470 t
<< " " << targets
.at(target
-1)->target
<< "-" << targetSuffixes
.at(suffix
) << "-ordered ";
2471 if(project
->isEmpty("QMAKE_NOFORCE"))
2473 t
<< out_directory_cdin
2474 << "$(MAKE)" << makefilein
<< " " << s
2475 << out_directory_cdout
<< endl
;
2477 t
<< subtarget
->target
<< "-" << targetSuffixes
.at(suffix
) << ": " << mkfile
;
2478 if(!subtarget
->depends
.isEmpty())
2479 t
<< " " << valGlue(subtarget
->depends
, QString(), "-" + targetSuffixes
.at(suffix
) + " ",
2480 "-"+targetSuffixes
.at(suffix
));
2481 if(project
->isEmpty("QMAKE_NOFORCE"))
2483 t
<< out_directory_cdin
2484 << "$(MAKE)" << makefilein
<< " " << s
2485 << out_directory_cdout
<< endl
;
2490 if (!(flags
& SubTargetSkipDefaultTargets
)) {
2491 if(project
->values("QMAKE_INTERNAL_QMAKE_DEPS").indexOf("qmake_all") == -1)
2492 project
->values("QMAKE_INTERNAL_QMAKE_DEPS").append("qmake_all");
2497 if(!targets
.isEmpty()) {
2498 for(QList
<SubTarget
*>::Iterator it
= targets
.begin(); it
!= targets
.end(); ++it
) {
2499 if(!(*it
)->profile
.isEmpty())
2500 t
<< " " << (*it
)->target
<< "-" << "qmake_all";
2503 if(project
->isEmpty("QMAKE_NOFORCE"))
2505 if(project
->isActiveConfig("no_empty_targets"))
2506 t
<< "\n\t" << "@cd .";
2510 for(int s
= 0; s
< targetSuffixes
.size(); ++s
) {
2511 QString suffix
= targetSuffixes
.at(s
);
2512 if(!(flags
& SubTargetInstalls
) && suffix
.endsWith("install"))
2516 for(int target
= 0; target
< targets
.size(); ++target
) {
2517 SubTarget
*subTarget
= targets
.at(target
);
2518 if((suffix
== "make_first" || suffix
== "make_default")
2519 && project
->values(subTarget
->name
+ ".CONFIG").indexOf("no_default_target") != -1) {
2522 QString targetRule
= subTarget
->target
+ "-" + suffix
;
2523 if(flags
& SubTargetOrdered
)
2524 targetRule
+= "-ordered";
2525 t
<< " " << targetRule
;
2527 if(suffix
== "all" || suffix
== "make_first")
2528 t
<< varGlue("ALL_DEPS"," "," ","");
2529 if(suffix
== "clean")
2530 t
<< varGlue("CLEAN_DEPS"," "," ","");
2531 if(project
->isEmpty("QMAKE_NOFORCE"))
2534 if(suffix
== "clean") {
2535 t
<< varGlue("QMAKE_CLEAN","\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ", "\n");
2536 } else if(suffix
== "distclean") {
2537 QString ofile
= Option::fixPathToTargetOS(fileFixify(Option::output
.fileName()));
2538 if(!ofile
.isEmpty())
2539 t
<< "\t-$(DEL_FILE) " << ofile
<< endl
;
2540 } else if(project
->isActiveConfig("no_empty_targets")) {
2541 t
<< "\t" << "@cd ." << endl
;
2545 // user defined targets
2546 QStringList
&qut
= project
->values("QMAKE_EXTRA_TARGETS");
2547 for(QStringList::Iterator qut_it
= qut
.begin(); qut_it
!= qut
.end(); ++qut_it
) {
2548 QString targ
= var((*qut_it
) + ".target"),
2549 cmd
= var((*qut_it
) + ".commands"), deps
;
2554 QStringList
&deplist
= project
->values((*qut_it
) + ".depends");
2555 for(QStringList::Iterator dep_it
= deplist
.begin(); dep_it
!= deplist
.end(); ++dep_it
) {
2556 QString dep
= var((*dep_it
) + ".target");
2558 dep
= Option::fixPathToTargetOS(*dep_it
, false);
2561 if(project
->values((*qut_it
) + ".CONFIG").indexOf("recursive") != -1) {
2562 QSet
<QString
> recurse
;
2563 if(project
->isSet((*qut_it
) + ".recurse")) {
2564 recurse
= project
->values((*qut_it
) + ".recurse").toSet();
2566 for(int target
= 0; target
< targets
.size(); ++target
)
2567 recurse
.insert(targets
.at(target
)->name
);
2569 for(int target
= 0; target
< targets
.size(); ++target
) {
2570 SubTarget
*subtarget
= targets
.at(target
);
2571 QString in_directory
= subtarget
->in_directory
;
2572 if(!in_directory
.isEmpty() && !in_directory
.endsWith(Option::dir_sep
))
2573 in_directory
+= Option::dir_sep
;
2574 QString out_directory
= subtarget
->out_directory
;
2575 if(!out_directory
.isEmpty() && !out_directory
.endsWith(Option::dir_sep
))
2576 out_directory
+= Option::dir_sep
;
2577 if(!abs_source_path
.isEmpty() && out_directory
.startsWith(abs_source_path
))
2578 out_directory
= Option::output_dir
+ out_directory
.mid(abs_source_path
.length());
2580 if(!recurse
.contains(subtarget
->name
))
2582 QString mkfile
= subtarget
->makefile
;
2583 if(!in_directory
.isEmpty()) {
2584 if(!out_directory
.endsWith(Option::dir_sep
))
2585 mkfile
.prepend(out_directory
+ Option::dir_sep
);
2587 mkfile
.prepend(out_directory
);
2589 QString out_directory_cdin
, out_directory_cdout
;
2590 MAKE_CD_IN_AND_OUT(out_directory
);
2592 //don't need the makefile arg if it isn't changed
2594 if(subtarget
->makefile
!= "$(MAKEFILE)")
2595 makefilein
= " -f " + subtarget
->makefile
;
2597 //write the rule/depends
2598 if(flags
& SubTargetOrdered
) {
2599 const QString dep
= subtarget
->target
+ "-" + (*qut_it
) + "_ordered";
2600 t
<< dep
<< ": " << mkfile
;
2602 t
<< " " << targets
.at(target
-1)->target
<< "-" << (*qut_it
) << "_ordered ";
2605 const QString dep
= subtarget
->target
+ "-" + (*qut_it
);
2606 t
<< dep
<< ": " << mkfile
;
2607 if(!subtarget
->depends
.isEmpty())
2608 t
<< " " << valGlue(subtarget
->depends
, QString(), "-" + (*qut_it
) + " ", "-" + (*qut_it
));
2612 QString sub_targ
= targ
;
2613 if(project
->isSet((*qut_it
) + ".recurse_target"))
2614 sub_targ
= project
->first((*qut_it
) + ".recurse_target");
2616 //write the commands
2617 if(!out_directory
.isEmpty()) {
2618 t
<< out_directory_cdin
2619 << "$(MAKE)" << makefilein
<< " " << sub_targ
2620 << out_directory_cdout
<< endl
;
2623 << "$(MAKE)" << makefilein
<< " " << sub_targ
<< endl
;
2627 if(project
->isEmpty("QMAKE_NOFORCE") &&
2628 project
->values((*qut_it
) + ".CONFIG").indexOf("phony") != -1)
2630 t
<< targ
<< ":" << deps
<< "\n";
2632 t
<< "\t" << cmd
<< endl
;
2635 if(flags
& SubTargetInstalls
) {
2636 project
->values("INSTALLDEPS") += "install_subtargets";
2637 project
->values("UNINSTALLDEPS") += "uninstall_subtargets";
2638 writeInstalls(t
, "INSTALLS", true);
2641 if(project
->isEmpty("QMAKE_NOFORCE"))
2642 t
<< "FORCE:" << endl
<< endl
;
2646 MakefileGenerator::writeMakeQmake(QTextStream
&t
)
2648 QString ofile
= Option::fixPathToTargetOS(fileFixify(Option::output
.fileName()));
2649 if(project
->isEmpty("QMAKE_FAILED_REQUIREMENTS") && !project
->isEmpty("QMAKE_INTERNAL_PRL_FILE")) {
2650 QStringList files
= fileFixify(Option::mkfile::project_files
);
2651 t
<< escapeDependencyPath(project
->first("QMAKE_INTERNAL_PRL_FILE")) << ": " << "\n\t"
2652 << "@$(QMAKE) -prl " << buildArgs() << " " << files
.join(" ") << endl
;
2655 QString pfile
= project
->projectFile();
2656 if(pfile
!= "(stdin)") {
2657 QString qmake
= build_args();
2658 if(!ofile
.isEmpty() && !project
->isActiveConfig("no_autoqmake")) {
2659 t
<< escapeFilePath(ofile
) << ": " << escapeDependencyPath(fileFixify(pfile
)) << " ";
2660 if(Option::mkfile::do_cache
)
2661 t
<< escapeDependencyPath(fileFixify(Option::mkfile::cachefile
)) << " ";
2662 if(!specdir().isEmpty()) {
2663 if(exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"qmake.conf")))
2664 t
<< escapeDependencyPath(specdir() + Option::dir_sep
+ "qmake.conf") << " ";
2665 else if(exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"tmake.conf")))
2666 t
<< escapeDependencyPath(specdir() + Option::dir_sep
+ "tmake.conf") << " ";
2668 const QStringList
&included
= project
->values("QMAKE_INTERNAL_INCLUDED_FILES");
2669 t
<< escapeDependencyPaths(included
).join(" \\\n\t\t") << "\n\t"
2671 for(int include
= 0; include
< included
.size(); ++include
) {
2672 const QString
i(included
.at(include
));
2674 t
<< i
<< ":" << endl
;
2677 if(project
->first("QMAKE_ORIG_TARGET") != "qmake") {
2679 project
->values("QMAKE_INTERNAL_QMAKE_DEPS").join(" \\\n\t\t");
2680 if(project
->isEmpty("QMAKE_NOFORCE"))
2682 t
<< "\n\t" << "@" << qmake
<< endl
<< endl
;
2688 MakefileGenerator::fileInfo(QString file
) const
2690 static QHash
<FileInfoCacheKey
, QFileInfo
> *cache
= 0;
2691 static QFileInfo noInfo
= QFileInfo();
2693 cache
= new QHash
<FileInfoCacheKey
, QFileInfo
>;
2694 qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFileInfoCacheKeyQFileInfo
, (void**)&cache
);
2696 FileInfoCacheKey
cacheKey(file
);
2697 QFileInfo value
= cache
->value(cacheKey
, noInfo
);
2698 if (value
!= noInfo
)
2703 cache
->insert(cacheKey
, fi
);
2708 MakefileGenerator::unescapeFilePath(const QString
&path
) const
2711 if(!ret
.isEmpty()) {
2712 if(ret
.contains(QLatin1String("\\ ")))
2713 ret
.replace(QLatin1String("\\ "), QLatin1String(" "));
2714 if(ret
.contains(QLatin1Char('\"')))
2715 ret
.remove(QLatin1Char('\"'));
2721 MakefileGenerator::escapeFilePaths(const QStringList
&paths
) const
2724 for(int i
= 0; i
< paths
.size(); ++i
)
2725 ret
.append(escapeFilePath(paths
.at(i
)));
2730 MakefileGenerator::escapeDependencyPaths(const QStringList
&paths
) const
2733 for(int i
= 0; i
< paths
.size(); ++i
)
2734 ret
.append(escapeDependencyPath(paths
.at(i
)));
2739 MakefileGenerator::unescapeFilePaths(const QStringList
&paths
) const
2742 for(int i
= 0; i
< paths
.size(); ++i
)
2743 ret
.append(unescapeFilePath(paths
.at(i
)));
2748 MakefileGenerator::fileFixify(const QStringList
& files
, const QString
&out_dir
, const QString
&in_dir
,
2749 FileFixifyType fix
, bool canon
) const
2754 for(QStringList::ConstIterator it
= files
.begin(); it
!= files
.end(); ++it
) {
2755 if(!(*it
).isEmpty())
2756 ret
<< fileFixify((*it
), out_dir
, in_dir
, fix
, canon
);
2762 MakefileGenerator::fileFixify(const QString
& file
, const QString
&out_d
, const QString
&in_d
,
2763 FileFixifyType fix
, bool canon
) const
2767 QString ret
= unescapeFilePath(file
);
2770 static QHash
<FileFixifyCacheKey
, QString
> *cache
= 0;
2772 cache
= new QHash
<FileFixifyCacheKey
, QString
>;
2773 qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFileFixifyCacheKeyQString
, (void**)&cache
);
2775 FileFixifyCacheKey
cacheKey(ret
, out_d
, in_d
, fix
, canon
);
2776 QString cacheVal
= cache
->value(cacheKey
);
2777 if(!cacheVal
.isNull())
2781 QString pwd
= qmake_getpwd();
2782 if (!pwd
.endsWith('/'))
2784 QString orig_file
= ret
;
2785 if(ret
.startsWith(QLatin1Char('~'))) {
2786 if(ret
.startsWith(QLatin1String("~/")))
2787 ret
= QDir::homePath() + ret
.mid(1);
2789 warn_msg(WarnLogic
, "Unable to expand ~ in %s", ret
.toLatin1().constData());
2791 if(fix
== FileFixifyAbsolute
|| (fix
== FileFixifyDefault
&& project
->isActiveConfig("no_fixpath"))) {
2792 if(fix
== FileFixifyAbsolute
&& QDir::isRelativePath(ret
)) //already absolute
2794 ret
= Option::fixPathToTargetOS(ret
, false, canon
);
2796 QString out_dir
= QDir(Option::output_dir
).absoluteFilePath(out_d
);
2797 QString in_dir
= QDir(pwd
).absoluteFilePath(in_d
);
2799 QFileInfo
in_fi(fileInfo(in_dir
));
2801 in_dir
= in_fi
.canonicalFilePath();
2802 QFileInfo
out_fi(fileInfo(out_dir
));
2804 out_dir
= out_fi
.canonicalFilePath();
2807 QString
qfile(Option::fixPathToLocalOS(ret
, true, canon
));
2808 QFileInfo
qfileinfo(fileInfo(qfile
));
2809 if(out_dir
!= in_dir
|| !qfileinfo
.isRelative()) {
2810 if(qfileinfo
.isRelative()) {
2811 ret
= in_dir
+ "/" + qfile
;
2812 qfileinfo
.setFile(ret
);
2814 ret
= Option::fixPathToTargetOS(ret
, false, canon
);
2815 if(canon
&& qfileinfo
.exists() &&
2816 file
== Option::fixPathToTargetOS(ret
, true, canon
))
2817 ret
= Option::fixPathToTargetOS(qfileinfo
.canonicalFilePath());
2818 QString match_dir
= Option::fixPathToTargetOS(out_dir
, false, canon
);
2819 if(ret
== match_dir
) {
2821 } else if(ret
.startsWith(match_dir
+ Option::dir_sep
)) {
2822 ret
= ret
.mid(match_dir
.length() + Option::dir_sep
.length());
2824 //figure out the depth
2826 if(Option::qmake_mode
== Option::QMAKE_GENERATE_MAKEFILE
||
2827 Option::qmake_mode
== Option::QMAKE_GENERATE_PRL
) {
2828 if(project
&& !project
->isEmpty("QMAKE_PROJECT_DEPTH"))
2829 depth
= project
->first("QMAKE_PROJECT_DEPTH").toInt();
2830 else if(Option::mkfile::cachefile_depth
!= -1)
2831 depth
= Option::mkfile::cachefile_depth
;
2833 //calculate how much can be removed
2835 for(int i
= 1; i
<= depth
; i
++) {
2836 int sl
= match_dir
.lastIndexOf(Option::dir_sep
);
2839 match_dir
= match_dir
.left(sl
);
2840 if(match_dir
.isEmpty())
2842 if(ret
.startsWith(match_dir
+ Option::dir_sep
)) {
2844 int remlen
= ret
.length() - (match_dir
.length() + 1);
2847 ret
= ret
.right(remlen
);
2849 for(int o
= 0; o
< i
; o
++)
2850 dot_prefix
+= ".." + Option::dir_sep
;
2853 ret
.prepend(dot_prefix
);
2856 ret
= Option::fixPathToTargetOS(ret
, false, canon
);
2861 debug_msg(3, "Fixed[%d,%d] %s :: to :: %s [%s::%s] [%s::%s]", fix
, canon
, orig_file
.toLatin1().constData(),
2862 ret
.toLatin1().constData(), in_d
.toLatin1().constData(), out_d
.toLatin1().constData(),
2863 pwd
.toLatin1().constData(), Option::output_dir
.toLatin1().constData());
2864 cache
->insert(cacheKey
, ret
);
2869 MakefileGenerator::checkMultipleDefinition(const QString
&f
, const QString
&w
)
2871 if(!(Option::warn_level
& WarnLogic
))
2874 int slsh
= f
.lastIndexOf(Option::dir_sep
);
2876 file
.remove(0, slsh
+ 1);
2877 QStringList
&l
= project
->values(w
);
2878 for(QStringList::Iterator val_it
= l
.begin(); val_it
!= l
.end(); ++val_it
) {
2879 QString
file2((*val_it
));
2880 slsh
= file2
.lastIndexOf(Option::dir_sep
);
2882 file2
.remove(0, slsh
+ 1);
2884 warn_msg(WarnLogic
, "Found potential symbol conflict of %s (%s) in %s",
2885 file
.toLatin1().constData(), (*val_it
).toLatin1().constData(), w
.toLatin1().constData());
2892 MakefileGenerator::fixPathForFile(const QMakeLocalFileName
&file
, bool forOpen
)
2895 return QMakeLocalFileName(fileFixify(file
.real(), qmake_getpwd(), Option::output_dir
));
2896 return QMakeLocalFileName(fileFixify(file
.real()));
2900 MakefileGenerator::findFileInfo(const QMakeLocalFileName
&file
)
2902 return fileInfo(file
.local());
2906 MakefileGenerator::findFileForDep(const QMakeLocalFileName
&dep
, const QMakeLocalFileName
&file
)
2908 QMakeLocalFileName ret
;
2909 if(!project
->isEmpty("SKIP_DEPENDS")) {
2911 QStringList
&nodeplist
= project
->values("SKIP_DEPENDS");
2912 for(QStringList::Iterator it
= nodeplist
.begin();
2913 it
!= nodeplist
.end(); ++it
) {
2914 QRegExp
regx((*it
));
2915 if(regx
.indexIn(dep
.local()) != -1) {
2924 ret
= QMakeSourceFileInfo::findFileForDep(dep
, file
);
2928 //these are some "hacky" heuristics it will try to do on an include
2929 //however these can be turned off at runtime, I'm not sure how
2930 //reliable these will be, most likely when problems arise turn it off
2931 //and see if they go away..
2932 if(Option::mkfile::do_dep_heuristics
) {
2933 if(depHeuristicsCache
.contains(dep
.real()))
2934 return depHeuristicsCache
[dep
.real()];
2936 if(Option::output_dir
!= qmake_getpwd()
2937 && QDir::isRelativePath(dep
.real())) { //is it from the shadow tree
2938 QList
<QMakeLocalFileName
> depdirs
= QMakeSourceFileInfo::dependencyPaths();
2939 depdirs
.prepend(fileInfo(file
.real()).absoluteDir().path());
2940 QString pwd
= qmake_getpwd();
2941 if(pwd
.at(pwd
.length()-1) != '/')
2943 for(int i
= 0; i
< depdirs
.count(); i
++) {
2944 QString dir
= depdirs
.at(i
).real();
2945 if(!QDir::isRelativePath(dir
) && dir
.startsWith(pwd
))
2946 dir
= dir
.mid(pwd
.length());
2947 if(QDir::isRelativePath(dir
)) {
2948 if(!dir
.endsWith(Option::dir_sep
))
2949 dir
+= Option::dir_sep
;
2950 QString shadow
= fileFixify(dir
+ dep
.local(), pwd
, Option::output_dir
);
2951 if(exists(shadow
)) {
2952 ret
= QMakeLocalFileName(shadow
);
2953 goto found_dep_from_heuristic
;
2958 { //is it from an EXTRA_TARGET
2959 const QString dep_basename
= dep
.local().section(Option::dir_sep
, -1);
2960 QStringList
&qut
= project
->values("QMAKE_EXTRA_TARGETS");
2961 for(QStringList::Iterator it
= qut
.begin(); it
!= qut
.end(); ++it
) {
2962 QString targ
= var((*it
) + ".target");
2965 QString out
= Option::fixPathToTargetOS(targ
);
2966 if(out
== dep
.real() || out
.section(Option::dir_sep
, -1) == dep_basename
) {
2967 ret
= QMakeLocalFileName(out
);
2968 goto found_dep_from_heuristic
;
2972 { //is it from an EXTRA_COMPILER
2973 const QString dep_basename
= dep
.local().section(Option::dir_sep
, -1);
2974 const QStringList
&quc
= project
->values("QMAKE_EXTRA_COMPILERS");
2975 for(QStringList::ConstIterator it
= quc
.begin(); it
!= quc
.end(); ++it
) {
2976 QString tmp_out
= project
->values((*it
) + ".output").first();
2977 if(tmp_out
.isEmpty())
2979 QStringList
&tmp
= project
->values((*it
) + ".input");
2980 for(QStringList::Iterator it2
= tmp
.begin(); it2
!= tmp
.end(); ++it2
) {
2981 QStringList
&inputs
= project
->values((*it2
));
2982 for(QStringList::Iterator input
= inputs
.begin(); input
!= inputs
.end(); ++input
) {
2983 QString out
= Option::fixPathToTargetOS(unescapeFilePath(replaceExtraCompilerVariables(tmp_out
, (*input
), QString())));
2984 if(out
== dep
.real() || out
.section(Option::dir_sep
, -1) == dep_basename
) {
2985 ret
= QMakeLocalFileName(fileFixify(out
, qmake_getpwd(), Option::output_dir
));
2986 goto found_dep_from_heuristic
;
2992 found_dep_from_heuristic
:
2993 depHeuristicsCache
.insert(dep
.real(), ret
);
2999 &MakefileGenerator::findDependencies(const QString
&file
)
3001 const QString fixedFile
= fileFixify(file
);
3002 if(!dependsCache
.contains(fixedFile
)) {
3004 QStringList deps
= QMakeSourceFileInfo::dependencies(file
);
3005 if(file
!= fixedFile
)
3006 deps
+= QMakeSourceFileInfo::dependencies(fixedFile
);
3008 QStringList deps
= QMakeSourceFileInfo::dependencies(fixedFile
);
3010 dependsCache
.insert(fixedFile
, deps
);
3012 return dependsCache
[fixedFile
];
3016 MakefileGenerator::specdir(const QString
&outdir
)
3022 spec
= fileFixify(Option::mkfile::qmakespec
, outdir
);
3027 MakefileGenerator::openOutput(QFile
&file
, const QString
&build
) const
3031 if(!file
.fileName().isEmpty()) {
3032 if(QDir::isRelativePath(file
.fileName()))
3033 file
.setFileName(Option::output_dir
+ "/" + file
.fileName()); //pwd when qmake was run
3034 QFileInfo
fi(fileInfo(file
.fileName()));
3036 outdir
= file
.fileName() + '/';
3038 if(!outdir
.isEmpty() || file
.fileName().isEmpty()) {
3039 QString fname
= "Makefile";
3040 if(!project
->isEmpty("MAKEFILE"))
3041 fname
= project
->first("MAKEFILE");
3042 file
.setFileName(outdir
+ fname
);
3045 if(QDir::isRelativePath(file
.fileName())) {
3046 QString fname
= Option::output_dir
; //pwd when qmake was run
3047 if(!fname
.endsWith("/"))
3049 fname
+= file
.fileName();
3050 file
.setFileName(fname
);
3052 if(!build
.isEmpty())
3053 file
.setFileName(file
.fileName() + "." + build
);
3054 if(project
->isEmpty("QMAKE_MAKEFILE"))
3055 project
->values("QMAKE_MAKEFILE").append(file
.fileName());
3056 int slsh
= file
.fileName().lastIndexOf('/');
3058 mkdir(file
.fileName().left(slsh
));
3059 if(file
.open(QIODevice::WriteOnly
| QIODevice::Text
| QIODevice::Truncate
)) {
3060 QFileInfo
fi(fileInfo(Option::output
.fileName()));
3063 od
= fileInfo(fi
.readLink()).absolutePath();
3066 od
= QDir::fromNativeSeparators(od
);
3067 if(QDir::isRelativePath(od
)) {
3068 QString dir
= Option::output_dir
;
3069 if (!dir
.endsWith('/') && !od
.isEmpty())
3073 Option::output_dir
= od
;