~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to qmake/generators/win32/winmakefile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the qmake application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "winmakefile.h"
 
30
#include "option.h"
 
31
#include "project.h"
 
32
#include "meta.h"
 
33
#include <qtextstream.h>
 
34
#include <qstring.h>
 
35
#include <qhash.h>
 
36
#include <qregexp.h>
 
37
#include <qstringlist.h>
 
38
#include <qdir.h>
 
39
#include <stdlib.h>
 
40
 
 
41
Win32MakefileGenerator::Win32MakefileGenerator() : MakefileGenerator()
 
42
{
 
43
}
 
44
 
 
45
int
 
46
Win32MakefileGenerator::findHighestVersion(const QString &d, const QString &stem)
 
47
{
 
48
    QString bd = Option::fixPathToLocalOS(d, true);
 
49
    if(!exists(bd))
 
50
        return -1;
 
51
 
 
52
    QString dllStem = stem + QTDLL_POSTFIX;
 
53
    QMakeMetaInfo libinfo;
 
54
    bool libInfoRead = libinfo.readLib(bd + Option::dir_sep + dllStem);
 
55
 
 
56
    // If the library, for which we're trying to find the highest version
 
57
    // number, is a static library
 
58
    if (libInfoRead && libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib"))
 
59
        return -1;
 
60
 
 
61
    if(!project->variables()["QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE"].isEmpty())
 
62
        return project->variables()["QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE"].first().toInt();
 
63
 
 
64
    int biggest=-1;
 
65
    if(!project->isActiveConfig("no_versionlink")) {
 
66
        QDir dir(bd);
 
67
        QStringList entries = dir.entryList();
 
68
        QRegExp regx("((lib)?" + dllStem + "([0-9]*)).(a|lib|prl)$", Qt::CaseInsensitive);
 
69
        for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
 
70
            if(regx.exactMatch((*it))) {
 
71
                                if (!regx.cap(3).isEmpty()) {
 
72
                                        bool ok = true;
 
73
                                        int num = regx.cap(3).toInt(&ok);
 
74
                                        biggest = qMax(biggest, (!ok ? -1 : num));
 
75
                                }
 
76
                        }
 
77
        }
 
78
    }
 
79
    if(libInfoRead
 
80
       && !libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib")
 
81
       && !libinfo.isEmpty("QMAKE_PRL_VERSION"))
 
82
       biggest = qMax(biggest, libinfo.first("QMAKE_PRL_VERSION").replace(".", "").toInt());
 
83
    return biggest;
 
84
}
 
85
 
 
86
bool
 
87
Win32MakefileGenerator::findLibraries(const QString &where)
 
88
{
 
89
    QStringList &l = project->variables()[where];
 
90
    QList<QMakeLocalFileName> dirs;
 
91
    {
 
92
        QStringList &libpaths = project->variables()["QMAKE_LIBDIR"];
 
93
        for(QStringList::Iterator libpathit = libpaths.begin();
 
94
            libpathit != libpaths.end(); ++libpathit)
 
95
            dirs.append(QMakeLocalFileName((*libpathit)));
 
96
    }
 
97
    for(QStringList::Iterator it = l.begin(); it != l.end();) {
 
98
        QChar quote;
 
99
        bool modified_opt = false, remove = false;
 
100
        QString opt = (*it).trimmed();
 
101
        if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0]) {
 
102
            quote = opt[0];
 
103
            opt = opt.mid(1, opt.length()-2);
 
104
        }
 
