| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 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 | **
|
|---|
| 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.
|
|---|
| 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia 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 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | NmakeMakefileGenerator::NmakeMakefileGenerator() : Win32MakefileGenerator(), init_flag(false)
|
|---|
| 52 | {
|
|---|
| 53 |
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | bool
|
|---|
| 57 | NmakeMakefileGenerator::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 |
|
|---|
| 88 | QStringList &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 |
|
|---|
| 105 | void 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 |
|
|---|
| 117 | QString 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 |
|
|---|
| 144 | void 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->isEmpty("QMAKE_COPY_FILE"))
|
|---|
| 160 | project->values("QMAKE_COPY_FILE").append("$(COPY)");
|
|---|
| 161 | if(project->isEmpty("QMAKE_COPY_DIR"))
|
|---|
| 162 | project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
|
|---|
| 163 | if(project->isEmpty("QMAKE_INSTALL_FILE"))
|
|---|
| 164 | project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
|
|---|
| 165 | if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
|
|---|
| 166 | project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
|
|---|
| 167 | if(project->isEmpty("QMAKE_INSTALL_DIR"))
|
|---|
| 168 | project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
|
|---|
| 169 | return;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
|
|---|
| 173 | project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
|
|---|
| 174 | processVars();
|
|---|
| 175 |
|
|---|
| 176 | if (!project->values("RES_FILE").isEmpty()) {
|
|---|
| 177 | project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | if(!project->values("DEF_FILE").isEmpty())
|
|---|
| 181 | project->values("QMAKE_LFLAGS").append(QString("/DEF:") + escapeFilePath(project->first("DEF_FILE")));
|
|---|
| 182 |
|
|---|
| 183 | if(!project->values("VERSION").isEmpty()) {
|
|---|
| 184 | QString version = project->values("VERSION")[0];
|
|---|
| 185 | int firstDot = version.indexOf(".");
|
|---|
| 186 | QString major = version.left(firstDot);
|
|---|
| 187 | QString minor = version.right(version.length() - firstDot - 1);
|
|---|
| 188 | minor.replace(".", "");
|
|---|
| 189 | project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | // Base class init!
|
|---|
| 193 | MakefileGenerator::init();
|
|---|
| 194 |
|
|---|
| 195 | // Setup PCH variables
|
|---|
| 196 | precompH = project->first("PRECOMPILED_HEADER");
|
|---|
| 197 | usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
|
|---|
| 198 | if (usePCH) {
|
|---|
| 199 | // Created files
|
|---|
| 200 | precompObj = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch" + Option::obj_ext;
|
|---|
| 201 | precompPch = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch.pch";
|
|---|
| 202 | // Add linking of precompObj (required for whole precompiled classes)
|
|---|
| 203 | project->values("OBJECTS") += precompObj;
|
|---|
| 204 | // Add pch file to cleanup
|
|---|
| 205 | project->values("QMAKE_CLEAN") += precompPch;
|
|---|
| 206 | // Return to variable pool
|
|---|
| 207 | project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
|
|---|
| 208 | project->values("PRECOMPILED_PCH") = QStringList(precompPch);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | QString version = project->first("TARGET_VERSION_EXT");
|
|---|
| 212 | if(project->isActiveConfig("shared")) {
|
|---|
| 213 | project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".exp");
|
|---|
| 214 | }
|
|---|
| 215 | if(project->isActiveConfig("debug")) {
|
|---|
| 216 | project->values("QMAKE_DISTCLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".pdb");
|
|---|
| 217 | project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".ilk");
|
|---|
| 218 | project->values("QMAKE_CLEAN").append("vc*.pdb");
|
|---|
| 219 | project->values("QMAKE_CLEAN").append("vc*.idb");
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | void NmakeMakefileGenerator::writeLibDirPart(QTextStream &t)
|
|---|
| 224 | {
|
|---|
| 225 | QStringList libDirs = project->values("QMAKE_LIBDIR");
|
|---|
| 226 | for (int i = 0; i < libDirs.size(); ++i)
|
|---|
| 227 | libDirs[i].remove("\"");
|
|---|
| 228 | t << valGlue(libDirs,"/LIBPATH:\"","\" /LIBPATH:\"","\"") << " ";
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
|
|---|
| 232 | {
|
|---|
| 233 | t << ".SUFFIXES:";
|
|---|
| 234 | for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
|
|---|
| 235 | t << " " << (*cit);
|
|---|
| 236 | for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
|---|
| 237 | t << " " << (*cppit);
|
|---|
| 238 | t << endl << endl;
|
|---|
| 239 |
|
|---|
| 240 | if(!project->isActiveConfig("no_batch")) {
|
|---|
| 241 | // Batchmode doesn't use the non implicit rules QMAKE_RUN_CXX & QMAKE_RUN_CC
|
|---|
| 242 | project->variables().remove("QMAKE_RUN_CXX");
|
|---|
| 243 | project->variables().remove("QMAKE_RUN_CC");
|
|---|
| 244 |
|
|---|
| 245 | QHash<QString, void*> source_directories;
|
|---|
| 246 | source_directories.insert(".", (void*)1);
|
|---|
| 247 | QString directories[] = { QString("UI_SOURCES_DIR"), QString("UI_DIR"), QString() };
|
|---|
| 248 | for(int y = 0; !directories[y].isNull(); y++) {
|
|---|
| 249 | QString dirTemp = project->first(directories[y]);
|
|---|
| 250 | if (dirTemp.endsWith("\\"))
|
|---|
| 251 | dirTemp.truncate(dirTemp.length()-1);
|
|---|
| 252 | if(!dirTemp.isEmpty())
|
|---|
| 253 | source_directories.insert(dirTemp, (void*)1);
|
|---|
| 254 | }
|
|---|
| 255 | QString srcs[] = { QString("SOURCES"), QString("GENERATED_SOURCES"), QString() };
|
|---|
| 256 | for(int x = 0; !srcs[x].isNull(); x++) {
|
|---|
| 257 | QStringList &l = project->values(srcs[x]);
|
|---|
| 258 | for(QStringList::Iterator sit = l.begin(); sit != l.end(); ++sit) {
|
|---|
| 259 | QString sep = "\\";
|
|---|
| 260 | if((*sit).indexOf(sep) == -1)
|
|---|
| 261 | sep = "/";
|
|---|
| 262 | QString dir = (*sit).section(sep, 0, -2);
|
|---|
| 263 | if(!dir.isEmpty() && !source_directories[dir])
|
|---|
| 264 | source_directories.insert(dir, (void*)1);
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | for(QHash<QString, void*>::Iterator it(source_directories.begin()); it != source_directories.end(); ++it) {
|
|---|
| 269 | if(it.key().isEmpty())
|
|---|
| 270 | continue;
|
|---|
| 271 | QString objDir = var("OBJECTS_DIR");
|
|---|
| 272 | if (objDir == ".\\")
|
|---|
| 273 | objDir = "";
|
|---|
| 274 | for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
|---|
| 275 | t << "{" << it.key() << "}" << (*cppit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
|
|---|
| 276 | << var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\t$<" << endl << "<<" << endl << endl;
|
|---|
| 277 | for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
|
|---|
| 278 | t << "{" << it.key() << "}" << (*cit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
|
|---|
| 279 | << var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\t$<" << endl << "<<" << endl << endl;
|
|---|
| 280 | }
|
|---|
| 281 | } else {
|
|---|
| 282 | for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
|---|
| 283 | t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
|
|---|
| 284 | for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
|
|---|
| 285 | t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t)
|
|---|
| 291 | {
|
|---|
| 292 | t << "first: all" << endl;
|
|---|
| 293 | t << "all: " << fileFixify(Option::output.fileName()) << " " << varGlue("ALL_DEPS"," "," "," ") << "$(DESTDIR_TARGET)" << endl << endl;
|
|---|
| 294 | t << "$(DESTDIR_TARGET): " << var("PRE_TARGETDEPS") << " $(OBJECTS) " << var("POST_TARGETDEPS");
|
|---|
| 295 |
|
|---|
| 296 | if(!project->isEmpty("QMAKE_PRE_LINK"))
|
|---|
| 297 | t << "\n\t" <<var("QMAKE_PRE_LINK");
|
|---|
| 298 | if(project->isActiveConfig("staticlib")) {
|
|---|
| 299 | t << "\n\t" << "$(LIBAPP) $(LIBFLAGS) /OUT:$(DESTDIR_TARGET) @<<" << "\n\t "
|
|---|
| 300 | << "$(OBJECTS)";
|
|---|
| 301 | } else {
|
|---|
| 302 | t << "\n\t" << "$(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<< " << "\n\t "
|
|---|
| 303 | << "$(OBJECTS) $(LIBS)";
|
|---|
| 304 | }
|
|---|
| 305 | t << endl << "<<";
|
|---|
| 306 | QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
|
|---|
| 307 | bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
|
|---|
| 308 | !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
|
|---|
| 309 | if(useSignature) {
|
|---|
| 310 | t << "\n\tsigntool sign /F " << signature << " $(DESTDIR_TARGET)";
|
|---|
| 311 | }
|
|---|
| 312 | if(!project->isEmpty("QMAKE_POST_LINK")) {
|
|---|
| 313 | t << "\n\t" << var("QMAKE_POST_LINK");
|
|---|
| 314 | }
|
|---|
| 315 | t << endl;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | QT_END_NAMESPACE
|
|---|