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