105
        if(opt.startsWith("/LIBPATH:")) {
 
106
            dirs.append(QMakeLocalFileName(opt.mid(9)));
 
107
        } else if(opt.startsWith("-L") || opt.startsWith("/L")) {
 
108
            QString libpath = opt.mid(2);
 
109
            dirs.append(QMakeLocalFileName(libpath));
 
110
            modified_opt = true;
 
111
            if (!quote.isNull()) {
 
112
                libpath = quote + libpath + quote;
 
113
                quote = QChar();
 
114
            }
 
115
            (*it) = "/LIBPATH:" + libpath;
 
116
        } else if(opt.startsWith("-l") || opt.startsWith("/l")) {
 
117
            QString lib = opt.right(opt.length() - 2), out;
 
118
            if(!lib.isEmpty()) {
 
119
                QString suffix;
 
120
                if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX"))
 
121
                    suffix = project->first("QMAKE_" + lib.toUpper() + "_SUFFIX");
 
122
                for(QList<QMakeLocalFileName>::Iterator it = dirs.begin();
 
123
                    it != dirs.end(); ++it) {
 
124
                    QString extension;
 
125
                    int ver = findHighestVersion((*it).local(), lib);
 
126
                    if(ver > 0)
 
127
                        extension += QString::number(ver);
 
128
                    extension += suffix;
 
129
                    extension += ".lib";
 
130
                    if(QMakeMetaInfo::libExists((*it).local() + Option::dir_sep + lib) ||
 
131
                       exists((*it).local() + Option::dir_sep + lib + extension)) {
 
132
                        out = (*it).real() + Option::dir_sep + lib + extension;
 
133
                        break;
 
134
                    }
 
135
                }
 
136
            }
 
137
            if(out.isEmpty())
 
138
                out = lib + ".lib";
 
139
            modified_opt = true;
 
140
            (*it) = out;
 
141
        } else if(!exists(Option::fixPathToLocalOS(opt))) {
 
142
            QList<QMakeLocalFileName> lib_dirs;
 
143
            QString file = opt;
 
144
            int slsh = file.lastIndexOf(Option::dir_sep);
 
145
            if(slsh != -1) {
 
146
                lib_dirs.append(QMakeLocalFileName(file.left(slsh+1)));
 
147
                file = file.right(file.length() - slsh - 1);
 
148
            } else {
 
149
                lib_dirs = dirs;
 
150
            }
 
151
            if(file.endsWith(".lib")) {
 
152
                file = file.left(file.length() - 4);
 
153
                if(!file.at(file.length()-1).isNumber()) {
 
154
                    QString suffix;
 
155
                    if(!project->isEmpty("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX"))
 
156
                        suffix = project->first("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX");
 
157
                    for(QList<QMakeLocalFileName>::Iterator dep_it = lib_dirs.begin(); dep_it != lib_dirs.end(); ++dep_it) {
 
158
                        QString lib_tmpl(file + "%1" + suffix + ".lib");
 
159
                        int ver = findHighestVersion((*dep_it).local(), file);
 
160
                        if(ver != -1) {
 
161
                            if(ver)
 
162
                                lib_tmpl = lib_tmpl.arg(ver);
 
163
                            else
 
164
                                lib_tmpl = lib_tmpl.arg("");
 
165
                            if(slsh != -1) {
 
166
                                QString dir = (*dep_it).real();
 
167
                                if(!dir.endsWith(Option::dir_sep))
 
168
                                    dir += Option::dir_sep;
 
169
                                lib_tmpl.prepend(dir);
 
170
                            }
 
171
                            modified_opt = true;
 
172
                            (*it) = lib_tmpl;
 
173
                            break;
 
174
                        }
 
175
                    }
 
176
                }
 
177
            }
 
178
        }
 
179
        if(remove) {
 
180
            it = l.erase(it);
 
181
        } else {
 
182
            if(!quote.isNull() && modified_opt)
 
183
                (*it) = quote + (*it) + quote;
 
184
            ++it;
 
185
        }
 
186
    }
 
187
    return true;
 
188
}
 
189
 
 
190
void
 
191
Win32MakefileGenerator::processPrlFiles()
 
192
{
 
193
    QHash<QString, bool> processed;
 
194
    QList<QMakeLocalFileName> libdirs;
 
195
    {
 
196
        QStringList &libpaths = project->variables()["QMAKE_LIBDIR"];
 
197
        for(QStringList::Iterator libpathit = libpaths.begin(); libpathit != libpaths.end(); ++libpathit)
 
198
            libdirs.append(QMakeLocalFileName((*libpathit)));
 
199
    }
 
200
    for(bool ret = false; true; ret = false) {
 
201
        //read in any prl files included..
 
202
        QStringList l_out;
 
203
        QString where = "QMAKE_LIBS";
 
204
        if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
 
205
            where = project->first("QMAKE_INTERNAL_PRL_LIBS");
 
206
        QStringList l = project->variables()[where];
 
207
        for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
 
208
            QString opt = (*it).trimmed();
 
209
            if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0])
 
210
                opt = opt.mid(1, opt.length()-2);
 
