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 "msvc_nmake.h"
44 #include "cesdkhandler.h"
52 NmakeMakefileGenerator::NmakeMakefileGenerator() : Win32MakefileGenerator(), init_flag(false)
58 NmakeMakefileGenerator::writeMakefile(QTextStream &t)
61 if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
62 const QStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
63 for (QStringList::ConstIterator it = qut.begin(); it != qut.end(); ++it)
65 t << "all first clean:" << "\n\t"
66 << "@echo \"Some of the required modules ("
67 << var("QMAKE_FAILED_REQUIREMENTS") << ") are not available.\"" << "\n\t"
68 << "@echo \"Skipped.\"" << endl << endl;
73 if(project->first("TEMPLATE") == "app" ||
74 project->first("TEMPLATE") == "lib" ||
75 project->first("TEMPLATE") == "aux") {
77 if(Option::mkfile::do_stub_makefile)
78 return MakefileGenerator::writeStubMakefile(t);
80 if (!project->isHostBuild()) {
81 const QHash<QString, QStringList> &variables = project->variables();
82 if (variables["QMAKESPEC"].first().contains("wince", Qt::CaseInsensitive)) {
83 CeSdkHandler sdkhandler;
85 const QString sdkName = variables["CE_SDK"].join(" ")
86 + " (" + variables["CE_ARCH"].join(" ") + ")";
87 const QList<CeSdkInfo> sdkList = sdkhandler.listAll();
89 foreach (const CeSdkInfo &info, sdkList) {
90 if (info.name().compare(sdkName, Qt::CaseInsensitive ) == 0) {
96 t << "\nINCLUDE = " << sdk.includePath();
97 t << "\nLIB = " << sdk.libPath();
98 t << "\nPATH = " << sdk.binPath() << "\n";
103 return MakefileGenerator::writeMakefile(t);
105 else if(project->first("TEMPLATE") == "subdirs") {
112 void NmakeMakefileGenerator::writeSubMakeCall(QTextStream &t, const QString &callPrefix,
113 const QString &makeArguments, const QString &callPostfix)
115 // Pass MAKEFLAGS as environment variable to sub-make calls.
116 // Unlike other make tools nmake doesn't do this automatically.
117 t << "\n\t@set MAKEFLAGS=$(MAKEFLAGS)";
118 Win32MakefileGenerator::writeSubMakeCall(t, callPrefix, makeArguments, callPostfix);
121 QString NmakeMakefileGenerator::getPdbTarget()
123 return QString(project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".pdb");
126 QString NmakeMakefileGenerator::defaultInstall(const QString &t)
128 if((t != "target" && t != "dlltarget") ||
129 (t == "dlltarget" && (project->first("TEMPLATE") != "lib" || !project->isActiveConfig("shared"))) ||
130 project->first("TEMPLATE") == "subdirs")
133 QString ret = Win32MakefileGenerator::defaultInstall(t);
135 const QString root = "$(INSTALL_ROOT)";
136 QStringList &uninst = project->values(t + ".uninstall");
137 QString targetdir = Option::fixPathToTargetOS(project->first(t + ".path"), false);
138 targetdir = fileFixify(targetdir, FileFixifyAbsolute);
139 if(targetdir.right(1) != Option::dir_sep)
140 targetdir += Option::dir_sep;
142 if(t == "target" && project->first("TEMPLATE") == "lib") {
143 if(project->isActiveConfig("shared") && project->isActiveConfig("debug")) {
144 QString pdb_target = getPdbTarget();
145 pdb_target.remove('"');
146 QString src_targ = (project->isEmpty("DESTDIR") ? QString("$(DESTDIR)") : project->first("DESTDIR")) + pdb_target;
147 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + pdb_target, FileFixifyAbsolute));
150 ret += QString("-$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
151 if(!uninst.isEmpty())
152 uninst.append("\n\t");
153 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
160 QStringList &NmakeMakefileGenerator::findDependencies(const QString &file)
162 QStringList &aList = MakefileGenerator::findDependencies(file);
163 // Note: The QMAKE_IMAGE_COLLECTION file have all images
164 // as dependency, so don't add precompiled header then
165 if (file == project->first("QMAKE_IMAGE_COLLECTION"))
167 for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
168 if(file.endsWith(*it)) {
169 if(!precompObj.isEmpty() && !aList.contains(precompObj))
177 void NmakeMakefileGenerator::writeNmakeParts(QTextStream &t)
179 writeStandardParts(t);
181 // precompiled header
183 QString precompRule = QString("-c -Yc -Fp%1 -Fo%2").arg(precompPch).arg(precompObj);
184 t << precompObj << ": " << precompH << " " << escapeDependencyPaths(findDependencies(precompH)).join(" \\\n\t\t")
185 << "\n\t" << "$(CXX) " + precompRule +" $(CXXFLAGS) $(INCPATH) -TP " << precompH << endl << endl;
189 QString NmakeMakefileGenerator::var(const QString &value)
192 if ((value == "QMAKE_RUN_CXX_IMP_BATCH"
193 || value == "QMAKE_RUN_CXX_IMP"
194 || value == "QMAKE_RUN_CXX")) {
195 QFileInfo precompHInfo(fileInfo(precompH));
196 QString precompRule = QString("-c -FI%1 -Yu%2 -Fp%3")
197 .arg(precompHInfo.fileName())
198 .arg(precompHInfo.fileName())
200 QString p = MakefileGenerator::var(value);
201 p.replace("-c", precompRule);
202 // Cannot use -Gm with -FI & -Yu, as this gives an
203 // internal compiler error, on the newer compilers
204 // ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
207 } else if (value == "QMAKE_CXXFLAGS") {
208 // Remove internal compiler error option
209 // ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
210 return MakefileGenerator::var(value).remove("-Gm");
215 return MakefileGenerator::var(value);
218 void NmakeMakefileGenerator::init()
224 /* this should probably not be here, but I'm using it to wrap the .t files */
225 if(project->first("TEMPLATE") == "app")
226 project->values("QMAKE_APP_FLAG").append("1");
227 else if(project->first("TEMPLATE") == "lib")
228 project->values("QMAKE_LIB_FLAG").append("1");
229 else if(project->first("TEMPLATE") == "subdirs") {
230 MakefileGenerator::init();
231 if(project->values("MAKEFILE").isEmpty())
232 project->values("MAKEFILE").append("Makefile");
233 if(project->isEmpty("QMAKE_COPY_FILE"))
234 project->values("QMAKE_COPY_FILE").append("$(COPY)");
235 if(project->isEmpty("QMAKE_COPY_DIR"))
236 project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
237 if(project->isEmpty("QMAKE_INSTALL_FILE"))
238 project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
239 if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
240 project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
241 if(project->isEmpty("QMAKE_INSTALL_DIR"))
242 project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
246 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
247 project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
250 if (!project->values("RES_FILE").isEmpty()) {
251 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
254 if (!project->values("DEF_FILE").isEmpty()) {
255 QString defFileName = fileFixify(project->values("DEF_FILE")).first();
256 project->values("QMAKE_LFLAGS").append(QString("/DEF:") + escapeFilePath(defFileName));
259 if(!project->values("VERSION").isEmpty()) {
260 QString version = project->values("VERSION")[0];
261 int firstDot = version.indexOf(".");
262 QString major = version.left(firstDot);
263 QString minor = version.right(version.length() - firstDot - 1);
264 minor.replace(".", "");
265 project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
269 MakefileGenerator::init();
271 // Setup PCH variables
272 precompH = project->first("PRECOMPILED_HEADER");
273 usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
276 precompObj = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch" + Option::obj_ext;
277 precompPch = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch.pch";
278 // Add linking of precompObj (required for whole precompiled classes)
279 project->values("OBJECTS") += precompObj;
280 // Add pch file to cleanup
281 project->values("QMAKE_CLEAN") += precompPch;
282 // Return to variable pool
283 project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
284 project->values("PRECOMPILED_PCH") = QStringList(precompPch);
287 QString version = project->first("TARGET_VERSION_EXT");
288 if(project->isActiveConfig("shared")) {
289 project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".exp");
291 if(project->isActiveConfig("debug")) {
292 project->values("QMAKE_DISTCLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".pdb");
293 project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".ilk");
294 project->values("QMAKE_CLEAN").append("vc*.pdb");
295 project->values("QMAKE_CLEAN").append("vc*.idb");
299 void NmakeMakefileGenerator::writeLibDirPart(QTextStream &t)
301 QStringList libDirs = project->values("QMAKE_LIBDIR");
302 for (int i = 0; i < libDirs.size(); ++i)
303 libDirs[i].remove("\"");
304 t << valGlue(libDirs,"/LIBPATH:\"","\" /LIBPATH:\"","\"") << " ";
307 void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
310 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
312 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
313 t << " " << (*cppit);
316 if(!project->isActiveConfig("no_batch")) {
317 // Batchmode doesn't use the non implicit rules QMAKE_RUN_CXX & QMAKE_RUN_CC
318 project->variables().remove("QMAKE_RUN_CXX");
319 project->variables().remove("QMAKE_RUN_CC");
321 QHash<QString, void*> source_directories;
322 source_directories.insert(".", (void*)1);
323 QString directories[] = { QString("UI_SOURCES_DIR"), QString("UI_DIR"), QString() };
324 for(int y = 0; !directories[y].isNull(); y++) {
325 QString dirTemp = project->first(directories[y]);
326 if (dirTemp.endsWith("\\"))
327 dirTemp.truncate(dirTemp.length()-1);
328 if(!dirTemp.isEmpty())
329 source_directories.insert(dirTemp, (void*)1);
331 QString srcs[] = { QString("SOURCES"), QString("GENERATED_SOURCES"), QString() };
332 for(int x = 0; !srcs[x].isNull(); x++) {
333 const QStringList &l = project->values(srcs[x]);
334 for (QStringList::ConstIterator sit = l.begin(); sit != l.end(); ++sit) {
336 if((*sit).indexOf(sep) == -1)
338 QString dir = (*sit).section(sep, 0, -2);
339 if(!dir.isEmpty() && !source_directories[dir])
340 source_directories.insert(dir, (void*)1);
344 for(QHash<QString, void*>::Iterator it(source_directories.begin()); it != source_directories.end(); ++it) {
345 if(it.key().isEmpty())
347 QString objDir = var("OBJECTS_DIR");
350 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
351 t << "{" << it.key() << "}" << (*cppit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
352 << var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\t$<" << endl << "<<" << endl << endl;
353 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
354 t << "{" << it.key() << "}" << (*cit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
355 << var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\t$<" << endl << "<<" << endl << endl;
358 for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
359 t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
360 for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
361 t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
366 void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t)
368 if (project->first("TEMPLATE") == "aux") {
369 t << "first:" << endl;
374 t << "first: all" << endl;
375 t << "all: " << fileFixify(Option::output.fileName()) << " " << varGlue("ALL_DEPS"," "," "," ") << "$(DESTDIR_TARGET)" << endl << endl;
376 t << "$(DESTDIR_TARGET): " << var("PRE_TARGETDEPS") << " $(OBJECTS) " << var("POST_TARGETDEPS");
378 if(!project->isEmpty("QMAKE_PRE_LINK"))
379 t << "\n\t" <<var("QMAKE_PRE_LINK");
380 if(project->isActiveConfig("staticlib")) {
381 t << "\n\t" << "$(LIBAPP) $(LIBFLAGS) /OUT:$(DESTDIR_TARGET) @<<" << "\n\t "
384 t << "\n\t" << "$(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<< " << "\n\t "
385 << "$(OBJECTS) $(LIBS)";
388 QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
389 bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
390 !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
392 t << "\n\tsigntool sign /F " << signature << " $(DESTDIR_TARGET)";
394 if(!project->isEmpty("QMAKE_POST_LINK")) {
395 t << "\n\t" << var("QMAKE_POST_LINK");