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