211
            if(opt.startsWith("/")) {
 
212
                if(opt.startsWith("/LIBPATH:"))
 
213
                    libdirs.append(QMakeLocalFileName(opt.mid(9)));
 
214
            } else if(!processed.contains(opt)) {
 
215
                if(processPrlFile(opt)) {
 
216
                    processed.insert(opt, true);
 
217
                    ret = true;
 
218
                } else if(QDir::isRelativePath(opt) || opt.startsWith("-l")) {
 
219
                    QString tmp;
 
220
                    if (opt.startsWith("-l"))
 
221
                        tmp = opt.mid(2);
 
222
                    else
 
223
                        tmp = opt;
 
224
                    for(QList<QMakeLocalFileName>::Iterator it = libdirs.begin(); it != libdirs.end(); ++it) {
 
225
                        QString prl = (*it).local() + Option::dir_sep + tmp;
 
226
                        // the orignal is used as the key
 
227
                        QString orgprl = prl;
 
228
                        if(processed.contains(prl)) {
 
229
                            break;
 
230
                        } else if(processPrlFile(prl)) {
 
231
                            processed.insert(orgprl, true);
 
232
                            ret = true;
 
233
                            break;
 
234
                        }
 
235
                    }
 
236
                }
 
237
            }
 
238
            if(!opt.isEmpty())
 
239
                l_out.append(opt);
 
240
        }
 
241
        if(ret)
 
242
            l = l_out;
 
243
        else
 
244
            break;
 
245
    }
 
246
}
 
247
 
 
248
 
 
249
void Win32MakefileGenerator::processVars()
 
250
{
 
251
    //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET
 
252
    if(!project->isEmpty("TARGET")) {
 
253
        QString targ = project->first("TARGET");
 
254
        int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep));
 
255
        if(slsh != -1) {
 
256
            if(project->isEmpty("DESTDIR"))
 
257
                project->values("DESTDIR").append("");
 
258
            else if(project->first("DESTDIR").right(1) != Option::dir_sep)
 
259
                project->variables()["DESTDIR"] = QStringList(project->first("DESTDIR") + Option::dir_sep);
 
260
            project->variables()["DESTDIR"] = QStringList(project->first("DESTDIR") + targ.left(slsh+1));
 
261
            project->variables()["TARGET"] = QStringList(targ.mid(slsh+1));
 
262
        }
 
263
    }
 
264
 
 
265
    project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
 
266
    if (!project->variables()["QMAKE_INCDIR"].isEmpty())
 
267
        project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR"];
 
268
 
 
269
    if (!project->variables()["VERSION"].isEmpty()) {
 
270
        QStringList l = project->first("VERSION").split('.');
 
271
        project->variables()["VER_MAJ"].append(l[0]);
 
272
        project->variables()["VER_MIN"].append(l[1]);
 
273
    }
 
274
 
 
275
    // TARGET_VERSION_EXT will be used to add a version number onto the target name
 
276
    if (project->variables()["TARGET_VERSION_EXT"].isEmpty()
 
277
        && !project->variables()["VER_MAJ"].isEmpty())
 
278
        project->variables()["TARGET_VERSION_EXT"].append(project->variables()["VER_MAJ"].first());
 
279
 
 
280
    if(project->isEmpty("QMAKE_COPY_FILE"))
 
281
        project->variables()["QMAKE_COPY_FILE"].append("$(COPY)");
 
282
    if(project->isEmpty("QMAKE_COPY_DIR"))
 
283
        project->variables()["QMAKE_COPY_DIR"].append("xcopy /s /q /y /i");
 
284
    if(project->isEmpty("QMAKE_INSTALL_FILE"))
 
285
        project->variables()["QMAKE_INSTALL_FILE"].append("$(COPY_FILE)");
 
286
    if(project->isEmpty("QMAKE_INSTALL_DIR"))
 
287
        project->variables()["QMAKE_INSTALL_DIR"].append("$(COPY_DIR)");
 
288
 
 
289
    fixTargetExt();
 
290
    processRcFileVar();
 
291
    processFileTagsVar();
 
292
 
 
293
    QStringList &incDir = project->variables()["INCLUDEPATH"];
 
294
    for(QStringList::Iterator incDir_it = incDir.begin(); incDir_it != incDir.end(); ++incDir_it) {
 
295
    if(!(*incDir_it).isEmpty())
 
296
        (*incDir_it) = Option::fixPathToTargetOS((*incDir_it), false, false);
 
297
    }
 
298
    QStringList &libDir = project->variables()["QMAKE_LIBDIR"];
 
