source: trunk/qmake/generators/win32/winmakefile.cpp@ 896

Last change on this file since 896 was 896, checked in by Dmitry A. Kuminov, 14 years ago

qmake: os2/gnumake: Don't try to install .pdb files.

File size: 36.9 KB
RevLine 
[2]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[561]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
[2]6**
7** This file is part of the qmake application of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
[561]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.
[2]27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
[561]36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
[2]38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "winmakefile.h"
43#include "option.h"
44#include "project.h"
45#include "meta.h"
46#include <qtextstream.h>
47#include <qstring.h>
48#include <qhash.h>
49#include <qregexp.h>
50#include <qstringlist.h>
51#include <qdir.h>
52#include <stdlib.h>
53
54QT_BEGIN_NAMESPACE
55
56Win32MakefileGenerator::Win32MakefileGenerator() : MakefileGenerator()
57{
58}
59
60int
61Win32MakefileGenerator::findHighestVersion(const QString &d, const QString &stem, const QString &ext)
62{
63 QString bd = Option::fixPathToLocalOS(d, true);
64 if(!exists(bd))
65 return -1;
66
67 QString dllStem = stem + QTDLL_POSTFIX;
68 QMakeMetaInfo libinfo;
69 bool libInfoRead = libinfo.readLib(bd + Option::dir_sep + dllStem);
70
71 // If the library, for which we're trying to find the highest version
72 // number, is a static library
73 if (libInfoRead && libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib"))
74 return -1;
75
76 if(!project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").isEmpty())
77 return project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").first().toInt();
78
79 int biggest=-1;
80 if(!project->isActiveConfig("no_versionlink")) {
81 QDir dir(bd);
82 QStringList entries = dir.entryList();
83 QRegExp regx(QString("((lib)?%1([0-9]*)).(%2|prl)$").arg(dllStem).arg(ext), Qt::CaseInsensitive);
84 for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
85 if(regx.exactMatch((*it))) {
86 if (!regx.cap(3).isEmpty()) {
87 bool ok = true;
88 int num = regx.cap(3).toInt(&ok);
89 biggest = qMax(biggest, (!ok ? -1 : num));
90 }
91 }
92 }
93 }
94 if(libInfoRead
95 && !libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib")
96 && !libinfo.isEmpty("QMAKE_PRL_VERSION"))
97 biggest = qMax(biggest, libinfo.first("QMAKE_PRL_VERSION").replace(".", "").toInt());
98 return biggest;
99}
100
101bool
102Win32MakefileGenerator::findLibraries(const QString &where)
103{
104 QStringList &l = project->values(where);
105 QList<QMakeLocalFileName> dirs;
106 {
107 QStringList &libpaths = project->values("QMAKE_LIBDIR");
108 for(QStringList::Iterator libpathit = libpaths.begin();
109 libpathit != libpaths.end(); ++libpathit)
110 dirs.append(QMakeLocalFileName((*libpathit)));
111 }
112 for(QStringList::Iterator it = l.begin(); it != l.end();) {
113 QChar quote;
114 bool modified_opt = false, remove = false;
115 QString opt = (*it).trimmed();
116 if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0]) {
117 quote = opt[0];
118 opt = opt.mid(1, opt.length()-2);
119 }
120 if(opt.startsWith("/LIBPATH:")) {
121 dirs.append(QMakeLocalFileName(opt.mid(9)));
122 } else if(opt.startsWith("-L") || opt.startsWith("/L")) {
123 QString libpath = opt.mid(2);
124 QMakeLocalFileName l(libpath);
125 if(!dirs.contains(l)) {
126 dirs.append(l);
127 modified_opt = true;
128 if (!quote.isNull()) {
129 libpath = quote + libpath + quote;
130 quote = QChar();
131 }
132 (*it) = "/LIBPATH:" + libpath;
133 } else {
134 remove = true;
135 }
136 } else if(opt.startsWith("-l") || opt.startsWith("/l")) {
137 QString lib = opt.right(opt.length() - 2), out;
138 if(!lib.isEmpty()) {
139 QString suffix;
140 if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX"))
141 suffix = project->first("QMAKE_" + lib.toUpper() + "_SUFFIX");
142 for(QList<QMakeLocalFileName>::Iterator it = dirs.begin();
143 it != dirs.end(); ++it) {
144 QString extension;
145 int ver = findHighestVersion((*it).local(), lib);
146 if(ver > 0)
147 extension += QString::number(ver);
148 extension += suffix;
149 extension += ".lib";
150 if(QMakeMetaInfo::libExists((*it).local() + Option::dir_sep + lib) ||
151 exists((*it).local() + Option::dir_sep + lib + extension)) {
152 out = (*it).real() + Option::dir_sep + lib + extension;
[769]153 if (out.contains(QLatin1Char(' '))) {
154 out.prepend(QLatin1Char('\"'));
155 out.append(QLatin1Char('\"'));
156 }
[2]157 break;
158 }
159 }
160 }
161 if(out.isEmpty())
162 out = lib + ".lib";
163 modified_opt = true;
164 (*it) = out;
165 } else if(!exists(Option::fixPathToLocalOS(opt))) {
166 QList<QMakeLocalFileName> lib_dirs;
167 QString file = opt;
168 int slsh = file.lastIndexOf(Option::dir_sep);
169 if(slsh != -1) {
170 lib_dirs.append(QMakeLocalFileName(file.left(slsh+1)));
171 file = file.right(file.length() - slsh - 1);
172 } else {
173 lib_dirs = dirs;
174 }
175 if(file.endsWith(".lib")) {
176 file = file.left(file.length() - 4);
177 if(!file.at(file.length()-1).isNumber()) {
178 QString suffix;
179 if(!project->isEmpty("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX"))
180 suffix = project->first("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX");
181 for(QList<QMakeLocalFileName>::Iterator dep_it = lib_dirs.begin(); dep_it != lib_dirs.end(); ++dep_it) {
182 QString lib_tmpl(file + "%1" + suffix + ".lib");
183 int ver = findHighestVersion((*dep_it).local(), file);
184 if(ver != -1) {
185 if(ver)
186 lib_tmpl = lib_tmpl.arg(ver);
187 else
188 lib_tmpl = lib_tmpl.arg("");
189 if(slsh != -1) {
190 QString dir = (*dep_it).real();
191 if(!dir.endsWith(Option::dir_sep))
192 dir += Option::dir_sep;
193 lib_tmpl.prepend(dir);
194 }
195 modified_opt = true;
196 (*it) = lib_tmpl;
197 break;
198 }
199 }
200 }
201 }
202 }
203 if(remove) {
204 it = l.erase(it);
205 } else {
206 if(!quote.isNull() && modified_opt)
207 (*it) = quote + (*it) + quote;
208 ++it;
209 }
210 }
211 return true;
212}
213
214void
215Win32MakefileGenerator::processPrlFiles()
216{
217 QHash<QString, bool> processed;
218 QList<QMakeLocalFileName> libdirs;
219 {
220 QStringList &libpaths = project->values("QMAKE_LIBDIR");
221 for(QStringList::Iterator libpathit = libpaths.begin(); libpathit != libpaths.end(); ++libpathit)
222 libdirs.append(QMakeLocalFileName((*libpathit)));
223 }
224 for(bool ret = false; true; ret = false) {
225 //read in any prl files included..
226 QStringList l_out;
227 QString where = "QMAKE_LIBS";
228 if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
229 where = project->first("QMAKE_INTERNAL_PRL_LIBS");
230 QStringList l = project->values(where);
231 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
232 QString opt = (*it).trimmed();
233 if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0])
234 opt = opt.mid(1, opt.length()-2);
235 if(opt.startsWith("/")) {
236 if(opt.startsWith("/LIBPATH:")) {
237 QMakeLocalFileName l(opt.mid(9));
238 if(!libdirs.contains(l))
239 libdirs.append(l);
240 }
241 } else if(!processed.contains(opt)) {
242 if(processPrlFile(opt)) {
243 processed.insert(opt, true);
244 ret = true;
245 } else if(QDir::isRelativePath(opt) || opt.startsWith("-l")) {
246 QString tmp;
247 if (opt.startsWith("-l"))
248 tmp = opt.mid(2);
249 else
250 tmp = opt;
251 for(QList<QMakeLocalFileName>::Iterator it = libdirs.begin(); it != libdirs.end(); ++it) {
[363]252 QString prl = (*it).local() + Option::dir_sep + tmp;
[2]253 // the original is used as the key
254 QString orgprl = prl;
255 if(processed.contains(prl)) {
256 break;
257 } else if(processPrlFile(prl)) {
258 processed.insert(orgprl, true);
259 ret = true;
260 break;
261 }
262 }
263 }
264 }
265 if(!opt.isEmpty())
266 l_out.append(opt);
267 }
268 if(ret)
269 l = l_out;
270 else
271 break;
272 }
273}
274
275
276void Win32MakefileGenerator::processVars()
277{
278 //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET
279 if(!project->isEmpty("TARGET")) {
280 QString targ = project->first("TARGET");
281 int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep));
282 if(slsh != -1) {
283 if(project->isEmpty("DESTDIR"))
284 project->values("DESTDIR").append("");
285 else if(project->first("DESTDIR").right(1) != Option::dir_sep)
286 project->values("DESTDIR") = QStringList(project->first("DESTDIR") + Option::dir_sep);
287 project->values("DESTDIR") = QStringList(project->first("DESTDIR") + targ.left(slsh+1));
288 project->values("TARGET") = QStringList(targ.mid(slsh+1));
289 }
290 }
291
292 project->values("QMAKE_ORIG_TARGET") = project->values("TARGET");
293 if (!project->values("QMAKE_INCDIR").isEmpty())
294 project->values("INCLUDEPATH") += project->values("QMAKE_INCDIR");
295
296 if (!project->values("VERSION").isEmpty()) {
297 QStringList l = project->first("VERSION").split('.');
298 if (l.size() > 0)
299 project->values("VER_MAJ").append(l[0]);
300 if (l.size() > 1)
301 project->values("VER_MIN").append(l[1]);
302 }
303
304 // TARGET_VERSION_EXT will be used to add a version number onto the target name
305 if (project->values("TARGET_VERSION_EXT").isEmpty()
306 && !project->values("VER_MAJ").isEmpty())
307 project->values("TARGET_VERSION_EXT").append(project->values("VER_MAJ").first());
308
309 if(project->isEmpty("QMAKE_COPY_FILE"))
310 project->values("QMAKE_COPY_FILE").append("$(COPY)");
311 if(project->isEmpty("QMAKE_COPY_DIR"))
312 project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
313 if(project->isEmpty("QMAKE_INSTALL_FILE"))
314 project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
315 if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
316 project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
317 if(project->isEmpty("QMAKE_INSTALL_DIR"))
318 project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
319
320 fixTargetExt();
321 processRcFileVar();
322 processFileTagsVar();
323
324 QStringList &incDir = project->values("INCLUDEPATH");
325 for(QStringList::Iterator incDir_it = incDir.begin(); incDir_it != incDir.end(); ++incDir_it) {
326 if(!(*incDir_it).isEmpty())
327 (*incDir_it) = Option::fixPathToTargetOS((*incDir_it), false, false);
328 }
329 QStringList &libDir = project->values("QMAKE_LIBDIR");
330 for(QStringList::Iterator libDir_it = libDir.begin(); libDir_it != libDir.end(); ++libDir_it) {
331 if(!(*libDir_it).isEmpty())
332 (*libDir_it) = Option::fixPathToTargetOS((*libDir_it), false, false);
333 }
334}
335
336void Win32MakefileGenerator::fixTargetExt()
337{
338 if (!project->values("QMAKE_APP_FLAG").isEmpty())
339 project->values("TARGET_EXT").append(".exe");
340 else if (project->isActiveConfig("shared"))
341 project->values("TARGET_EXT").append(project->first("TARGET_VERSION_EXT") + ".dll");
342 else
343 project->values("TARGET_EXT").append(".lib");
344}
345
346void Win32MakefileGenerator::processRcFileVar()
347{
348 if (Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
349 return;
350
351 if (((!project->values("VERSION").isEmpty())
352 && project->values("RC_FILE").isEmpty()
353 && project->values("RES_FILE").isEmpty()
354 && !project->isActiveConfig("no_generated_target_info")
355 && (project->isActiveConfig("shared") || !project->values("QMAKE_APP_FLAG").isEmpty()))
356 || !project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty()){
357
358 QByteArray rcString;
359 QTextStream ts(&rcString, QFile::WriteOnly);
360
361 QStringList vers = project->values("VERSION").first().split(".");
362 for (int i = vers.size(); i < 4; i++)
363 vers += "0";
364 QString versionString = vers.join(".");
365
366 QString companyName;
367 if (!project->values("QMAKE_TARGET_COMPANY").isEmpty())
368 companyName = project->values("QMAKE_TARGET_COMPANY").join(" ");
369
370 QString description;
371 if (!project->values("QMAKE_TARGET_DESCRIPTION").isEmpty())
372 description = project->values("QMAKE_TARGET_DESCRIPTION").join(" ");
373
374 QString copyright;
375 if (!project->values("QMAKE_TARGET_COPYRIGHT").isEmpty())
376 copyright = project->values("QMAKE_TARGET_COPYRIGHT").join(" ");
377
378 QString productName;
379 if (!project->values("QMAKE_TARGET_PRODUCT").isEmpty())
380 productName = project->values("QMAKE_TARGET_PRODUCT").join(" ");
381 else
382 productName = project->values("TARGET").first();
383
384 QString originalName = project->values("TARGET").first() + project->values("TARGET_EXT").first();
385
386 ts << "# if defined(UNDER_CE)" << endl;
387 ts << "# include <winbase.h>" << endl;
388 ts << "# else" << endl;
389 ts << "# include <winver.h>" << endl;
390 ts << "# endif" << endl;
391 ts << endl;
392 ts << "VS_VERSION_INFO VERSIONINFO" << endl;
393 ts << "\tFILEVERSION " << QString(versionString).replace(".", ",") << endl;
394 ts << "\tPRODUCTVERSION " << QString(versionString).replace(".", ",") << endl;
395 ts << "\tFILEFLAGSMASK 0x3fL" << endl;
396 ts << "#ifdef _DEBUG" << endl;
397 ts << "\tFILEFLAGS VS_FF_DEBUG" << endl;
398 ts << "#else" << endl;
399 ts << "\tFILEFLAGS 0x0L" << endl;
400 ts << "#endif" << endl;
401 ts << "\tFILEOS VOS__WINDOWS32" << endl;
402 if (project->isActiveConfig("shared"))
403 ts << "\tFILETYPE VFT_DLL" << endl;
404 else
405 ts << "\tFILETYPE VFT_APP" << endl;
406 ts << "\tFILESUBTYPE 0x0L" << endl;
407 ts << "\tBEGIN" << endl;
408 ts << "\t\tBLOCK \"StringFileInfo\"" << endl;
409 ts << "\t\tBEGIN" << endl;
410 ts << "\t\t\tBLOCK \"040904B0\"" << endl;
411 ts << "\t\t\tBEGIN" << endl;
412 ts << "\t\t\t\tVALUE \"CompanyName\", \"" << companyName << "\\0\"" << endl;
413 ts << "\t\t\t\tVALUE \"FileDescription\", \"" << description << "\\0\"" << endl;
414 ts << "\t\t\t\tVALUE \"FileVersion\", \"" << versionString << "\\0\"" << endl;
415 ts << "\t\t\t\tVALUE \"LegalCopyright\", \"" << copyright << "\\0\"" << endl;
416 ts << "\t\t\t\tVALUE \"OriginalFilename\", \"" << originalName << "\\0\"" << endl;
417 ts << "\t\t\t\tVALUE \"ProductName\", \"" << productName << "\\0\"" << endl;
418 ts << "\t\t\tEND" << endl;
419 ts << "\t\tEND" << endl;
420 ts << "\tEND" << endl;
421 ts << "/* End of Version info */" << endl;
422 ts << endl;
423
424 ts.flush();
425
426
427 QString rcFilename = project->values("OUT_PWD").first()
428 + "/"
429 + project->values("TARGET").first()
430 + "_resource"
431 + ".rc";
432 QFile rcFile(QDir::cleanPath(rcFilename));
433
434 bool writeRcFile = true;
435 if (rcFile.exists() && rcFile.open(QFile::ReadOnly)) {
436 writeRcFile = rcFile.readAll() != rcString;
437 rcFile.close();
438 }
[561]439 if (writeRcFile) {
440 bool ok;
441 ok = rcFile.open(QFile::WriteOnly);
442 if (!ok) {
443 // The file can't be opened... try creating the containing
444 // directory first (needed for clean shadow builds)
445 QDir().mkpath(QFileInfo(rcFile).path());
446 ok = rcFile.open(QFile::WriteOnly);
447 }
448 if (!ok) {
449 ::fprintf(stderr, "Cannot open for writing: %s", rcFile.fileName().toLatin1().constData());
450 ::exit(1);
451 }
452 rcFile.write(rcString);
453 rcFile.close();
[2]454 }
455 if (project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty())
456 project->values("RC_FILE").insert(0, rcFile.fileName());
457 }
458 if (!project->values("RC_FILE").isEmpty()) {
459 if (!project->values("RES_FILE").isEmpty()) {
460 fprintf(stderr, "Both rc and res file specified.\n");
461 fprintf(stderr, "Please specify one of them, not both.");
462 exit(1);
463 }
464 QString resFile = project->values("RC_FILE").first();
465
466 // if this is a shadow build then use the absolute path of the rc file
467 if (Option::output_dir != qmake_getpwd()) {
468 QFileInfo fi(resFile);
469 project->values("RC_FILE").first() = fi.absoluteFilePath();
470 }
471
472 resFile.replace(".rc", Option::res_ext);
473 project->values("RES_FILE").prepend(fileInfo(resFile).fileName());
[529]474 if (!project->values("OBJECTS_DIR").isEmpty()) {
[846]475 QString resDestDir;
476 if (project->isActiveConfig("staticlib"))
477 resDestDir = fileInfo(project->first("DESTDIR")).absoluteFilePath();
[2]478 else
[846]479 resDestDir = project->first("OBJECTS_DIR");
480 resDestDir.append(Option::dir_sep);
481 project->values("RES_FILE").first().prepend(resDestDir);
[529]482 }
[2]483 project->values("RES_FILE").first() = Option::fixPathToTargetOS(project->values("RES_FILE").first(), false, false);
484 project->values("POST_TARGETDEPS") += project->values("RES_FILE");
485 project->values("CLEAN_FILES") += project->values("RES_FILE");
486 }
487}
488
489void Win32MakefileGenerator::processFileTagsVar()
490{
491 QStringList tags;
492 tags << "SOURCES" << "GENERATED_SOURCES" << "DEF_FILE" << "RC_FILE"
493 << "TARGET" << "QMAKE_LIBS" << "DESTDIR" << "DLLDESTDIR" << "INCLUDEPATH";
494 if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
495 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
496 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it)
497 tags += project->values((*it)+".input");
498 }
499
500 //clean path
501 QStringList &filetags = project->values("QMAKE_FILETAGS");
502 for(int i = 0; i < tags.size(); ++i)
503 filetags += Option::fixPathToTargetOS(tags.at(i), false);
504}
505
506void Win32MakefileGenerator::writeCleanParts(QTextStream &t)
507{
[37]508 const QString del_statement("-$(DEL_FILE)");
509 const QString del_suffix =
510 Option::target_mode == Option::TARG_OS2_MODE ?
[189]511 QString(" >nul 2>&1"): // reduce noise
512 QString::null;
[37]513
514 const int commandlineLimit =
515 Option::target_mode == Option::TARG_OS2_MODE ?
[189]516 1000: // OS/2 CMD.EXE limit (1024 - suffix - reserve)
[37]517 2047; // NT limit, expanded
518
[2]519 t << "clean: compiler_clean " << var("CLEAN_DEPS");
520 {
521 const char *clean_targets[] = { "OBJECTS", "QMAKE_CLEAN", "CLEAN_FILES", 0 };
522 for(int i = 0; clean_targets[i]; ++i) {
523 const QStringList &list = project->values(clean_targets[i]);
524 if(project->isActiveConfig("no_delete_multiple_files")) {
525 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
[37]526 t << "\n\t" << del_statement << " " << escapeFilePath((*it)) << del_suffix;
[2]527 } else {
528 QString files, file;
529 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
530 file = " " + escapeFilePath((*it));
531 if(del_statement.length() + files.length() +
[37]532 qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit &&
533 !files.isEmpty()) {
534 t << "\n\t" << del_statement << files << del_suffix;
[2]535 files.clear();
536 }
537 files += file;
538 }
539 if(!files.isEmpty())
[37]540 t << "\n\t" << del_statement << files << del_suffix;
[2]541 }
542 }
543 }
544 t << endl << endl;
545
546 t << "distclean: clean";
547 {
548 const char *clean_targets[] = { "QMAKE_DISTCLEAN", 0 };
549 for(int i = 0; clean_targets[i]; ++i) {
550 const QStringList &list = project->values(clean_targets[i]);
551 if(project->isActiveConfig("no_delete_multiple_files")) {
552 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
[37]553 t << "\n\t" << del_statement << " " << escapeFilePath((*it)) << del_suffix;
[2]554 } else {
555 QString files, file;
556 for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
557 file = " " + escapeFilePath((*it));
558 if(del_statement.length() + files.length() +
[37]559 qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit &&
560 !files.isEmpty()) {
561 t << "\n\t" << del_statement << files << del_suffix;
[2]562 files.clear();
563 }
564 files += file;
565 }
566 if(!files.isEmpty())
[37]567 t << "\n\t" << del_statement << files << del_suffix;
[2]568 }
569 }
570 }
[37]571 t << "\n\t" << del_statement << " $(DESTDIR_TARGET)" << del_suffix << endl;
[2]572 {
573 QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
574 if(!ofile.isEmpty())
[37]575 t << "\t" << del_statement << " " << ofile << del_suffix << endl;
[2]576 }
577 t << endl;
578}
579
580void Win32MakefileGenerator::writeIncPart(QTextStream &t)
581{
582 t << "INCPATH = ";
583
584 const QStringList &incs = project->values("INCLUDEPATH");
585 for(int i = 0; i < incs.size(); ++i) {
586 QString inc = incs.at(i);
587 inc.replace(QRegExp("\\\\$"), "");
588 inc.replace(QRegExp("\""), "");
589 if(!inc.isEmpty())
590 t << "-I" << "\"" << inc << "\" ";
591 }
592 t << "-I\"" << specdir() << "\""
593 << endl;
594}
595
596void Win32MakefileGenerator::writeStandardParts(QTextStream &t)
597{
598 t << "####### Compiler, tools and options" << endl << endl;
599 t << "CC = " << var("QMAKE_CC") << endl;
600 t << "CXX = " << var("QMAKE_CXX") << endl;
601 t << "DEFINES = "
602 << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
603 << varGlue("DEFINES","-D"," -D","") << endl;
604 t << "CFLAGS = " << var("QMAKE_CFLAGS") << " $(DEFINES)" << endl;
605 t << "CXXFLAGS = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)" << endl;
606
607 writeIncPart(t);
608 writeLibsPart(t);
609
[846]610 t << "QMAKE = " << var("QMAKE_QMAKE") << endl;
[2]611 t << "IDC = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
612 Option::fixPathToTargetOS(var("QMAKE_IDC"), false)) << endl;
613 t << "IDL = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
614 Option::fixPathToTargetOS(var("QMAKE_IDL"), false)) << endl;
[193]615 t << "RC = " << (project->isEmpty("QMAKE_RC") ? QString("rc") :
616 Option::fixPathToTargetOS(var("QMAKE_RC"), false)) << endl;
[2]617 t << "ZIP = " << var("QMAKE_ZIP") << endl;
618 t << "COPY = " << var("QMAKE_COPY") << endl;
619 t << "COPY_FILE = " << var("QMAKE_COPY_FILE") << endl;
620 t << "COPY_DIR = " << var("QMAKE_COPY_DIR") << endl;
621 t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl;
622 t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl;
623 t << "MOVE = " << var("QMAKE_MOVE") << endl;
624 t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl;
625 t << "MKDIR = " << var("QMAKE_MKDIR") << endl;
626 t << "INSTALL_FILE = " << var("QMAKE_INSTALL_FILE") << endl;
627 t << "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl;
628 t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl;
629 t << endl;
630
631 t << "####### Output directory" << endl << endl;
632 if(!project->values("OBJECTS_DIR").isEmpty())
633 t << "OBJECTS_DIR = " << var("OBJECTS_DIR").replace(QRegExp("\\\\$"),"") << endl;
634 else
[547]635 t << "OBJECTS_DIR = ." << endl;
[2]636 t << endl;
637
638 t << "####### Files" << endl << endl;
639 t << "SOURCES = " << valList(escapeFilePaths(project->values("SOURCES")))
640 << " " << valList(escapeFilePaths(project->values("GENERATED_SOURCES"))) << endl;
641
642 // do this here so we can set DEST_TARGET to be the complete path to the final target if it is needed.
643 QString orgDestDir = var("DESTDIR");
644 QString destDir = Option::fixPathToTargetOS(orgDestDir, false);
[561]645 if (!destDir.isEmpty() && (orgDestDir.endsWith('/') || orgDestDir.endsWith(Option::dir_sep)))
[2]646 destDir += Option::dir_sep;
[158]647 QString target = project->first("TARGET_SHORT");
648 if (target.isEmpty())
649 target = project->first("TARGET");
650 target += project->first("TARGET_EXT");
[2]651 target.remove("\"");
652 project->values("DEST_TARGET").prepend(destDir + target);
653
654 writeObjectsPart(t);
[38]655 writeRcAndDefVariables(t);
[2]656
657 writeExtraCompilerVariables(t);
658 writeExtraVariables(t);
659
660 t << "DIST = " << varList("DISTFILES") << endl;
661 t << "QMAKE_TARGET = " << var("QMAKE_ORIG_TARGET") << endl;
[885]662 t << "DESTDIR = " << escapeFilePath(destDir) << endl;
[2]663 t << "TARGET = " << escapeFilePath(target) << endl;
664 t << "DESTDIR_TARGET = " << escapeFilePath(var("DEST_TARGET")) << endl;
665 t << endl;
666
667 t << "####### Implicit rules" << endl << endl;
668 writeImplicitRulesPart(t);
669
670 t << "####### Build rules" << endl << endl;
671 writeBuildRulesPart(t);
672
673 if(project->isActiveConfig("shared") && !project->values("DLLDESTDIR").isEmpty()) {
674 QStringList dlldirs = project->values("DLLDESTDIR");
675 for (QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
676 t << "\n\t" << "-$(COPY_FILE) \"$(DESTDIR_TARGET)\" " << Option::fixPathToTargetOS(*dlldir, false);
677 }
678 }
679 t << endl << endl;
680
[38]681 writeRcAndDefPart(t);
[2]682
683 writeMakeQmake(t);
684
685 QStringList dist_files = fileFixify(Option::mkfile::project_files);
686 if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES"))
687 dist_files += project->values("QMAKE_INTERNAL_INCLUDED_FILES");
688 if(!project->isEmpty("TRANSLATIONS"))
689 dist_files << var("TRANSLATIONS");
690 if(!project->isEmpty("FORMS")) {
691 QStringList &forms = project->values("FORMS");
692 for(QStringList::Iterator formit = forms.begin(); formit != forms.end(); ++formit) {
693 QString ui_h = fileFixify((*formit) + Option::h_ext.first());
694 if(exists(ui_h))
695 dist_files << ui_h;
696 }
697 }
698 t << "dist:" << "\n\t"
699 << "$(ZIP) " << var("QMAKE_ORIG_TARGET") << ".zip " << "$(SOURCES) $(DIST) "
[682]700 << dist_files.join(" ") << " ";
[2]701 if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
702 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
703 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
704 const QStringList &inputs = project->values((*it)+".input");
705 for(QStringList::ConstIterator input = inputs.begin(); input != inputs.end(); ++input) {
706 t << (*input) << " ";
707 }
708 }
709 }
710 t << endl << endl;
711
712 writeCleanParts(t);
713 writeExtraTargets(t);
714 writeExtraCompilerTargets(t);
715 t << endl << endl;
716}
717
718void Win32MakefileGenerator::writeLibsPart(QTextStream &t)
719{
720 if(project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") {
721 t << "LIBAPP = " << var("QMAKE_LIB") << endl;
722 t << "LIBFLAGS = " << var("QMAKE_LIBFLAGS") << endl;
723 } else {
724 t << "LINK = " << var("QMAKE_LINK") << endl;
725 t << "LFLAGS = ";
726 if(!project->values("QMAKE_LIBDIR").isEmpty())
727 writeLibDirPart(t);
728 t << var("QMAKE_LFLAGS") << endl;
[561]729 t << "LIBS = " << var("QMAKE_LIBS") << " " << var("QMAKE_LIBS_PRIVATE") << endl;
[2]730 }
731}
732
733void Win32MakefileGenerator::writeLibDirPart(QTextStream &t)
734{
735 QStringList libDirs = project->values("QMAKE_LIBDIR");
736 for (int i = 0; i < libDirs.size(); ++i)
737 libDirs[i].remove("\"");
738 t << valGlue(libDirs,"-L\"","\" -L\"","\"") << " ";
739}
740
741void Win32MakefileGenerator::writeObjectsPart(QTextStream &t)
742{
743 t << "OBJECTS = " << valList(escapeDependencyPaths(project->values("OBJECTS"))) << endl;
744}
745
746void Win32MakefileGenerator::writeImplicitRulesPart(QTextStream &t)
747{
748 t << ".SUFFIXES:";
749 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
750 t << " " << (*cppit);
751 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
752 t << " " << (*cit);
753 t << endl << endl;
754 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
755 t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
756 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
757 t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
758}
759
760void Win32MakefileGenerator::writeBuildRulesPart(QTextStream &)
761{
762}
763
[38]764void Win32MakefileGenerator::writeRcAndDefVariables(QTextStream &t)
[2]765{
[38]766 t << "DEF_FILE = " << varList("DEF_FILE") << endl;
767 t << "RES_FILE = " << varList("RES_FILE") << endl; // Not on mingw, can't see why not though...
768}
769
770void Win32MakefileGenerator::writeRcAndDefPart(QTextStream &t)
771{
[2]772 if(!project->values("RC_FILE").isEmpty()) {
773 const QString res_file = project->first("RES_FILE"),
774 rc_file = fileFixify(project->first("RC_FILE"));
775 // The resource tool needs to have the same defines passed in as the compiler, since you may
776 // use these defines in the .rc file itself. Also, we need to add the _DEBUG define manually
777 // since the compiler defines this symbol by itself, and we use it in the automatically
778 // created rc file when VERSION is define the .pro file.
779 t << res_file << ": " << rc_file << "\n\t"
780 << var("QMAKE_RC") << (project->isActiveConfig("debug") ? " -D_DEBUG" : "") << " $(DEFINES) -fo " << res_file << " " << rc_file;
781 t << endl << endl;
782 }
783}
784
785QString Win32MakefileGenerator::getLibTarget()
786{
[886]787 return QString(project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".lib");
[2]788}
789
[846]790QString Win32MakefileGenerator::getPdbTarget()
791{
792 return QString(project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".pdb");
793}
794
[2]795QString Win32MakefileGenerator::defaultInstall(const QString &t)
796{
797 if((t != "target" && t != "dlltarget") ||
798 (t == "dlltarget" && (project->first("TEMPLATE") != "lib" || !project->isActiveConfig("shared"))) ||
799 project->first("TEMPLATE") == "subdirs")
800 return QString();
801
802 const QString root = "$(INSTALL_ROOT)";
803 QStringList &uninst = project->values(t + ".uninstall");
804 QString ret;
805 QString targetdir = Option::fixPathToTargetOS(project->first(t + ".path"), false);
806 targetdir = fileFixify(targetdir, FileFixifyAbsolute);
807 if(targetdir.right(1) != Option::dir_sep)
808 targetdir += Option::dir_sep;
809
[189]810 const QString del_suffix =
811 Option::target_mode == Option::TARG_OS2_MODE ?
812 QString(" >nul 2>&1"): // reduce noise
813 QString::null;
814
[535]815 const QString inst_prefix =
816 Option::target_mode == Option::TARG_OS2_MODE ?
817 QString::null: // report errors (copy command overwrites quietly)
818 QString("-");
819
[2]820 if(t == "target" && project->first("TEMPLATE") == "lib") {
821 if(project->isActiveConfig("create_prl") && !project->isActiveConfig("no_install_prl") &&
822 !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) {
823 QString dst_prl = Option::fixPathToTargetOS(project->first("QMAKE_INTERNAL_PRL_FILE"));
824 int slsh = dst_prl.lastIndexOf(Option::dir_sep);
825 if(slsh != -1)
826 dst_prl = dst_prl.right(dst_prl.length() - slsh - 1);
827 dst_prl = filePrefixRoot(root, targetdir + dst_prl);
[535]828 ret += inst_prefix + "$(INSTALL_FILE) \"" + project->first("QMAKE_INTERNAL_PRL_FILE") + "\" \"" + dst_prl + "\"";
[2]829 if(!uninst.isEmpty())
830 uninst.append("\n\t");
[189]831 uninst.append("-$(DEL_FILE) \"" + dst_prl + "\"" + del_suffix);
[2]832 }
833 if(project->isActiveConfig("shared") && !project->isActiveConfig("plugin")) {
834 QString lib_target = getLibTarget();
835 lib_target.remove('"');
836 QString src_targ = (project->isEmpty("DESTDIR") ? QString("$(DESTDIR)") : project->first("DESTDIR")) + lib_target;
837 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + lib_target, FileFixifyAbsolute));
838 if(!ret.isEmpty())
839 ret += "\n\t";
[535]840 ret += QString(inst_prefix + "$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
[2]841 if(!uninst.isEmpty())
842 uninst.append("\n\t");
[189]843 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"" + del_suffix);
[2]844 }
[846]845 if(project->isActiveConfig("shared") && project->isActiveConfig("debug")) {
846 QString pdb_target = getPdbTarget();
[896]847 if (!pdb_target.isEmpty()) {
848 pdb_target.remove('"');
849 QString src_targ = (project->isEmpty("DESTDIR") ? QString("$(DESTDIR)") : project->first("DESTDIR")) + pdb_target;
850 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + pdb_target, FileFixifyAbsolute));
851 if(!ret.isEmpty())
852 ret += "\n\t";
853 ret += QString("-$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
854 if(!uninst.isEmpty())
855 uninst.append("\n\t");
856 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
857 }
[846]858 }
[2]859 }
860
861 if(t == "dlltarget" || project->values(t + ".CONFIG").indexOf("no_dll") == -1) {
862 QString src_targ = "$(DESTDIR_TARGET)";
863 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + "$(TARGET)", FileFixifyAbsolute));
864 if(!ret.isEmpty())
865 ret += "\n\t";
[535]866 ret += QString(inst_prefix + "$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
[2]867 if(!uninst.isEmpty())
868 uninst.append("\n\t");
[189]869 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"" + del_suffix);
[2]870 }
871 return ret;
872}
873
874QString Win32MakefileGenerator::escapeFilePath(const QString &path) const
875{
876 QString ret = path;
877 if(!ret.isEmpty()) {
878 ret = unescapeFilePath(ret);
[885]879 // Note: also quote paths ending with the backslash to avoid
880 // interpreting it as a linebreak
881 if(ret.contains(' ') || ret.endsWith('\\'))
[2]882 ret = "\"" + ret + "\"";
883 debug_msg(2, "EscapeFilePath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData());
884 }
885 return ret;
886}
887
888QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.