| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 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 qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "makefile.h"
|
|---|
| 43 | #include "option.h"
|
|---|
| 44 | #include "cachekeys.h"
|
|---|
| 45 | #include "meta.h"
|
|---|
| 46 | #include <qdir.h>
|
|---|
| 47 | #include <qfile.h>
|
|---|
| 48 | #include <qtextstream.h>
|
|---|
| 49 | #include <qregexp.h>
|
|---|
| 50 | #include <qhash.h>
|
|---|
| 51 | #include <qdebug.h>
|
|---|
| 52 | #include <qbuffer.h>
|
|---|
| 53 | #include <qsettings.h>
|
|---|
| 54 | #include <qdatetime.h>
|
|---|
| 55 | #if defined(Q_OS_UNIX)
|
|---|
| 56 | #include <unistd.h>
|
|---|
| 57 | #else
|
|---|
| 58 | #include <io.h>
|
|---|
| 59 | #endif
|
|---|
| 60 | #include <qdebug.h>
|
|---|
| 61 | #include <stdio.h>
|
|---|
| 62 | #include <stdlib.h>
|
|---|
| 63 | #include <time.h>
|
|---|
| 64 | #include <fcntl.h>
|
|---|
| 65 | #include <sys/types.h>
|
|---|
| 66 | #include <sys/stat.h>
|
|---|
| 67 |
|
|---|
| 68 | QT_BEGIN_NAMESPACE
|
|---|
| 69 |
|
|---|
| 70 | // Well, Windows doesn't have this, so here's the macro
|
|---|
| 71 | #ifndef S_ISDIR
|
|---|
| 72 | # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|---|
| 73 | #endif
|
|---|
| 74 |
|
|---|
| 75 | bool MakefileGenerator::canExecute(const QStringList &cmdline, int *a) const
|
|---|
| 76 | {
|
|---|
| 77 | int argv0 = -1;
|
|---|
| 78 | for(int i = 0; i < cmdline.count(); ++i) {
|
|---|
| 79 | if(!cmdline.at(i).contains('=')) {
|
|---|
| 80 | argv0 = i;
|
|---|
| 81 | break;
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 | if(a)
|
|---|
| 85 | *a = argv0;
|
|---|
| 86 | if(argv0 != -1) {
|
|---|
| 87 | const QString c = Option::fixPathToLocalOS(cmdline.at(argv0), true);
|
|---|
| 88 | if(exists(c))
|
|---|
| 89 | return true;
|
|---|
| 90 | }
|
|---|
| 91 | return false;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | QString MakefileGenerator::mkdir_p_asstring(const QString &dir, bool escape) const
|
|---|
| 95 | {
|
|---|
| 96 | QString ret = "@$(CHK_DIR_EXISTS) ";
|
|---|
| 97 | if(escape)
|
|---|
| 98 | ret += escapeFilePath(dir);
|
|---|
| 99 | else
|
|---|
| 100 | ret += dir;
|
|---|
| 101 | ret += " ";
|
|---|
| 102 | if(isDosLikeShell())
|
|---|
| 103 | ret += "$(MKDIR)";
|
|---|
| 104 | else
|
|---|
| 105 | ret += "|| $(MKDIR)";
|
|---|
| 106 | ret += " ";
|
|---|
| 107 | if(escape)
|
|---|
| 108 | ret += escapeFilePath(dir);
|
|---|
| 109 | else
|
|---|
| 110 | ret += dir;
|
|---|
| 111 | ret += " ";
|
|---|
| 112 | return ret;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | bool MakefileGenerator::mkdir(const QString &in_path) const
|
|---|
| 116 | {
|
|---|
| 117 | QString path = Option::fixPathToLocalOS(in_path);
|
|---|
| 118 | if(QFile::exists(path))
|
|---|
| 119 | return true;
|
|---|
| 120 |
|
|---|
| 121 | QDir d;
|
|---|
| 122 | if(path.startsWith(QDir::separator())) {
|
|---|
| 123 | d.cd(QString(QDir::separator()));
|
|---|
| 124 | path.remove(0, 1);
|
|---|
| 125 | }
|
|---|
| 126 | bool ret = true;
|
|---|
| 127 | #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
|---|
| 128 | bool driveExists = true;
|
|---|
| 129 | if(!QDir::isRelativePath(path)) {
|
|---|
| 130 | if(QFile::exists(path.left(3))) {
|
|---|
| 131 | d.cd(path.left(3));
|
|---|
| 132 | path.remove(0, 3);
|
|---|
| 133 | } else {
|
|---|
| 134 | warn_msg(WarnLogic, "Cannot access drive '%s' (%s)",
|
|---|
| 135 | path.left(3).toLatin1().data(), path.toLatin1().data());
|
|---|
| 136 | driveExists = false;
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 | if(driveExists)
|
|---|
| 140 | #endif
|
|---|
| 141 | {
|
|---|
| 142 | QStringList subs = path.split(QDir::separator());
|
|---|
| 143 | for(QStringList::Iterator subit = subs.begin(); subit != subs.end(); ++subit) {
|
|---|
| 144 | if(!d.cd(*subit)) {
|
|---|
| 145 | d.mkdir((*subit));
|
|---|
| 146 | if(d.exists((*subit))) {
|
|---|
| 147 | d.cd((*subit));
|
|---|
| 148 | } else {
|
|---|
| 149 | ret = false;
|
|---|
| 150 | break;
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 | return ret;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | // ** base makefile generator
|
|---|
| 159 | MakefileGenerator::MakefileGenerator() :
|
|---|
| 160 | init_opath_already(false), init_already(false), no_io(false), project(0)
|
|---|
| 161 | {
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | void
|
|---|
| 166 | MakefileGenerator::verifyCompilers()
|
|---|
| 167 | {
|
|---|
| 168 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 169 | QStringList &quc = v["QMAKE_EXTRA_COMPILERS"];
|
|---|
| 170 | for(int i = 0; i < quc.size(); ) {
|
|---|
| 171 | bool error = false;
|
|---|
| 172 | QString comp = quc.at(i);
|
|---|
| 173 | if(v[comp + ".output"].isEmpty()) {
|
|---|
| 174 | if(!v[comp + ".output_function"].isEmpty()) {
|
|---|
| 175 | v[comp + ".output"].append("${QMAKE_FUNC_FILE_IN_" + v[comp + ".output_function"].first() + "}");
|
|---|
| 176 | } else {
|
|---|
| 177 | error = true;
|
|---|
| 178 | warn_msg(WarnLogic, "Compiler: %s: No output file specified", comp.toLatin1().constData());
|
|---|
| 179 | }
|
|---|
| 180 | } else if(v[comp + ".input"].isEmpty()) {
|
|---|
| 181 | error = true;
|
|---|
| 182 | warn_msg(WarnLogic, "Compiler: %s: No input variable specified", comp.toLatin1().constData());
|
|---|
| 183 | }
|
|---|
| 184 | if(error)
|
|---|
| 185 | quc.removeAt(i);
|
|---|
| 186 | else
|
|---|
| 187 | ++i;
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void
|
|---|
| 192 | MakefileGenerator::initOutPaths()
|
|---|
| 193 | {
|
|---|
| 194 | if(init_opath_already)
|
|---|
| 195 | return;
|
|---|
| 196 | verifyCompilers();
|
|---|
| 197 | init_opath_already = true;
|
|---|
| 198 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 199 | //for shadow builds
|
|---|
| 200 | if(!v.contains("QMAKE_ABSOLUTE_SOURCE_PATH")) {
|
|---|
| 201 | if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty() &&
|
|---|
| 202 | v.contains("QMAKE_ABSOLUTE_SOURCE_ROOT")) {
|
|---|
| 203 | QString root = v["QMAKE_ABSOLUTE_SOURCE_ROOT"].first();
|
|---|
| 204 | root = QDir::fromNativeSeparators(root);
|
|---|
| 205 | if(!root.isEmpty()) {
|
|---|
| 206 | QFileInfo fi = fileInfo(Option::mkfile::cachefile);
|
|---|
| 207 | if(!fi.makeAbsolute()) {
|
|---|
| 208 | QString cache_r = fi.path(), pwd = Option::output_dir;
|
|---|
| 209 | if(pwd.startsWith(cache_r) && !pwd.startsWith(root)) {
|
|---|
| 210 | pwd = root + pwd.mid(cache_r.length());
|
|---|
| 211 | if(exists(pwd))
|
|---|
| 212 | v.insert("QMAKE_ABSOLUTE_SOURCE_PATH", QStringList(pwd));
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | if(!v["QMAKE_ABSOLUTE_SOURCE_PATH"].isEmpty()) {
|
|---|
| 219 | QString &asp = v["QMAKE_ABSOLUTE_SOURCE_PATH"].first();
|
|---|
| 220 | asp = QDir::fromNativeSeparators(asp);
|
|---|
| 221 | if(asp.isEmpty() || asp == Option::output_dir) //if they're the same, why bother?
|
|---|
| 222 | v["QMAKE_ABSOLUTE_SOURCE_PATH"].clear();
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | QString currentDir = qmake_getpwd(); //just to go back to
|
|---|
| 226 |
|
|---|
| 227 | //some builtin directories
|
|---|
| 228 | if(project->isEmpty("PRECOMPILED_DIR") && !project->isEmpty("OBJECTS_DIR"))
|
|---|
| 229 | v["PRECOMPILED_DIR"] = v["OBJECTS_DIR"];
|
|---|
| 230 | QString dirs[] = { QString("OBJECTS_DIR"), QString("DESTDIR"), QString("QMAKE_PKGCONFIG_DESTDIR"),
|
|---|
| 231 | QString("SUBLIBS_DIR"), QString("DLLDESTDIR"), QString("QMAKE_LIBTOOL_DESTDIR"),
|
|---|
| 232 | QString("PRECOMPILED_DIR"), QString() };
|
|---|
| 233 | for(int x = 0; !dirs[x].isEmpty(); x++) {
|
|---|
| 234 | if(v[dirs[x]].isEmpty())
|
|---|
| 235 | continue;
|
|---|
| 236 | const QString orig_path = v[dirs[x]].first();
|
|---|
| 237 |
|
|---|
| 238 | QString &pathRef = v[dirs[x]].first();
|
|---|
| 239 | pathRef = fileFixify(pathRef, Option::output_dir, Option::output_dir);
|
|---|
| 240 |
|
|---|
| 241 | #ifdef Q_OS_WIN
|
|---|
| 242 | // We don't want to add a separator for DLLDESTDIR on Windows (###why?)
|
|---|
| 243 | if(!(dirs[x] == "DLLDESTDIR"))
|
|---|
| 244 | #endif
|
|---|
| 245 | {
|
|---|
| 246 | if(!pathRef.endsWith(Option::dir_sep))
|
|---|
| 247 | pathRef += Option::dir_sep;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | if(noIO())
|
|---|
| 251 | continue;
|
|---|
| 252 |
|
|---|
| 253 | QString path = project->first(dirs[x]); //not to be changed any further
|
|---|
| 254 | path = fileFixify(path, currentDir, Option::output_dir);
|
|---|
| 255 | debug_msg(3, "Fixed output_dir %s (%s) into %s", dirs[x].toLatin1().constData(),
|
|---|
| 256 | orig_path.toLatin1().constData(), path.toLatin1().constData());
|
|---|
| 257 | if(!mkdir(path))
|
|---|
| 258 | warn_msg(WarnLogic, "%s: Cannot access directory '%s'", dirs[x].toLatin1().constData(),
|
|---|
| 259 | path.toLatin1().constData());
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | //out paths from the extra compilers
|
|---|
| 263 | const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
|
|---|
| 264 | for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
|
|---|
| 265 | QString tmp_out = project->values((*it) + ".output").first();
|
|---|
| 266 | if(tmp_out.isEmpty())
|
|---|
| 267 | continue;
|
|---|
| 268 | const QStringList &tmp = project->values((*it) + ".input");
|
|---|
| 269 | for(QStringList::ConstIterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
|
|---|
| 270 | QStringList &inputs = project->values((*it2));
|
|---|
| 271 | for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
|
|---|
| 272 | (*input) = fileFixify((*input), Option::output_dir, Option::output_dir);
|
|---|
| 273 | QString path = unescapeFilePath(replaceExtraCompilerVariables(tmp_out, (*input), QString()));
|
|---|
| 274 | path = Option::fixPathToTargetOS(path);
|
|---|
| 275 | int slash = path.lastIndexOf(Option::dir_sep);
|
|---|
| 276 | if(slash != -1) {
|
|---|
| 277 | path = path.left(slash);
|
|---|
| 278 | // Make out path only if it does not contain makefile variables
|
|---|
| 279 | if(!path.contains("${"))
|
|---|
| 280 | if(path != "." &&
|
|---|
| 281 | !mkdir(fileFixify(path, qmake_getpwd(), Option::output_dir)))
|
|---|
| 282 | warn_msg(WarnLogic, "%s: Cannot access directory '%s'",
|
|---|
| 283 | (*it).toLatin1().constData(), path.toLatin1().constData());
|
|---|
| 284 | }
|
|---|
| 285 | }
|
|---|
| 286 | }
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | if(!v["DESTDIR"].isEmpty()) {
|
|---|
| 290 | QDir d(v["DESTDIR"].first());
|
|---|
| 291 | if(Option::fixPathToLocalOS(d.absolutePath()) == Option::fixPathToLocalOS(Option::output_dir))
|
|---|
| 292 | v.remove("DESTDIR");
|
|---|
| 293 | }
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | QMakeProject
|
|---|
| 297 | *MakefileGenerator::projectFile() const
|
|---|
| 298 | {
|
|---|
| 299 | return project;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | void
|
|---|
| 303 | MakefileGenerator::setProjectFile(QMakeProject *p)
|
|---|
| 304 | {
|
|---|
| 305 | if(project)
|
|---|
| 306 | return;
|
|---|
| 307 | project = p;
|
|---|
| 308 | init();
|
|---|
| 309 | usePlatformDir();
|
|---|
| 310 | findLibraries();
|
|---|
| 311 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE &&
|
|---|
| 312 | project->isActiveConfig("link_prl")) //load up prl's'
|
|---|
| 313 | processPrlFiles();
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | QStringList
|
|---|
| 317 | MakefileGenerator::findFilesInVPATH(QStringList l, uchar flags, const QString &vpath_var)
|
|---|
| 318 | {
|
|---|
| 319 | QStringList vpath;
|
|---|
| 320 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 321 | for(int val_it = 0; val_it < l.count(); ) {
|
|---|
| 322 | bool remove_file = false;
|
|---|
| 323 | QString &val = l[val_it];
|
|---|
| 324 | if(!val.isEmpty()) {
|
|---|
| 325 | QString file = fixEnvVariables(val);
|
|---|
| 326 | if(!(flags & VPATH_NoFixify))
|
|---|
| 327 | file = fileFixify(file, qmake_getpwd(), Option::output_dir);
|
|---|
| 328 | if (file.at(0) == '\"' && file.at(file.length() - 1) == '\"')
|
|---|
| 329 | file = file.mid(1, file.length() - 2);
|
|---|
| 330 |
|
|---|
| 331 | if(exists(file)) {
|
|---|
| 332 | ++val_it;
|
|---|
| 333 | continue;
|
|---|
| 334 | }
|
|---|
| 335 | bool found = false;
|
|---|
| 336 | if(QDir::isRelativePath(val)) {
|
|---|
| 337 | if(vpath.isEmpty()) {
|
|---|
| 338 | if(!vpath_var.isEmpty())
|
|---|
| 339 | vpath = v[vpath_var];
|
|---|
| 340 | vpath += v["VPATH"] + v["QMAKE_ABSOLUTE_SOURCE_PATH"] + v["DEPENDPATH"];
|
|---|
| 341 | if(Option::output_dir != qmake_getpwd())
|
|---|
| 342 | vpath += Option::output_dir;
|
|---|
| 343 | }
|
|---|
| 344 | for(QStringList::Iterator vpath_it = vpath.begin();
|
|---|
| 345 | vpath_it != vpath.end(); ++vpath_it) {
|
|---|
| 346 | QString real_dir = Option::fixPathToLocalOS((*vpath_it));
|
|---|
| 347 | if(exists(real_dir + QDir::separator() + val)) {
|
|---|
| 348 | QString dir = (*vpath_it);
|
|---|
| 349 | if(!dir.endsWith(Option::dir_sep))
|
|---|
| 350 | dir += Option::dir_sep;
|
|---|
| 351 | val = dir + val;
|
|---|
| 352 | if(!(flags & VPATH_NoFixify))
|
|---|
| 353 | val = fileFixify(val);
|
|---|
| 354 | found = true;
|
|---|
| 355 | debug_msg(1, "Found file through vpath %s -> %s",
|
|---|
| 356 | file.toLatin1().constData(), val.toLatin1().constData());
|
|---|
| 357 | break;
|
|---|
| 358 | }
|
|---|
| 359 | }
|
|---|
| 360 | }
|
|---|
| 361 | if(!found) {
|
|---|
| 362 | QString dir, regex = val, real_dir;
|
|---|
| 363 | if(regex.lastIndexOf(Option::dir_sep) != -1) {
|
|---|
| 364 | dir = regex.left(regex.lastIndexOf(Option::dir_sep) + 1);
|
|---|
| 365 | real_dir = dir;
|
|---|
| 366 | if(!(flags & VPATH_NoFixify))
|
|---|
| 367 | real_dir = fileFixify(real_dir, qmake_getpwd(), Option::output_dir);
|
|---|
| 368 | regex.remove(0, dir.length());
|
|---|
| 369 | }
|
|---|
| 370 | if(real_dir.isEmpty() || exists(real_dir)) {
|
|---|
| 371 | QStringList files = QDir(real_dir).entryList(QStringList(regex));
|
|---|
| 372 | if(files.isEmpty()) {
|
|---|
| 373 | debug_msg(1, "%s:%d Failure to find %s in vpath (%s)",
|
|---|
| 374 | __FILE__, __LINE__,
|
|---|
| 375 | val.toLatin1().constData(), vpath.join("::").toLatin1().constData());
|
|---|
| 376 | if(flags & VPATH_RemoveMissingFiles)
|
|---|
| 377 | remove_file = true;
|
|---|
| 378 | else if(flags & VPATH_WarnMissingFiles)
|
|---|
| 379 | warn_msg(WarnLogic, "Failure to find: %s", val.toLatin1().constData());
|
|---|
| 380 | } else {
|
|---|
| 381 | l.removeAt(val_it);
|
|---|
| 382 | QString a;
|
|---|
| 383 | for(int i = (int)files.count()-1; i >= 0; i--) {
|
|---|
| 384 | if(files[i] == "." || files[i] == "..")
|
|---|
| 385 | continue;
|
|---|
| 386 | a = dir + files[i];
|
|---|
| 387 | if(!(flags & VPATH_NoFixify))
|
|---|
| 388 | a = fileFixify(a);
|
|---|
| 389 | l.insert(val_it, a);
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 | } else {
|
|---|
| 393 | debug_msg(1, "%s:%d Cannot match %s%c%s, as %s does not exist.",
|
|---|
| 394 | __FILE__, __LINE__, real_dir.toLatin1().constData(),
|
|---|
| 395 | QDir::separator().toLatin1(),
|
|---|
| 396 | regex.toLatin1().constData(), real_dir.toLatin1().constData());
|
|---|
| 397 | if(flags & VPATH_RemoveMissingFiles)
|
|---|
| 398 | remove_file = true;
|
|---|
| 399 | else if(flags & VPATH_WarnMissingFiles)
|
|---|
| 400 | warn_msg(WarnLogic, "Failure to find: %s", val.toLatin1().constData());
|
|---|
| 401 | }
|
|---|
| 402 | }
|
|---|
| 403 | }
|
|---|
| 404 | if(remove_file)
|
|---|
| 405 | l.removeAt(val_it);
|
|---|
| 406 | else
|
|---|
| 407 | ++val_it;
|
|---|
| 408 | }
|
|---|
| 409 | return l;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | void
|
|---|
| 413 | MakefileGenerator::initCompiler(const MakefileGenerator::Compiler &comp)
|
|---|
| 414 | {
|
|---|
| 415 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 416 | QStringList &l = v[comp.variable_in];
|
|---|
| 417 | // find all the relevant file inputs
|
|---|
| 418 | if(!init_compiler_already.contains(comp.variable_in)) {
|
|---|
| 419 | init_compiler_already.insert(comp.variable_in, true);
|
|---|
| 420 | if(!noIO())
|
|---|
| 421 | l = findFilesInVPATH(l, (comp.flags & Compiler::CompilerRemoveNoExist) ?
|
|---|
| 422 | VPATH_RemoveMissingFiles : VPATH_WarnMissingFiles, "VPATH_" + comp.variable_in);
|
|---|
| 423 | }
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | void
|
|---|
| 427 | MakefileGenerator::init()
|
|---|
| 428 | {
|
|---|
| 429 | initOutPaths();
|
|---|
| 430 | if(init_already)
|
|---|
| 431 | return;
|
|---|
| 432 | verifyCompilers();
|
|---|
| 433 | init_already = true;
|
|---|
| 434 |
|
|---|
| 435 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 436 | QStringList &quc = v["QMAKE_EXTRA_COMPILERS"];
|
|---|
| 437 |
|
|---|
| 438 | //make sure the COMPILERS are in the correct input/output chain order
|
|---|
| 439 | for(int comp_out = 0, jump_count = 0; comp_out < quc.size(); ++comp_out) {
|
|---|
| 440 | continue_compiler_chain:
|
|---|
| 441 | if(jump_count > quc.size()) //just to avoid an infinite loop here
|
|---|
| 442 | break;
|
|---|
| 443 | if(project->variables().contains(quc.at(comp_out) + ".variable_out")) {
|
|---|
| 444 | const QStringList &outputs = project->variables().value(quc.at(comp_out) + ".variable_out");
|
|---|
| 445 | for(int out = 0; out < outputs.size(); ++out) {
|
|---|
| 446 | for(int comp_in = 0; comp_in < quc.size(); ++comp_in) {
|
|---|
| 447 | if(comp_in == comp_out)
|
|---|
| 448 | continue;
|
|---|
| 449 | if(project->variables().contains(quc.at(comp_in) + ".input")) {
|
|---|
| 450 | const QStringList &inputs = project->variables().value(quc.at(comp_in) + ".input");
|
|---|
| 451 | for(int in = 0; in < inputs.size(); ++in) {
|
|---|
| 452 | if(inputs.at(in) == outputs.at(out) && comp_out > comp_in) {
|
|---|
| 453 | ++jump_count;
|
|---|
| 454 | //move comp_out to comp_in and continue the compiler chain
|
|---|
| 455 | quc.move(comp_out, comp_in);
|
|---|
| 456 | comp_out = comp_in;
|
|---|
| 457 | goto continue_compiler_chain;
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 | }
|
|---|
| 461 | }
|
|---|
| 462 | }
|
|---|
| 463 | }
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | if(!project->isEmpty("QMAKE_SUBSTITUTES")) {
|
|---|
| 467 | const QStringList &subs = v["QMAKE_SUBSTITUTES"];
|
|---|
| 468 | for(int i = 0; i < subs.size(); ++i) {
|
|---|
| 469 | if(!subs.at(i).endsWith(".in")) {
|
|---|
| 470 | warn_msg(WarnLogic, "Substitute '%s' does not end with '.in'",
|
|---|
| 471 | subs.at(i).toLatin1().constData());
|
|---|
| 472 | continue;
|
|---|
| 473 | }
|
|---|
| 474 | QFile in(fileFixify(subs.at(i))), out(fileInfo(subs.at(i)).fileName());
|
|---|
| 475 | if(out.fileName().endsWith(".in"))
|
|---|
| 476 | out.setFileName(out.fileName().left(out.fileName().length()-3));
|
|---|
| 477 | if(in.open(QFile::ReadOnly)) {
|
|---|
| 478 | QString contents;
|
|---|
| 479 | QStack<int> state;
|
|---|
| 480 | enum { IN_CONDITION, MET_CONDITION, PENDING_CONDITION };
|
|---|
| 481 | for(int count = 1; !in.atEnd(); ++count) {
|
|---|
| 482 | QString line = QString::fromUtf8(in.readLine());
|
|---|
| 483 | if(line.startsWith("!!IF ")) {
|
|---|
| 484 | if(state.isEmpty() || state.top() == IN_CONDITION) {
|
|---|
| 485 | QString test = line.mid(5, line.length()-(5+1));
|
|---|
| 486 | if(project->test(test))
|
|---|
| 487 | state.push(IN_CONDITION);
|
|---|
| 488 | else
|
|---|
| 489 | state.push(PENDING_CONDITION);
|
|---|
| 490 | } else {
|
|---|
| 491 | state.push(MET_CONDITION);
|
|---|
| 492 | }
|
|---|
| 493 | } else if(line.startsWith("!!ELIF ")) {
|
|---|
| 494 | if(state.isEmpty()) {
|
|---|
| 495 | warn_msg(WarnLogic, "(%s:%d): Unexpected else condition",
|
|---|
| 496 | in.fileName().toLatin1().constData(), count);
|
|---|
| 497 | } else if(state.top() == PENDING_CONDITION) {
|
|---|
| 498 | QString test = line.mid(7, line.length()-(7+1));
|
|---|
| 499 | if(project->test(test)) {
|
|---|
| 500 | state.pop();
|
|---|
| 501 | state.push(IN_CONDITION);
|
|---|
| 502 | }
|
|---|
| 503 | } else if(state.top() == IN_CONDITION) {
|
|---|
| 504 | state.pop();
|
|---|
| 505 | state.push(MET_CONDITION);
|
|---|
| 506 | }
|
|---|
| 507 | } else if(line.startsWith("!!ELSE")) {
|
|---|
| 508 | if(state.isEmpty()) {
|
|---|
| 509 | warn_msg(WarnLogic, "(%s:%d): Unexpected else condition",
|
|---|
| 510 | in.fileName().toLatin1().constData(), count);
|
|---|
| 511 | } else if(state.top() == PENDING_CONDITION) {
|
|---|
| 512 | state.pop();
|
|---|
| 513 | state.push(IN_CONDITION);
|
|---|
| 514 | } else if(state.top() == IN_CONDITION) {
|
|---|
| 515 | state.pop();
|
|---|
| 516 | state.push(MET_CONDITION);
|
|---|
| 517 | }
|
|---|
| 518 | } else if(line.startsWith("!!ENDIF")) {
|
|---|
| 519 | if(state.isEmpty())
|
|---|
| 520 | warn_msg(WarnLogic, "(%s:%d): Unexpected endif",
|
|---|
| 521 | in.fileName().toLatin1().constData(), count);
|
|---|
| 522 | else
|
|---|
| 523 | state.pop();
|
|---|
| 524 | } else if(state.isEmpty() || state.top() == IN_CONDITION) {
|
|---|
| 525 | contents += project->expand(line).join(QString(Option::field_sep));
|
|---|
| 526 | }
|
|---|
| 527 | }
|
|---|
| 528 | if(out.exists() && out.open(QFile::ReadOnly)) {
|
|---|
| 529 | QString old = QString::fromUtf8(out.readAll());
|
|---|
| 530 | if(contents == old) {
|
|---|
| 531 | v["QMAKE_INTERNAL_INCLUDED_FILES"].append(subs.at(i));
|
|---|
| 532 | continue;
|
|---|
| 533 | }
|
|---|
| 534 | out.close();
|
|---|
| 535 | if(!out.remove()) {
|
|---|
| 536 | warn_msg(WarnLogic, "Cannot clear substitute '%s'",
|
|---|
| 537 | out.fileName().toLatin1().constData());
|
|---|
| 538 | continue;
|
|---|
| 539 | }
|
|---|
| 540 | }
|
|---|
| 541 | if(out.open(QFile::WriteOnly)) {
|
|---|
| 542 | v["QMAKE_INTERNAL_INCLUDED_FILES"].append(subs.at(i));
|
|---|
| 543 | out.write(contents.toUtf8());
|
|---|
| 544 | } else {
|
|---|
| 545 | warn_msg(WarnLogic, "Cannot open substitute for output '%s'",
|
|---|
| 546 | out.fileName().toLatin1().constData());
|
|---|
| 547 | }
|
|---|
| 548 | } else {
|
|---|
| 549 | warn_msg(WarnLogic, "Cannot open substitute for input '%s'",
|
|---|
| 550 | in.fileName().toLatin1().constData());
|
|---|
| 551 | }
|
|---|
| 552 | }
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | int x;
|
|---|
| 556 |
|
|---|
| 557 | //build up a list of compilers
|
|---|
| 558 | QList<Compiler> compilers;
|
|---|
| 559 | {
|
|---|
| 560 | const char *builtins[] = { "OBJECTS", "SOURCES", "PRECOMPILED_HEADER", 0 };
|
|---|
| 561 | for(x = 0; builtins[x]; ++x) {
|
|---|
| 562 | Compiler compiler;
|
|---|
| 563 | compiler.variable_in = builtins[x];
|
|---|
| 564 | compiler.flags = Compiler::CompilerBuiltin;
|
|---|
| 565 | compiler.type = QMakeSourceFileInfo::TYPE_C;
|
|---|
| 566 | if(!strcmp(builtins[x], "OBJECTS"))
|
|---|
| 567 | compiler.flags |= Compiler::CompilerNoCheckDeps;
|
|---|
| 568 | compilers.append(compiler);
|
|---|
| 569 | }
|
|---|
| 570 | for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
|
|---|
| 571 | const QStringList &inputs = v[(*it) + ".input"];
|
|---|
| 572 | for(x = 0; x < inputs.size(); ++x) {
|
|---|
| 573 | Compiler compiler;
|
|---|
| 574 | compiler.variable_in = inputs.at(x);
|
|---|
| 575 | compiler.flags = Compiler::CompilerNoFlags;
|
|---|
| 576 | if(v[(*it) + ".CONFIG"].indexOf("ignore_no_exist") != -1)
|
|---|
| 577 | compiler.flags |= Compiler::CompilerRemoveNoExist;
|
|---|
| 578 | if(v[(*it) + ".CONFIG"].indexOf("no_dependencies") != -1)
|
|---|
| 579 | compiler.flags |= Compiler::CompilerNoCheckDeps;
|
|---|
| 580 |
|
|---|
| 581 | QString dep_type;
|
|---|
| 582 | if(!project->isEmpty((*it) + ".dependency_type"))
|
|---|
| 583 | dep_type = project->first((*it) + ".dependency_type");
|
|---|
| 584 | if (dep_type.isEmpty())
|
|---|
| 585 | compiler.type = QMakeSourceFileInfo::TYPE_UNKNOWN;
|
|---|
| 586 | else if(dep_type == "TYPE_UI")
|
|---|
| 587 | compiler.type = QMakeSourceFileInfo::TYPE_UI;
|
|---|
| 588 | else
|
|---|
| 589 | compiler.type = QMakeSourceFileInfo::TYPE_C;
|
|---|
| 590 | compilers.append(compiler);
|
|---|
| 591 | }
|
|---|
| 592 | }
|
|---|
| 593 | }
|
|---|
| 594 | { //do the path fixifying
|
|---|
| 595 | QStringList paths;
|
|---|
| 596 | for(x = 0; x < compilers.count(); ++x) {
|
|---|
| 597 | if(!paths.contains(compilers.at(x).variable_in))
|
|---|
| 598 | paths << compilers.at(x).variable_in;
|
|---|
| 599 | }
|
|---|
| 600 | paths << "INCLUDEPATH" << "QMAKE_INTERNAL_INCLUDED_FILES" << "PRECOMPILED_HEADER";
|
|---|
| 601 | for(int y = 0; y < paths.count(); y++) {
|
|---|
| 602 | QStringList &l = v[paths[y]];
|
|---|
| 603 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 604 | if((*it).isEmpty())
|
|---|
| 605 | continue;
|
|---|
| 606 | if(exists((*it)))
|
|---|
| 607 | (*it) = fileFixify((*it));
|
|---|
| 608 | }
|
|---|
| 609 | }
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | if(noIO() || !doDepends())
|
|---|
| 613 | QMakeSourceFileInfo::setDependencyMode(QMakeSourceFileInfo::NonRecursive);
|
|---|
| 614 | for(x = 0; x < compilers.count(); ++x)
|
|---|
| 615 | initCompiler(compilers.at(x));
|
|---|
| 616 |
|
|---|
| 617 | //merge actual compiler outputs into their variable_out. This is done last so that
|
|---|
| 618 | //files are already properly fixified.
|
|---|
| 619 | for(QStringList::Iterator it = quc.begin(); it != quc.end(); ++it) {
|
|---|
| 620 | QString tmp_out = project->values((*it) + ".output").first();
|
|---|
| 621 | if(tmp_out.isEmpty())
|
|---|
| 622 | continue;
|
|---|
| 623 | if(project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
|
|---|
| 624 | QStringList &compilerInputs = project->values((*it) + ".input");
|
|---|
| 625 | // Don't generate compiler output if it doesn't have input.
|
|---|
| 626 | if (compilerInputs.isEmpty() || project->values(compilerInputs.first()).isEmpty())
|
|---|
| 627 | continue;
|
|---|
| 628 | if(tmp_out.indexOf("$") == -1) {
|
|---|
| 629 | if(!verifyExtraCompiler((*it), QString())) //verify
|
|---|
| 630 | continue;
|
|---|
| 631 | QString out = fileFixify(tmp_out, Option::output_dir, Option::output_dir);
|
|---|
| 632 | bool pre_dep = (project->values((*it) + ".CONFIG").indexOf("target_predeps") != -1);
|
|---|
| 633 | if(project->variables().contains((*it) + ".variable_out")) {
|
|---|
| 634 | const QStringList &var_out = project->variables().value((*it) + ".variable_out");
|
|---|
| 635 | for(int i = 0; i < var_out.size(); ++i) {
|
|---|
| 636 | QString v = var_out.at(i);
|
|---|
| 637 | if(v == QLatin1String("SOURCES"))
|
|---|
| 638 | v = "GENERATED_SOURCES";
|
|---|
| 639 | else if(v == QLatin1String("OBJECTS"))
|
|---|
| 640 | pre_dep = false;
|
|---|
| 641 | QStringList &list = project->values(v);
|
|---|
| 642 | if(!list.contains(out))
|
|---|
| 643 | list.append(out);
|
|---|
| 644 | }
|
|---|
| 645 | } else if(project->values((*it) + ".CONFIG").indexOf("no_link") == -1) {
|
|---|
| 646 | QStringList &list = project->values("OBJECTS");
|
|---|
| 647 | pre_dep = false;
|
|---|
| 648 | if(!list.contains(out))
|
|---|
| 649 | list.append(out);
|
|---|
| 650 | } else {
|
|---|
| 651 | QStringList &list = project->values("UNUSED_SOURCES");
|
|---|
| 652 | if(!list.contains(out))
|
|---|
| 653 | list.append(out);
|
|---|
| 654 | }
|
|---|
| 655 | if(pre_dep) {
|
|---|
| 656 | QStringList &list = project->variables()["PRE_TARGETDEPS"];
|
|---|
| 657 | if(!list.contains(out))
|
|---|
| 658 | list.append(out);
|
|---|
| 659 | }
|
|---|
| 660 | }
|
|---|
| 661 | } else {
|
|---|
| 662 | QStringList &tmp = project->values((*it) + ".input");
|
|---|
| 663 | for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
|
|---|
| 664 | const QStringList inputs = project->values((*it2));
|
|---|
| 665 | for(QStringList::ConstIterator input = inputs.constBegin(); input != inputs.constEnd(); ++input) {
|
|---|
| 666 | if((*input).isEmpty())
|
|---|
| 667 | continue;
|
|---|
| 668 | QString in = Option::fixPathToTargetOS((*input), false);
|
|---|
| 669 | if(!verifyExtraCompiler((*it), in)) //verify
|
|---|
| 670 | continue;
|
|---|
| 671 | QString out = replaceExtraCompilerVariables(tmp_out, (*input), QString());
|
|---|
| 672 | out = fileFixify(out, Option::output_dir, Option::output_dir);
|
|---|
| 673 | bool pre_dep = (project->values((*it) + ".CONFIG").indexOf("target_predeps") != -1);
|
|---|
| 674 | if(project->variables().contains((*it) + ".variable_out")) {
|
|---|
| 675 | const QStringList &var_out = project->variables().value((*it) + ".variable_out");
|
|---|
| 676 | for(int i = 0; i < var_out.size(); ++i) {
|
|---|
| 677 | QString v = var_out.at(i);
|
|---|
| 678 | if(v == QLatin1String("SOURCES"))
|
|---|
| 679 | v = "GENERATED_SOURCES";
|
|---|
| 680 | else if(v == QLatin1String("OBJECTS"))
|
|---|
| 681 | pre_dep = false;
|
|---|
| 682 | QStringList &list = project->values(v);
|
|---|
| 683 | if(!list.contains(out))
|
|---|
| 684 | list.append(out);
|
|---|
| 685 | }
|
|---|
| 686 | } else if(project->values((*it) + ".CONFIG").indexOf("no_link") == -1) {
|
|---|
| 687 | pre_dep = false;
|
|---|
| 688 | QStringList &list = project->values("OBJECTS");
|
|---|
| 689 | if(!list.contains(out))
|
|---|
| 690 | list.append(out);
|
|---|
| 691 | } else {
|
|---|
| 692 | QStringList &list = project->values("UNUSED_SOURCES");
|
|---|
| 693 | if(!list.contains(out))
|
|---|
| 694 | list.append(out);
|
|---|
| 695 | }
|
|---|
| 696 | if(pre_dep) {
|
|---|
| 697 | QStringList &list = project->variables()["PRE_TARGETDEPS"];
|
|---|
| 698 | if(!list.contains(out))
|
|---|
| 699 | list.append(out);
|
|---|
| 700 | }
|
|---|
| 701 | }
|
|---|
| 702 | }
|
|---|
| 703 | }
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | //handle dependencies
|
|---|
| 707 | depHeuristicsCache.clear();
|
|---|
| 708 | if(!noIO()) {
|
|---|
| 709 | // dependency paths
|
|---|
| 710 | QStringList incDirs = v["DEPENDPATH"] + v["QMAKE_ABSOLUTE_SOURCE_PATH"];
|
|---|
| 711 | if(project->isActiveConfig("depend_includepath"))
|
|---|
| 712 | incDirs += v["INCLUDEPATH"];
|
|---|
| 713 | if(!project->isActiveConfig("no_include_pwd")) {
|
|---|
| 714 | QString pwd = qmake_getpwd();
|
|---|
| 715 | if(pwd.isEmpty())
|
|---|
| 716 | pwd = ".";
|
|---|
| 717 | incDirs += pwd;
|
|---|
| 718 | }
|
|---|
| 719 | QList<QMakeLocalFileName> deplist;
|
|---|
| 720 | for(QStringList::Iterator it = incDirs.begin(); it != incDirs.end(); ++it)
|
|---|
| 721 | deplist.append(QMakeLocalFileName(unescapeFilePath((*it))));
|
|---|
| 722 | QMakeSourceFileInfo::setDependencyPaths(deplist);
|
|---|
| 723 | debug_msg(1, "Dependency Directories: %s", incDirs.join(" :: ").toLatin1().constData());
|
|---|
| 724 | //cache info
|
|---|
| 725 | if(project->isActiveConfig("qmake_cache")) {
|
|---|
| 726 | QString cache_file;
|
|---|
| 727 | if(!project->isEmpty("QMAKE_INTERNAL_CACHE_FILE")) {
|
|---|
| 728 | cache_file = QDir::fromNativeSeparators(project->first("QMAKE_INTERNAL_CACHE_FILE"));
|
|---|
| 729 | } else {
|
|---|
| 730 | cache_file = ".qmake.internal.cache";
|
|---|
| 731 | if(project->isActiveConfig("build_pass"))
|
|---|
| 732 | cache_file += ".BUILD." + project->first("BUILD_PASS");
|
|---|
| 733 | }
|
|---|
| 734 | if(cache_file.indexOf('/') == -1)
|
|---|
| 735 | cache_file.prepend(Option::output_dir + '/');
|
|---|
| 736 | QMakeSourceFileInfo::setCacheFile(cache_file);
|
|---|
| 737 | }
|
|---|
| 738 |
|
|---|
| 739 | //add to dependency engine
|
|---|
| 740 | for(x = 0; x < compilers.count(); ++x) {
|
|---|
| 741 | const MakefileGenerator::Compiler &comp = compilers.at(x);
|
|---|
| 742 | if(!(comp.flags & Compiler::CompilerNoCheckDeps))
|
|---|
| 743 | addSourceFiles(v[comp.variable_in], QMakeSourceFileInfo::SEEK_DEPS,
|
|---|
| 744 | (QMakeSourceFileInfo::SourceFileType)comp.type);
|
|---|
| 745 | }
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | processSources(); //remove anything in SOURCES which is included (thus it need not be linked in)
|
|---|
| 749 |
|
|---|
| 750 | //all sources and generated sources must be turned into objects at some point (the one builtin compiler)
|
|---|
| 751 | v["OBJECTS"] += createObjectList(v["SOURCES"]) + createObjectList(v["GENERATED_SOURCES"]);
|
|---|
| 752 |
|
|---|
| 753 | //Translation files
|
|---|
| 754 | if(!project->isEmpty("TRANSLATIONS")) {
|
|---|
| 755 | QStringList &trf = project->values("TRANSLATIONS");
|
|---|
| 756 | for(QStringList::Iterator it = trf.begin(); it != trf.end(); ++it)
|
|---|
| 757 | (*it) = Option::fixPathToLocalOS((*it));
|
|---|
| 758 | }
|
|---|
| 759 |
|
|---|
| 760 | { //get the output_dir into the pwd
|
|---|
| 761 | if(fileFixify(Option::output_dir) != fileFixify(qmake_getpwd()))
|
|---|
| 762 | project->values("INCLUDEPATH").append(fileFixify(Option::output_dir,
|
|---|
| 763 | Option::output_dir,
|
|---|
| 764 | Option::output_dir));
|
|---|
| 765 | }
|
|---|
| 766 |
|
|---|
| 767 | //fix up the target deps
|
|---|
| 768 | QString fixpaths[] = { QString("PRE_TARGETDEPS"), QString("POST_TARGETDEPS"), QString() };
|
|---|
| 769 | for(int path = 0; !fixpaths[path].isNull(); path++) {
|
|---|
| 770 | QStringList &l = v[fixpaths[path]];
|
|---|
| 771 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 772 | if(!(*val_it).isEmpty())
|
|---|
| 773 | (*val_it) = escapeDependencyPath(Option::fixPathToTargetOS((*val_it), false, false));
|
|---|
| 774 | }
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | //extra depends
|
|---|
| 778 | if(!project->isEmpty("DEPENDS")) {
|
|---|
| 779 | QStringList &l = v["DEPENDS"];
|
|---|
| 780 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 781 | QStringList files = v[(*it) + ".file"] + v[(*it) + ".files"]; //why do I support such evil things?
|
|---|
| 782 | for(QStringList::Iterator file_it = files.begin(); file_it != files.end(); ++file_it) {
|
|---|
| 783 | QStringList &out_deps = findDependencies(*file_it);
|
|---|
| 784 | QStringList &in_deps = v[(*it) + ".depends"]; //even more evilness..
|
|---|
| 785 | for(QStringList::Iterator dep_it = in_deps.begin(); dep_it != in_deps.end(); ++dep_it) {
|
|---|
| 786 | if(exists(*dep_it)) {
|
|---|
| 787 | out_deps.append(*dep_it);
|
|---|
| 788 | } else {
|
|---|
| 789 | QString dir, regex = Option::fixPathToLocalOS((*dep_it));
|
|---|
| 790 | if(regex.lastIndexOf(Option::dir_sep) != -1) {
|
|---|
| 791 | dir = regex.left(regex.lastIndexOf(Option::dir_sep) + 1);
|
|---|
| 792 | regex.remove(0, dir.length());
|
|---|
| 793 | }
|
|---|
| 794 | QStringList files = QDir(dir).entryList(QStringList(regex));
|
|---|
| 795 | if(files.isEmpty()) {
|
|---|
| 796 | warn_msg(WarnLogic, "Dependency for [%s]: Not found %s", (*file_it).toLatin1().constData(),
|
|---|
| 797 | (*dep_it).toLatin1().constData());
|
|---|
| 798 | } else {
|
|---|
| 799 | for(int i = 0; i < files.count(); i++)
|
|---|
| 800 | out_deps.append(dir + files[i]);
|
|---|
| 801 | }
|
|---|
| 802 | }
|
|---|
| 803 | }
|
|---|
| 804 | }
|
|---|
| 805 | }
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | // escape qmake command
|
|---|
| 809 | if (!project->isEmpty("QMAKE_QMAKE")) {
|
|---|
| 810 | project->values("QMAKE_QMAKE") = escapeFilePaths(project->values("QMAKE_QMAKE"));
|
|---|
| 811 | }
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | bool
|
|---|
| 815 | MakefileGenerator::processPrlFile(QString &file)
|
|---|
| 816 | {
|
|---|
| 817 | bool ret = false, try_replace_file=false;
|
|---|
| 818 | QString meta_file, orig_file = file;
|
|---|
| 819 | if(QMakeMetaInfo::libExists(file)) {
|
|---|
| 820 | try_replace_file = true;
|
|---|
| 821 | meta_file = file;
|
|---|
| 822 | file = "";
|
|---|
| 823 | } else {
|
|---|
| 824 | QString tmp = file;
|
|---|
| 825 | int ext = tmp.lastIndexOf('.');
|
|---|
| 826 | if(ext != -1)
|
|---|
| 827 | tmp = tmp.left(ext);
|
|---|
| 828 | meta_file = tmp;
|
|---|
| 829 | }
|
|---|
| 830 | // meta_file = fileFixify(meta_file);
|
|---|
| 831 | QString real_meta_file = Option::fixPathToLocalOS(meta_file);
|
|---|
| 832 | if(!meta_file.isEmpty()) {
|
|---|
| 833 | QString f = fileFixify(real_meta_file, qmake_getpwd(), Option::output_dir);
|
|---|
| 834 | if(QMakeMetaInfo::libExists(f)) {
|
|---|
| 835 | QMakeMetaInfo libinfo;
|
|---|
| 836 | debug_msg(1, "Processing PRL file: %s", real_meta_file.toLatin1().constData());
|
|---|
| 837 | if(!libinfo.readLib(f)) {
|
|---|
| 838 | fprintf(stderr, "Error processing meta file: %s\n", real_meta_file.toLatin1().constData());
|
|---|
| 839 | } else if(project->isActiveConfig("no_read_prl_" + libinfo.type().toLower())) {
|
|---|
| 840 | debug_msg(2, "Ignored meta file %s [%s]", real_meta_file.toLatin1().constData(), libinfo.type().toLatin1().constData());
|
|---|
| 841 | } else {
|
|---|
| 842 | ret = true;
|
|---|
| 843 | QMap<QString, QStringList> &vars = libinfo.variables();
|
|---|
| 844 | for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it)
|
|---|
| 845 | processPrlVariable(it.key(), it.value());
|
|---|
| 846 | if(try_replace_file && !libinfo.isEmpty("QMAKE_PRL_TARGET")) {
|
|---|
| 847 | QString dir;
|
|---|
| 848 | int slsh = real_meta_file.lastIndexOf(Option::dir_sep);
|
|---|
| 849 | if(slsh != -1)
|
|---|
| 850 | dir = real_meta_file.left(slsh+1);
|
|---|
| 851 | file = libinfo.first("QMAKE_PRL_TARGET");
|
|---|
| 852 | if(QDir::isRelativePath(file))
|
|---|
| 853 | file.prepend(dir);
|
|---|
| 854 | }
|
|---|
| 855 | }
|
|---|
| 856 | }
|
|---|
| 857 | if(ret) {
|
|---|
| 858 | QString mf = QMakeMetaInfo::findLib(meta_file);
|
|---|
| 859 | if(project->values("QMAKE_PRL_INTERNAL_FILES").indexOf(mf) == -1)
|
|---|
| 860 | project->values("QMAKE_PRL_INTERNAL_FILES").append(mf);
|
|---|
| 861 | if(project->values("QMAKE_INTERNAL_INCLUDED_FILES").indexOf(mf) == -1)
|
|---|
| 862 | project->values("QMAKE_INTERNAL_INCLUDED_FILES").append(mf);
|
|---|
| 863 | }
|
|---|
| 864 | }
|
|---|
| 865 | if(try_replace_file && file.isEmpty()) {
|
|---|
| 866 | #if 0
|
|---|
| 867 | warn_msg(WarnLogic, "Found prl [%s] file with no target [%s]!", meta_file.toLatin1().constData(),
|
|---|
| 868 | orig_file.toLatin1().constData());
|
|---|
| 869 | #endif
|
|---|
| 870 | file = orig_file;
|
|---|
| 871 | }
|
|---|
| 872 | return ret;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | void
|
|---|
| 876 | MakefileGenerator::filterIncludedFiles(const QString &var)
|
|---|
| 877 | {
|
|---|
| 878 | QStringList &inputs = project->values(var);
|
|---|
| 879 | for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ) {
|
|---|
| 880 | if(QMakeSourceFileInfo::included((*input)) > 0)
|
|---|
| 881 | input = inputs.erase(input);
|
|---|
| 882 | else
|
|---|
| 883 | ++input;
|
|---|
| 884 | }
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 887 | void
|
|---|
| 888 | MakefileGenerator::processPrlVariable(const QString &var, const QStringList &l)
|
|---|
| 889 | {
|
|---|
| 890 | if(var == "QMAKE_PRL_LIBS") {
|
|---|
| 891 | QString where = "QMAKE_LIBS";
|
|---|
| 892 | if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
|
|---|
| 893 | where = project->first("QMAKE_INTERNAL_PRL_LIBS");
|
|---|
| 894 | QStringList &out = project->values(where);
|
|---|
| 895 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 896 | if(out.indexOf((*it)) == -1)
|
|---|
| 897 | out.append((*it));
|
|---|
| 898 | }
|
|---|
| 899 | } else if(var == "QMAKE_PRL_DEFINES") {
|
|---|
| 900 | QStringList &out = project->values("DEFINES");
|
|---|
| 901 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 902 | if(out.indexOf((*it)) == -1 &&
|
|---|
| 903 | project->values("PRL_EXPORT_DEFINES").indexOf((*it)) == -1)
|
|---|
| 904 | out.append((*it));
|
|---|
| 905 | }
|
|---|
| 906 | }
|
|---|
| 907 | }
|
|---|
| 908 |
|
|---|
| 909 | void
|
|---|
| 910 | MakefileGenerator::processPrlFiles()
|
|---|
| 911 | {
|
|---|
| 912 | QHash<QString, bool> processed;
|
|---|
| 913 | for(bool ret = false; true; ret = false) {
|
|---|
| 914 | //read in any prl files included..
|
|---|
| 915 | QStringList l_out;
|
|---|
| 916 | QString where = "QMAKE_LIBS";
|
|---|
| 917 | if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
|
|---|
| 918 | where = project->first("QMAKE_INTERNAL_PRL_LIBS");
|
|---|
| 919 | QStringList &l = project->values(where);
|
|---|
| 920 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 921 | QString file = (*it);
|
|---|
| 922 | if(!processed.contains(file) && processPrlFile(file)) {
|
|---|
| 923 | processed.insert(file, true);
|
|---|
| 924 | ret = true;
|
|---|
| 925 | }
|
|---|
| 926 | if(!file.isEmpty())
|
|---|
| 927 | l_out.append(file);
|
|---|
| 928 | }
|
|---|
| 929 | if(ret)
|
|---|
| 930 | l = l_out;
|
|---|
| 931 | else
|
|---|
| 932 | break;
|
|---|
| 933 | }
|
|---|
| 934 | }
|
|---|
| 935 |
|
|---|
| 936 | void
|
|---|
| 937 | MakefileGenerator::writePrlFile(QTextStream &t)
|
|---|
| 938 | {
|
|---|
| 939 | QString target = project->first("TARGET");
|
|---|
| 940 | int slsh = target.lastIndexOf(Option::dir_sep);
|
|---|
| 941 | if(slsh != -1)
|
|---|
| 942 | target.remove(0, slsh + 1);
|
|---|
| 943 | QString bdir = Option::output_dir;
|
|---|
| 944 | if(bdir.isEmpty())
|
|---|
| 945 | bdir = qmake_getpwd();
|
|---|
| 946 | t << "QMAKE_PRL_BUILD_DIR = " << bdir << endl;
|
|---|
| 947 |
|
|---|
| 948 | if(!project->projectFile().isEmpty() && project->projectFile() != "-")
|
|---|
| 949 | t << "QMAKE_PRO_INPUT = " << project->projectFile().section('/', -1) << endl;
|
|---|
| 950 |
|
|---|
| 951 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
|
|---|
| 952 | t << "QMAKE_PRL_SOURCE_DIR = " << project->first("QMAKE_ABSOLUTE_SOURCE_PATH") << endl;
|
|---|
| 953 | if(!project->isEmpty("TARGET_SHORT"))
|
|---|
| 954 | t << "QMAKE_PRL_TARGET = " << project->first("TARGET_SHORT") << endl;
|
|---|
| 955 | else
|
|---|
| 956 | t << "QMAKE_PRL_TARGET = " << target << endl;
|
|---|
| 957 | if(!project->isEmpty("PRL_EXPORT_DEFINES"))
|
|---|
| 958 | t << "QMAKE_PRL_DEFINES = " << project->values("PRL_EXPORT_DEFINES").join(" ") << endl;
|
|---|
| 959 | if(!project->isEmpty("PRL_EXPORT_CFLAGS"))
|
|---|
| 960 | t << "QMAKE_PRL_CFLAGS = " << project->values("PRL_EXPORT_CFLAGS").join(" ") << endl;
|
|---|
| 961 | if(!project->isEmpty("PRL_EXPORT_CXXFLAGS"))
|
|---|
| 962 | t << "QMAKE_PRL_CXXFLAGS = " << project->values("PRL_EXPORT_CXXFLAGS").join(" ") << endl;
|
|---|
| 963 | if(!project->isEmpty("CONFIG"))
|
|---|
| 964 | t << "QMAKE_PRL_CONFIG = " << project->values("CONFIG").join(" ") << endl;
|
|---|
| 965 | if(!project->isEmpty("TARGET_VERSION_EXT"))
|
|---|
| 966 | t << "QMAKE_PRL_VERSION = " << project->first("TARGET_VERSION_EXT") << endl;
|
|---|
| 967 | else if(!project->isEmpty("VERSION"))
|
|---|
| 968 | t << "QMAKE_PRL_VERSION = " << project->first("VERSION") << endl;
|
|---|
| 969 | if(project->isActiveConfig("staticlib") || project->isActiveConfig("explicitlib") ||
|
|---|
| 970 | !project->isEmpty("PRL_EXPORT_LIBS")) {
|
|---|
| 971 | t << "QMAKE_PRL_LIBS = ";
|
|---|
| 972 | if (!project->isEmpty("PRL_EXPORT_LIBS")) {
|
|---|
| 973 | // PRL_EXPORT_LIBS overrides anything else
|
|---|
| 974 | t << project->values("PRL_EXPORT_LIBS").join(" ");
|
|---|
| 975 | } else {
|
|---|
| 976 | QStringList libs;
|
|---|
| 977 | if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
|
|---|
| 978 | libs = project->values("QMAKE_INTERNAL_PRL_LIBS");
|
|---|
| 979 | else
|
|---|
| 980 | libs << "QMAKE_LIBS"; //obvious one
|
|---|
| 981 | if(project->isActiveConfig("staticlib"))
|
|---|
| 982 | libs << "QMAKE_LIBS_PRIVATE";
|
|---|
| 983 | for(QStringList::Iterator it = libs.begin(); it != libs.end(); ++it)
|
|---|
| 984 | t << project->values((*it)).join(" ") << " ";
|
|---|
| 985 | }
|
|---|
| 986 | t << endl;
|
|---|
| 987 | }
|
|---|
| 988 | }
|
|---|
| 989 |
|
|---|
| 990 | bool
|
|---|
| 991 | MakefileGenerator::writeProjectMakefile()
|
|---|
| 992 | {
|
|---|
| 993 | usePlatformDir();
|
|---|
| 994 | QTextStream t(&Option::output);
|
|---|
| 995 |
|
|---|
| 996 | //header
|
|---|
| 997 | writeHeader(t);
|
|---|
| 998 |
|
|---|
| 999 | QList<SubTarget*> targets;
|
|---|
| 1000 | {
|
|---|
| 1001 | QStringList builds = project->values("BUILDS");
|
|---|
| 1002 | for(QStringList::Iterator it = builds.begin(); it != builds.end(); ++it) {
|
|---|
| 1003 | SubTarget *st = new SubTarget;
|
|---|
| 1004 | targets.append(st);
|
|---|
| 1005 | st->makefile = "$(MAKEFILE)." + (*it);
|
|---|
| 1006 | st->name = (*it);
|
|---|
| 1007 | st->target = project->isEmpty((*it) + ".target") ? (*it) : project->first((*it) + ".target");
|
|---|
| 1008 | }
|
|---|
| 1009 | }
|
|---|
| 1010 | if(project->isActiveConfig("build_all")) {
|
|---|
| 1011 | t << "first: all" << endl;
|
|---|
| 1012 | QList<SubTarget*>::Iterator it;
|
|---|
| 1013 |
|
|---|
| 1014 | //install
|
|---|
| 1015 | t << "install: ";
|
|---|
| 1016 | for(it = targets.begin(); it != targets.end(); ++it)
|
|---|
| 1017 | t << (*it)->target << "-install ";
|
|---|
| 1018 | t << endl;
|
|---|
| 1019 |
|
|---|
| 1020 | //uninstall
|
|---|
| 1021 | t << "uninstall: ";
|
|---|
| 1022 | for(it = targets.begin(); it != targets.end(); ++it)
|
|---|
| 1023 | t << (*it)->target << "-uninstall ";
|
|---|
| 1024 | t << endl;
|
|---|
| 1025 | } else {
|
|---|
| 1026 | t << "first: " << targets.first()->target << endl
|
|---|
| 1027 | << "install: " << targets.first()->target << "-install" << endl
|
|---|
| 1028 | << "uninstall: " << targets.first()->target << "-uninstall" << endl;
|
|---|
| 1029 | }
|
|---|
| 1030 |
|
|---|
| 1031 | writeSubTargets(t, targets, SubTargetsNoFlags);
|
|---|
| 1032 | if(!project->isActiveConfig("no_autoqmake")) {
|
|---|
| 1033 | for(QList<SubTarget*>::Iterator it = targets.begin(); it != targets.end(); ++it)
|
|---|
| 1034 | t << (*it)->makefile << ": " <<
|
|---|
| 1035 | Option::fixPathToTargetOS(fileFixify(Option::output.fileName())) << endl;
|
|---|
| 1036 | }
|
|---|
| 1037 | qDeleteAll(targets);
|
|---|
| 1038 | return true;
|
|---|
| 1039 | }
|
|---|
| 1040 |
|
|---|
| 1041 | bool
|
|---|
| 1042 | MakefileGenerator::write()
|
|---|
| 1043 | {
|
|---|
| 1044 | if(!project)
|
|---|
| 1045 | return false;
|
|---|
| 1046 | writePrlFile();
|
|---|
| 1047 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || //write makefile
|
|---|
| 1048 | Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
|
|---|
| 1049 | QTextStream t(&Option::output);
|
|---|
| 1050 | if(!writeMakefile(t)) {
|
|---|
| 1051 | #if 1
|
|---|
| 1052 | warn_msg(WarnLogic, "Unable to generate output for: %s [TEMPLATE %s]",
|
|---|
| 1053 | Option::output.fileName().toLatin1().constData(),
|
|---|
| 1054 | project->first("TEMPLATE").toLatin1().constData());
|
|---|
| 1055 | if(Option::output.exists())
|
|---|
| 1056 | Option::output.remove();
|
|---|
| 1057 | #endif
|
|---|
| 1058 | }
|
|---|
| 1059 | }
|
|---|
| 1060 | return true;
|
|---|
| 1061 | }
|
|---|
| 1062 |
|
|---|
| 1063 | QString
|
|---|
| 1064 | MakefileGenerator::prlFileName(bool fixify)
|
|---|
| 1065 | {
|
|---|
| 1066 | QString ret = project->first("TARGET_PRL");;
|
|---|
| 1067 | if(ret.isEmpty())
|
|---|
| 1068 | ret = project->first("TARGET");
|
|---|
| 1069 | int slsh = ret.lastIndexOf(Option::dir_sep);
|
|---|
| 1070 | if(slsh != -1)
|
|---|
| 1071 | ret.remove(0, slsh);
|
|---|
| 1072 | if(!ret.endsWith(Option::prl_ext)) {
|
|---|
| 1073 | int dot = ret.indexOf('.');
|
|---|
| 1074 | if(dot != -1)
|
|---|
| 1075 | ret.truncate(dot);
|
|---|
| 1076 | ret += Option::prl_ext;
|
|---|
| 1077 | }
|
|---|
| 1078 | if(!project->isEmpty("QMAKE_BUNDLE"))
|
|---|
| 1079 | ret.prepend(project->first("QMAKE_BUNDLE") + Option::dir_sep);
|
|---|
| 1080 | if(fixify) {
|
|---|
| 1081 | if(!project->isEmpty("DESTDIR"))
|
|---|
| 1082 | ret.prepend(project->first("DESTDIR"));
|
|---|
| 1083 | ret = Option::fixPathToLocalOS(fileFixify(ret, qmake_getpwd(), Option::output_dir));
|
|---|
| 1084 | }
|
|---|
| 1085 | return ret;
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 | void
|
|---|
| 1089 | MakefileGenerator::writePrlFile()
|
|---|
| 1090 | {
|
|---|
| 1091 | // note: on OS/2, we need .prl even for plugins since we use
|
|---|
| 1092 | // QMAKE_PRL_TARGET from there to translate universally used long plugin
|
|---|
| 1093 | // names to short names of actual OS/2 DLL libraries (which cannot exceed
|
|---|
| 1094 | // the 8x3 limit)
|
|---|
| 1095 |
|
|---|
| 1096 | if((Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|---|
| 1097 | Option::qmake_mode == Option::QMAKE_GENERATE_PRL)
|
|---|
| 1098 | && project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()
|
|---|
| 1099 | && project->isActiveConfig("create_prl")
|
|---|
| 1100 | && (project->first("TEMPLATE") == "lib"
|
|---|
| 1101 | || project->first("TEMPLATE") == "vclib")
|
|---|
| 1102 | && (project->isActiveConfig("os2") || !project->isActiveConfig("plugin"))
|
|---|
| 1103 | ) { //write prl file
|
|---|
| 1104 | QString local_prl = prlFileName();
|
|---|
| 1105 | QString prl = fileFixify(local_prl);
|
|---|
| 1106 | mkdir(fileInfo(local_prl).path());
|
|---|
| 1107 | QFile ft(local_prl);
|
|---|
| 1108 | if(ft.open(QIODevice::WriteOnly)) {
|
|---|
| 1109 | project->values("ALL_DEPS").append(prl);
|
|---|
| 1110 | project->values("QMAKE_INTERNAL_PRL_FILE").append(prl);
|
|---|
| 1111 | QTextStream t(&ft);
|
|---|
| 1112 | writePrlFile(t);
|
|---|
| 1113 | }
|
|---|
| 1114 | }
|
|---|
| 1115 | }
|
|---|
| 1116 |
|
|---|
| 1117 | // Manipulate directories, so it's possible to build
|
|---|
| 1118 | // several cross-platform targets concurrently
|
|---|
| 1119 | void
|
|---|
| 1120 | MakefileGenerator::usePlatformDir()
|
|---|
| 1121 | {
|
|---|
| 1122 | QString pltDir(project->first("QMAKE_PLATFORM_DIR"));
|
|---|
| 1123 | if(pltDir.isEmpty())
|
|---|
| 1124 | return;
|
|---|
| 1125 | QChar sep = QDir::separator();
|
|---|
| 1126 | QString slashPltDir = sep + pltDir;
|
|---|
| 1127 |
|
|---|
| 1128 | QString dirs[] = { QString("OBJECTS_DIR"), QString("DESTDIR"), QString("QMAKE_PKGCONFIG_DESTDIR"),
|
|---|
| 1129 | QString("SUBLIBS_DIR"), QString("DLLDESTDIR"), QString("QMAKE_LIBTOOL_DESTDIR"),
|
|---|
| 1130 | QString("PRECOMPILED_DIR"), QString("QMAKE_LIBDIR_QT"), QString() };
|
|---|
| 1131 | for(int i = 0; !dirs[i].isEmpty(); ++i) {
|
|---|
| 1132 | QString filePath = project->first(dirs[i]);
|
|---|
| 1133 | project->values(dirs[i]) = QStringList(filePath + (filePath.isEmpty() ? pltDir : slashPltDir));
|
|---|
| 1134 | }
|
|---|
| 1135 |
|
|---|
| 1136 | QString libs[] = { QString("QMAKE_LIBS_QT"), QString("QMAKE_LIBS_QT_THREAD"), QString("QMAKE_LIBS_QT_ENTRY"), QString() };
|
|---|
| 1137 | for(int i = 0; !libs[i].isEmpty(); ++i) {
|
|---|
| 1138 | QString filePath = project->first(libs[i]);
|
|---|
| 1139 | int fpi = filePath.lastIndexOf(sep);
|
|---|
| 1140 | if(fpi == -1)
|
|---|
| 1141 | project->values(libs[i]).prepend(pltDir + sep);
|
|---|
| 1142 | else
|
|---|
| 1143 | project->values(libs[i]) = QStringList(filePath.left(fpi) + slashPltDir + filePath.mid(fpi));
|
|---|
| 1144 | }
|
|---|
| 1145 | }
|
|---|
| 1146 |
|
|---|
| 1147 | void
|
|---|
| 1148 | MakefileGenerator::writeObj(QTextStream &t, const QString &src)
|
|---|
| 1149 | {
|
|---|
| 1150 | QStringList &srcl = project->values(src);
|
|---|
| 1151 | QStringList objl = createObjectList(srcl);
|
|---|
| 1152 |
|
|---|
| 1153 | QStringList::Iterator oit = objl.begin();
|
|---|
| 1154 | QStringList::Iterator sit = srcl.begin();
|
|---|
| 1155 | QString stringSrc("$src");
|
|---|
| 1156 | QString stringObj("$obj");
|
|---|
| 1157 | for(;sit != srcl.end() && oit != objl.end(); ++oit, ++sit) {
|
|---|
| 1158 | if((*sit).isEmpty())
|
|---|
| 1159 | continue;
|
|---|
| 1160 |
|
|---|
| 1161 | t << escapeDependencyPath((*oit)) << ": " << escapeDependencyPath((*sit)) << " " << escapeDependencyPaths(findDependencies((*sit))).join(" \\\n\t\t");
|
|---|
| 1162 |
|
|---|
| 1163 | QString comp, cimp;
|
|---|
| 1164 | for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) {
|
|---|
| 1165 | if((*sit).endsWith((*cppit))) {
|
|---|
| 1166 | comp = "QMAKE_RUN_CXX";
|
|---|
| 1167 | cimp = "QMAKE_RUN_CXX_IMP";
|
|---|
| 1168 | break;
|
|---|
| 1169 | }
|
|---|
| 1170 | }
|
|---|
| 1171 | if(comp.isEmpty()) {
|
|---|
| 1172 | comp = "QMAKE_RUN_CC";
|
|---|
| 1173 | cimp = "QMAKE_RUN_CC_IMP";
|
|---|
| 1174 | }
|
|---|
| 1175 | bool use_implicit_rule = !project->isEmpty(cimp);
|
|---|
| 1176 | use_implicit_rule = false;
|
|---|
| 1177 | if(use_implicit_rule) {
|
|---|
| 1178 | if(!project->isEmpty("OBJECTS_DIR")) {
|
|---|
| 1179 | use_implicit_rule = false;
|
|---|
| 1180 | } else {
|
|---|
| 1181 | int dot = (*sit).lastIndexOf('.');
|
|---|
| 1182 | if(dot == -1 || ((*sit).left(dot) + Option::obj_ext != (*oit)))
|
|---|
| 1183 | use_implicit_rule = false;
|
|---|
| 1184 | }
|
|---|
| 1185 | }
|
|---|
| 1186 | if (!use_implicit_rule && !project->isEmpty(comp)) {
|
|---|
| 1187 | QString p = var(comp), srcf(*sit);
|
|---|
| 1188 | p.replace(stringSrc, escapeFilePath(srcf));
|
|---|
| 1189 | p.replace(stringObj, escapeFilePath((*oit)));
|
|---|
| 1190 | t << "\n\t" << p;
|
|---|
| 1191 | }
|
|---|
| 1192 | t << endl << endl;
|
|---|
| 1193 | }
|
|---|
| 1194 | }
|
|---|
| 1195 |
|
|---|
| 1196 | QString
|
|---|
| 1197 | MakefileGenerator::filePrefixRoot(const QString &root, const QString &path)
|
|---|
| 1198 | {
|
|---|
| 1199 | QString ret(root + path);
|
|---|
| 1200 | if(path.length() > 2 && path[1] == ':') { //c:\foo
|
|---|
| 1201 | if (Option::target_mode == Option::TARG_OS2_MODE)
|
|---|
| 1202 | ret = root + path.mid(2);
|
|---|
| 1203 | else
|
|---|
| 1204 | ret = path.mid(0, 2) + root + path.mid(2);
|
|---|
| 1205 | }
|
|---|
| 1206 | while(ret.endsWith("\\"))
|
|---|
| 1207 | ret = ret.left(ret.length()-1);
|
|---|
| 1208 | return ret;
|
|---|
| 1209 | }
|
|---|
| 1210 |
|
|---|
| 1211 | void
|
|---|
| 1212 | MakefileGenerator::writeInstalls(QTextStream &t, const QString &installs, bool noBuild)
|
|---|
| 1213 | {
|
|---|
| 1214 | const QString del_suffix =
|
|---|
| 1215 | Option::target_mode == Option::TARG_OS2_MODE ?
|
|---|
| 1216 | QString(" >nul 2>&1"): // reduce noise
|
|---|
| 1217 | QString::null;
|
|---|
| 1218 |
|
|---|
| 1219 | const QString inst_prefix =
|
|---|
| 1220 | Option::target_mode == Option::TARG_OS2_MODE ?
|
|---|
| 1221 | QString::null: // report errors (copy command overwrites quietly)
|
|---|
| 1222 | QString("-");
|
|---|
| 1223 |
|
|---|
| 1224 | QString rm_dir_contents("-$(DEL_FILE)");
|
|---|
| 1225 | if (!isDosLikeShell()) //ick
|
|---|
| 1226 | rm_dir_contents = "-$(DEL_FILE) -r";
|
|---|
| 1227 |
|
|---|
| 1228 | QString all_installs, all_uninstalls;
|
|---|
| 1229 | QStringList &l = project->values(installs);
|
|---|
| 1230 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1231 | QString pvar = (*it) + ".path";
|
|---|
| 1232 | if(project->values((*it) + ".CONFIG").indexOf("no_path") == -1 &&
|
|---|
| 1233 | project->values((*it) + ".CONFIG").indexOf("dummy_install") == -1 &&
|
|---|
| 1234 | project->values(pvar).isEmpty()) {
|
|---|
| 1235 | warn_msg(WarnLogic, "%s is not defined: install target not created\n", pvar.toLatin1().constData());
|
|---|
| 1236 | continue;
|
|---|
| 1237 | }
|
|---|
| 1238 |
|
|---|
| 1239 | bool do_default = true;
|
|---|
| 1240 | const QString root = "$(INSTALL_ROOT)";
|
|---|
| 1241 | QString target, dst;
|
|---|
| 1242 | if(project->values((*it) + ".CONFIG").indexOf("no_path") == -1 &&
|
|---|
| 1243 | project->values((*it) + ".CONFIG").indexOf("dummy_install") == -1) {
|
|---|
| 1244 | dst = fileFixify(unescapeFilePath(project->values(pvar).first()), FileFixifyAbsolute, false);
|
|---|
| 1245 | }
|
|---|
| 1246 | dst = escapeFilePath(dst);
|
|---|
| 1247 | if(dst.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 1248 | dst += Option::dir_sep;
|
|---|
| 1249 |
|
|---|
| 1250 | QStringList tmp, uninst = project->values((*it) + ".uninstall");
|
|---|
| 1251 | //other
|
|---|
| 1252 | tmp = project->values((*it) + ".extra");
|
|---|
| 1253 | if(tmp.isEmpty())
|
|---|
| 1254 | tmp = project->values((*it) + ".commands"); //to allow compatible name
|
|---|
| 1255 | if(!tmp.isEmpty()) {
|
|---|
| 1256 | do_default = false;
|
|---|
| 1257 | if(!target.isEmpty())
|
|---|
| 1258 | target += "\n\t";
|
|---|
| 1259 | target += tmp.join(" ");
|
|---|
| 1260 | }
|
|---|
| 1261 | //masks
|
|---|
| 1262 | tmp = findFilesInVPATH(project->values((*it) + ".files"), VPATH_NoFixify);
|
|---|
| 1263 | tmp = fileFixify(tmp, FileFixifyAbsolute);
|
|---|
| 1264 | if(!tmp.isEmpty()) {
|
|---|
| 1265 | if(!target.isEmpty())
|
|---|
| 1266 | target += "\n";
|
|---|
| 1267 | do_default = false;
|
|---|
| 1268 | for(QStringList::Iterator wild_it = tmp.begin(); wild_it != tmp.end(); ++wild_it) {
|
|---|
| 1269 | QString wild = Option::fixPathToTargetOS((*wild_it), false, false);
|
|---|
| 1270 | QString dirstr = qmake_getpwd(), filestr = wild;
|
|---|
| 1271 | int slsh = filestr.lastIndexOf(Option::dir_sep);
|
|---|
| 1272 | if(slsh != -1) {
|
|---|
| 1273 | dirstr = filestr.left(slsh+1);
|
|---|
| 1274 | filestr.remove(0, slsh+1);
|
|---|
| 1275 | }
|
|---|
| 1276 | if(!dirstr.endsWith(Option::dir_sep))
|
|---|
| 1277 | dirstr += Option::dir_sep;
|
|---|
| 1278 | if(exists(wild)) { //real file
|
|---|
| 1279 | QString file = wild;
|
|---|
| 1280 | QFileInfo fi(fileInfo(wild));
|
|---|
| 1281 | if(!target.isEmpty())
|
|---|
| 1282 | target += "\t";
|
|---|
| 1283 | QString dst_file = filePrefixRoot(root, dst);
|
|---|
| 1284 | if(fi.isDir() && project->isActiveConfig("copy_dir_files")) {
|
|---|
| 1285 | if(!dst_file.endsWith(Option::dir_sep))
|
|---|
| 1286 | dst_file += Option::dir_sep;
|
|---|
| 1287 | dst_file += fi.fileName();
|
|---|
| 1288 | }
|
|---|
| 1289 | QString cmd;
|
|---|
| 1290 | if (fi.isDir())
|
|---|
| 1291 | cmd = inst_prefix + "$(INSTALL_DIR)";
|
|---|
| 1292 | else if (fi.isExecutable())
|
|---|
| 1293 | cmd = inst_prefix + "$(INSTALL_PROGRAM)";
|
|---|
| 1294 | else
|
|---|
| 1295 | cmd = inst_prefix + "$(INSTALL_FILE)";
|
|---|
| 1296 | cmd += " " + escapeFilePath(wild) + " " + dst_file + "\n";
|
|---|
| 1297 | target += cmd;
|
|---|
| 1298 | if(!project->isActiveConfig("debug") && !project->isActiveConfig("nostrip") &&
|
|---|
| 1299 | !fi.isDir() && fi.isExecutable() && !project->isEmpty("QMAKE_STRIP"))
|
|---|
| 1300 | target += QString("\t-") + var("QMAKE_STRIP") + " " +
|
|---|
| 1301 | filePrefixRoot(root, fileFixify(dst + filestr, FileFixifyAbsolute, false)) + "\n";
|
|---|
| 1302 | if(!uninst.isEmpty())
|
|---|
| 1303 | uninst.append("\n\t");
|
|---|
| 1304 | uninst.append(rm_dir_contents + " " + filePrefixRoot(root, fileFixify(dst + filestr, FileFixifyAbsolute, false)) + del_suffix);
|
|---|
| 1305 | continue;
|
|---|
| 1306 | }
|
|---|
| 1307 | QString local_dirstr = Option::fixPathToLocalOS(dirstr, true);
|
|---|
| 1308 | QStringList files = QDir(local_dirstr).entryList(QStringList(filestr));
|
|---|
| 1309 | const QStringList &installConfigValues = project->values((*it) + ".CONFIG");
|
|---|
| 1310 | if (installConfigValues.contains("no_check_exist") && files.isEmpty()) {
|
|---|
| 1311 | if(!target.isEmpty())
|
|---|
| 1312 | target += "\t";
|
|---|
| 1313 | QString dst_file = filePrefixRoot(root, dst);
|
|---|
| 1314 | QFileInfo fi(fileInfo(wild));
|
|---|
| 1315 | QString cmd;
|
|---|
| 1316 | if (installConfigValues.contains("directory")) {
|
|---|
| 1317 | cmd = inst_prefix + QLatin1String("$(INSTALL_DIR)");
|
|---|
| 1318 | if (!dst_file.endsWith(Option::dir_sep))
|
|---|
| 1319 | dst_file += Option::dir_sep;
|
|---|
| 1320 | dst_file += fi.fileName();
|
|---|
| 1321 | } else if (installConfigValues.contains("executable")) {
|
|---|
| 1322 | cmd = inst_prefix + QLatin1String("$(INSTALL_PROGRAM)");
|
|---|
| 1323 | } else if (installConfigValues.contains("data")) {
|
|---|
| 1324 | cmd = inst_prefix + QLatin1String("$(INSTALL_FILE)");
|
|---|
| 1325 | } else {
|
|---|
| 1326 | cmd = inst_prefix + QString(fi.isExecutable() ? "$(INSTALL_PROGRAM)" : "$(INSTALL_FILE)");
|
|---|
| 1327 | }
|
|---|
| 1328 | cmd += " " + wild + " " + dst_file + "\n";
|
|---|
| 1329 | target += cmd;
|
|---|
| 1330 | if(!uninst.isEmpty())
|
|---|
| 1331 | uninst.append("\n\t");
|
|---|
| 1332 | uninst.append(rm_dir_contents + " " + filePrefixRoot(root, fileFixify(dst + filestr, FileFixifyAbsolute, false)) + del_suffix);
|
|---|
| 1333 | }
|
|---|
| 1334 | for(int x = 0; x < files.count(); x++) {
|
|---|
| 1335 | QString file = files[x];
|
|---|
| 1336 | if(file == "." || file == "..") //blah
|
|---|
| 1337 | continue;
|
|---|
| 1338 | if(!uninst.isEmpty())
|
|---|
| 1339 | uninst.append("\n\t");
|
|---|
| 1340 | uninst.append(rm_dir_contents + " " + filePrefixRoot(root, fileFixify(dst + file, FileFixifyAbsolute, false)) + del_suffix);
|
|---|
| 1341 | QFileInfo fi(fileInfo(dirstr + file));
|
|---|
| 1342 | if(!target.isEmpty())
|
|---|
| 1343 | target += "\t";
|
|---|
| 1344 | QString dst_file = filePrefixRoot(root, fileFixify(dst, FileFixifyAbsolute, false));
|
|---|
| 1345 | if(fi.isDir() && project->isActiveConfig("copy_dir_files")) {
|
|---|
| 1346 | if(!dst_file.endsWith(Option::dir_sep))
|
|---|
| 1347 | dst_file += Option::dir_sep;
|
|---|
| 1348 | dst_file += fi.fileName();
|
|---|
| 1349 | }
|
|---|
| 1350 | QString cmd = inst_prefix + QString(fi.isDir() ? "$(INSTALL_DIR)" : "$(INSTALL_FILE)") + " " +
|
|---|
| 1351 | dirstr + file + " " + dst_file + "\n";
|
|---|
| 1352 | target += cmd;
|
|---|
| 1353 | if(!project->isActiveConfig("debug") && !project->isActiveConfig("nostrip") &&
|
|---|
| 1354 | !fi.isDir() && fi.isExecutable() && !project->isEmpty("QMAKE_STRIP"))
|
|---|
| 1355 | target += QString("\t-") + var("QMAKE_STRIP") + " " +
|
|---|
| 1356 | filePrefixRoot(root, fileFixify(dst + file, FileFixifyAbsolute, false)) +
|
|---|
| 1357 | "\n";
|
|---|
| 1358 | }
|
|---|
| 1359 | }
|
|---|
| 1360 | }
|
|---|
| 1361 | //default?
|
|---|
| 1362 | if(do_default) {
|
|---|
| 1363 | target = defaultInstall((*it));
|
|---|
| 1364 | uninst = project->values((*it) + ".uninstall");
|
|---|
| 1365 | }
|
|---|
| 1366 |
|
|---|
| 1367 | if(!target.isEmpty() || project->values((*it) + ".CONFIG").indexOf("dummy_install") != -1) {
|
|---|
| 1368 | if(noBuild || project->values((*it) + ".CONFIG").indexOf("no_build") != -1)
|
|---|
| 1369 | t << "install_" << (*it) << ":";
|
|---|
| 1370 | else if(project->isActiveConfig("build_all"))
|
|---|
| 1371 | t << "install_" << (*it) << ": all";
|
|---|
| 1372 | else
|
|---|
| 1373 | t << "install_" << (*it) << ": first";
|
|---|
| 1374 | const QStringList &deps = project->values((*it) + ".depends");
|
|---|
| 1375 | if(!deps.isEmpty()) {
|
|---|
| 1376 | for(QStringList::ConstIterator dep_it = deps.begin(); dep_it != deps.end(); ++dep_it) {
|
|---|
| 1377 | QString targ = var((*dep_it) + ".target");
|
|---|
| 1378 | if(targ.isEmpty())
|
|---|
| 1379 | targ = (*dep_it);
|
|---|
| 1380 | t << " " << escapeDependencyPath(targ);
|
|---|
| 1381 | }
|
|---|
| 1382 | }
|
|---|
| 1383 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 1384 | t << " FORCE";
|
|---|
| 1385 | t << "\n\t";
|
|---|
| 1386 | const QStringList &dirs = project->values(pvar);
|
|---|
| 1387 | for(QStringList::ConstIterator pit = dirs.begin(); pit != dirs.end(); ++pit) {
|
|---|
| 1388 | QString tmp_dst = fileFixify((*pit), FileFixifyAbsolute, false);
|
|---|
| 1389 | if (!isDosLikeShell() && !tmp_dst.endsWith(Option::dir_sep))
|
|---|
| 1390 | tmp_dst += Option::dir_sep;
|
|---|
| 1391 | t << mkdir_p_asstring(filePrefixRoot(root, tmp_dst)) << "\n\t";
|
|---|
| 1392 | }
|
|---|
| 1393 | t << target << endl << endl;
|
|---|
| 1394 | if(!uninst.isEmpty()) {
|
|---|
| 1395 | t << "uninstall_" << (*it) << ": ";
|
|---|
| 1396 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 1397 | t << " FORCE";
|
|---|
| 1398 | t << "\n\t"
|
|---|
| 1399 | << uninst.join(" ") << "\n\t"
|
|---|
| 1400 | << "-$(DEL_DIR) " << filePrefixRoot(root, dst) << " " << del_suffix << endl << endl;
|
|---|
| 1401 | }
|
|---|
| 1402 | t << endl;
|
|---|
| 1403 |
|
|---|
| 1404 | if(project->values((*it) + ".CONFIG").indexOf("no_default_install") == -1) {
|
|---|
| 1405 | all_installs += QString("install_") + (*it) + " ";
|
|---|
| 1406 | if(!uninst.isEmpty())
|
|---|
| 1407 | all_uninstalls += "uninstall_" + (*it) + " ";
|
|---|
| 1408 | }
|
|---|
| 1409 | } else {
|
|---|
| 1410 | debug_msg(1, "no definition for install %s: install target not created",(*it).toLatin1().constData());
|
|---|
| 1411 | }
|
|---|
| 1412 | }
|
|---|
| 1413 | t << "install: " << var("INSTALLDEPS") << " " << all_installs;
|
|---|
| 1414 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 1415 | t << " FORCE";
|
|---|
| 1416 | t << "\n\n";
|
|---|
| 1417 | t << "uninstall: " << all_uninstalls << " " << var("UNINSTALLDEPS");
|
|---|
| 1418 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 1419 | t << " FORCE";
|
|---|
| 1420 | t << "\n\n";
|
|---|
| 1421 | }
|
|---|
| 1422 |
|
|---|
| 1423 | QString
|
|---|
| 1424 | MakefileGenerator::var(const QString &var)
|
|---|
| 1425 | {
|
|---|
| 1426 | return val(project->values(var));
|
|---|
| 1427 | }
|
|---|
| 1428 |
|
|---|
| 1429 | QString
|
|---|
| 1430 | MakefileGenerator::val(const QStringList &varList)
|
|---|
| 1431 | {
|
|---|
| 1432 | return valGlue(varList, "", " ", "");
|
|---|
| 1433 | }
|
|---|
| 1434 |
|
|---|
| 1435 | QString
|
|---|
| 1436 | MakefileGenerator::varGlue(const QString &var, const QString &before, const QString &glue, const QString &after)
|
|---|
| 1437 | {
|
|---|
| 1438 | return valGlue(project->values(var), before, glue, after);
|
|---|
| 1439 | }
|
|---|
| 1440 |
|
|---|
| 1441 | QString
|
|---|
| 1442 | MakefileGenerator::valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after)
|
|---|
| 1443 | {
|
|---|
| 1444 | QString ret;
|
|---|
| 1445 | for(QStringList::ConstIterator it = varList.begin(); it != varList.end(); ++it) {
|
|---|
| 1446 | if(!(*it).isEmpty()) {
|
|---|
| 1447 | if(!ret.isEmpty())
|
|---|
| 1448 | ret += glue;
|
|---|
| 1449 | ret += (*it);
|
|---|
| 1450 | }
|
|---|
| 1451 | }
|
|---|
| 1452 | return ret.isEmpty() ? QString("") : before + ret + after;
|
|---|
| 1453 | }
|
|---|
| 1454 |
|
|---|
| 1455 |
|
|---|
| 1456 | QString
|
|---|
| 1457 | MakefileGenerator::varList(const QString &var)
|
|---|
| 1458 | {
|
|---|
| 1459 | return valList(project->values(var));
|
|---|
| 1460 | }
|
|---|
| 1461 |
|
|---|
| 1462 | QString
|
|---|
| 1463 | MakefileGenerator::valList(const QStringList &varList)
|
|---|
| 1464 | {
|
|---|
| 1465 | return valGlue(varList, "", " \\\n\t\t", "");
|
|---|
| 1466 | }
|
|---|
| 1467 |
|
|---|
| 1468 | QStringList
|
|---|
| 1469 | MakefileGenerator::createObjectList(const QStringList &sources)
|
|---|
| 1470 | {
|
|---|
| 1471 | QStringList ret;
|
|---|
| 1472 | QString objdir;
|
|---|
| 1473 | if(!project->values("OBJECTS_DIR").isEmpty())
|
|---|
| 1474 | objdir = project->first("OBJECTS_DIR");
|
|---|
| 1475 | for(QStringList::ConstIterator it = sources.begin(); it != sources.end(); ++it) {
|
|---|
| 1476 | QFileInfo fi(fileInfo(Option::fixPathToLocalOS((*it))));
|
|---|
| 1477 | QString dir;
|
|---|
| 1478 | if(objdir.isEmpty() && project->isActiveConfig("object_with_source")) {
|
|---|
| 1479 | QString fName = Option::fixPathToTargetOS((*it), false);
|
|---|
| 1480 | int dl = fName.lastIndexOf(Option::dir_sep);
|
|---|
| 1481 | if(dl != -1)
|
|---|
| 1482 | dir = fName.left(dl + 1);
|
|---|
| 1483 | } else {
|
|---|
| 1484 | dir = objdir;
|
|---|
| 1485 | }
|
|---|
| 1486 | ret.append(dir + fi.completeBaseName() + Option::obj_ext);
|
|---|
| 1487 | }
|
|---|
| 1488 | return ret;
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | ReplaceExtraCompilerCacheKey::ReplaceExtraCompilerCacheKey(const QString &v, const QStringList &i, const QStringList &o)
|
|---|
| 1492 | {
|
|---|
| 1493 | hash = 0;
|
|---|
| 1494 | pwd = qmake_getpwd();
|
|---|
| 1495 | var = v;
|
|---|
| 1496 | {
|
|---|
| 1497 | QStringList il = i;
|
|---|
| 1498 | il.sort();
|
|---|
| 1499 | in = il.join("::");
|
|---|
| 1500 | }
|
|---|
| 1501 | {
|
|---|
| 1502 | QStringList ol = o;
|
|---|
| 1503 | ol.sort();
|
|---|
| 1504 | out = ol.join("::");
|
|---|
| 1505 | }
|
|---|
| 1506 | }
|
|---|
| 1507 |
|
|---|
| 1508 | bool ReplaceExtraCompilerCacheKey::operator==(const ReplaceExtraCompilerCacheKey &f) const
|
|---|
| 1509 | {
|
|---|
| 1510 | return (hashCode() == f.hashCode() &&
|
|---|
| 1511 | f.in == in &&
|
|---|
| 1512 | f.out == out &&
|
|---|
| 1513 | f.var == var &&
|
|---|
| 1514 | f.pwd == pwd);
|
|---|
| 1515 | }
|
|---|
| 1516 |
|
|---|
| 1517 |
|
|---|
| 1518 | QString
|
|---|
| 1519 | MakefileGenerator::replaceExtraCompilerVariables(const QString &orig_var, const QStringList &in, const QStringList &out)
|
|---|
| 1520 | {
|
|---|
| 1521 | //lazy cache
|
|---|
| 1522 | ReplaceExtraCompilerCacheKey cacheKey(orig_var, in, out);
|
|---|
| 1523 | QString cacheVal = extraCompilerVariablesCache.value(cacheKey);
|
|---|
| 1524 | if(!cacheVal.isNull())
|
|---|
| 1525 | return cacheVal;
|
|---|
| 1526 |
|
|---|
| 1527 | //do the work
|
|---|
| 1528 | QString ret = orig_var;
|
|---|
| 1529 | QRegExp reg_var("\\$\\{.*\\}");
|
|---|
| 1530 | reg_var.setMinimal(true);
|
|---|
| 1531 | for(int rep = 0; (rep = reg_var.indexIn(ret, rep)) != -1; ) {
|
|---|
| 1532 | QStringList val;
|
|---|
| 1533 | const QString var = ret.mid(rep + 2, reg_var.matchedLength() - 3);
|
|---|
| 1534 | bool filePath = false;
|
|---|
| 1535 | if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_VAR_"))) {
|
|---|
| 1536 | const QString varname = var.mid(10);
|
|---|
| 1537 | val += project->values(varname);
|
|---|
| 1538 | }
|
|---|
| 1539 | if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_VAR_FIRST_"))) {
|
|---|
| 1540 | const QString varname = var.mid(16);
|
|---|
| 1541 | val += project->first(varname);
|
|---|
| 1542 | }
|
|---|
| 1543 |
|
|---|
| 1544 | if(val.isEmpty() && !in.isEmpty()) {
|
|---|
| 1545 | if(var.startsWith(QLatin1String("QMAKE_FUNC_FILE_IN_"))) {
|
|---|
| 1546 | filePath = true;
|
|---|
| 1547 | const QString funcname = var.mid(19);
|
|---|
| 1548 | val += project->expand(funcname, QList<QStringList>() << in);
|
|---|
| 1549 | } else if(var == QLatin1String("QMAKE_FILE_BASE") || var == QLatin1String("QMAKE_FILE_IN_BASE")) {
|
|---|
| 1550 | //filePath = true;
|
|---|
| 1551 | for(int i = 0; i < in.size(); ++i) {
|
|---|
| 1552 | QFileInfo fi(fileInfo(Option::fixPathToLocalOS(in.at(i))));
|
|---|
| 1553 | QString base = fi.completeBaseName();
|
|---|
| 1554 | if(base.isNull())
|
|---|
| 1555 | base = fi.fileName();
|
|---|
| 1556 | val += base;
|
|---|
| 1557 | }
|
|---|
| 1558 | } else if(var == QLatin1String("QMAKE_FILE_EXT")) {
|
|---|
| 1559 | filePath = true;
|
|---|
| 1560 | for(int i = 0; i < in.size(); ++i) {
|
|---|
| 1561 | QFileInfo fi(fileInfo(Option::fixPathToLocalOS(in.at(i))));
|
|---|
| 1562 | QString ext;
|
|---|
| 1563 | // Ensure complementarity with QMAKE_FILE_BASE
|
|---|
| 1564 | int baseLen = fi.completeBaseName().length();
|
|---|
| 1565 | if(baseLen == 0)
|
|---|
| 1566 | ext = fi.fileName();
|
|---|
| 1567 | else
|
|---|
| 1568 | ext = fi.fileName().remove(0, baseLen);
|
|---|
| 1569 | val += ext;
|
|---|
| 1570 | }
|
|---|
| 1571 | } else if(var == QLatin1String("QMAKE_FILE_PATH") || var == QLatin1String("QMAKE_FILE_IN_PATH")) {
|
|---|
| 1572 | filePath = true;
|
|---|
| 1573 | for(int i = 0; i < in.size(); ++i)
|
|---|
| 1574 | val += fileInfo(Option::fixPathToLocalOS(in.at(i))).path();
|
|---|
| 1575 | } else if(var == QLatin1String("QMAKE_FILE_NAME") || var == QLatin1String("QMAKE_FILE_IN")) {
|
|---|
| 1576 | filePath = true;
|
|---|
| 1577 | for(int i = 0; i < in.size(); ++i)
|
|---|
| 1578 | val += fileInfo(Option::fixPathToLocalOS(in.at(i))).filePath();
|
|---|
| 1579 |
|
|---|
| 1580 | }
|
|---|
| 1581 | }
|
|---|
| 1582 | if(val.isEmpty() && !out.isEmpty()) {
|
|---|
| 1583 | if(var.startsWith(QLatin1String("QMAKE_FUNC_FILE_OUT_"))) {
|
|---|
| 1584 | filePath = true;
|
|---|
| 1585 | const QString funcname = var.mid(20);
|
|---|
| 1586 | val += project->expand(funcname, QList<QStringList>() << out);
|
|---|
| 1587 | } else if(var == QLatin1String("QMAKE_FILE_OUT")) {
|
|---|
| 1588 | filePath = true;
|
|---|
| 1589 | for(int i = 0; i < out.size(); ++i)
|
|---|
| 1590 | val += fileInfo(Option::fixPathToLocalOS(out.at(i))).filePath();
|
|---|
| 1591 | } else if(var == QLatin1String("QMAKE_FILE_OUT_BASE")) {
|
|---|
| 1592 | //filePath = true;
|
|---|
| 1593 | for(int i = 0; i < out.size(); ++i) {
|
|---|
| 1594 | QFileInfo fi(fileInfo(Option::fixPathToLocalOS(out.at(i))));
|
|---|
| 1595 | QString base = fi.completeBaseName();
|
|---|
| 1596 | if(base.isNull())
|
|---|
| 1597 | base = fi.fileName();
|
|---|
| 1598 | val += base;
|
|---|
| 1599 | }
|
|---|
| 1600 | }
|
|---|
| 1601 | }
|
|---|
| 1602 | if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_FUNC_"))) {
|
|---|
| 1603 | const QString funcname = var.mid(11);
|
|---|
| 1604 | val += project->expand(funcname, QList<QStringList>() << in << out);
|
|---|
| 1605 | }
|
|---|
| 1606 |
|
|---|
| 1607 | if(!val.isEmpty()) {
|
|---|
| 1608 | QString fullVal;
|
|---|
| 1609 | if(filePath) {
|
|---|
| 1610 | for(int i = 0; i < val.size(); ++i) {
|
|---|
| 1611 | const QString file = Option::fixPathToTargetOS(unescapeFilePath(val.at(i)), false);
|
|---|
| 1612 | if(!fullVal.isEmpty())
|
|---|
| 1613 | fullVal += " ";
|
|---|
| 1614 | fullVal += escapeFilePath(file);
|
|---|
| 1615 | }
|
|---|
| 1616 | } else {
|
|---|
| 1617 | fullVal = val.join(" ");
|
|---|
| 1618 | }
|
|---|
| 1619 | ret.replace(rep, reg_var.matchedLength(), fullVal);
|
|---|
| 1620 | rep += fullVal.length();
|
|---|
| 1621 | } else {
|
|---|
| 1622 | rep += reg_var.matchedLength();
|
|---|
| 1623 | }
|
|---|
| 1624 | }
|
|---|
| 1625 |
|
|---|
| 1626 | //cache the value
|
|---|
| 1627 | extraCompilerVariablesCache.insert(cacheKey, ret);
|
|---|
| 1628 | return ret;
|
|---|
| 1629 | }
|
|---|
| 1630 |
|
|---|
| 1631 | bool
|
|---|
| 1632 | MakefileGenerator::verifyExtraCompiler(const QString &comp, const QString &file_unfixed)
|
|---|
| 1633 | {
|
|---|
| 1634 | if(noIO())
|
|---|
| 1635 | return false;
|
|---|
| 1636 | const QString file = Option::fixPathToLocalOS(file_unfixed);
|
|---|
| 1637 |
|
|---|
| 1638 | if(project->values(comp + ".CONFIG").indexOf("moc_verify") != -1) {
|
|---|
| 1639 | if(!file.isNull()) {
|
|---|
| 1640 | QMakeSourceFileInfo::addSourceFile(file, QMakeSourceFileInfo::SEEK_MOCS);
|
|---|
| 1641 | if(!mocable(file)) {
|
|---|
| 1642 | return false;
|
|---|
| 1643 | } else {
|
|---|
| 1644 | project->values("MOCABLES").append(file);
|
|---|
| 1645 | }
|
|---|
| 1646 | }
|
|---|
| 1647 | } else if(project->values(comp + ".CONFIG").indexOf("function_verify") != -1) {
|
|---|
| 1648 | QString tmp_out = project->values(comp + ".output").first();
|
|---|
| 1649 | if(tmp_out.isEmpty())
|
|---|
| 1650 | return false;
|
|---|
| 1651 | QStringList verify_function = project->values(comp + ".verify_function");
|
|---|
| 1652 | if(verify_function.isEmpty())
|
|---|
| 1653 | return false;
|
|---|
| 1654 |
|
|---|
| 1655 | for(int i = 0; i < verify_function.size(); ++i) {
|
|---|
| 1656 | bool invert = false;
|
|---|
| 1657 | QString verify = verify_function.at(i);
|
|---|
| 1658 | if(verify.at(0) == QLatin1Char('!')) {
|
|---|
| 1659 | invert = true;
|
|---|
| 1660 | verify = verify.mid(1);
|
|---|
| 1661 | }
|
|---|
| 1662 |
|
|---|
| 1663 | if(project->values(comp + ".CONFIG").indexOf("combine") != -1) {
|
|---|
| 1664 | bool pass = project->test(verify, QList<QStringList>() << QStringList(tmp_out) << QStringList(file));
|
|---|
| 1665 | if(invert)
|
|---|
| 1666 | pass = !pass;
|
|---|
| 1667 | if(!pass)
|
|---|
| 1668 | return false;
|
|---|
| 1669 | } else {
|
|---|
| 1670 | QStringList &tmp = project->values(comp + ".input");
|
|---|
| 1671 | for(QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) {
|
|---|
| 1672 | QStringList &inputs = project->values((*it));
|
|---|
| 1673 | for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
|
|---|
| 1674 | if((*input).isEmpty())
|
|---|
| 1675 | continue;
|
|---|
| 1676 | QString in = fileFixify(Option::fixPathToTargetOS((*input), false));
|
|---|
| 1677 | if(in == file) {
|
|---|
| 1678 | bool pass = project->test(verify,
|
|---|
| 1679 | QList<QStringList>() << QStringList(replaceExtraCompilerVariables(tmp_out, (*input), QString())) <<
|
|---|
| 1680 | QStringList(file));
|
|---|
| 1681 | if(invert)
|
|---|
| 1682 | pass = !pass;
|
|---|
| 1683 | if(!pass)
|
|---|
| 1684 | return false;
|
|---|
| 1685 | break;
|
|---|
| 1686 | }
|
|---|
| 1687 | }
|
|---|
| 1688 | }
|
|---|
| 1689 | }
|
|---|
| 1690 | }
|
|---|
| 1691 | } else if(project->values(comp + ".CONFIG").indexOf("verify") != -1) {
|
|---|
| 1692 | QString tmp_out = project->values(comp + ".output").first();
|
|---|
| 1693 | if(tmp_out.isEmpty())
|
|---|
| 1694 | return false;
|
|---|
| 1695 | QString tmp_cmd;
|
|---|
| 1696 | if(!project->isEmpty(comp + ".commands")) {
|
|---|
| 1697 | int argv0 = -1;
|
|---|
| 1698 | QStringList cmdline = project->values(comp + ".commands");
|
|---|
| 1699 | for(int i = 0; i < cmdline.count(); ++i) {
|
|---|
| 1700 | if(!cmdline.at(i).contains('=')) {
|
|---|
| 1701 | argv0 = i;
|
|---|
| 1702 | break;
|
|---|
| 1703 | }
|
|---|
| 1704 | }
|
|---|
| 1705 | if(argv0 != -1) {
|
|---|
| 1706 | cmdline[argv0] = Option::fixPathToTargetOS(cmdline.at(argv0), false);
|
|---|
| 1707 | tmp_cmd = cmdline.join(" ");
|
|---|
| 1708 | }
|
|---|
| 1709 | }
|
|---|
| 1710 |
|
|---|
| 1711 | if(project->values(comp + ".CONFIG").indexOf("combine") != -1) {
|
|---|
| 1712 | QString cmd = replaceExtraCompilerVariables(tmp_cmd, QString(), tmp_out);
|
|---|
| 1713 | if(system(cmd.toLatin1().constData()))
|
|---|
| 1714 | return false;
|
|---|
| 1715 | } else {
|
|---|
| 1716 | QStringList &tmp = project->values(comp + ".input");
|
|---|
| 1717 | for(QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) {
|
|---|
| 1718 | QStringList &inputs = project->values((*it));
|
|---|
| 1719 | for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
|
|---|
| 1720 | if((*input).isEmpty())
|
|---|
| 1721 | continue;
|
|---|
| 1722 | QString in = fileFixify(Option::fixPathToTargetOS((*input), false));
|
|---|
| 1723 | if(in == file) {
|
|---|
| 1724 | QString out = replaceExtraCompilerVariables(tmp_out, (*input), QString());
|
|---|
| 1725 | QString cmd = replaceExtraCompilerVariables(tmp_cmd, in, out);
|
|---|
| 1726 | if(system(cmd.toLatin1().constData()))
|
|---|
| 1727 | return false;
|
|---|
| 1728 | break;
|
|---|
| 1729 | }
|
|---|
| 1730 | }
|
|---|
| 1731 | }
|
|---|
| 1732 | }
|
|---|
| 1733 | }
|
|---|
| 1734 | return true;
|
|---|
| 1735 | }
|
|---|
| 1736 |
|
|---|
| 1737 | void
|
|---|
| 1738 | MakefileGenerator::writeExtraTargets(QTextStream &t)
|
|---|
| 1739 | {
|
|---|
| 1740 | QStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
|
|---|
| 1741 | for(QStringList::Iterator it = qut.begin(); it != qut.end(); ++it) {
|
|---|
| 1742 | QString targ = var((*it) + ".target"),
|
|---|
| 1743 | cmd = var((*it) + ".commands"), deps;
|
|---|
| 1744 | if(targ.isEmpty())
|
|---|
| 1745 | targ = (*it);
|
|---|
| 1746 | QStringList &deplist = project->values((*it) + ".depends");
|
|---|
| 1747 | for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) {
|
|---|
| 1748 | QString dep = var((*dep_it) + ".target");
|
|---|
| 1749 | if(dep.isEmpty())
|
|---|
| 1750 | dep = (*dep_it);
|
|---|
| 1751 | deps += " " + escapeDependencyPath(dep);
|
|---|
| 1752 | }
|
|---|
| 1753 | if(project->values((*it) + ".CONFIG").indexOf("fix_target") != -1)
|
|---|
| 1754 | targ = fileFixify(targ);
|
|---|
| 1755 | if(project->isEmpty("QMAKE_NOFORCE") &&
|
|---|
| 1756 | project->values((*it) + ".CONFIG").indexOf("phony") != -1)
|
|---|
| 1757 | deps += QString(" ") + "FORCE";
|
|---|
| 1758 | t << escapeDependencyPath(targ) << ":" << deps;
|
|---|
| 1759 | if(!cmd.isEmpty())
|
|---|
| 1760 | t << "\n\t" << cmd;
|
|---|
| 1761 | t << endl << endl;
|
|---|
| 1762 |
|
|---|
| 1763 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it)) << escapeDependencyPath(targ);
|
|---|
| 1764 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(targ)) << deps.split(" ", QString::SkipEmptyParts);
|
|---|
| 1765 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it) + escapeDependencyPath(targ)) << cmd;
|
|---|
| 1766 | }
|
|---|
| 1767 | }
|
|---|
| 1768 |
|
|---|
| 1769 | void
|
|---|
| 1770 | MakefileGenerator::writeExtraCompilerTargets(QTextStream &t)
|
|---|
| 1771 | {
|
|---|
| 1772 | QString clean_targets;
|
|---|
| 1773 | const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
|
|---|
| 1774 | for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
|
|---|
| 1775 | QString tmp_out = fileFixify(project->values((*it) + ".output").first(),
|
|---|
| 1776 | Option::output_dir, Option::output_dir);
|
|---|
| 1777 | QString tmp_cmd;
|
|---|
| 1778 | if(!project->isEmpty((*it) + ".commands")) {
|
|---|
| 1779 | QStringList cmdline = project->values((*it) + ".commands");
|
|---|
| 1780 | int argv0 = findExecutable(cmdline);
|
|---|
| 1781 | if(argv0 != -1) {
|
|---|
| 1782 | cmdline[argv0] = escapeFilePath(Option::fixPathToTargetOS(cmdline.at(argv0), false));
|
|---|
| 1783 | tmp_cmd = cmdline.join(" ");
|
|---|
| 1784 | }
|
|---|
| 1785 | }
|
|---|
| 1786 | QStringList tmp_dep = project->values((*it) + ".depends");
|
|---|
| 1787 | QString tmp_dep_cmd;
|
|---|
| 1788 | if(!project->isEmpty((*it) + ".depend_command")) {
|
|---|
| 1789 | int argv0 = -1;
|
|---|
| 1790 | QStringList cmdline = project->values((*it) + ".depend_command");
|
|---|
| 1791 | for(int i = 0; i < cmdline.count(); ++i) {
|
|---|
| 1792 | if(!cmdline.at(i).contains('=')) {
|
|---|
| 1793 | argv0 = i;
|
|---|
| 1794 | break;
|
|---|
| 1795 | }
|
|---|
| 1796 | }
|
|---|
| 1797 | if(argv0 != -1) {
|
|---|
| 1798 | const QString c = Option::fixPathToLocalOS(cmdline.at(argv0), true);
|
|---|
| 1799 | if(exists(c)) {
|
|---|
| 1800 | cmdline[argv0] = escapeFilePath(Option::fixPathToLocalOS(cmdline.at(argv0), false));
|
|---|
| 1801 | tmp_dep_cmd = cmdline.join(" ");
|
|---|
| 1802 | } else {
|
|---|
| 1803 | cmdline[argv0] = escapeFilePath(cmdline.at(argv0));
|
|---|
| 1804 | }
|
|---|
| 1805 | }
|
|---|
| 1806 | }
|
|---|
| 1807 | QStringList &vars = project->values((*it) + ".variables");
|
|---|
| 1808 | if(tmp_out.isEmpty() || tmp_cmd.isEmpty())
|
|---|
| 1809 | continue;
|
|---|
| 1810 | QStringList tmp_inputs;
|
|---|
| 1811 | {
|
|---|
| 1812 | const QStringList &comp_inputs = project->values((*it) + ".input");
|
|---|
| 1813 | for(QStringList::ConstIterator it2 = comp_inputs.begin(); it2 != comp_inputs.end(); ++it2) {
|
|---|
| 1814 | const QStringList &tmp = project->values((*it2));
|
|---|
| 1815 | for(QStringList::ConstIterator input = tmp.begin(); input != tmp.end(); ++input) {
|
|---|
| 1816 | QString in = Option::fixPathToTargetOS((*input), false);
|
|---|
| 1817 | if(verifyExtraCompiler((*it), in))
|
|---|
| 1818 | tmp_inputs.append((*input));
|
|---|
| 1819 | }
|
|---|
| 1820 | }
|
|---|
| 1821 | }
|
|---|
| 1822 |
|
|---|
| 1823 | t << "compiler_" << (*it) << "_make_all:";
|
|---|
| 1824 | if(project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
|
|---|
| 1825 | // compilers with a combined input only have one output
|
|---|
| 1826 | QString input = project->values((*it) + ".output").first();
|
|---|
| 1827 | t << " " << escapeDependencyPath(replaceExtraCompilerVariables(tmp_out, input, QString()));
|
|---|
| 1828 | } else {
|
|---|
| 1829 | for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) {
|
|---|
| 1830 | QString in = Option::fixPathToTargetOS((*input), false);
|
|---|
| 1831 | t << " " << escapeDependencyPath(replaceExtraCompilerVariables(tmp_out, (*input), QString()));
|
|---|
| 1832 | }
|
|---|
| 1833 | }
|
|---|
| 1834 | t << endl;
|
|---|
| 1835 |
|
|---|
| 1836 | if(project->values((*it) + ".CONFIG").indexOf("no_clean") == -1) {
|
|---|
| 1837 | QString tmp_clean = project->values((*it) + ".clean").join(" ");
|
|---|
| 1838 | QString tmp_clean_cmds = project->values((*it) + ".clean_commands").join(" ");
|
|---|
| 1839 | if(!tmp_inputs.isEmpty())
|
|---|
| 1840 | clean_targets += QString("compiler_" + (*it) + "_clean ");
|
|---|
| 1841 | t << "compiler_" << (*it) << "_clean:";
|
|---|
| 1842 | bool wrote_clean_cmds = false, wrote_clean = false;
|
|---|
| 1843 | if(tmp_clean_cmds.isEmpty()) {
|
|---|
| 1844 | wrote_clean_cmds = true;
|
|---|
| 1845 | } else if(tmp_clean_cmds.indexOf("${QMAKE_") == -1) {
|
|---|
| 1846 | t << "\n\t" << tmp_clean_cmds;
|
|---|
| 1847 | wrote_clean_cmds = true;
|
|---|
| 1848 | }
|
|---|
| 1849 | if(tmp_clean.isEmpty())
|
|---|
| 1850 | tmp_clean = tmp_out;
|
|---|
| 1851 |
|
|---|
| 1852 | const QString del_statement("-$(DEL_FILE)");
|
|---|
| 1853 | const QString del_suffix =
|
|---|
| 1854 | Option::target_mode == Option::TARG_OS2_MODE ?
|
|---|
| 1855 | QString(" >nul 2>&1") : // reduce noise
|
|---|
| 1856 | isForSymbian() ?
|
|---|
| 1857 | QString(" 2> NUL") :
|
|---|
| 1858 | QString::null;
|
|---|
| 1859 |
|
|---|
| 1860 | if(tmp_clean.indexOf("${QMAKE_") == -1) {
|
|---|
| 1861 | t << "\n\t" << del_statement << " " << tmp_clean << del_suffix;
|
|---|
| 1862 | if (isForSymbian())
|
|---|
| 1863 | t << " 2> NUL"; // Eliminate unnecessary warnings
|
|---|
| 1864 | wrote_clean = true;
|
|---|
| 1865 | }
|
|---|
| 1866 | if(!wrote_clean_cmds || !wrote_clean) {
|
|---|
| 1867 | QStringList cleans;
|
|---|
| 1868 | if(!wrote_clean) {
|
|---|
| 1869 | if(project->isActiveConfig("no_delete_multiple_files")) {
|
|---|
| 1870 | for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input)
|
|---|
| 1871 | cleans.append(" " + replaceExtraCompilerVariables(tmp_clean, (*input),
|
|---|
| 1872 | replaceExtraCompilerVariables(tmp_out, (*input), QString())));
|
|---|
| 1873 | } else {
|
|---|
| 1874 | QString files, file;
|
|---|
| 1875 | const int commandlineLimit =
|
|---|
| 1876 | Option::target_mode == Option::TARG_OS2_MODE ?
|
|---|
| 1877 | 1000: // OS/2 CMD.EXE limit (1024 - suffix - reserve)
|
|---|
| 1878 | 2047; // NT limit, expanded
|
|---|
| 1879 | for(int input = 0; input < tmp_inputs.size(); ++input) {
|
|---|
| 1880 | file = " " + replaceExtraCompilerVariables(tmp_clean, tmp_inputs.at(input),
|
|---|
| 1881 | replaceExtraCompilerVariables(tmp_out, tmp_inputs.at(input), QString()));
|
|---|
| 1882 | if(del_statement.length() + files.length() +
|
|---|
| 1883 | qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
|
|---|
| 1884 | cleans.append(files);
|
|---|
| 1885 | files.clear();
|
|---|
| 1886 | }
|
|---|
| 1887 | files += file;
|
|---|
| 1888 | }
|
|---|
| 1889 | if(!files.isEmpty())
|
|---|
| 1890 | cleans.append(files);
|
|---|
| 1891 | }
|
|---|
| 1892 | }
|
|---|
| 1893 | if(!cleans.isEmpty()) {
|
|---|
| 1894 | t << valGlue(cleans, "\n\t" + del_statement, del_suffix + "\n\t" + del_statement, del_suffix);
|
|---|
| 1895 | }
|
|---|
| 1896 | if(!wrote_clean_cmds) {
|
|---|
| 1897 | for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) {
|
|---|
| 1898 | t << "\n\t" << replaceExtraCompilerVariables(tmp_clean_cmds, (*input),
|
|---|
| 1899 | replaceExtraCompilerVariables(tmp_out, (*input), QString()));
|
|---|
| 1900 | }
|
|---|
| 1901 | }
|
|---|
| 1902 | }
|
|---|
| 1903 | t << endl;
|
|---|
| 1904 | }
|
|---|
| 1905 | if(project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
|
|---|
| 1906 | if(tmp_out.indexOf("${QMAKE_") != -1) {
|
|---|
| 1907 | warn_msg(WarnLogic, "QMAKE_EXTRA_COMPILERS(%s) with combine has variable output.",
|
|---|
| 1908 | (*it).toLatin1().constData());
|
|---|
| 1909 | continue;
|
|---|
| 1910 | }
|
|---|
| 1911 | QStringList deps, inputs;
|
|---|
| 1912 | if(!tmp_dep.isEmpty())
|
|---|
| 1913 | deps += fileFixify(tmp_dep, Option::output_dir, Option::output_dir);
|
|---|
| 1914 | for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) {
|
|---|
| 1915 | deps += findDependencies((*input));
|
|---|
| 1916 | inputs += Option::fixPathToTargetOS((*input), false);
|
|---|
| 1917 | if(!tmp_dep_cmd.isEmpty() && doDepends()) {
|
|---|
| 1918 | char buff[256];
|
|---|
| 1919 | QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, (*input),
|
|---|
| 1920 | tmp_out);
|
|---|
| 1921 | dep_cmd = fixEnvVariables(dep_cmd);
|
|---|
| 1922 | if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
|
|---|
| 1923 | QString indeps;
|
|---|
| 1924 | while(!feof(proc)) {
|
|---|
| 1925 | int read_in = (int)fread(buff, 1, 255, proc);
|
|---|
| 1926 | if(!read_in)
|
|---|
| 1927 | break;
|
|---|
| 1928 | indeps += QByteArray(buff, read_in);
|
|---|
| 1929 | }
|
|---|
| 1930 | QT_PCLOSE(proc);
|
|---|
| 1931 | if(!indeps.isEmpty()) {
|
|---|
| 1932 | QStringList dep_cmd_deps = indeps.replace('\n', ' ').simplified().split(' ');
|
|---|
| 1933 | for(int i = 0; i < dep_cmd_deps.count(); ++i) {
|
|---|
| 1934 | QString &file = dep_cmd_deps[i];
|
|---|
| 1935 | if(!exists(file)) {
|
|---|
| 1936 | QString localFile;
|
|---|
| 1937 | QList<QMakeLocalFileName> depdirs = QMakeSourceFileInfo::dependencyPaths();
|
|---|
| 1938 | for(QList<QMakeLocalFileName>::Iterator it = depdirs.begin();
|
|---|
| 1939 | it != depdirs.end(); ++it) {
|
|---|
| 1940 | if(exists((*it).real() + Option::dir_sep + file)) {
|
|---|
| 1941 | localFile = (*it).local() + Option::dir_sep + file;
|
|---|
| 1942 | break;
|
|---|
| 1943 | }
|
|---|
| 1944 | }
|
|---|
| 1945 | file = localFile;
|
|---|
| 1946 | }
|
|---|
| 1947 | if(!file.isEmpty())
|
|---|
| 1948 | file = fileFixify(file);
|
|---|
| 1949 | }
|
|---|
| 1950 | deps += dep_cmd_deps;
|
|---|
| 1951 | }
|
|---|
| 1952 | }
|
|---|
| 1953 | }
|
|---|
| 1954 | }
|
|---|
| 1955 | for(int i = 0; i < inputs.size(); ) {
|
|---|
| 1956 | if(tmp_out == inputs.at(i))
|
|---|
| 1957 | inputs.removeAt(i);
|
|---|
| 1958 | else
|
|---|
| 1959 | ++i;
|
|---|
| 1960 | }
|
|---|
| 1961 | for(int i = 0; i < deps.size(); ) {
|
|---|
| 1962 | if(tmp_out == deps.at(i))
|
|---|
| 1963 | deps.removeAt(i);
|
|---|
| 1964 | else
|
|---|
| 1965 | ++i;
|
|---|
| 1966 | }
|
|---|
| 1967 | if (inputs.isEmpty())
|
|---|
| 1968 | continue;
|
|---|
| 1969 |
|
|---|
| 1970 | QString cmd;
|
|---|
| 1971 | if (isForSymbianSbsv2()) {
|
|---|
| 1972 | // In sbsv2 the command inputs and outputs need to use absolute paths
|
|---|
| 1973 | cmd = replaceExtraCompilerVariables(tmp_cmd,
|
|---|
| 1974 | fileFixify(escapeFilePaths(inputs), FileFixifyAbsolute),
|
|---|
| 1975 | fileFixify(QStringList(tmp_out), FileFixifyAbsolute));
|
|---|
| 1976 | } else {
|
|---|
| 1977 | cmd = replaceExtraCompilerVariables(tmp_cmd, escapeFilePaths(inputs), QStringList(tmp_out));
|
|---|
| 1978 | }
|
|---|
| 1979 |
|
|---|
| 1980 | t << escapeDependencyPath(tmp_out) << ":";
|
|---|
| 1981 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it)) << escapeDependencyPath(tmp_out);
|
|---|
| 1982 | // compiler.CONFIG+=explicit_dependencies means that ONLY compiler.depends gets to cause Makefile dependencies
|
|---|
| 1983 | if(project->values((*it) + ".CONFIG").indexOf("explicit_dependencies") != -1) {
|
|---|
| 1984 | t << " " << valList(escapeDependencyPaths(fileFixify(tmp_dep, Option::output_dir, Option::output_dir)));
|
|---|
| 1985 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(tmp_out)) << tmp_dep;
|
|---|
| 1986 | } else {
|
|---|
| 1987 | t << " " << valList(escapeDependencyPaths(inputs)) << " " << valList(escapeDependencyPaths(deps));
|
|---|
| 1988 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(tmp_out)) << inputs << deps;
|
|---|
| 1989 | }
|
|---|
| 1990 | t << "\n\t" << cmd << endl << endl;
|
|---|
| 1991 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it) + escapeDependencyPath(tmp_out)) << cmd;
|
|---|
| 1992 | continue;
|
|---|
| 1993 | }
|
|---|
| 1994 | for(QStringList::ConstIterator input = tmp_inputs.begin(); input != tmp_inputs.end(); ++input) {
|
|---|
| 1995 | QString in = Option::fixPathToTargetOS((*input), false);
|
|---|
| 1996 | QStringList deps = findDependencies((*input));
|
|---|
| 1997 | deps += escapeDependencyPath(in);
|
|---|
| 1998 | QString out = replaceExtraCompilerVariables(tmp_out, (*input), QString());
|
|---|
| 1999 | if(!tmp_dep.isEmpty()) {
|
|---|
| 2000 | QStringList pre_deps = fileFixify(tmp_dep, Option::output_dir, Option::output_dir);
|
|---|
| 2001 | for(int i = 0; i < pre_deps.size(); ++i)
|
|---|
| 2002 | deps += replaceExtraCompilerVariables(pre_deps.at(i), (*input), out);
|
|---|
| 2003 | }
|
|---|
| 2004 | QString cmd = replaceExtraCompilerVariables(tmp_cmd, (*input), out);
|
|---|
| 2005 | // NOTE: The var -> QMAKE_COMP_var replace feature is unsupported, do not use!
|
|---|
| 2006 | if (isForSymbianSbsv2()) {
|
|---|
| 2007 | // In sbsv2 the command inputs and outputs need to use absolute paths
|
|---|
| 2008 | cmd = replaceExtraCompilerVariables(tmp_cmd,
|
|---|
| 2009 | fileFixify((*input), FileFixifyAbsolute),
|
|---|
| 2010 | fileFixify(out, FileFixifyAbsolute));
|
|---|
| 2011 | } else {
|
|---|
| 2012 | cmd = replaceExtraCompilerVariables(tmp_cmd, (*input), out);
|
|---|
| 2013 | }
|
|---|
| 2014 | for(QStringList::ConstIterator it3 = vars.constBegin(); it3 != vars.constEnd(); ++it3)
|
|---|
| 2015 | cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")");
|
|---|
| 2016 | if(!tmp_dep_cmd.isEmpty() && doDepends()) {
|
|---|
| 2017 | char buff[256];
|
|---|
| 2018 | QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, (*input), out);
|
|---|
| 2019 | dep_cmd = fixEnvVariables(dep_cmd);
|
|---|
| 2020 | if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
|
|---|
| 2021 | QString indeps;
|
|---|
| 2022 | while(!feof(proc)) {
|
|---|
| 2023 | int read_in = (int)fread(buff, 1, 255, proc);
|
|---|
| 2024 | if(!read_in)
|
|---|
| 2025 | break;
|
|---|
| 2026 | indeps += QByteArray(buff, read_in);
|
|---|
| 2027 | }
|
|---|
| 2028 | QT_PCLOSE(proc);
|
|---|
| 2029 | if(!indeps.isEmpty()) {
|
|---|
| 2030 | QStringList dep_cmd_deps = indeps.replace('\n', ' ').simplified().split(' ');
|
|---|
| 2031 | for(int i = 0; i < dep_cmd_deps.count(); ++i) {
|
|---|
| 2032 | QString &file = dep_cmd_deps[i];
|
|---|
| 2033 | if(!exists(file)) {
|
|---|
| 2034 | QString localFile;
|
|---|
| 2035 | QList<QMakeLocalFileName> depdirs = QMakeSourceFileInfo::dependencyPaths();
|
|---|
| 2036 | for(QList<QMakeLocalFileName>::Iterator it = depdirs.begin();
|
|---|
| 2037 | it != depdirs.end(); ++it) {
|
|---|
| 2038 | if(exists((*it).real() + Option::dir_sep + file)) {
|
|---|
| 2039 | localFile = (*it).local() + Option::dir_sep + file;
|
|---|
| 2040 | break;
|
|---|
| 2041 | }
|
|---|
| 2042 | }
|
|---|
| 2043 | file = localFile;
|
|---|
| 2044 | }
|
|---|
| 2045 | if(!file.isEmpty())
|
|---|
| 2046 | file = fileFixify(file);
|
|---|
| 2047 | }
|
|---|
| 2048 | deps += dep_cmd_deps;
|
|---|
| 2049 | }
|
|---|
| 2050 | }
|
|---|
| 2051 | //use the depend system to find includes of these included files
|
|---|
| 2052 | QStringList inc_deps;
|
|---|
| 2053 | for(int i = 0; i < deps.size(); ++i) {
|
|---|
| 2054 | const QString dep = deps.at(i);
|
|---|
| 2055 | if(QFile::exists(dep)) {
|
|---|
| 2056 | SourceFileType type = TYPE_UNKNOWN;
|
|---|
| 2057 | if(type == TYPE_UNKNOWN) {
|
|---|
| 2058 | for(QStringList::Iterator cit = Option::c_ext.begin();
|
|---|
| 2059 | cit != Option::c_ext.end(); ++cit) {
|
|---|
| 2060 | if(dep.endsWith((*cit))) {
|
|---|
| 2061 | type = TYPE_C;
|
|---|
| 2062 | break;
|
|---|
| 2063 | }
|
|---|
| 2064 | }
|
|---|
| 2065 | }
|
|---|
| 2066 | if(type == TYPE_UNKNOWN) {
|
|---|
| 2067 | for(QStringList::Iterator cppit = Option::cpp_ext.begin();
|
|---|
| 2068 | cppit != Option::cpp_ext.end(); ++cppit) {
|
|---|
| 2069 | if(dep.endsWith((*cppit))) {
|
|---|
| 2070 | type = TYPE_C;
|
|---|
| 2071 | break;
|
|---|
| 2072 | }
|
|---|
| 2073 | }
|
|---|
| 2074 | }
|
|---|
| 2075 | if(type == TYPE_UNKNOWN) {
|
|---|
| 2076 | for(QStringList::Iterator hit = Option::h_ext.begin();
|
|---|
| 2077 | type == TYPE_UNKNOWN && hit != Option::h_ext.end(); ++hit) {
|
|---|
| 2078 | if(dep.endsWith((*hit))) {
|
|---|
| 2079 | type = TYPE_C;
|
|---|
| 2080 | break;
|
|---|
| 2081 | }
|
|---|
| 2082 | }
|
|---|
| 2083 | }
|
|---|
| 2084 | if(type != TYPE_UNKNOWN) {
|
|---|
| 2085 | if(!QMakeSourceFileInfo::containsSourceFile(dep, type))
|
|---|
| 2086 | QMakeSourceFileInfo::addSourceFile(dep, type);
|
|---|
| 2087 | inc_deps += QMakeSourceFileInfo::dependencies(dep);
|
|---|
| 2088 | }
|
|---|
| 2089 | }
|
|---|
| 2090 | }
|
|---|
| 2091 | deps += inc_deps;
|
|---|
| 2092 | }
|
|---|
| 2093 | for(int i = 0; i < deps.size(); ) {
|
|---|
| 2094 | QString &dep = deps[i];
|
|---|
| 2095 | dep = Option::fixPathToTargetOS(unescapeFilePath(dep), false);
|
|---|
| 2096 | if(out == dep)
|
|---|
| 2097 | deps.removeAt(i);
|
|---|
| 2098 | else
|
|---|
| 2099 | ++i;
|
|---|
| 2100 | }
|
|---|
| 2101 | t << escapeDependencyPath(out) << ": " << valList(escapeDependencyPaths(deps)) << "\n\t"
|
|---|
| 2102 | << cmd << endl << endl;
|
|---|
| 2103 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_TARGETS.") + (*it)) << escapeDependencyPath(out);
|
|---|
| 2104 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_DEPS.") + (*it) + escapeDependencyPath(out)) << deps;
|
|---|
| 2105 | project->values(QLatin1String("QMAKE_INTERNAL_ET_PARSED_CMD.") + (*it) + escapeDependencyPath(out)) << cmd;
|
|---|
| 2106 | }
|
|---|
| 2107 | }
|
|---|
| 2108 | t << "compiler_clean: " << clean_targets << endl << endl;
|
|---|
| 2109 | }
|
|---|
| 2110 |
|
|---|
| 2111 | void
|
|---|
| 2112 | MakefileGenerator::writeExtraCompilerVariables(QTextStream &t)
|
|---|
| 2113 | {
|
|---|
| 2114 | bool first = true;
|
|---|
| 2115 | const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
|
|---|
| 2116 | for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
|
|---|
| 2117 | const QStringList &vars = project->values((*it) + ".variables");
|
|---|
| 2118 | for(QStringList::ConstIterator varit = vars.begin(); varit != vars.end(); ++varit) {
|
|---|
| 2119 | if(first) {
|
|---|
| 2120 | t << "\n####### Custom Compiler Variables" << endl;
|
|---|
| 2121 | first = false;
|
|---|
| 2122 | }
|
|---|
| 2123 | t << "QMAKE_COMP_" << (*varit) << " = "
|
|---|
| 2124 | << valList(project->values((*varit))) << endl;
|
|---|
| 2125 | }
|
|---|
| 2126 | }
|
|---|
| 2127 | if(!first)
|
|---|
| 2128 | t << endl;
|
|---|
| 2129 | }
|
|---|
| 2130 |
|
|---|
| 2131 | void
|
|---|
| 2132 | MakefileGenerator::writeExtraVariables(QTextStream &t)
|
|---|
| 2133 | {
|
|---|
| 2134 | bool first = true;
|
|---|
| 2135 | QMap<QString, QStringList> &vars = project->variables();
|
|---|
| 2136 | QStringList &exports = project->values("QMAKE_EXTRA_VARIABLES");
|
|---|
| 2137 | for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it) {
|
|---|
| 2138 | for(QStringList::Iterator exp_it = exports.begin(); exp_it != exports.end(); ++exp_it) {
|
|---|
| 2139 | QRegExp rx((*exp_it), Qt::CaseInsensitive, QRegExp::Wildcard);
|
|---|
| 2140 | if(rx.exactMatch(it.key())) {
|
|---|
| 2141 | if(first) {
|
|---|
| 2142 | t << "\n####### Custom Variables" << endl;
|
|---|
| 2143 | first = false;
|
|---|
| 2144 | }
|
|---|
| 2145 | t << "EXPORT_" << it.key() << " = " << it.value().join(" ") << endl;
|
|---|
| 2146 | }
|
|---|
| 2147 | }
|
|---|
| 2148 | }
|
|---|
| 2149 | if(!first)
|
|---|
| 2150 | t << endl;
|
|---|
| 2151 | }
|
|---|
| 2152 |
|
|---|
| 2153 | bool
|
|---|
| 2154 | MakefileGenerator::writeStubMakefile(QTextStream &t)
|
|---|
| 2155 | {
|
|---|
| 2156 | t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE")) << endl;
|
|---|
| 2157 | QStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
|
|---|
| 2158 | for(QStringList::ConstIterator it = qut.begin(); it != qut.end(); ++it)
|
|---|
| 2159 | t << *it << " ";
|
|---|
| 2160 | //const QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
|
|---|
| 2161 | t << "first all clean install distclean uninstall: " << "qmake" << endl
|
|---|
| 2162 | << "qmake_all:" << endl;
|
|---|
| 2163 | writeMakeQmake(t);
|
|---|
| 2164 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2165 | t << "FORCE:" << endl << endl;
|
|---|
| 2166 | return true;
|
|---|
| 2167 | }
|
|---|
| 2168 |
|
|---|
| 2169 | bool
|
|---|
| 2170 | MakefileGenerator::writeMakefile(QTextStream &t)
|
|---|
| 2171 | {
|
|---|
| 2172 | t << "####### Compile" << endl << endl;
|
|---|
| 2173 | writeObj(t, "SOURCES");
|
|---|
| 2174 | writeObj(t, "GENERATED_SOURCES");
|
|---|
| 2175 |
|
|---|
| 2176 | t << "####### Install" << endl << endl;
|
|---|
| 2177 | writeInstalls(t, "INSTALLS");
|
|---|
| 2178 |
|
|---|
| 2179 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2180 | t << "FORCE:" << endl << endl;
|
|---|
| 2181 | return true;
|
|---|
| 2182 | }
|
|---|
| 2183 |
|
|---|
| 2184 | QString MakefileGenerator::buildArgs(const QString &outdir)
|
|---|
| 2185 | {
|
|---|
| 2186 | QString ret;
|
|---|
| 2187 | //special variables
|
|---|
| 2188 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
|
|---|
| 2189 | ret += " QMAKE_ABSOLUTE_SOURCE_PATH=" + escapeFilePath(project->first("QMAKE_ABSOLUTE_SOURCE_PATH"));
|
|---|
| 2190 |
|
|---|
| 2191 | //warnings
|
|---|
| 2192 | else if(Option::warn_level == WarnNone)
|
|---|
| 2193 | ret += " -Wnone";
|
|---|
| 2194 | else if(Option::warn_level == WarnAll)
|
|---|
| 2195 | ret += " -Wall";
|
|---|
| 2196 | else if(Option::warn_level & WarnParser)
|
|---|
| 2197 | ret += " -Wparser";
|
|---|
| 2198 | //other options
|
|---|
| 2199 | if(!Option::user_template.isEmpty())
|
|---|
| 2200 | ret += " -t " + Option::user_template;
|
|---|
| 2201 | if(!Option::user_template_prefix.isEmpty())
|
|---|
| 2202 | ret += " -tp " + Option::user_template_prefix;
|
|---|
| 2203 | if(!Option::mkfile::do_cache)
|
|---|
| 2204 | ret += " -nocache";
|
|---|
| 2205 | if(!Option::mkfile::do_deps)
|
|---|
| 2206 | ret += " -nodepend";
|
|---|
| 2207 | if(!Option::mkfile::do_dep_heuristics)
|
|---|
| 2208 | ret += " -nodependheuristics";
|
|---|
| 2209 | if(!Option::mkfile::qmakespec_commandline.isEmpty())
|
|---|
| 2210 | ret += " -spec " + specdir(outdir);
|
|---|
| 2211 | if(Option::target_mode == Option::TARG_MAC9_MODE)
|
|---|
| 2212 | ret += " -mac9";
|
|---|
| 2213 | else if(Option::target_mode == Option::TARG_MACX_MODE)
|
|---|
| 2214 | ret += " -macx";
|
|---|
| 2215 | else if(Option::target_mode == Option::TARG_UNIX_MODE)
|
|---|
| 2216 | ret += " -unix";
|
|---|
| 2217 | else if(Option::target_mode == Option::TARG_WIN_MODE)
|
|---|
| 2218 | ret += " -win32";
|
|---|
| 2219 | else if(Option::target_mode == Option::TARG_OS2_MODE)
|
|---|
| 2220 | ret += " -os2";
|
|---|
| 2221 |
|
|---|
| 2222 | //configs
|
|---|
| 2223 | for(QStringList::Iterator it = Option::user_configs.begin();
|
|---|
| 2224 | it != Option::user_configs.end(); ++it)
|
|---|
| 2225 | ret += " -config " + (*it);
|
|---|
| 2226 | //arguments
|
|---|
| 2227 | for(QStringList::Iterator it = Option::before_user_vars.begin();
|
|---|
| 2228 | it != Option::before_user_vars.end(); ++it) {
|
|---|
| 2229 | if((*it).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH")
|
|---|
| 2230 | ret += " " + escapeFilePath((*it));
|
|---|
| 2231 | }
|
|---|
| 2232 | if(Option::after_user_vars.count()) {
|
|---|
| 2233 | ret += " -after ";
|
|---|
| 2234 | for(QStringList::Iterator it = Option::after_user_vars.begin();
|
|---|
| 2235 | it != Option::after_user_vars.end(); ++it) {
|
|---|
| 2236 | if((*it).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH")
|
|---|
| 2237 | ret += " " + escapeFilePath((*it));
|
|---|
| 2238 | }
|
|---|
| 2239 | }
|
|---|
| 2240 | return ret;
|
|---|
| 2241 | }
|
|---|
| 2242 |
|
|---|
| 2243 | //could get stored argv, but then it would have more options than are
|
|---|
| 2244 | //probably necesary this will try to guess the bare minimum..
|
|---|
| 2245 | QString MakefileGenerator::build_args(const QString &outdir)
|
|---|
| 2246 | {
|
|---|
| 2247 | QString ret = "$(QMAKE)";
|
|---|
| 2248 |
|
|---|
| 2249 | // general options and arguments
|
|---|
| 2250 | ret += buildArgs(outdir);
|
|---|
| 2251 |
|
|---|
| 2252 | //output
|
|---|
| 2253 | QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
|
|---|
| 2254 | if(!ofile.isEmpty() && ofile != project->first("QMAKE_MAKEFILE"))
|
|---|
| 2255 | ret += " -o " + escapeFilePath(ofile);
|
|---|
| 2256 |
|
|---|
| 2257 | //inputs
|
|---|
| 2258 | ret += " " + escapeFilePath(fileFixify(project->projectFile(), outdir));
|
|---|
| 2259 |
|
|---|
| 2260 | return ret;
|
|---|
| 2261 | }
|
|---|
| 2262 |
|
|---|
| 2263 | void
|
|---|
| 2264 | MakefileGenerator::writeHeader(QTextStream &t)
|
|---|
| 2265 | {
|
|---|
| 2266 | t << "#############################################################################" << endl;
|
|---|
| 2267 | t << "# Makefile for building: " << escapeFilePath(var("TARGET")) << endl;
|
|---|
| 2268 | t << "# Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: ";
|
|---|
| 2269 | t << QDateTime::currentDateTime().toString() << endl;
|
|---|
| 2270 | t << "# Project: " << fileFixify(project->projectFile()) << endl;
|
|---|
| 2271 | t << "# Template: " << var("TEMPLATE") << endl;
|
|---|
| 2272 | if(!project->isActiveConfig("build_pass"))
|
|---|
| 2273 | t << "# Command: " << build_args().replace("$(QMAKE)",
|
|---|
| 2274 | (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE"))) << endl;
|
|---|
| 2275 | t << "#############################################################################" << endl;
|
|---|
| 2276 | t << endl;
|
|---|
| 2277 | }
|
|---|
| 2278 |
|
|---|
| 2279 | QList<MakefileGenerator::SubTarget*>
|
|---|
| 2280 | MakefileGenerator::findSubDirsSubTargets() const
|
|---|
| 2281 | {
|
|---|
| 2282 | QList<SubTarget*> targets;
|
|---|
| 2283 | {
|
|---|
| 2284 | const QStringList subdirs = project->values("SUBDIRS");
|
|---|
| 2285 | for(int subdir = 0; subdir < subdirs.size(); ++subdir) {
|
|---|
| 2286 | QString fixedSubdir = subdirs[subdir];
|
|---|
| 2287 | fixedSubdir = fixedSubdir.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
|
|---|
| 2288 |
|
|---|
| 2289 | SubTarget *st = new SubTarget;
|
|---|
| 2290 | st->name = subdirs[subdir];
|
|---|
| 2291 | targets.append(st);
|
|---|
| 2292 |
|
|---|
| 2293 | bool fromFile = false;
|
|---|
| 2294 | QString file = subdirs[subdir];
|
|---|
| 2295 | if(!project->isEmpty(fixedSubdir + ".file")) {
|
|---|
| 2296 | if(!project->isEmpty(fixedSubdir + ".subdir"))
|
|---|
| 2297 | warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s",
|
|---|
| 2298 | subdirs[subdir].toLatin1().constData());
|
|---|
| 2299 | file = project->first(fixedSubdir + ".file");
|
|---|
| 2300 | fromFile = true;
|
|---|
| 2301 | } else if(!project->isEmpty(fixedSubdir + ".subdir")) {
|
|---|
| 2302 | file = project->first(fixedSubdir + ".subdir");
|
|---|
| 2303 | fromFile = false;
|
|---|
| 2304 | } else {
|
|---|
| 2305 | fromFile = file.endsWith(Option::pro_ext);
|
|---|
| 2306 | }
|
|---|
| 2307 | file = Option::fixPathToTargetOS(file);
|
|---|
| 2308 |
|
|---|
| 2309 | if(fromFile) {
|
|---|
| 2310 | int slsh = file.lastIndexOf(Option::dir_sep);
|
|---|
| 2311 | if(slsh != -1) {
|
|---|
| 2312 | st->in_directory = file.left(slsh+1);
|
|---|
| 2313 | st->profile = file.mid(slsh+1);
|
|---|
| 2314 | } else {
|
|---|
| 2315 | st->profile = file;
|
|---|
| 2316 | }
|
|---|
| 2317 | } else {
|
|---|
| 2318 | if(!file.isEmpty() && !project->isActiveConfig("subdir_first_pro"))
|
|---|
| 2319 | st->profile = file.section(Option::dir_sep, -1) + Option::pro_ext;
|
|---|
| 2320 | st->in_directory = file;
|
|---|
| 2321 | }
|
|---|
| 2322 | while(st->in_directory.endsWith(Option::dir_sep))
|
|---|
| 2323 | st->in_directory.chop(1);
|
|---|
| 2324 | if(fileInfo(st->in_directory).isRelative())
|
|---|
| 2325 | st->out_directory = st->in_directory;
|
|---|
| 2326 | else
|
|---|
| 2327 | st->out_directory = fileFixify(st->in_directory, qmake_getpwd(), Option::output_dir);
|
|---|
| 2328 | if(!project->isEmpty(fixedSubdir + ".makefile")) {
|
|---|
| 2329 | st->makefile = project->first(fixedSubdir + ".makefile");
|
|---|
| 2330 | } else {
|
|---|
| 2331 | st->makefile = "$(MAKEFILE)";
|
|---|
| 2332 | if(!st->profile.isEmpty()) {
|
|---|
| 2333 | QString basename = st->in_directory;
|
|---|
| 2334 | int new_slsh = basename.lastIndexOf(Option::dir_sep);
|
|---|
| 2335 | if(new_slsh != -1)
|
|---|
| 2336 | basename = basename.mid(new_slsh+1);
|
|---|
| 2337 | if(st->profile != basename + Option::pro_ext)
|
|---|
| 2338 | st->makefile += "." + st->profile.left(st->profile.length() - Option::pro_ext.length());
|
|---|
| 2339 | }
|
|---|
| 2340 | }
|
|---|
| 2341 | if(!project->isEmpty(fixedSubdir + ".depends")) {
|
|---|
| 2342 | const QStringList depends = project->values(fixedSubdir + ".depends");
|
|---|
| 2343 | for(int depend = 0; depend < depends.size(); ++depend) {
|
|---|
| 2344 | bool found = false;
|
|---|
| 2345 | for(int subDep = 0; subDep < subdirs.size(); ++subDep) {
|
|---|
| 2346 | if(subdirs[subDep] == depends.at(depend)) {
|
|---|
| 2347 | QString fixedSubDep = subdirs[subDep];
|
|---|
| 2348 | fixedSubDep = fixedSubDep.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
|
|---|
| 2349 | if(!project->isEmpty(fixedSubDep + ".target")) {
|
|---|
| 2350 | st->depends += project->first(fixedSubDep + ".target");
|
|---|
| 2351 | } else {
|
|---|
| 2352 | QString d = Option::fixPathToLocalOS(subdirs[subDep]);
|
|---|
| 2353 | if(!project->isEmpty(fixedSubDep + ".file"))
|
|---|
| 2354 | d = project->first(fixedSubDep + ".file");
|
|---|
| 2355 | else if(!project->isEmpty(fixedSubDep + ".subdir"))
|
|---|
| 2356 | d = project->first(fixedSubDep + ".subdir");
|
|---|
| 2357 | st->depends += "sub-" + d.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
|
|---|
| 2358 | }
|
|---|
| 2359 | found = true;
|
|---|
| 2360 | break;
|
|---|
| 2361 | }
|
|---|
| 2362 | }
|
|---|
| 2363 | if(!found) {
|
|---|
| 2364 | QString depend_str = depends.at(depend);
|
|---|
| 2365 | st->depends += depend_str.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
|
|---|
| 2366 | }
|
|---|
| 2367 | }
|
|---|
| 2368 | }
|
|---|
| 2369 | if(!project->isEmpty(fixedSubdir + ".target")) {
|
|---|
| 2370 | st->target = project->first(fixedSubdir + ".target");
|
|---|
| 2371 | } else {
|
|---|
| 2372 | st->target = "sub-" + file;
|
|---|
| 2373 | st->target = st->target.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
|
|---|
| 2374 | }
|
|---|
| 2375 | }
|
|---|
| 2376 | }
|
|---|
| 2377 | return targets;
|
|---|
| 2378 | }
|
|---|
| 2379 |
|
|---|
| 2380 | void
|
|---|
| 2381 | MakefileGenerator::writeSubDirs(QTextStream &t)
|
|---|
| 2382 | {
|
|---|
| 2383 | QList<SubTarget*> targets = findSubDirsSubTargets();
|
|---|
| 2384 | t << "first: make_default" << endl;
|
|---|
| 2385 | int flags = SubTargetInstalls;
|
|---|
| 2386 | if(project->isActiveConfig("ordered"))
|
|---|
| 2387 | flags |= SubTargetOrdered;
|
|---|
| 2388 | writeSubTargets(t, targets, flags);
|
|---|
| 2389 | qDeleteAll(targets);
|
|---|
| 2390 | }
|
|---|
| 2391 |
|
|---|
| 2392 | void
|
|---|
| 2393 | MakefileGenerator::writeSubTargets(QTextStream &t, QList<MakefileGenerator::SubTarget*> targets, int flags)
|
|---|
| 2394 | {
|
|---|
| 2395 | // blasted includes
|
|---|
| 2396 | QStringList &qeui = project->values("QMAKE_EXTRA_INCLUDES");
|
|---|
| 2397 | for(QStringList::Iterator qeui_it = qeui.begin(); qeui_it != qeui.end(); ++qeui_it)
|
|---|
| 2398 | t << "include " << (*qeui_it) << endl;
|
|---|
| 2399 |
|
|---|
| 2400 | if (!(flags & SubTargetSkipDefaultVariables)) {
|
|---|
| 2401 | QString ofile = Option::fixPathToTargetOS(Option::output.fileName());
|
|---|
| 2402 | if(ofile.lastIndexOf(Option::dir_sep) != -1)
|
|---|
| 2403 | ofile.remove(0, ofile.lastIndexOf(Option::dir_sep) +1);
|
|---|
| 2404 | t << "MAKEFILE = " << ofile << endl;
|
|---|
| 2405 | /* Calling Option::fixPathToTargetOS() is necessary for MinGW/MSYS, which requires
|
|---|
| 2406 | * back-slashes to be turned into slashes. */
|
|---|
| 2407 | t << "QMAKE = " << Option::fixPathToTargetOS(var("QMAKE_QMAKE")) << endl;
|
|---|
| 2408 | t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl;
|
|---|
| 2409 | t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl;
|
|---|
| 2410 | t << "MKDIR = " << var("QMAKE_MKDIR") << endl;
|
|---|
| 2411 | t << "COPY = " << var("QMAKE_COPY") << endl;
|
|---|
| 2412 | t << "COPY_FILE = " << var("QMAKE_COPY_FILE") << endl;
|
|---|
| 2413 | t << "COPY_DIR = " << var("QMAKE_COPY_DIR") << endl;
|
|---|
| 2414 | t << "INSTALL_FILE = " << var("QMAKE_INSTALL_FILE") << endl;
|
|---|
| 2415 | t << "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl;
|
|---|
| 2416 | t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl;
|
|---|
| 2417 | t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl;
|
|---|
| 2418 | t << "SYMLINK = " << var("QMAKE_SYMBOLIC_LINK") << endl;
|
|---|
| 2419 | t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl;
|
|---|
| 2420 | t << "MOVE = " << var("QMAKE_MOVE") << endl;
|
|---|
| 2421 | t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl;
|
|---|
| 2422 | t << "MKDIR = " << var("QMAKE_MKDIR") << endl;
|
|---|
| 2423 | t << "SUBTARGETS = "; // subtargets are sub-directory
|
|---|
| 2424 | for(int target = 0; target < targets.size(); ++target)
|
|---|
| 2425 | t << " \\\n\t\t" << targets.at(target)->target;
|
|---|
| 2426 | t << endl << endl;
|
|---|
| 2427 | }
|
|---|
| 2428 | writeExtraVariables(t);
|
|---|
| 2429 |
|
|---|
| 2430 | QStringList targetSuffixes;
|
|---|
| 2431 | const QString abs_source_path = project->first("QMAKE_ABSOLUTE_SOURCE_PATH");
|
|---|
| 2432 | if (!(flags & SubTargetSkipDefaultTargets)) {
|
|---|
| 2433 | targetSuffixes << "make_default" << "make_first" << "all" << "clean" << "distclean"
|
|---|
| 2434 | << QString((flags & SubTargetInstalls) ? "install_subtargets" : "install")
|
|---|
| 2435 | << QString((flags & SubTargetInstalls) ? "uninstall_subtargets" : "uninstall");
|
|---|
| 2436 | }
|
|---|
| 2437 |
|
|---|
| 2438 | // generate target rules
|
|---|
| 2439 | for(int target = 0; target < targets.size(); ++target) {
|
|---|
| 2440 | SubTarget *subtarget = targets.at(target);
|
|---|
| 2441 | QString in_directory = subtarget->in_directory;
|
|---|
| 2442 | if(!in_directory.isEmpty() && !in_directory.endsWith(Option::dir_sep))
|
|---|
| 2443 | in_directory += Option::dir_sep;
|
|---|
| 2444 | QString out_directory = subtarget->out_directory;
|
|---|
| 2445 | if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep))
|
|---|
| 2446 | out_directory += Option::dir_sep;
|
|---|
| 2447 | if(!abs_source_path.isEmpty() && out_directory.startsWith(abs_source_path))
|
|---|
| 2448 | out_directory = Option::output_dir + out_directory.mid(abs_source_path.length());
|
|---|
| 2449 |
|
|---|
| 2450 | QString mkfile = subtarget->makefile;
|
|---|
| 2451 | if(!in_directory.isEmpty())
|
|---|
| 2452 | mkfile.prepend(out_directory);
|
|---|
| 2453 |
|
|---|
| 2454 | QString in_directory_cdin, in_directory_cdout, out_directory_cdin, out_directory_cdout;
|
|---|
| 2455 | #define MAKE_CD_IN_AND_OUT(directory) \
|
|---|
| 2456 | if(!directory.isEmpty()) { \
|
|---|
| 2457 | if(project->isActiveConfig("cd_change_global")) { \
|
|---|
| 2458 | directory ## _cdin = "\n\tcd " + directory + "\n\t"; \
|
|---|
| 2459 | QDir pwd(Option::output_dir); \
|
|---|
| 2460 | QStringList in = directory.split(Option::dir_sep), out; \
|
|---|
| 2461 | for(int i = 0; i < in.size(); i++) { \
|
|---|
| 2462 | if(in.at(i) == "..") \
|
|---|
| 2463 | out.prepend(fileInfo(pwd.path()).fileName()); \
|
|---|
| 2464 | else if(in.at(i) != ".") \
|
|---|
| 2465 | out.prepend(".."); \
|
|---|
| 2466 | pwd.cd(in.at(i)); \
|
|---|
| 2467 | } \
|
|---|
| 2468 | directory ## _cdout = "\n\t@cd " + escapeFilePath(out.join(Option::dir_sep)); \
|
|---|
| 2469 | } else { \
|
|---|
| 2470 | directory ## _cdin = "\n\tcd " + escapeFilePath(directory) + " && "; \
|
|---|
| 2471 | } \
|
|---|
| 2472 | } else { \
|
|---|
| 2473 | directory ## _cdin = "\n\t"; \
|
|---|
| 2474 | }
|
|---|
| 2475 | MAKE_CD_IN_AND_OUT(in_directory);
|
|---|
| 2476 | MAKE_CD_IN_AND_OUT(out_directory);
|
|---|
| 2477 |
|
|---|
| 2478 | //qmake it
|
|---|
| 2479 | if(!subtarget->profile.isEmpty()) {
|
|---|
| 2480 | QString out = subtarget->makefile;
|
|---|
| 2481 | QString in = fileFixify(in_directory + subtarget->profile, out_directory, QString(), FileFixifyAbsolute);
|
|---|
| 2482 | if(out.startsWith(out_directory))
|
|---|
| 2483 | out = out.mid(out_directory.length());
|
|---|
| 2484 | t << mkfile << ": " << "\n\t";
|
|---|
| 2485 | if(!in_directory.isEmpty()) {
|
|---|
| 2486 | t << mkdir_p_asstring(out_directory)
|
|---|
| 2487 | << out_directory_cdin
|
|---|
| 2488 | << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out
|
|---|
| 2489 | << in_directory_cdout << endl;
|
|---|
| 2490 | } else {
|
|---|
| 2491 | t << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out << endl;
|
|---|
| 2492 | }
|
|---|
| 2493 | t << subtarget->target << "-qmake_all: ";
|
|---|
| 2494 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2495 | t << " FORCE";
|
|---|
| 2496 | t << "\n\t";
|
|---|
| 2497 | if(!in_directory.isEmpty()) {
|
|---|
| 2498 | t << mkdir_p_asstring(out_directory)
|
|---|
| 2499 | << out_directory_cdin
|
|---|
| 2500 | << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out
|
|---|
| 2501 | << in_directory_cdout << endl;
|
|---|
| 2502 | } else {
|
|---|
| 2503 | t << "$(QMAKE) " << in << buildArgs(in_directory) << " -o " << out << endl;
|
|---|
| 2504 | }
|
|---|
| 2505 | }
|
|---|
| 2506 |
|
|---|
| 2507 | QString makefilein = " -f " + subtarget->makefile;
|
|---|
| 2508 |
|
|---|
| 2509 | { //actually compile
|
|---|
| 2510 | t << subtarget->target << ": " << mkfile;
|
|---|
| 2511 | if(!subtarget->depends.isEmpty())
|
|---|
| 2512 | t << " " << valList(subtarget->depends);
|
|---|
| 2513 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2514 | t << " FORCE";
|
|---|
| 2515 | t << out_directory_cdin
|
|---|
| 2516 | << "$(MAKE)" << makefilein
|
|---|
| 2517 | << out_directory_cdout << endl;
|
|---|
| 2518 | }
|
|---|
| 2519 |
|
|---|
| 2520 | for(int suffix = 0; suffix < targetSuffixes.size(); ++suffix) {
|
|---|
| 2521 | QString s = targetSuffixes.at(suffix);
|
|---|
| 2522 | if(s == "install_subtargets")
|
|---|
| 2523 | s = "install";
|
|---|
| 2524 | else if(s == "uninstall_subtargets")
|
|---|
| 2525 | s = "uninstall";
|
|---|
| 2526 | else if(s == "make_first")
|
|---|
| 2527 | s = "first";
|
|---|
| 2528 | else if(s == "make_default")
|
|---|
| 2529 | s = QString();
|
|---|
| 2530 |
|
|---|
| 2531 | if(flags & SubTargetOrdered) {
|
|---|
| 2532 | t << subtarget->target << "-" << targetSuffixes.at(suffix) << "-ordered: " << mkfile;
|
|---|
| 2533 | if(target)
|
|---|
| 2534 | t << " " << targets.at(target-1)->target << "-" << targetSuffixes.at(suffix) << "-ordered ";
|
|---|
| 2535 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2536 | t << " FORCE";
|
|---|
| 2537 | t << out_directory_cdin
|
|---|
| 2538 | << "$(MAKE)" << makefilein << " " << s
|
|---|
| 2539 | << out_directory_cdout << endl;
|
|---|
| 2540 | }
|
|---|
| 2541 | t << subtarget->target << "-" << targetSuffixes.at(suffix) << ": " << mkfile;
|
|---|
| 2542 | if(!subtarget->depends.isEmpty())
|
|---|
| 2543 | t << " " << valGlue(subtarget->depends, QString(), "-" + targetSuffixes.at(suffix) + " ",
|
|---|
| 2544 | "-"+targetSuffixes.at(suffix));
|
|---|
| 2545 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2546 | t << " FORCE";
|
|---|
| 2547 | t << out_directory_cdin
|
|---|
| 2548 | << "$(MAKE)" << makefilein << " " << s
|
|---|
| 2549 | << out_directory_cdout << endl;
|
|---|
| 2550 | }
|
|---|
| 2551 | }
|
|---|
| 2552 | t << endl;
|
|---|
| 2553 |
|
|---|
| 2554 | if (!(flags & SubTargetSkipDefaultTargets)) {
|
|---|
| 2555 | if(project->values("QMAKE_INTERNAL_QMAKE_DEPS").indexOf("qmake_all") == -1)
|
|---|
| 2556 | project->values("QMAKE_INTERNAL_QMAKE_DEPS").append("qmake_all");
|
|---|
| 2557 |
|
|---|
| 2558 | writeMakeQmake(t);
|
|---|
| 2559 |
|
|---|
| 2560 | t << "qmake_all:";
|
|---|
| 2561 | if(!targets.isEmpty()) {
|
|---|
| 2562 | for(QList<SubTarget*>::Iterator it = targets.begin(); it != targets.end(); ++it) {
|
|---|
| 2563 | if(!(*it)->profile.isEmpty())
|
|---|
| 2564 | t << " " << (*it)->target << "-" << "qmake_all";
|
|---|
| 2565 | }
|
|---|
| 2566 | }
|
|---|
| 2567 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2568 | t << " FORCE";
|
|---|
| 2569 | if(project->isActiveConfig("no_empty_targets"))
|
|---|
| 2570 | t << "\n\t" << "@cd .";
|
|---|
| 2571 | t << endl << endl;
|
|---|
| 2572 | }
|
|---|
| 2573 |
|
|---|
| 2574 | for(int s = 0; s < targetSuffixes.size(); ++s) {
|
|---|
| 2575 | QString suffix = targetSuffixes.at(s);
|
|---|
| 2576 | if(!(flags & SubTargetInstalls) && suffix.endsWith("install"))
|
|---|
| 2577 | continue;
|
|---|
| 2578 |
|
|---|
| 2579 | t << suffix << ":";
|
|---|
| 2580 | for(int target = 0; target < targets.size(); ++target) {
|
|---|
| 2581 | SubTarget *subTarget = targets.at(target);
|
|---|
| 2582 | if((suffix == "make_first" || suffix == "make_default")
|
|---|
| 2583 | && project->values(subTarget->name + ".CONFIG").indexOf("no_default_target") != -1) {
|
|---|
| 2584 | continue;
|
|---|
| 2585 | }
|
|---|
| 2586 | QString targetRule = subTarget->target + "-" + suffix;
|
|---|
| 2587 | if(flags & SubTargetOrdered)
|
|---|
| 2588 | targetRule += "-ordered";
|
|---|
| 2589 | t << " " << targetRule;
|
|---|
| 2590 | }
|
|---|
| 2591 | if(suffix == "all" || suffix == "make_first")
|
|---|
| 2592 | t << varGlue("ALL_DEPS"," "," ","");
|
|---|
| 2593 | if(suffix == "clean")
|
|---|
| 2594 | t << varGlue("CLEAN_DEPS"," "," ","");
|
|---|
| 2595 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2596 | t << " FORCE";
|
|---|
| 2597 | t << endl;
|
|---|
| 2598 | const QString del_suffix =
|
|---|
| 2599 | Option::target_mode == Option::TARG_OS2_MODE ?
|
|---|
| 2600 | QString(" >nul 2>&1"): // reduce noise
|
|---|
| 2601 | QString::null;
|
|---|
| 2602 | if(suffix == "clean") {
|
|---|
| 2603 | t << varGlue("QMAKE_CLEAN","\t-$(DEL_FILE) ",del_suffix+"\n\t-$(DEL_FILE) ", del_suffix) << endl;
|
|---|
| 2604 | } else if(suffix == "distclean") {
|
|---|
| 2605 | QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
|
|---|
| 2606 | if(!ofile.isEmpty())
|
|---|
| 2607 | t << "\t-$(DEL_FILE) " << ofile << del_suffix << endl;
|
|---|
| 2608 | t << varGlue("QMAKE_DISTCLEAN","\t-$(DEL_FILE) "," ","\n");
|
|---|
| 2609 | } else if(project->isActiveConfig("no_empty_targets")) {
|
|---|
| 2610 | t << "\t" << "@cd ." << endl;
|
|---|
| 2611 | }
|
|---|
| 2612 | }
|
|---|
| 2613 |
|
|---|
| 2614 | // user defined targets
|
|---|
| 2615 | QStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
|
|---|
| 2616 | for(QStringList::Iterator qut_it = qut.begin(); qut_it != qut.end(); ++qut_it) {
|
|---|
| 2617 | QString targ = var((*qut_it) + ".target"),
|
|---|
| 2618 | cmd = var((*qut_it) + ".commands"), deps;
|
|---|
| 2619 | if(targ.isEmpty())
|
|---|
| 2620 | targ = (*qut_it);
|
|---|
| 2621 | t << endl;
|
|---|
| 2622 |
|
|---|
| 2623 | QStringList &deplist = project->values((*qut_it) + ".depends");
|
|---|
| 2624 | for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) {
|
|---|
| 2625 | QString dep = var((*dep_it) + ".target");
|
|---|
| 2626 | if(dep.isEmpty())
|
|---|
| 2627 | dep = Option::fixPathToTargetOS(*dep_it, false);
|
|---|
| 2628 | deps += " " + dep;
|
|---|
| 2629 | }
|
|---|
| 2630 | if(project->values((*qut_it) + ".CONFIG").indexOf("recursive") != -1) {
|
|---|
| 2631 | QSet<QString> recurse;
|
|---|
| 2632 | if(project->isSet((*qut_it) + ".recurse")) {
|
|---|
| 2633 | recurse = project->values((*qut_it) + ".recurse").toSet();
|
|---|
| 2634 | } else {
|
|---|
| 2635 | for(int target = 0; target < targets.size(); ++target)
|
|---|
| 2636 | recurse.insert(targets.at(target)->name);
|
|---|
| 2637 | }
|
|---|
| 2638 | for(int target = 0; target < targets.size(); ++target) {
|
|---|
| 2639 | SubTarget *subtarget = targets.at(target);
|
|---|
| 2640 | QString in_directory = subtarget->in_directory;
|
|---|
| 2641 | if(!in_directory.isEmpty() && !in_directory.endsWith(Option::dir_sep))
|
|---|
| 2642 | in_directory += Option::dir_sep;
|
|---|
| 2643 | QString out_directory = subtarget->out_directory;
|
|---|
| 2644 | if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep))
|
|---|
| 2645 | out_directory += Option::dir_sep;
|
|---|
| 2646 | if(!abs_source_path.isEmpty() && out_directory.startsWith(abs_source_path))
|
|---|
| 2647 | out_directory = Option::output_dir + out_directory.mid(abs_source_path.length());
|
|---|
| 2648 |
|
|---|
| 2649 | if(!recurse.contains(subtarget->name))
|
|---|
| 2650 | continue;
|
|---|
| 2651 | QString mkfile = subtarget->makefile;
|
|---|
| 2652 | if(!in_directory.isEmpty()) {
|
|---|
| 2653 | if(!out_directory.endsWith(Option::dir_sep))
|
|---|
| 2654 | mkfile.prepend(out_directory + Option::dir_sep);
|
|---|
| 2655 | else
|
|---|
| 2656 | mkfile.prepend(out_directory);
|
|---|
| 2657 | }
|
|---|
| 2658 | QString out_directory_cdin, out_directory_cdout;
|
|---|
| 2659 | MAKE_CD_IN_AND_OUT(out_directory);
|
|---|
| 2660 |
|
|---|
| 2661 | // note that we always pass the makefile as argument since it's
|
|---|
| 2662 | // hard to tell if it matches the platform make's default
|
|---|
| 2663 | // file name or not (and it can be also specified indirectly
|
|---|
| 2664 | // through $(MAKEFILE))
|
|---|
| 2665 | QString makefilein = " -f " + subtarget->makefile;
|
|---|
| 2666 |
|
|---|
| 2667 | //write the rule/depends
|
|---|
| 2668 | if(flags & SubTargetOrdered) {
|
|---|
| 2669 | const QString dep = subtarget->target + "-" + (*qut_it) + "_ordered";
|
|---|
| 2670 | t << dep << ": " << mkfile;
|
|---|
| 2671 | if(target)
|
|---|
| 2672 | t << " " << targets.at(target-1)->target << "-" << (*qut_it) << "_ordered ";
|
|---|
| 2673 | deps += " " + dep;
|
|---|
| 2674 | } else {
|
|---|
| 2675 | const QString dep = subtarget->target + "-" + (*qut_it);
|
|---|
| 2676 | t << dep << ": " << mkfile;
|
|---|
| 2677 | if(!subtarget->depends.isEmpty())
|
|---|
| 2678 | t << " " << valGlue(subtarget->depends, QString(), "-" + (*qut_it) + " ", "-" + (*qut_it));
|
|---|
| 2679 | deps += " " + dep;
|
|---|
| 2680 | }
|
|---|
| 2681 |
|
|---|
| 2682 | QString sub_targ = targ;
|
|---|
| 2683 | if(project->isSet((*qut_it) + ".recurse_target"))
|
|---|
| 2684 | sub_targ = project->first((*qut_it) + ".recurse_target");
|
|---|
| 2685 |
|
|---|
| 2686 | //write the commands
|
|---|
| 2687 | if(!out_directory.isEmpty()) {
|
|---|
| 2688 | t << out_directory_cdin
|
|---|
| 2689 | << "$(MAKE)" << makefilein << " " << sub_targ
|
|---|
| 2690 | << out_directory_cdout << endl;
|
|---|
| 2691 | } else {
|
|---|
| 2692 | t << "\n\t"
|
|---|
| 2693 | << "$(MAKE)" << makefilein << " " << sub_targ << endl;
|
|---|
| 2694 | }
|
|---|
| 2695 | }
|
|---|
| 2696 | }
|
|---|
| 2697 | if(project->isEmpty("QMAKE_NOFORCE") &&
|
|---|
| 2698 | project->values((*qut_it) + ".CONFIG").indexOf("phony") != -1)
|
|---|
| 2699 | deps += " FORCE";
|
|---|
| 2700 | t << targ << ":" << deps << "\n";
|
|---|
| 2701 | if(!cmd.isEmpty())
|
|---|
| 2702 | t << "\t" << cmd << endl;
|
|---|
| 2703 | }
|
|---|
| 2704 |
|
|---|
| 2705 | if(flags & SubTargetInstalls) {
|
|---|
| 2706 | project->values("INSTALLDEPS") += "install_subtargets";
|
|---|
| 2707 | project->values("UNINSTALLDEPS") += "uninstall_subtargets";
|
|---|
| 2708 | writeInstalls(t, "INSTALLS", true);
|
|---|
| 2709 | }
|
|---|
| 2710 |
|
|---|
| 2711 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2712 | t << "FORCE:" << endl << endl;
|
|---|
| 2713 | }
|
|---|
| 2714 |
|
|---|
| 2715 | void
|
|---|
| 2716 | MakefileGenerator::writeMakeQmake(QTextStream &t)
|
|---|
| 2717 | {
|
|---|
| 2718 | QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
|
|---|
| 2719 | if(project->isEmpty("QMAKE_FAILED_REQUIREMENTS") && !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) {
|
|---|
| 2720 | QStringList files = fileFixify(Option::mkfile::project_files);
|
|---|
| 2721 | t << escapeDependencyPath(project->first("QMAKE_INTERNAL_PRL_FILE")) << ": " << "\n\t"
|
|---|
| 2722 | << "@$(QMAKE) -prl " << buildArgs() << " " << files.join(" ") << endl;
|
|---|
| 2723 | }
|
|---|
| 2724 |
|
|---|
| 2725 | QString pfile = project->projectFile();
|
|---|
| 2726 | if(pfile != "(stdin)") {
|
|---|
| 2727 | QString qmake = build_args();
|
|---|
| 2728 | if(!ofile.isEmpty() && !project->isActiveConfig("no_autoqmake")) {
|
|---|
| 2729 | t << escapeFilePath(ofile) << ": " << escapeDependencyPath(fileFixify(pfile)) << " ";
|
|---|
| 2730 | if(Option::mkfile::do_cache)
|
|---|
| 2731 | t << escapeDependencyPath(fileFixify(Option::mkfile::cachefile)) << " ";
|
|---|
| 2732 | if(!specdir().isEmpty()) {
|
|---|
| 2733 | if(exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"qmake.conf")))
|
|---|
| 2734 | t << escapeDependencyPath(specdir() + Option::dir_sep + "qmake.conf") << " ";
|
|---|
| 2735 | else if(exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"tmake.conf")))
|
|---|
| 2736 | t << escapeDependencyPath(specdir() + Option::dir_sep + "tmake.conf") << " ";
|
|---|
| 2737 | }
|
|---|
| 2738 | const QStringList &included = project->values("QMAKE_INTERNAL_INCLUDED_FILES");
|
|---|
| 2739 | t << escapeDependencyPaths(included).join(" \\\n\t\t") << "\n\t"
|
|---|
| 2740 | << qmake << endl;
|
|---|
| 2741 | for(int include = 0; include < included.size(); ++include) {
|
|---|
| 2742 | const QString i(included.at(include));
|
|---|
| 2743 | if(!i.isEmpty())
|
|---|
| 2744 | t << i << ":" << endl;
|
|---|
| 2745 | }
|
|---|
| 2746 | }
|
|---|
| 2747 | if(project->first("QMAKE_ORIG_TARGET") != "qmake") {
|
|---|
| 2748 | t << "qmake: " <<
|
|---|
| 2749 | project->values("QMAKE_INTERNAL_QMAKE_DEPS").join(" \\\n\t\t");
|
|---|
| 2750 | if(project->isEmpty("QMAKE_NOFORCE"))
|
|---|
| 2751 | t << " FORCE";
|
|---|
| 2752 | t << "\n\t" << "@" << qmake << endl << endl;
|
|---|
| 2753 | }
|
|---|
| 2754 | }
|
|---|
| 2755 | }
|
|---|
| 2756 |
|
|---|
| 2757 | QFileInfo
|
|---|
| 2758 | MakefileGenerator::fileInfo(QString file) const
|
|---|
| 2759 | {
|
|---|
| 2760 | static QHash<FileInfoCacheKey, QFileInfo> *cache = 0;
|
|---|
| 2761 | static QFileInfo noInfo = QFileInfo();
|
|---|
| 2762 | if(!cache) {
|
|---|
| 2763 | cache = new QHash<FileInfoCacheKey, QFileInfo>;
|
|---|
| 2764 | qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFileInfoCacheKeyQFileInfo, (void**)&cache);
|
|---|
| 2765 | }
|
|---|
| 2766 | FileInfoCacheKey cacheKey(file);
|
|---|
| 2767 | QFileInfo value = cache->value(cacheKey, noInfo);
|
|---|
| 2768 | if (value != noInfo)
|
|---|
| 2769 | return value;
|
|---|
| 2770 |
|
|---|
| 2771 | QFileInfo fi(file);
|
|---|
| 2772 | if (fi.exists())
|
|---|
| 2773 | cache->insert(cacheKey, fi);
|
|---|
| 2774 | return fi;
|
|---|
| 2775 | }
|
|---|
| 2776 |
|
|---|
| 2777 | QString
|
|---|
| 2778 | MakefileGenerator::unescapeFilePath(const QString &path) const
|
|---|
| 2779 | {
|
|---|
| 2780 | QString ret = path;
|
|---|
| 2781 | if(!ret.isEmpty()) {
|
|---|
| 2782 | if(ret.contains(QLatin1String("\\ ")))
|
|---|
| 2783 | ret.replace(QLatin1String("\\ "), QLatin1String(" "));
|
|---|
| 2784 | if(ret.contains(QLatin1Char('\"')))
|
|---|
| 2785 | ret.remove(QLatin1Char('\"'));
|
|---|
| 2786 | }
|
|---|
| 2787 | return ret;
|
|---|
| 2788 | }
|
|---|
| 2789 |
|
|---|
| 2790 | QStringList
|
|---|
| 2791 | MakefileGenerator::escapeFilePaths(const QStringList &paths) const
|
|---|
| 2792 | {
|
|---|
| 2793 | QStringList ret;
|
|---|
| 2794 | for(int i = 0; i < paths.size(); ++i)
|
|---|
| 2795 | ret.append(escapeFilePath(paths.at(i)));
|
|---|
| 2796 | return ret;
|
|---|
| 2797 | }
|
|---|
| 2798 |
|
|---|
| 2799 | QStringList
|
|---|
| 2800 | MakefileGenerator::escapeDependencyPaths(const QStringList &paths) const
|
|---|
| 2801 | {
|
|---|
| 2802 | QStringList ret;
|
|---|
| 2803 | for(int i = 0; i < paths.size(); ++i)
|
|---|
| 2804 | ret.append(escapeDependencyPath(paths.at(i)));
|
|---|
| 2805 | return ret;
|
|---|
| 2806 | }
|
|---|
| 2807 |
|
|---|
| 2808 | QStringList
|
|---|
| 2809 | MakefileGenerator::unescapeFilePaths(const QStringList &paths) const
|
|---|
| 2810 | {
|
|---|
| 2811 | QStringList ret;
|
|---|
| 2812 | for(int i = 0; i < paths.size(); ++i)
|
|---|
| 2813 | ret.append(unescapeFilePath(paths.at(i)));
|
|---|
| 2814 | return ret;
|
|---|
| 2815 | }
|
|---|
| 2816 |
|
|---|
| 2817 | QStringList
|
|---|
| 2818 | MakefileGenerator::fileFixify(const QStringList& files, const QString &out_dir, const QString &in_dir,
|
|---|
| 2819 | FileFixifyType fix, bool canon) const
|
|---|
| 2820 | {
|
|---|
| 2821 | if(files.isEmpty())
|
|---|
| 2822 | return files;
|
|---|
| 2823 | QStringList ret;
|
|---|
| 2824 | for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it) {
|
|---|
| 2825 | if(!(*it).isEmpty())
|
|---|
| 2826 | ret << fileFixify((*it), out_dir, in_dir, fix, canon);
|
|---|
| 2827 | }
|
|---|
| 2828 | return ret;
|
|---|
| 2829 | }
|
|---|
| 2830 |
|
|---|
| 2831 | QString
|
|---|
| 2832 | MakefileGenerator::fileFixify(const QString& file, const QString &out_d, const QString &in_d,
|
|---|
| 2833 | FileFixifyType fix, bool canon) const
|
|---|
| 2834 | {
|
|---|
| 2835 | if(file.isEmpty())
|
|---|
| 2836 | return file;
|
|---|
| 2837 | QString ret = unescapeFilePath(file);
|
|---|
| 2838 |
|
|---|
| 2839 | //setup the cache
|
|---|
| 2840 | static QHash<FileFixifyCacheKey, QString> *cache = 0;
|
|---|
| 2841 | if(!cache) {
|
|---|
| 2842 | cache = new QHash<FileFixifyCacheKey, QString>;
|
|---|
| 2843 | qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFileFixifyCacheKeyQString, (void**)&cache);
|
|---|
| 2844 | }
|
|---|
| 2845 | FileFixifyCacheKey cacheKey(ret, out_d, in_d, fix, canon);
|
|---|
| 2846 | QString cacheVal = cache->value(cacheKey);
|
|---|
| 2847 | if(!cacheVal.isNull())
|
|---|
| 2848 | return cacheVal;
|
|---|
| 2849 |
|
|---|
| 2850 | //do the fixin'
|
|---|
| 2851 | QString pwd = qmake_getpwd();
|
|---|
| 2852 | if (!pwd.endsWith('/'))
|
|---|
| 2853 | pwd += '/';
|
|---|
| 2854 | QString orig_file = ret;
|
|---|
| 2855 | if(ret.startsWith(QLatin1Char('~'))) {
|
|---|
| 2856 | if(ret.startsWith(QLatin1String("~/")))
|
|---|
| 2857 | ret = QDir::homePath() + ret.mid(1);
|
|---|
| 2858 | else
|
|---|
| 2859 | warn_msg(WarnLogic, "Unable to expand ~ in %s", ret.toLatin1().constData());
|
|---|
| 2860 | }
|
|---|
| 2861 | if(fix == FileFixifyAbsolute || (fix == FileFixifyDefault && project->isActiveConfig("no_fixpath"))) {
|
|---|
| 2862 | if(fix == FileFixifyAbsolute && QDir::isRelativePath(ret)) //already absolute
|
|---|
| 2863 | ret.prepend(pwd);
|
|---|
| 2864 | ret = Option::fixPathToTargetOS(ret, false, canon);
|
|---|
| 2865 | } else { //fix it..
|
|---|
| 2866 | QString out_dir = QDir(Option::output_dir).absoluteFilePath(out_d);
|
|---|
| 2867 | QString in_dir = QDir(pwd).absoluteFilePath(in_d);
|
|---|
| 2868 | {
|
|---|
| 2869 | QFileInfo in_fi(fileInfo(in_dir));
|
|---|
| 2870 | if(in_fi.exists())
|
|---|
| 2871 | in_dir = in_fi.canonicalFilePath();
|
|---|
| 2872 | QFileInfo out_fi(fileInfo(out_dir));
|
|---|
| 2873 | if(out_fi.exists())
|
|---|
| 2874 | out_dir = out_fi.canonicalFilePath();
|
|---|
| 2875 | }
|
|---|
| 2876 |
|
|---|
| 2877 | QString qfile(Option::fixPathToLocalOS(ret, true, canon));
|
|---|
| 2878 | QFileInfo qfileinfo(fileInfo(qfile));
|
|---|
| 2879 | if(out_dir != in_dir || !qfileinfo.isRelative()) {
|
|---|
| 2880 | if(qfileinfo.isRelative()) {
|
|---|
| 2881 | ret = in_dir + "/" + qfile;
|
|---|
| 2882 | qfileinfo.setFile(ret);
|
|---|
| 2883 | }
|
|---|
| 2884 | ret = Option::fixPathToTargetOS(ret, false, canon);
|
|---|
| 2885 | if(canon && qfileinfo.exists() &&
|
|---|
| 2886 | file == Option::fixPathToTargetOS(ret, true, canon))
|
|---|
| 2887 | ret = Option::fixPathToTargetOS(qfileinfo.canonicalFilePath());
|
|---|
| 2888 | QString match_dir = Option::fixPathToTargetOS(out_dir, false, canon);
|
|---|
| 2889 | if(ret == match_dir) {
|
|---|
| 2890 | ret = "";
|
|---|
| 2891 | } else if(ret.startsWith(match_dir + Option::dir_sep)) {
|
|---|
| 2892 | ret = ret.mid(match_dir.length() + Option::dir_sep.length());
|
|---|
| 2893 | } else {
|
|---|
| 2894 | //figure out the depth
|
|---|
| 2895 | int depth = 4;
|
|---|
| 2896 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|---|
| 2897 | Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
|---|
| 2898 | if(project && !project->isEmpty("QMAKE_PROJECT_DEPTH"))
|
|---|
| 2899 | depth = project->first("QMAKE_PROJECT_DEPTH").toInt();
|
|---|
| 2900 | else if(Option::mkfile::cachefile_depth != -1)
|
|---|
| 2901 | depth = Option::mkfile::cachefile_depth;
|
|---|
| 2902 | }
|
|---|
| 2903 | //calculate how much can be removed
|
|---|
| 2904 | QString dot_prefix;
|
|---|
| 2905 | for(int i = 1; i <= depth; i++) {
|
|---|
| 2906 | int sl = match_dir.lastIndexOf(Option::dir_sep);
|
|---|
| 2907 | if(sl == -1)
|
|---|
| 2908 | break;
|
|---|
| 2909 | match_dir = match_dir.left(sl);
|
|---|
| 2910 | if(match_dir.isEmpty())
|
|---|
| 2911 | break;
|
|---|
| 2912 | if(ret.startsWith(match_dir + Option::dir_sep)) {
|
|---|
| 2913 | //concat
|
|---|
| 2914 | int remlen = ret.length() - (match_dir.length() + 1);
|
|---|
| 2915 | if(remlen < 0)
|
|---|
| 2916 | remlen = 0;
|
|---|
| 2917 | ret = ret.right(remlen);
|
|---|
| 2918 | //prepend
|
|---|
| 2919 | for(int o = 0; o < i; o++)
|
|---|
| 2920 | dot_prefix += ".." + Option::dir_sep;
|
|---|
| 2921 | }
|
|---|
| 2922 | }
|
|---|
| 2923 | ret.prepend(dot_prefix);
|
|---|
| 2924 | }
|
|---|
| 2925 | } else {
|
|---|
| 2926 | ret = Option::fixPathToTargetOS(ret, false, canon);
|
|---|
| 2927 | }
|
|---|
| 2928 | }
|
|---|
| 2929 | if(ret.isEmpty())
|
|---|
| 2930 | ret = ".";
|
|---|
| 2931 | debug_msg(3, "Fixed[%d,%d] %s :: to :: %s [%s::%s] [%s::%s]", fix, canon, orig_file.toLatin1().constData(),
|
|---|
| 2932 | ret.toLatin1().constData(), in_d.toLatin1().constData(), out_d.toLatin1().constData(),
|
|---|
| 2933 | pwd.toLatin1().constData(), Option::output_dir.toLatin1().constData());
|
|---|
| 2934 | cache->insert(cacheKey, ret);
|
|---|
| 2935 | return ret;
|
|---|
| 2936 | }
|
|---|
| 2937 |
|
|---|
| 2938 | void
|
|---|
| 2939 | MakefileGenerator::checkMultipleDefinition(const QString &f, const QString &w)
|
|---|
| 2940 | {
|
|---|
| 2941 | if(!(Option::warn_level & WarnLogic))
|
|---|
| 2942 | return;
|
|---|
| 2943 | QString file = f;
|
|---|
| 2944 | int slsh = f.lastIndexOf(Option::dir_sep);
|
|---|
| 2945 | if(slsh != -1)
|
|---|
| 2946 | file.remove(0, slsh + 1);
|
|---|
| 2947 | QStringList &l = project->values(w);
|
|---|
| 2948 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 2949 | QString file2((*val_it));
|
|---|
| 2950 | slsh = file2.lastIndexOf(Option::dir_sep);
|
|---|
| 2951 | if(slsh != -1)
|
|---|
| 2952 | file2.remove(0, slsh + 1);
|
|---|
| 2953 | if(file2 == file) {
|
|---|
| 2954 | warn_msg(WarnLogic, "Found potential symbol conflict of %s (%s) in %s",
|
|---|
| 2955 | file.toLatin1().constData(), (*val_it).toLatin1().constData(), w.toLatin1().constData());
|
|---|
| 2956 | break;
|
|---|
| 2957 | }
|
|---|
| 2958 | }
|
|---|
| 2959 | }
|
|---|
| 2960 |
|
|---|
| 2961 | QMakeLocalFileName
|
|---|
| 2962 | MakefileGenerator::fixPathForFile(const QMakeLocalFileName &file, bool forOpen)
|
|---|
| 2963 | {
|
|---|
| 2964 | if(forOpen)
|
|---|
| 2965 | return QMakeLocalFileName(fileFixify(file.real(), qmake_getpwd(), Option::output_dir));
|
|---|
| 2966 | return QMakeLocalFileName(fileFixify(file.real()));
|
|---|
| 2967 | }
|
|---|
| 2968 |
|
|---|
| 2969 | QFileInfo
|
|---|
| 2970 | MakefileGenerator::findFileInfo(const QMakeLocalFileName &file)
|
|---|
| 2971 | {
|
|---|
| 2972 | return fileInfo(file.local());
|
|---|
| 2973 | }
|
|---|
| 2974 |
|
|---|
| 2975 | QMakeLocalFileName
|
|---|
| 2976 | MakefileGenerator::findFileForDep(const QMakeLocalFileName &dep, const QMakeLocalFileName &file)
|
|---|
| 2977 | {
|
|---|
| 2978 | QMakeLocalFileName ret;
|
|---|
| 2979 | if(!project->isEmpty("SKIP_DEPENDS")) {
|
|---|
| 2980 | bool found = false;
|
|---|
| 2981 | QStringList &nodeplist = project->values("SKIP_DEPENDS");
|
|---|
| 2982 | for(QStringList::Iterator it = nodeplist.begin();
|
|---|
| 2983 | it != nodeplist.end(); ++it) {
|
|---|
| 2984 | QRegExp regx((*it));
|
|---|
| 2985 | if(regx.indexIn(dep.local()) != -1) {
|
|---|
| 2986 | found = true;
|
|---|
| 2987 | break;
|
|---|
| 2988 | }
|
|---|
| 2989 | }
|
|---|
| 2990 | if(found)
|
|---|
| 2991 | return ret;
|
|---|
| 2992 | }
|
|---|
| 2993 |
|
|---|
| 2994 | ret = QMakeSourceFileInfo::findFileForDep(dep, file);
|
|---|
| 2995 | if(!ret.isNull())
|
|---|
| 2996 | return ret;
|
|---|
| 2997 |
|
|---|
| 2998 | //these are some "hacky" heuristics it will try to do on an include
|
|---|
| 2999 | //however these can be turned off at runtime, I'm not sure how
|
|---|
| 3000 | //reliable these will be, most likely when problems arise turn it off
|
|---|
| 3001 | //and see if they go away..
|
|---|
| 3002 | if(Option::mkfile::do_dep_heuristics) {
|
|---|
| 3003 | if(depHeuristicsCache.contains(dep.real()))
|
|---|
| 3004 | return depHeuristicsCache[dep.real()];
|
|---|
| 3005 |
|
|---|
| 3006 | if(Option::output_dir != qmake_getpwd()
|
|---|
| 3007 | && QDir::isRelativePath(dep.real())) { //is it from the shadow tree
|
|---|
| 3008 | QList<QMakeLocalFileName> depdirs = QMakeSourceFileInfo::dependencyPaths();
|
|---|
| 3009 | depdirs.prepend(fileInfo(file.real()).absoluteDir().path());
|
|---|
| 3010 | QString pwd = qmake_getpwd();
|
|---|
| 3011 | if(pwd.at(pwd.length()-1) != '/')
|
|---|
| 3012 | pwd += '/';
|
|---|
| 3013 | for(int i = 0; i < depdirs.count(); i++) {
|
|---|
| 3014 | QString dir = depdirs.at(i).real();
|
|---|
| 3015 | if(!QDir::isRelativePath(dir) && dir.startsWith(pwd))
|
|---|
| 3016 | dir = dir.mid(pwd.length());
|
|---|
| 3017 | if(QDir::isRelativePath(dir)) {
|
|---|
| 3018 | if(!dir.endsWith(Option::dir_sep))
|
|---|
| 3019 | dir += Option::dir_sep;
|
|---|
| 3020 | QString shadow = fileFixify(dir + dep.local(), pwd, Option::output_dir);
|
|---|
| 3021 | if(exists(shadow)) {
|
|---|
| 3022 | ret = QMakeLocalFileName(shadow);
|
|---|
| 3023 | goto found_dep_from_heuristic;
|
|---|
| 3024 | }
|
|---|
| 3025 | }
|
|---|
| 3026 | }
|
|---|
| 3027 | }
|
|---|
| 3028 | { //is it from an EXTRA_TARGET
|
|---|
| 3029 | const QString dep_basename = dep.local().section(Option::dir_sep, -1);
|
|---|
| 3030 | QStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
|
|---|
| 3031 | for(QStringList::Iterator it = qut.begin(); it != qut.end(); ++it) {
|
|---|
| 3032 | QString targ = var((*it) + ".target");
|
|---|
| 3033 | if(targ.isEmpty())
|
|---|
| 3034 | targ = (*it);
|
|---|
| 3035 | QString out = Option::fixPathToTargetOS(targ);
|
|---|
| 3036 | if(out == dep.real() || out.section(Option::dir_sep, -1) == dep_basename) {
|
|---|
| 3037 | ret = QMakeLocalFileName(out);
|
|---|
| 3038 | goto found_dep_from_heuristic;
|
|---|
| 3039 | }
|
|---|
| 3040 | }
|
|---|
| 3041 | }
|
|---|
| 3042 | { //is it from an EXTRA_COMPILER
|
|---|
| 3043 | const QString dep_basename = dep.local().section(Option::dir_sep, -1);
|
|---|
| 3044 | const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
|
|---|
| 3045 | for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
|
|---|
| 3046 | QString tmp_out = project->values((*it) + ".output").first();
|
|---|
| 3047 | if(tmp_out.isEmpty())
|
|---|
| 3048 | continue;
|
|---|
| 3049 | QStringList &tmp = project->values((*it) + ".input");
|
|---|
| 3050 | for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
|
|---|
| 3051 | QStringList &inputs = project->values((*it2));
|
|---|
| 3052 | for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
|
|---|
| 3053 | QString out = Option::fixPathToTargetOS(unescapeFilePath(replaceExtraCompilerVariables(tmp_out, (*input), QString())));
|
|---|
| 3054 | if(out == dep.real() || out.section(Option::dir_sep, -1) == dep_basename) {
|
|---|
| 3055 | ret = QMakeLocalFileName(fileFixify(out, qmake_getpwd(), Option::output_dir));
|
|---|
| 3056 | goto found_dep_from_heuristic;
|
|---|
| 3057 | }
|
|---|
| 3058 | }
|
|---|
| 3059 | }
|
|---|
| 3060 | }
|
|---|
| 3061 | }
|
|---|
| 3062 | found_dep_from_heuristic:
|
|---|
| 3063 | depHeuristicsCache.insert(dep.real(), ret);
|
|---|
| 3064 | }
|
|---|
| 3065 | return ret;
|
|---|
| 3066 | }
|
|---|
| 3067 |
|
|---|
| 3068 | QStringList
|
|---|
| 3069 | &MakefileGenerator::findDependencies(const QString &file)
|
|---|
| 3070 | {
|
|---|
| 3071 | const QString fixedFile = fileFixify(file);
|
|---|
| 3072 | if(!dependsCache.contains(fixedFile)) {
|
|---|
| 3073 | #if 1
|
|---|
| 3074 | QStringList deps = QMakeSourceFileInfo::dependencies(file);
|
|---|
| 3075 | if(file != fixedFile)
|
|---|
| 3076 | deps += QMakeSourceFileInfo::dependencies(fixedFile);
|
|---|
| 3077 | #else
|
|---|
| 3078 | QStringList deps = QMakeSourceFileInfo::dependencies(fixedFile);
|
|---|
| 3079 | #endif
|
|---|
| 3080 | dependsCache.insert(fixedFile, deps);
|
|---|
| 3081 | }
|
|---|
| 3082 | return dependsCache[fixedFile];
|
|---|
| 3083 | }
|
|---|
| 3084 |
|
|---|
| 3085 | QString
|
|---|
| 3086 | MakefileGenerator::specdir(const QString &outdir)
|
|---|
| 3087 | {
|
|---|
| 3088 | #if 0
|
|---|
| 3089 | if(!spec.isEmpty())
|
|---|
| 3090 | return spec;
|
|---|
| 3091 | #endif
|
|---|
| 3092 | spec = fileFixify(Option::mkfile::qmakespec, outdir);
|
|---|
| 3093 | return spec;
|
|---|
| 3094 | }
|
|---|
| 3095 |
|
|---|
| 3096 | bool
|
|---|
| 3097 | MakefileGenerator::openOutput(QFile &file, const QString &build) const
|
|---|
| 3098 | {
|
|---|
| 3099 | {
|
|---|
| 3100 | QString outdir;
|
|---|
| 3101 | if(!file.fileName().isEmpty()) {
|
|---|
| 3102 | if(QDir::isRelativePath(file.fileName()))
|
|---|
| 3103 | file.setFileName(Option::output_dir + "/" + file.fileName()); //pwd when qmake was run
|
|---|
| 3104 | QFileInfo fi(fileInfo(file.fileName()));
|
|---|
| 3105 | if(fi.isDir())
|
|---|
| 3106 | outdir = file.fileName() + '/';
|
|---|
| 3107 | }
|
|---|
| 3108 | if(!outdir.isEmpty() || file.fileName().isEmpty()) {
|
|---|
| 3109 | QString fname = "Makefile";
|
|---|
| 3110 | if(!project->isEmpty("MAKEFILE"))
|
|---|
| 3111 | fname = project->first("MAKEFILE");
|
|---|
| 3112 | file.setFileName(outdir + fname);
|
|---|
| 3113 | }
|
|---|
| 3114 | }
|
|---|
| 3115 | if(QDir::isRelativePath(file.fileName())) {
|
|---|
| 3116 | QString fname = Option::output_dir; //pwd when qmake was run
|
|---|
| 3117 | if(!fname.endsWith("/"))
|
|---|
| 3118 | fname += "/";
|
|---|
| 3119 | fname += file.fileName();
|
|---|
| 3120 | file.setFileName(fname);
|
|---|
| 3121 | }
|
|---|
| 3122 | if(!build.isEmpty())
|
|---|
| 3123 | file.setFileName(file.fileName() + "." + build);
|
|---|
| 3124 | if(project->isEmpty("QMAKE_MAKEFILE"))
|
|---|
| 3125 | project->values("QMAKE_MAKEFILE").append(file.fileName());
|
|---|
| 3126 | int slsh = file.fileName().lastIndexOf('/');
|
|---|
| 3127 | if(slsh != -1)
|
|---|
| 3128 | mkdir(file.fileName().left(slsh));
|
|---|
| 3129 | if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
|---|
| 3130 | QFileInfo fi(fileInfo(Option::output.fileName()));
|
|---|
| 3131 | QString od;
|
|---|
| 3132 | if(fi.isSymLink())
|
|---|
| 3133 | od = fileInfo(fi.readLink()).absolutePath();
|
|---|
| 3134 | else
|
|---|
| 3135 | od = fi.path();
|
|---|
| 3136 | od = QDir::fromNativeSeparators(od);
|
|---|
| 3137 | if(QDir::isRelativePath(od)) {
|
|---|
| 3138 | QString dir = Option::output_dir;
|
|---|
| 3139 | if (!dir.endsWith('/') && !od.isEmpty())
|
|---|
| 3140 | dir += '/';
|
|---|
| 3141 | od.prepend(dir);
|
|---|
| 3142 | }
|
|---|
| 3143 | Option::output_dir = od;
|
|---|
| 3144 | return true;
|
|---|
| 3145 | }
|
|---|
| 3146 | return false;
|
|---|
| 3147 | }
|
|---|
| 3148 |
|
|---|
| 3149 | QT_END_NAMESPACE
|
|---|