299
    for(QStringList::Iterator libDir_it = libDir.begin(); libDir_it != libDir.end(); ++libDir_it) {
 
300
    if(!(*libDir_it).isEmpty())
 
301
        (*libDir_it) = Option::fixPathToTargetOS((*libDir_it), false, false);
 
302
    }
 
303
}
 
304
 
 
305
void Win32MakefileGenerator::fixTargetExt()
 
306
{
 
307
    if (project->isActiveConfig("dll")) {
 
308
            project->variables()["TARGET_EXT"].append(project->first("TARGET_VERSION_EXT") + ".dll");
 
309
    } else {
 
310
        if (!project->variables()["QMAKE_APP_FLAG"].isEmpty())
 
311
            project->variables()["TARGET_EXT"].append(".exe");
 
312
        else
 
313
            project->variables()["TARGET_EXT"].append(".lib");
 
314
    }
 
315
}
 
316
 
 
317
void Win32MakefileGenerator::processRcFileVar()
 
318
{
 
319
    if ((!project->variables()["VERSION"].isEmpty())
 
320
        && project->variables()["RC_FILE"].isEmpty()
 
321
        && project->variables()["RES_FILE"].isEmpty()
 
322
        && !project->isActiveConfig("no_generated_target_info")
 
323
        && (project->isActiveConfig("dll") || !project->variables()["QMAKE_APP_FLAG"].isEmpty())) {
 
324
 
 
325
        QByteArray rcString;
 
326
        QTextStream ts(&rcString, QFile::WriteOnly);
 
327
 
 
328
        QStringList vers = project->variables()["VERSION"].first().split(".");
 
329
        for (int i = vers.size(); i < 4; i++)
 
330
            vers += "0";
 
331
        QString versionString = vers.join(".");
 
332
 
 
333
        QString companyName;
 
334
        if (!project->variables()["QMAKE_TARGET_COMPANY"].isEmpty())
 
335
            companyName = project->variables()["QMAKE_TARGET_COMPANY"].join(" ");
 
336
 
 
337
        QString description;
 
338
        if (!project->variables()["QMAKE_TARGET_DESCRIPTION"].isEmpty())
 
339
            description = project->variables()["QMAKE_TARGET_DESCRIPTION"].join(" ");
 
340
 
 
341
        QString copyright;
 
342
        if (!project->variables()["QMAKE_TARGET_COPYRIGHT"].isEmpty())
 
343
            copyright = project->variables()["QMAKE_TARGET_COPYRIGHT"].join(" ");
 
344
 
 
345
        QString productName;
 
346
        if (!project->variables()["QMAKE_TARGET_PRODUCT"].isEmpty())
 
347
            productName = project->variables()["QMAKE_TARGET_PRODUCT"].join(" ");
 
348
        else
 
349
            productName = project->variables()["TARGET"].first();
 
350
 
 
351
        QString originalName = project->variables()["TARGET"].first() + project->variables()["TARGET_EXT"].first();
 
352
 
 
353
        ts << "#ifndef Q_CC_BOR" << endl;
 
354
        ts << "# if defined(UNDER_CE) && UNDER_CE >= 400" << endl;
 
355
        ts << "#  include <winbase.h>" << endl;
 
356
        ts << "# else" << endl;
 
357
        ts << "#  include <winver.h>" << endl;
 
358
        ts << "# endif" << endl;
 
359
        ts << "#endif" << endl;
 
360
        ts << endl;
 
361
        ts << "VS_VERSION_INFO VERSIONINFO" << endl;
 
362
        ts << "\tFILEVERSION " << QString(versionString).replace(".", ",") << endl;
 
363
        ts << "\tPRODUCTVERSION " << QString(versionString).replace(".", ",") << endl;
 
364
        ts << "\tFILEFLAGSMASK 0x3fL" << endl;
 
365
        ts << "#ifdef _DEBUG" << endl;
 
366
        ts << "\tFILEFLAGS VS_FF_DEBUG" << endl;
 
367
        ts << "#else" << endl;
 
368
        ts << "\tFILEFLAGS 0x0L" << endl;
 
369
        ts << "#endif" << endl;
 
370
        ts << "\tFILEOS VOS__WINDOWS32" << endl;
 
371
        if (project->isActiveConfig("dll"))
 
372
            ts << "\tFILETYPE VFT_DLL" << endl;
 
373
        else
 
374
            ts << "\tFILETYPE VFT_APP" << endl;
 
375
        ts << "\tFILESUBTYPE 0x0L" << endl;
 
376
        ts << "\tBEGIN" << endl;
 
377
        ts << "\t\tBLOCK \"StringFileInfo\"" << endl;
 
378
        ts << "\t\tBEGIN" << endl;
 
379
        ts << "\t\t\tBLOCK \"040904B0\"" << endl;
 
380
        ts << "\t\t\tBEGIN" << endl;
 
381
        ts << "\t\t\t\tVALUE \"CompanyName\", \"" << companyName << "\\0\"" << endl;
 
382
        ts << "\t\t\t\tVALUE \"FileDescription\", \"" <<  description << "\\0\"" << endl;
 
383
        ts << "\t\t\t\tVALUE \"FileVersion\", \"" << versionString << "\\0\"" << endl;
 
384
        ts << "\t\t\t\tVALUE \"LegalCopyright\", \"" << copyright << "\\0\"" << endl;
 
385
        ts << "\t\t\t\tVALUE \"OriginalFilename\", \"" << originalName << "\\0\"" << endl;
 
386
        ts << "\t\t\t\tVALUE \"ProductName\", \"" << productName << "\\0\"" << endl;
 
387
        ts << "\t\t\tEND" << endl;
 
388
        ts << "\t\tEND" << endl;
 
389
        ts << "\tEND" << endl;
 
390
        ts << "/* End of Version info */" << endl;
 
391
        ts << endl;
 
392
 
 
393
        ts.flush();
 
394
 
 
395
 
 
396
        QFile rcFile(project->variables()["TARGET"].first() + "_resource" + ".rc");
 
397
        bool writeRcFile = true;
 
398
        if (rcFile.exists() && rcFile.open(QFile::ReadOnly)) {
 
399
            writeRcFile = rcFile.readAll() != rcString;
 
400
            rcFile.close();
 
401
        }
 
402
        if (writeRcFile && rcFile.open(QFile::WriteOnly)) {
 
403
            rcFile.write(rcString);
 
404
            rcFile.close();
 
405
        }
 
406
        project->variables()["RC_FILE"].insert(0, Option::fixPathToTargetOS(rcFile.fileName(), false, false));
 
407
    }
 
408
    if (!project->variables()["RC_FILE"].isEmpty()) {
 
409
        if (!project->variables()["RES_FILE"].isEmpty()) {
 
410
            fprintf(stderr, "Both rc and res file specified.\n");
 
411
            fprintf(stderr, "Please specify one of them, not both.");
 
412
            exit(666);
 
413
        }
 
414
        QString resFile = project->variables()["RC_FILE"].first();
 
415
        resFile.replace(".rc", Option::res_ext);
 
416
        project->variables()["RES_FILE"].prepend(fileInfo(resFile).fileName());
 
417
        if (!project->variables()["OBJECTS_DIR"].isEmpty())
 
418
            project->variables()["RES_FILE"].first().prepend(project->variables()["OBJECTS_DIR"].first() + Option::dir_sep);
 
419
        project->variables()["RES_FILE"].first() = Option::fixPathToTargetOS(project->variables()["RES_FILE"].first(), false, false);
 
420
        project->variables()["POST_TARGETDEPS"] += project->variables()["RES_FILE"];
 
421
        project->variables()["CLEAN_FILES"] += project->variables()["RES_FILE"];
 
422
    }
 
423
}
 
424
 
 
425
void Win32MakefileGenerator::processFileTagsVar()
 
426
{
 
427
    QStringList tags;
 
428
    tags << "SOURCES" << "GENERATED_SOURCES" << "DEF_FILE" << "RC_FILE"
 
429
         << "TARGET" << "QMAKE_LIBS" << "DESTDIR" << "DLLDESTDIR" << "INCLUDEPATH";
 
430
    if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
 
431
        const QStringList &quc = project->variables()["QMAKE_EXTRA_COMPILERS"];
 
432
        for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it)
 
433
            tags += project->variables()[(*it)+".input"];
 
434
    }
 
435
 
 
436
    //clean path
 
437
    QStringList &filetags = project->variables()["QMAKE_FILETAGS"];
 
438
    for(int i = 0; i < tags.size(); ++i)
 
439
        filetags += Option::fixPathToTargetOS(tags.at(i), false);
 
440
}
 
441
 
 
442
void Win32MakefileGenerator::writeCleanParts(QTextStream &t)
 
443
{
 
444
    t << "clean: compiler_clean";
 
445
    const char *clean_targets[] = { "OBJECTS", "QMAKE_CLEAN", "CLEAN_FILES", 0 };
 
446
    for(int i = 0; clean_targets[i]; ++i) {
 
447
        const QStringList &list = project->values(clean_targets[i]);
 
448
        const QString del_statement("-$(DEL_FILE)");
 
449
        if(project->isActiveConfig("no_delete_multiple_files")) {
 
450
            for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
 
451
                t << "\n\t" << del_statement << " " << (*it);
 
452
        } else {
 
453
            QString files, file;
 
454
            const int commandlineLimit = 2047; // NT limit, expanded
 
455
            for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
 
456
                file = " " + (*it);
 
457
                if(del_statement.length() + files.length() +
 
458
                   qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
 
459
                    t << "\n\t" << del_statement << files;
 
460
                    files.clear();
 
461
                }
 
462
                files += file;
 
463
            }
 
464
            if(!files.isEmpty())
 
465
                t << "\n\t" << del_statement << files;
 
466
        }
 
467
    }
 
