1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "winmakefile.h"
46 #include <qtextstream.h>
50 #include <qstringlist.h>
56 Win32MakefileGenerator::Win32MakefileGenerator() : MakefileGenerator()
61 Win32MakefileGenerator::findHighestVersion(const QString &d, const QString &stem, const QString &ext)
63 QString bd = Option::fixPathToLocalOS(d, true);
67 QMakeMetaInfo libinfo;
68 bool libInfoRead = libinfo.readLib(bd + Option::dir_sep + stem);
70 // If the library, for which we're trying to find the highest version
71 // number, is a static library
72 if (libInfoRead && libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib"))
75 if(!project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").isEmpty())
76 return project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").first().toInt();
79 if(!project->isActiveConfig("no_versionlink")) {
80 static QHash<QString, QStringList> dirEntryListCache;
81 QStringList entries = dirEntryListCache.value(bd);
82 if (entries.isEmpty()) {
84 entries = dir.entryList();
85 dirEntryListCache.insert(bd, entries);
88 QRegExp regx(QString("((lib)?%1([0-9]*)).(%2|prl)$").arg(stem).arg(ext), Qt::CaseInsensitive);
89 for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
90 if(regx.exactMatch((*it))) {
91 if (!regx.cap(3).isEmpty()) {
93 int num = regx.cap(3).toInt(&ok);
94 biggest = qMax(biggest, (!ok ? -1 : num));
100 && !libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib")
101 && !libinfo.isEmpty("QMAKE_PRL_VERSION"))
102 biggest = qMax(biggest, libinfo.first("QMAKE_PRL_VERSION").replace(".", "").toInt());
107 Win32MakefileGenerator::findLibraries()
109 QList<QMakeLocalFileName> dirs;
111 const QStringList &libpaths = project->values("QMAKE_LIBDIR");
112 for (QStringList::ConstIterator libpathit = libpaths.begin();
113 libpathit != libpaths.end(); ++libpathit)
114 dirs.append(QMakeLocalFileName((*libpathit)));
116 const QString lflags[] = { "QMAKE_LIBS", "QMAKE_LIBS_PRIVATE", QString() };
117 for (int i = 0; !lflags[i].isNull(); i++) {
118 QStringList &l = project->values(lflags[i]);
119 for(QStringList::Iterator it = l.begin(); it != l.end();) {
121 bool modified_opt = false, remove = false;
122 QString opt = (*it).trimmed();
123 if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0]) {
125 opt = opt.mid(1, opt.length()-2);
127 if(opt.startsWith("/LIBPATH:")) {
128 dirs.append(QMakeLocalFileName(opt.mid(9)));
129 } else if(opt.startsWith("-L") || opt.startsWith("/L")) {
130 QString libpath = opt.mid(2);
131 QMakeLocalFileName l(libpath);
132 if(!dirs.contains(l)) {
135 if (!quote.isNull()) {
136 libpath = quote + libpath + quote;
139 (*it) = "/LIBPATH:" + libpath;
143 } else if(opt.startsWith("-l") || opt.startsWith("/l")) {
144 QString lib = opt.right(opt.length() - 2), out;
147 if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX"))
148 suffix = project->first("QMAKE_" + lib.toUpper() + "_SUFFIX");
149 for(QList<QMakeLocalFileName>::Iterator it = dirs.begin();
150 it != dirs.end(); ++it) {
152 int ver = findHighestVersion((*it).local(), lib);
154 extension += QString::number(ver);
157 if(QMakeMetaInfo::libExists((*it).local() + Option::dir_sep + lib) ||
158 exists((*it).local() + Option::dir_sep + lib + extension)) {
159 out = (*it).real() + Option::dir_sep + lib + extension;
160 if (out.contains(QLatin1Char(' '))) {
161 out.prepend(QLatin1Char('\"'));
162 out.append(QLatin1Char('\"'));
172 } else if(!exists(Option::fixPathToLocalOS(opt))) {
173 QList<QMakeLocalFileName> lib_dirs;
175 int slsh = file.lastIndexOf(Option::dir_sep);
177 lib_dirs.append(QMakeLocalFileName(file.left(slsh+1)));
178 file = file.right(file.length() - slsh - 1);
182 if(file.endsWith(".lib")) {
183 file = file.left(file.length() - 4);
184 if(!file.at(file.length()-1).isNumber()) {
186 if(!project->isEmpty("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX"))
187 suffix = project->first("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX");
188 for(QList<QMakeLocalFileName>::Iterator dep_it = lib_dirs.begin(); dep_it != lib_dirs.end(); ++dep_it) {
189 QString lib_tmpl(file + "%1" + suffix + ".lib");
190 int ver = findHighestVersion((*dep_it).local(), file);
193 lib_tmpl = lib_tmpl.arg(ver);
195 lib_tmpl = lib_tmpl.arg("");
197 QString dir = (*dep_it).real();
198 if(!dir.endsWith(Option::dir_sep))
199 dir += Option::dir_sep;
200 lib_tmpl.prepend(dir);
213 if(!quote.isNull() && modified_opt)
214 (*it) = quote + (*it) + quote;
223 Win32MakefileGenerator::processPrlFiles()
225 QHash<QString, bool> processed;
226 QList<QMakeLocalFileName> libdirs;
228 const QStringList &libpaths = project->values("QMAKE_LIBDIR");
229 for (QStringList::ConstIterator libpathit = libpaths.begin(); libpathit != libpaths.end(); ++libpathit)
230 libdirs.append(QMakeLocalFileName((*libpathit)));
232 for(bool ret = false; true; ret = false) {
233 //read in any prl files included..
235 QStringList l = project->values("QMAKE_LIBS");
236 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
237 QString opt = (*it).trimmed();
238 if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0])
239 opt = opt.mid(1, opt.length()-2);
240 if(opt.startsWith("/")) {
241 if(opt.startsWith("/LIBPATH:")) {
242 QMakeLocalFileName l(opt.mid(9));
243 if(!libdirs.contains(l))
246 } else if(!processed.contains(opt)) {
247 if(processPrlFile(opt)) {
248 processed.insert(opt, true);
250 } else if(QDir::isRelativePath(opt) || opt.startsWith("-l")) {
252 if (opt.startsWith("-l"))
256 for(QList<QMakeLocalFileName>::Iterator it = libdirs.begin(); it != libdirs.end(); ++it) {
257 QString prl = (*it).local() + Option::dir_sep + tmp;
258 // the original is used as the key
259 QString orgprl = prl;
260 if(processed.contains(prl)) {
262 } else if(processPrlFile(prl)) {
263 processed.insert(orgprl, true);
281 void Win32MakefileGenerator::processVars()
283 //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET
284 if(!project->isEmpty("TARGET")) {
285 QString targ = project->first("TARGET");
286 int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep));
288 if(project->isEmpty("DESTDIR"))
289 project->values("DESTDIR").append("");
290 else if(project->first("DESTDIR").right(1) != Option::dir_sep)
291 project->values("DESTDIR") = QStringList(project->first("DESTDIR") + Option::dir_sep);
292 project->values("DESTDIR") = QStringList(project->first("DESTDIR") + targ.left(slsh+1));
293 project->values("TARGET") = QStringList(targ.mid(slsh+1));
297 project->values("QMAKE_ORIG_TARGET") = project->values("TARGET");
298 if (project->isEmpty("QMAKE_PROJECT_NAME"))
299 project->values("QMAKE_PROJECT_NAME") = project->values("QMAKE_ORIG_TARGET");
300 else if (project->first("TEMPLATE").startsWith("vc"))
301 project->values("MAKEFILE") = project->values("QMAKE_PROJECT_NAME");
303 if (!project->values("QMAKE_INCDIR").isEmpty())
304 project->values("INCLUDEPATH") += project->values("QMAKE_INCDIR");
306 if (!project->values("VERSION").isEmpty()) {
307 QStringList l = project->first("VERSION").split('.');
309 project->values("VER_MAJ").append(l[0]);
311 project->values("VER_MIN").append(l[1]);
314 // TARGET_VERSION_EXT will be used to add a version number onto the target name
315 if (project->values("TARGET_VERSION_EXT").isEmpty()
316 && !project->values("VER_MAJ").isEmpty())
317 project->values("TARGET_VERSION_EXT").append(project->values("VER_MAJ").first());
319 if(project->isEmpty("QMAKE_COPY_FILE"))
320 project->values("QMAKE_COPY_FILE").append("$(COPY)");
321 if(project->isEmpty("QMAKE_COPY_DIR"))
322 project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
323 if(project->isEmpty("QMAKE_INSTALL_FILE"))
324 project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
325 if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
326 project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
327 if(project->isEmpty("QMAKE_INSTALL_DIR"))
328 project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
332 processFileTagsVar();
334 QStringList &incDir = project->values("INCLUDEPATH");
335 for(QStringList::Iterator incDir_it = incDir.begin(); incDir_it != incDir.end(); ++incDir_it) {
336 if(!(*incDir_it).isEmpty())
337 (*incDir_it) = Option::fixPathToTargetOS((*incDir_it), false, false);
339 QStringList &libDir = project->values("QMAKE_LIBDIR");
340 for(QStringList::Iterator libDir_it = libDir.begin(); libDir_it != libDir.end(); ++libDir_it) {
341 if(!(*libDir_it).isEmpty())
342 (*libDir_it) = Option::fixPathToTargetOS((*libDir_it), false, false);
345 if (project->values("TEMPLATE").contains("app")) {
346 project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_APP");
347 project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_APP");
348 project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_APP");
349 } else if (project->values("TEMPLATE").contains("lib") && project->isActiveConfig("dll")) {
350 if(!project->isActiveConfig("plugin") || !project->isActiveConfig("plugin_no_share_shlib_cflags")) {
351 project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_SHLIB");
352 project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_SHLIB");
354 if (project->isActiveConfig("plugin")) {
355 project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_PLUGIN");
356 project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_PLUGIN");
357 project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_PLUGIN");
359 project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SHLIB");
364 void Win32MakefileGenerator::fixTargetExt()
366 if (project->isEmpty("QMAKE_EXTENSION_STATICLIB"))
367 project->values("QMAKE_EXTENSION_STATICLIB").append("lib");
368 if (project->isEmpty("QMAKE_EXTENSION_SHLIB"))
369 project->values("QMAKE_EXTENSION_SHLIB").append("dll");
371 if (!project->values("QMAKE_APP_FLAG").isEmpty()) {
372 project->values("TARGET_EXT").append(".exe");
373 } else if (project->isActiveConfig("shared")) {
374 project->values("TARGET_EXT").append(project->first("TARGET_VERSION_EXT") + "."
375 + project->first("QMAKE_EXTENSION_SHLIB"));
376 project->values("TARGET").first() = project->first("QMAKE_PREFIX_SHLIB") + project->first("TARGET");
378 project->values("TARGET_EXT").append("." + project->first("QMAKE_EXTENSION_STATICLIB"));
379 project->values("TARGET").first() = project->first("QMAKE_PREFIX_STATICLIB") + project->first("TARGET");
383 void Win32MakefileGenerator::processRcFileVar()
385 if (Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
388 if (((!project->values("VERSION").isEmpty())
389 && project->values("RC_FILE").isEmpty()
390 && project->values("RES_FILE").isEmpty()
391 && !project->isActiveConfig("no_generated_target_info")
392 && (project->isActiveConfig("shared") || !project->values("QMAKE_APP_FLAG").isEmpty()))
393 || !project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty()){
396 QTextStream ts(&rcString, QFile::WriteOnly);
398 QStringList vers = project->values("VERSION").first().split(".");
399 for (int i = vers.size(); i < 4; i++)
401 QString versionString = vers.join(".");
404 if (!project->values("QMAKE_TARGET_COMPANY").isEmpty())
405 companyName = project->values("QMAKE_TARGET_COMPANY").join(" ");
408 if (!project->values("QMAKE_TARGET_DESCRIPTION").isEmpty())
409 description = project->values("QMAKE_TARGET_DESCRIPTION").join(" ");
412 if (!project->values("QMAKE_TARGET_COPYRIGHT").isEmpty())
413 copyright = project->values("QMAKE_TARGET_COPYRIGHT").join(" ");
416 if (!project->values("QMAKE_TARGET_PRODUCT").isEmpty())
417 productName = project->values("QMAKE_TARGET_PRODUCT").join(" ");
419 productName = project->values("TARGET").first();
421 QString originalName = project->values("TARGET").first() + project->values("TARGET_EXT").first();
422 int rcLang = project->intValue("RC_LANG", 1033); // default: English(USA)
423 int rcCodePage = project->intValue("RC_CODEPAGE", 1200); // default: Unicode
425 ts << "# if defined(UNDER_CE)" << endl;
426 ts << "# include <winbase.h>" << endl;
427 ts << "# else" << endl;
428 ts << "# include <winver.h>" << endl;
429 ts << "# endif" << endl;
431 ts << "VS_VERSION_INFO VERSIONINFO" << endl;
432 ts << "\tFILEVERSION " << QString(versionString).replace(".", ",") << endl;
433 ts << "\tPRODUCTVERSION " << QString(versionString).replace(".", ",") << endl;
434 ts << "\tFILEFLAGSMASK 0x3fL" << endl;
435 ts << "#ifdef _DEBUG" << endl;
436 ts << "\tFILEFLAGS VS_FF_DEBUG" << endl;
437 ts << "#else" << endl;
438 ts << "\tFILEFLAGS 0x0L" << endl;
439 ts << "#endif" << endl;
440 ts << "\tFILEOS VOS__WINDOWS32" << endl;
441 if (project->isActiveConfig("shared"))
442 ts << "\tFILETYPE VFT_DLL" << endl;
444 ts << "\tFILETYPE VFT_APP" << endl;
445 ts << "\tFILESUBTYPE 0x0L" << endl;
446 ts << "\tBEGIN" << endl;
447 ts << "\t\tBLOCK \"StringFileInfo\"" << endl;
448 ts << "\t\tBEGIN" << endl;
449 ts << "\t\t\tBLOCK \""
450 << QString("%1%2").arg(rcLang, 4, 16, QLatin1Char('0')).arg(rcCodePage, 4, 16, QLatin1Char('0'))
452 ts << "\t\t\tBEGIN" << endl;
453 ts << "\t\t\t\tVALUE \"CompanyName\", \"" << companyName << "\\0\"" << endl;
454 ts << "\t\t\t\tVALUE \"FileDescription\", \"" << description << "\\0\"" << endl;
455 ts << "\t\t\t\tVALUE \"FileVersion\", \"" << versionString << "\\0\"" << endl;
456 ts << "\t\t\t\tVALUE \"LegalCopyright\", \"" << copyright << "\\0\"" << endl;
457 ts << "\t\t\t\tVALUE \"OriginalFilename\", \"" << originalName << "\\0\"" << endl;
458 ts << "\t\t\t\tVALUE \"ProductName\", \"" << productName << "\\0\"" << endl;
459 ts << "\t\t\tEND" << endl;
460 ts << "\t\tEND" << endl;
461 ts << "\t\tBLOCK \"VarFileInfo\"" << endl;
462 ts << "\t\tBEGIN" << endl;
463 ts << "\t\t\tVALUE \"Translation\", "
464 << QString("0x%1").arg(rcLang, 4, 16, QLatin1Char('0'))
465 << ", " << QString("%1").arg(rcCodePage, 4) << endl;
466 ts << "\t\tEND" << endl;
467 ts << "\t\tBLOCK \"VarFileInfo\"" << endl;
468 ts << "\t\tBEGIN" << endl;
469 ts << "\t\t\tVALUE \"Translation\", 0x409, 1200" << endl;
470 ts << "\t\tEND" << endl;
471 ts << "\tEND" << endl;
472 ts << "/* End of Version info */" << endl;
478 QString rcFilename = project->values("OUT_PWD").first()
480 + project->values("TARGET").first()
483 QFile rcFile(QDir::cleanPath(rcFilename));
485 bool writeRcFile = true;
486 if (rcFile.exists() && rcFile.open(QFile::ReadOnly)) {
487 writeRcFile = rcFile.readAll() != rcString;
492 ok = rcFile.open(QFile::WriteOnly);
494 // The file can't be opened... try creating the containing
495 // directory first (needed for clean shadow builds)
496 QDir().mkpath(QFileInfo(rcFile).path());
497 ok = rcFile.open(QFile::WriteOnly);
500 ::fprintf(stderr, "Cannot open for writing: %s", rcFile.fileName().toLatin1().constData());
503 rcFile.write(rcString);
506 if (project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty())
507 project->values("RC_FILE").insert(0, rcFile.fileName());
509 if (!project->values("RC_FILE").isEmpty()) {
510 if (!project->values("RES_FILE").isEmpty()) {
511 fprintf(stderr, "Both rc and res file specified.\n");
512 fprintf(stderr, "Please specify one of them, not both.");
515 QString resFile = project->values("RC_FILE").first();
517 // if this is a shadow build then use the absolute path of the rc file
518 if (Option::output_dir != qmake_getpwd()) {
519 QFileInfo fi(resFile);
520 project->values("RC_FILE").first() = fi.absoluteFilePath();
523 resFile.replace(".rc", Option::res_ext);
524 project->values("RES_FILE").prepend(fileInfo(resFile).fileName());
525 if (!project->values("OBJECTS_DIR").isEmpty()) {
527 if (project->isActiveConfig("staticlib"))
528 resDestDir = fileInfo(project->first("DESTDIR")).absoluteFilePath();
530 resDestDir = project->first("OBJECTS_DIR");
531 resDestDir.append(Option::dir_sep);
532 project->values("RES_FILE").first().prepend(resDestDir);
534 project->values("RES_FILE").first() = Option::fixPathToTargetOS(project->values("RES_FILE").first(), false, false);
535 project->values("POST_TARGETDEPS") += project->values("RES_FILE");
536 project->values("CLEAN_FILES") += project->values("RES_FILE");
540 void Win32MakefileGenerator::processFileTagsVar()
543 tags << "SOURCES" << "GENERATED_SOURCES" << "DEF_FILE" << "RC_FILE"
544 << "TARGET" << "QMAKE_LIBS" << "DESTDIR" << "DLLDESTDIR" << "INCLUDEPATH";
545 if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
546 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
547 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it)
548 tags += project->values((*it)+".input");
552 QStringList &filetags = project->values("QMAKE_FILETAGS");
553 for(int i = 0; i < tags.size(); ++i)
554 filetags += Option::fixPathToTargetOS(tags.at(i), false);
557 void Win32MakefileGenerator::writeCleanParts(QTextStream &t)
559 t << "clean: compiler_clean " << var("CLEAN_DEPS");
561 const char *clean_targets[] = { "OBJECTS", "QMAKE_CLEAN", "CLEAN_FILES", 0 };
562 for(int i = 0; clean_targets[i]; ++i) {
563 const QStringList &list = project->values(clean_targets[i]);
564 const QString del_statement("-$(DEL_FILE)");
565 if(project->isActiveConfig("no_delete_multiple_files")) {
566 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
567 t << "\n\t" << del_statement << " " << escapeFilePath((*it));
570 const int commandlineLimit = 2047; // NT limit, expanded
571 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
572 file = " " + escapeFilePath((*it));
573 if(del_statement.length() + files.length() +
574 qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
575 t << "\n\t" << del_statement << files;
581 t << "\n\t" << del_statement << files;
587 t << "distclean: clean";
589 const char *clean_targets[] = { "QMAKE_DISTCLEAN", 0 };
590 for(int i = 0; clean_targets[i]; ++i) {
591 const QStringList &list = project->values(clean_targets[i]);
592 const QString del_statement("-$(DEL_FILE)");
593 if(project->isActiveConfig("no_delete_multiple_files")) {
594 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
595 t << "\n\t" << del_statement << " "
596 << escapeFilePath(Option::fixPathToTargetOS(*it));
599 const int commandlineLimit = 2047; // NT limit, expanded
600 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
601 file = " " + escapeFilePath(Option::fixPathToTargetOS(*it));
602 if(del_statement.length() + files.length() +
603 qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
604 t << "\n\t" << del_statement << files;
610 t << "\n\t" << del_statement << files;
614 t << "\n\t-$(DEL_FILE) $(DESTDIR_TARGET)" << endl;
616 QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
618 t << "\t-$(DEL_FILE) " << ofile << endl;
623 void Win32MakefileGenerator::writeIncPart(QTextStream &t)
627 const QStringList &incs = project->values("INCLUDEPATH");
628 for(int i = 0; i < incs.size(); ++i) {
629 QString inc = incs.at(i);
630 inc.replace(QRegExp("\\\\$"), "");
631 inc.replace(QRegExp("\""), "");
633 t << "-I" << "\"" << inc << "\" ";
635 t << "-I\"" << specdir() << "\""
639 void Win32MakefileGenerator::writeStandardParts(QTextStream &t)
641 t << "####### Compiler, tools and options" << endl << endl;
642 t << "CC = " << var("QMAKE_CC") << endl;
643 t << "CXX = " << var("QMAKE_CXX") << endl;
645 << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
646 << varGlue("DEFINES","-D"," -D","") << endl;
647 t << "CFLAGS = " << var("QMAKE_CFLAGS") << " $(DEFINES)" << endl;
648 t << "CXXFLAGS = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)" << endl;
653 t << "QMAKE = " << var("QMAKE_QMAKE") << endl;
654 t << "IDC = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
655 Option::fixPathToTargetOS(var("QMAKE_IDC"), false)) << endl;
656 t << "IDL = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
657 Option::fixPathToTargetOS(var("QMAKE_IDL"), false)) << endl;
658 t << "ZIP = " << var("QMAKE_ZIP") << endl;
659 t << "DEF_FILE = " << varList("DEF_FILE") << endl;
660 t << "RES_FILE = " << varList("RES_FILE") << endl; // Not on mingw, can't see why not though...
661 t << "COPY = " << var("QMAKE_COPY") << endl;
662 t << "SED = " << var("QMAKE_STREAM_EDITOR") << endl;
663 t << "COPY_FILE = " << var("QMAKE_COPY_FILE") << endl;
664 t << "COPY_DIR = " << var("QMAKE_COPY_DIR") << endl;
665 t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl;
666 t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl;
667 t << "MOVE = " << var("QMAKE_MOVE") << endl;
668 t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl;
669 t << "MKDIR = " << var("QMAKE_MKDIR") << endl;
670 t << "INSTALL_FILE = " << var("QMAKE_INSTALL_FILE") << endl;
671 t << "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl;
672 t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl;
675 t << "####### Output directory" << endl << endl;
676 if(!project->values("OBJECTS_DIR").isEmpty())
677 t << "OBJECTS_DIR = " << var("OBJECTS_DIR").replace(QRegExp("\\\\$"),"") << endl;
679 t << "OBJECTS_DIR = . " << endl;
682 t << "####### Files" << endl << endl;
683 t << "SOURCES = " << valList(escapeFilePaths(project->values("SOURCES")))
684 << " " << valList(escapeFilePaths(project->values("GENERATED_SOURCES"))) << endl;
686 // do this here so we can set DEST_TARGET to be the complete path to the final target if it is needed.
687 QString orgDestDir = var("DESTDIR");
688 QString destDir = Option::fixPathToTargetOS(orgDestDir, false);
689 if (!destDir.isEmpty() && (orgDestDir.endsWith('/') || orgDestDir.endsWith(Option::dir_sep)))
690 destDir += Option::dir_sep;
691 QString target = QString(project->first("TARGET")+project->first("TARGET_EXT"));
693 project->values("DEST_TARGET").prepend(destDir + target);
697 writeExtraCompilerVariables(t);
698 writeExtraVariables(t);
700 t << "DIST = " << varList("DISTFILES") << endl;
701 t << "QMAKE_TARGET = " << var("QMAKE_ORIG_TARGET") << endl;
702 // The comment is important to maintain variable compatibility with Unix
703 // Makefiles, while not interpreting a trailing-slash as a linebreak
704 t << "DESTDIR = " << escapeFilePath(destDir) << " #avoid trailing-slash linebreak" << endl;
705 t << "TARGET = " << escapeFilePath(target) << endl;
706 t << "DESTDIR_TARGET = " << escapeFilePath(var("DEST_TARGET")) << endl;
709 t << "####### Implicit rules" << endl << endl;
710 writeImplicitRulesPart(t);
712 t << "####### Build rules" << endl << endl;
713 writeBuildRulesPart(t);
715 if(project->isActiveConfig("shared") && !project->values("DLLDESTDIR").isEmpty()) {
716 QStringList dlldirs = project->values("DLLDESTDIR");
717 for (QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
718 t << "\t" << "-$(COPY_FILE) \"$(DESTDIR_TARGET)\" " << Option::fixPathToTargetOS(*dlldir, false) << endl;
727 QStringList dist_files = fileFixify(Option::mkfile::project_files);
728 if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES"))
729 dist_files += project->values("QMAKE_INTERNAL_INCLUDED_FILES");
730 if(!project->isEmpty("TRANSLATIONS"))
731 dist_files << var("TRANSLATIONS");
732 if(!project->isEmpty("FORMS")) {
733 const QStringList &forms = project->values("FORMS");
734 for (QStringList::ConstIterator formit = forms.begin(); formit != forms.end(); ++formit) {
735 QString ui_h = fileFixify((*formit) + Option::h_ext.first());
740 t << "dist:" << "\n\t"
741 << "$(ZIP) " << var("QMAKE_ORIG_TARGET") << ".zip " << "$(SOURCES) $(DIST) "
742 << dist_files.join(" ") << " " << var("TRANSLATIONS") << " ";
743 if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
744 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
745 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
746 const QStringList &inputs = project->values((*it)+".input");
747 for(QStringList::ConstIterator input = inputs.begin(); input != inputs.end(); ++input) {
748 t << (*input) << " ";
755 writeExtraTargets(t);
756 writeExtraCompilerTargets(t);
760 void Win32MakefileGenerator::writeLibsPart(QTextStream &t)
762 if(project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") {
763 t << "LIBAPP = " << var("QMAKE_LIB") << endl;
764 t << "LIBFLAGS = " << var("QMAKE_LIBFLAGS") << endl;
766 t << "LINK = " << var("QMAKE_LINK") << endl;
767 t << "LFLAGS = " << var("QMAKE_LFLAGS") << endl;
769 if(!project->values("QMAKE_LIBDIR").isEmpty())
771 t << var("QMAKE_LIBS") << " " << var("QMAKE_LIBS_PRIVATE") << endl;
775 void Win32MakefileGenerator::writeLibDirPart(QTextStream &t)
777 QStringList libDirs = project->values("QMAKE_LIBDIR");
778 for (int i = 0; i < libDirs.size(); ++i)
779 libDirs[i].remove("\"");
780 t << valGlue(libDirs,"-L\"","\" -L\"","\"") << " ";
783 void Win32MakefileGenerator::writeObjectsPart(QTextStream &t)
785 t << "OBJECTS = " << valList(escapeDependencyPaths(project->values("OBJECTS"))) << endl;
788 void Win32MakefileGenerator::writeImplicitRulesPart(QTextStream &t)
791 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
792 t << " " << (*cppit);
793 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
796 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
797 t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
798 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
799 t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
802 void Win32MakefileGenerator::writeBuildRulesPart(QTextStream &)
806 void Win32MakefileGenerator::writeRcFilePart(QTextStream &t)
808 if(!project->values("RC_FILE").isEmpty()) {
809 const QString res_file = project->first("RES_FILE"),
810 rc_file = fileFixify(project->first("RC_FILE"));
811 // The resource tool needs to have the same defines passed in as the compiler, since you may
812 // use these defines in the .rc file itself. Also, we need to add the _DEBUG define manually
813 // since the compiler defines this symbol by itself, and we use it in the automatically
814 // created rc file when VERSION is define the .pro file.
815 t << res_file << ": " << rc_file << "\n\t"
816 << var("QMAKE_RC") << (project->isActiveConfig("debug") ? " -D_DEBUG" : "") << " $(DEFINES) -fo " << res_file << " " << rc_file;
821 QString Win32MakefileGenerator::getLibTarget()
823 return QString(project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".lib");
826 QString Win32MakefileGenerator::defaultInstall(const QString &t)
828 if((t != "target" && t != "dlltarget") ||
829 (t == "dlltarget" && (project->first("TEMPLATE") != "lib" || !project->isActiveConfig("shared"))) ||
830 project->first("TEMPLATE") == "subdirs")
833 const QString root = "$(INSTALL_ROOT)";
834 QStringList &uninst = project->values(t + ".uninstall");
836 QString targetdir = Option::fixPathToTargetOS(project->first(t + ".path"), false);
837 targetdir = fileFixify(targetdir, FileFixifyAbsolute);
838 if(targetdir.right(1) != Option::dir_sep)
839 targetdir += Option::dir_sep;
841 if(t == "target" && project->first("TEMPLATE") == "lib") {
842 if(project->isActiveConfig("create_prl") && !project->isActiveConfig("no_install_prl") &&
843 !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) {
844 QString dst_prl = Option::fixPathToTargetOS(project->first("QMAKE_INTERNAL_PRL_FILE"));
845 int slsh = dst_prl.lastIndexOf(Option::dir_sep);
847 dst_prl = dst_prl.right(dst_prl.length() - slsh - 1);
848 dst_prl = filePrefixRoot(root, targetdir + dst_prl);
849 ret += "-$(INSTALL_FILE) \"" + project->first("QMAKE_INTERNAL_PRL_FILE") + "\" \"" + dst_prl + "\"";
850 if(!uninst.isEmpty())
851 uninst.append("\n\t");
852 uninst.append("-$(DEL_FILE) \"" + dst_prl + "\"");
854 if(project->isActiveConfig("create_pc")) {
855 QString dst_pc = pkgConfigFileName(false);
856 if (!dst_pc.isEmpty()) {
857 dst_pc = filePrefixRoot(root, targetdir + dst_pc);
858 const QString dst_pc_dir = fileInfo(dst_pc).path();
859 if (!dst_pc_dir.isEmpty()) {
862 ret += mkdir_p_asstring(dst_pc_dir, true);
866 const QString replace_rule("QMAKE_PKGCONFIG_INSTALL_REPLACE");
867 if (project->isEmpty(replace_rule)
868 || project->isActiveConfig("no_sed_meta_install")
869 || project->isEmpty("QMAKE_STREAM_EDITOR")) {
870 ret += "-$(INSTALL_FILE) \"" + pkgConfigFileName(true) + "\" \"" + dst_pc + "\"";
873 QStringList replace_rules = project->values(replace_rule);
874 for (int r = 0; r < replace_rules.size(); ++r) {
875 const QString match = project->first(replace_rules.at(r) + ".match"),
876 replace = project->first(replace_rules.at(r) + ".replace");
877 if (!match.isEmpty() /*&& match != replace*/)
878 ret += " -e \"s," + match + "," + replace + ",g\"";
880 ret += " \"" + pkgConfigFileName(true) + "\" >\"" + dst_pc + "\"";
882 if(!uninst.isEmpty())
883 uninst.append("\n\t");
884 uninst.append("-$(DEL_FILE) \"" + dst_pc + "\"");
887 if(project->isActiveConfig("shared") && !project->isActiveConfig("plugin")) {
888 QString lib_target = getLibTarget();
889 lib_target.remove('"');
890 QString src_targ = (project->isEmpty("DESTDIR") ? QString("$(DESTDIR)") : project->first("DESTDIR")) + lib_target;
891 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + lib_target, FileFixifyAbsolute));
894 ret += QString("-$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
895 if(!uninst.isEmpty())
896 uninst.append("\n\t");
897 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
901 if(t == "dlltarget" || project->values(t + ".CONFIG").indexOf("no_dll") == -1) {
902 QString src_targ = "$(DESTDIR_TARGET)";
903 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + "$(TARGET)", FileFixifyAbsolute));
906 ret += QString("-$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
907 if(!uninst.isEmpty())
908 uninst.append("\n\t");
909 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
914 QString Win32MakefileGenerator::escapeFilePath(const QString &path) const
918 ret = unescapeFilePath(ret);
919 if(ret.contains(" "))
920 ret = "\"" + ret + "\"";
921 debug_msg(2, "EscapeFilePath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData());