source: trunk/qmake/generators/win32/msvc_nmake.cpp@ 247

Last change on this file since 247 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 13.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the qmake application of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "msvc_nmake.h"
43#include "option.h"
44#include <qregexp.h>
45#include <qhash.h>
46#include <qdir.h>
47#include <time.h>
48
49QT_BEGIN_NAMESPACE
50
51NmakeMakefileGenerator::NmakeMakefileGenerator() : Win32MakefileGenerator(), init_flag(false)
52{
53
54}
55
56bool
57NmakeMakefileGenerator::writeMakefile(QTextStream &t)
58{
59 writeHeader(t);
60 if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
61 QStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
62 for(QStringList::ConstIterator it = qut.begin(); it != qut.end(); ++it)
63 t << *it << " ";
64 t << "all first clean:" << "\n\t"
65 << "@echo \"Some of the required modules ("
66 << var("QMAKE_FAILED_REQUIREMENTS") << ") are not available.\"" << "\n\t"
67 << "@echo \"Skipped.\"" << endl << endl;
68 writeMakeQmake(t);
69 return true;
70 }
71
72 if(project->first("TEMPLATE") == "app" ||
73 project->first("TEMPLATE") == "lib") {
74#if 0
75 if(Option::mkfile::do_stub_makefile)
76 return MakefileGenerator::writeStubMakefile(t);
77#endif
78 writeNmakeParts(t);
79 return MakefileGenerator::writeMakefile(t);
80 }
81 else if(project->first("TEMPLATE") == "subdirs") {
82 writeSubDirs(t);
83 return true;
84 }
85 return false;
86}
87
88QStringList &NmakeMakefileGenerator::findDependencies(const QString &file)
89{
90 QStringList &aList = MakefileGenerator::findDependencies(file);
91 // Note: The QMAKE_IMAGE_COLLECTION file have all images
92 // as dependency, so don't add precompiled header then
93 if (file == project->first("QMAKE_IMAGE_COLLECTION"))
94 return aList;
95 for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
96 if(file.endsWith(*it)) {
97 if(!precompObj.isEmpty() && !aList.contains(precompObj))
98 aList += precompObj;
99 break;
100 }
101 }
102 return aList;
103}
104
105void NmakeMakefileGenerator::writeNmakeParts(QTextStream &t)
106{
107 writeStandardParts(t);
108
109 // precompiled header
110 if(usePCH) {
111 QString precompRule = QString("-c -Yc -Fp%1 -Fo%2").arg(precompPch).arg(precompObj);
112 t << precompObj << ": " << precompH << " " << findDependencies(precompH).join(" \\\n\t\t")
113 << "\n\t" << "$(CXX) " + precompRule +" $(CXXFLAGS) $(INCPATH) -TP " << precompH << endl << endl;
114 }
115}
116
117QString NmakeMakefileGenerator::var(const QString &value)
118{
119 if (usePCH) {
120 if ((value == "QMAKE_RUN_CXX_IMP_BATCH"
121 || value == "QMAKE_RUN_CXX_IMP"
122 || value == "QMAKE_RUN_CXX")) {
123 QFileInfo precompHInfo(fileInfo(precompH));
124 QString precompRule = QString("-c -FI%1 -Yu%2 -Fp%3")
125 .arg(precompHInfo.fileName())
126 .arg(precompHInfo.fileName())
127 .arg(precompPch);
128 QString p = MakefileGenerator::var(value);
129 p.replace("-c", precompRule);
130 // Cannot use -Gm with -FI & -Yu, as this gives an
131 // internal compiler error, on the newer compilers
132 p.remove("-Gm");
133 return p;
134 } else if (value == "QMAKE_CXXFLAGS") {
135 // Remove internal compiler error option
136 return MakefileGenerator::var(value).remove("-Gm");
137 }
138 }
139
140 // Normal val
141 return MakefileGenerator::var(value);
142}
143
144void NmakeMakefileGenerator::init()
145{
146 if(init_flag)
147 return;
148 init_flag = true;
149
150 /* this should probably not be here, but I'm using it to wrap the .t files */
151 if(project->first("TEMPLATE") == "app")
152 project->values("QMAKE_APP_FLAG").append("1");
153 else if(project->first("TEMPLATE") == "lib")
154 project->values("QMAKE_LIB_FLAG").append("1");
155 else if(project->first("TEMPLATE") == "subdirs") {
156 MakefileGenerator::init();
157 if(project->values("MAKEFILE").isEmpty())
158 project->values("MAKEFILE").append("Makefile");
159 if(project->values("QMAKE_QMAKE").isEmpty())
160 project->values("QMAKE_QMAKE").append("qmake");
161 if(project->isEmpty("QMAKE_COPY_FILE"))
162 project->values("QMAKE_COPY_FILE").append("$(COPY)");
163 if(project->isEmpty("QMAKE_COPY_DIR"))
164 project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
165 if(project->isEmpty("QMAKE_INSTALL_FILE"))
166 project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
167 if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
168 project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
169 if(project->isEmpty("QMAKE_INSTALL_DIR"))
170 project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
171 return;
172 }
173
174 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
175 processVars();
176
177 if (!project->values("RES_FILE").isEmpty()) {
178 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
179 }
180
181 if(!project->values("DEF_FILE").isEmpty())
182 project->values("QMAKE_LFLAGS").append(QString("/DEF:") + escapeFilePath(project->first("DEF_FILE")));
183
184 if(!project->values("VERSION").isEmpty()) {
185 QString version = project->values("VERSION")[0];
186 int firstDot = version.indexOf(".");
187 QString major = version.left(firstDot);
188 QString minor = version.right(version.length() - firstDot - 1);
189 minor.replace(".", "");
190 project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
191 }
192
193 // Base class init!
194 MakefileGenerator::init();
195
196 // Setup PCH variables
197 precompH = project->first("PRECOMPILED_HEADER");
198 usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
199 if (usePCH) {
200 // Created files
201 precompObj = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch" + Option::obj_ext;
202 precompPch = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch.pch";
203 // Add linking of precompObj (required for whole precompiled classes)
204 project->values("OBJECTS") += precompObj;
205 // Add pch file to cleanup
206 project->values("QMAKE_CLEAN") += precompPch;
207 // Return to variable pool
208 project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
209 project->values("PRECOMPILED_PCH") = QStringList(precompPch);
210 }
211
212 QString version = project->first("TARGET_VERSION_EXT");
213 if(project->isActiveConfig("shared")) {
214 project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".exp");
215 }
216 if(project->isActiveConfig("debug")) {
217 project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".pdb");
218 project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".ilk");
219 project->values("QMAKE_CLEAN").append("vc*.pdb");
220 project->values("QMAKE_CLEAN").append("vc*.idb");
221 }
222}
223
224void NmakeMakefileGenerator::writeLibDirPart(QTextStream &t)
225{
226 QStringList libDirs = project->values("QMAKE_LIBDIR");
227 for (int i = 0; i < libDirs.size(); ++i)
228 libDirs[i].remove("\"");
229 t << valGlue(libDirs,"/LIBPATH:\"","\" /LIBPATH:\"","\"") << " ";
230}
231
232void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
233{
234 t << ".SUFFIXES:";
235 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
236 t << " " << (*cit);
237 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
238 t << " " << (*cppit);
239 t << endl << endl;
240
241 if(!project->isActiveConfig("no_batch")) {
242 // Batchmode doesn't use the non implicit rules QMAKE_RUN_CXX & QMAKE_RUN_CC
243 project->variables().remove("QMAKE_RUN_CXX");
244 project->variables().remove("QMAKE_RUN_CC");
245
246 QHash<QString, void*> source_directories;
247 source_directories.insert(".", (void*)1);
248 QString directories[] = { QString("UI_SOURCES_DIR"), QString("UI_DIR"), QString() };
249 for(int y = 0; !directories[y].isNull(); y++) {
250 QString dirTemp = project->first(directories[y]);
251 if (dirTemp.endsWith("\\"))
252 dirTemp.truncate(dirTemp.length()-1);
253 if(!dirTemp.isEmpty())
254 source_directories.insert(dirTemp, (void*)1);
255 }
256 QString srcs[] = { QString("SOURCES"), QString("GENERATED_SOURCES"), QString() };
257 for(int x = 0; !srcs[x].isNull(); x++) {
258 QStringList &l = project->values(srcs[x]);
259 for(QStringList::Iterator sit = l.begin(); sit != l.end(); ++sit) {
260 QString sep = "\\";
261 if((*sit).indexOf(sep) == -1)
262 sep = "/";
263 QString dir = (*sit).section(sep, 0, -2);
264 if(!dir.isEmpty() && !source_directories[dir])
265 source_directories.insert(dir, (void*)1);
266 }
267 }
268
269 for(QHash<QString, void*>::Iterator it(source_directories.begin()); it != source_directories.end(); ++it) {
270 if(it.key().isEmpty())
271 continue;
272 QString objDir = var("OBJECTS_DIR");
273 if (objDir == ".\\")
274 objDir = "";
275 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
276 t << "{" << it.key() << "}" << (*cppit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
277 << var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\t$<" << endl << "<<" << endl << endl;
278 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
279 t << "{" << it.key() << "}" << (*cit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
280 << var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\t$<" << endl << "<<" << endl << endl;
281 }
282 } else {
283 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
284 t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
285 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
286 t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
287 }
288
289}
290
291void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t)
292{
293 t << "first: all" << endl;
294 t << "all: " << fileFixify(Option::output.fileName()) << " " << varGlue("ALL_DEPS"," "," "," ") << "$(DESTDIR_TARGET)" << endl << endl;
295 t << "$(DESTDIR_TARGET): " << var("PRE_TARGETDEPS") << " $(OBJECTS) " << var("POST_TARGETDEPS");
296
297 if(!project->isEmpty("QMAKE_PRE_LINK"))
298 t << "\n\t" <<var("QMAKE_PRE_LINK");
299 if(project->isActiveConfig("staticlib")) {
300 t << "\n\t" << "$(LIBAPP) $(LIBFLAGS) /OUT:$(DESTDIR_TARGET) @<<" << "\n\t "
301 << "$(OBJECTS)";
302 } else {
303 t << "\n\t" << "$(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<< " << "\n\t "
304 << "$(OBJECTS) $(LIBS)";
305 }
306 t << endl << "<<";
307 QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
308 bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
309 !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
310 if(useSignature) {
311 t << "\n\tsigntool sign /F " << signature << " $(DESTDIR_TARGET)";
312 }
313 if(!project->isEmpty("QMAKE_POST_LINK")) {
314 if (useSignature)
315 t << " && " << var("QMAKE_POST_LINK");
316 else
317 t << "\n\t" << var("QMAKE_POST_LINK");
318 }
319 t << endl;
320}
321
322QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.