468
    t << endl << endl;
 
469
 
 
470
    t << "distclean: clean"
 
471
      << "\n\t-$(DEL_FILE) \"$(TARGET)\"" << endl;
 
472
    {
 
473
        QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
 
474
        if(!ofile.isEmpty())
 
475
            t << "\t-$(DEL_FILE) " << ofile << endl;
 
476
    }
 
477
    t << endl;
 
478
}
 
479
 
 
480
void Win32MakefileGenerator::writeStandardParts(QTextStream &t)
 
481
{
 
482
    t << "####### Compiler, tools and options" << endl << endl;
 
483
    t << "CC            = " << var("QMAKE_CC") << endl;
 
484
    t << "CXX           = " << var("QMAKE_CXX") << endl;
 
485
    t << "LEX           = " << var("QMAKE_LEX") << endl;
 
486
    t << "YACC          = " << var("QMAKE_YACC") << endl;
 
487
    t << "DEFINES       = "
 
488
      << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
 
489
      << varGlue("DEFINES","-D"," -D","") << endl;
 
490
    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES)" << endl;
 
491
    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)" << endl;
 
492
    t << "LEXFLAGS      = " << var("QMAKE_LEXFLAGS") << endl;
 
493
    t << "YACCFLAGS     = " << var("QMAKE_YACCFLAGS") << endl;
 
494
    t << "INCPATH       = ";
 
495
 
 
496
    QStringList &incs = project->variables()["INCLUDEPATH"];
 
497
    for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
 
498
        QString inc = (*incit);
 
499
        inc.replace(QRegExp("\\\\$"), "");
 
500
        inc.replace(QRegExp("\""), "");
 
501
        t << "-I" << "\"" << inc << "\" ";
 
502
    }
 
503
    t << "-I\"" << specdir() << "\""
 
504
      << endl;
 
505
 
 
506
    writeLibsPart(t);
 
507
 
 
508
    t << "QMAKE         = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") :
 
509
                              Option::fixPathToTargetOS(var("QMAKE_QMAKE"), false)) << endl;
 
510
    t << "IDC           = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
 
511
                              Option::fixPathToTargetOS(var("QMAKE_IDC"), false)) << endl;
 
512
    t << "IDL           = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
 
513
                              Option::fixPathToTargetOS(var("QMAKE_IDL"), false)) << endl;
 
514
    t << "ZIP           = " << var("QMAKE_ZIP") << endl;
 
515
    t << "DEF_FILE      = " << varList("DEF_FILE") << endl;
 
516
    t << "RES_FILE      = " << varList("RES_FILE") << endl; // Not on mingw, can't see why not though...
 
517
    t << "COPY          = " << var("QMAKE_COPY") << endl;
 
518
    t << "COPY_FILE     = " << var("QMAKE_COPY_FILE") << endl;
 
519
    t << "COPY_DIR      = " << var("QMAKE_COPY_DIR") << endl;
 
520
    t << "DEL_FILE      = " << var("QMAKE_DEL_FILE") << endl;
 
521
    t << "DEL_DIR       = " << var("QMAKE_DEL_DIR") << endl;
 
522
    t << "MOVE          = " << var("QMAKE_MOVE") << endl;
 
523
    t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl;
 
524
    t << "MKDIR         = " << var("QMAKE_MKDIR") << endl;
 
525
    t << "INSTALL_FILE  = " << var("QMAKE_INSTALL_FILE") << endl;
 
526
    t << "INSTALL_DIR   = " << var("QMAKE_INSTALL_DIR") << endl;
 
527
    t << endl;
 
528
 
 
529
    t << "####### Output directory" << endl << endl;
 
530
    if(!project->variables()["OBJECTS_DIR"].isEmpty())
 
531
        t << "OBJECTS_DIR   = " << var("OBJECTS_DIR").replace(QRegExp("\\\\$"),"") << endl;
 
532
    else
 
533
        t << "OBJECTS_DIR   = . " << endl;
 
534
    t << endl;
 
535
 
 
536
    t << "####### Files" << endl << endl;
 
537
    t << "SOURCES       = " << varList("SOURCES") << " " << varList("GENERATED_SOURCES") << endl;
 
538
 
 
539
    writeObjectsPart(t);
 
540
 
 
541
    writeExtraCompilerVariables(t);
 
542
    writeExtraVariables(t);
 
543
 
 
544
    t << "DIST          = " << varList("DISTFILES") << endl;
 
545
    t << "QMAKE_TARGET  = " << var("QMAKE_ORIG_TARGET") << endl;
 
546
    // The comment is important to maintain variable compatability with Unix
 
547
    // Makefiles, while not interpreting a trailing-slash as a linebreak
 
548
    t << "DESTDIR       = " << var("DESTDIR") << " #avoid trailing-slash linebreak" << endl;
 
549
    t << "TARGET        = ";
 
550
    QString target = var("DESTDIR") + project->first("TARGET") + project->first("TARGET_EXT");
 
551
    target.remove('"');
 
552
    t << target;
 
553
    t << endl << endl;
 
554
 
 
555
    t << "####### Implicit rules" << endl << endl;
 
556
    writeImplicitRulesPart(t);
 
557
 
 
558
    t << "####### Build rules" << endl << endl;
 
559
    writeBuildRulesPart(t);
 
560
 
 
561
    if (!project->variables()["QMAKE_POST_LINK"].isEmpty())
 
562
        t << "\t" <<var("QMAKE_POST_LINK") << endl;
 
563
 
 
564
    if(project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty()) {
 
565
        QStringList dlldirs = project->variables()["DLLDESTDIR"];
 
566
        for (QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
 
567
            t << "\n\t" << "-$(COPY_FILE) \"$(TARGET)\" " << *dlldir;
 
568
        }
 
569
    }
 
570
    t << endl << endl;
 
571
 
 
572
    writeRcFilePart(t);
 
573
 
 
574
    writeMakeQmake(t);
 
575
 
 
576
    QStringList dist_files = fileFixify(Option::mkfile::project_files);
 
577
    if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES"))
 
578
        dist_files += project->variables()["QMAKE_INTERNAL_INCLUDED_FILES"];
 
579
    if(!project->isEmpty("TRANSLATIONS"))
 
580
        dist_files << var("TRANSLATIONS");
 
581
    if(!project->isEmpty("FORMS")) {
 
582
        QStringList &forms = project->variables()["FORMS"];
 
583
        for(QStringList::Iterator formit = forms.begin(); formit != forms.end(); ++formit) {
 
584
            QString ui_h = fileFixify((*formit) + Option::h_ext.first());
 
585
            if(exists(ui_h))
 
586
                dist_files << ui_h;
 
587
        }
 
588
    }
 
589
    t << "dist:" << "\n\t"
 
590
      << "$(ZIP) " << var("QMAKE_ORIG_TARGET") << ".zip " << "$(SOURCES) $(DIST) "
 
591
      << dist_files.join(" ") << " " << var("TRANSLATIONS") << " ";
 
592
    if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
 
593
        const QStringList &quc = project->variables()["QMAKE_EXTRA_COMPILERS"];
 
594
        for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
 
595
            const QStringList &inputs = project->variables()[(*it)+".input"];
 
596
            for(QStringList::ConstIterator input = inputs.begin(); input != inputs.end(); ++input) {
 
597
                t << (*input) << " ";
 
598
            }
 
599
        }
 
600
    }
 
601
    t << endl << endl;
 
602
 
 
603
    writeCleanParts(t);
 
604
    writeExtraTargets(t);
 
605
    writeExtraCompilerTargets(t);
 
606
    t << endl << endl;
 
607
}
 
608
 
 
609
void Win32MakefileGenerator::writeLibsPart(QTextStream &t)
 
610
{
 
611
    if(project->isActiveConfig("staticlib")) {
 
612
        t << "LIB           = " << var("QMAKE_LIB") << endl;
 
613
    } else {
 
614
        t << "LINK          = " << var("QMAKE_LINK") << endl;
 
615
        t << "LFLAGS        = ";
 
616
        if(!project->variables()["QMAKE_LIBDIR"].isEmpty())
 
617
            writeLibDirPart(t);
 
618
        t << var("QMAKE_LFLAGS") << endl;
 
619
        t << "LIBS          = " << var("QMAKE_LIBS") << endl;
 
620
    }
 
621
}
 
622
 
 
623
void Win32MakefileGenerator::writeLibDirPart(QTextStream &t)
 
624
{
 
625
    t << varGlue("QMAKE_LIBDIR","-L\"","\" -L\"","\"") << " ";
 
626
}
 
627
 
 
628
void Win32MakefileGenerator::writeObjectsPart(QTextStream &t)
 
629
{
 
630
    t << "OBJECTS       = " << varList("OBJECTS") << endl;
 
631
}
 
632
 
 
633
void Win32MakefileGenerator::writeImplicitRulesPart(QTextStream &t)
 
634
{
 
635
    t << ".SUFFIXES: .c";
 
636
    QStringList::Iterator cppit;
 
637
    for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
 
638
        t << " " << (*cppit);
 
639
    t << endl << endl;
 
640
    for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
 
641
        t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
 
642
    t << ".c" << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
 
643
}
 
644
 
 
645
void Win32MakefileGenerator::writeBuildRulesPart(QTextStream &)
 
646
{
 
647
}
 
648
 
 
649
void Win32MakefileGenerator::writeRcFilePart(QTextStream &t)
 
650
{
 
651
    if(!project->variables()["RC_FILE"].isEmpty()) {
 
652
        t << var("RES_FILE") << ": " << var("RC_FILE") << "\n\t"
 
653
          << var("QMAKE_RC") << " -fo " << var("RES_FILE") << " "
 
654
          << var("RC_FILE");
 
655
        t << endl << endl;
 
656
    }
 
657
}
 
658
 
 
659
QString Win32MakefileGenerator::defaultInstall(const QString &t)
 
660
{
 
661
    if(t != "target" || project->first("TEMPLATE") == "subdirs")
 
662
        return QString();
 
663
 
 
664
    const QString root = "$(INSTALL_ROOT)";
 
665
    QStringList &uninst = project->variables()[t + ".uninstall"];
 
666
    QString ret;
 
667
    QString targetdir = Option::fixPathToTargetOS(project->first("target.path"), false);
 
668
    targetdir = fileFixify(targetdir, FileFixifyAbsolute);
 
669
    if(targetdir.right(1) != Option::dir_sep)
 
670
        targetdir += Option::dir_sep;
 
671
 
 
672
    QStringList links;
 
673
    QString target="$(TARGET)";
 
674
    if(project->first("TEMPLATE") == "lib") {
 
675
        if(project->isActiveConfig("create_prl") && !project->isActiveConfig("no_install_prl") &&
 
676
           !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) {
 
677
            QString dst_prl = project->first("QMAKE_INTERNAL_PRL_FILE");
 
678
            int slsh = dst_prl.lastIndexOf('/');
 
679
            if(slsh != -1)
 
680
                dst_prl = dst_prl.right(dst_prl.length() - slsh - 1);
 
681
            dst_prl = filePrefixRoot(root, targetdir + dst_prl);
 
682
            ret += "-$(INSTALL_FILE) \"" + project->first("QMAKE_INTERNAL_PRL_FILE") + "\" \"" + dst_prl + "\"";
 
683
            if(!uninst.isEmpty())
 
684
                uninst.append("\n\t");
 
685
            uninst.append("-$(DEL_FILE) \"" + dst_prl + "\"");
 
686
        }
 
687
    }
 
688
 
 
689
    QString src_targ = target;
 
690
    QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + target, FileFixifyAbsolute));
 
691
    if(!ret.isEmpty())
 
692
        ret += "\n\t";
 
693
    ret += QString("-$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
 
694
    if(!uninst.isEmpty())
 
695
        uninst.append("\n\t");
 
696
    uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
 
697
    return ret;
 
698
}