| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 |
|
| 4 |
#include "unixmake.h" |
| 5 |
#include "option.h" |
| 6 |
#include <qfile.h> |
| 7 |
#include <qhash.h> |
| 8 |
#include <qdir.h> |
| 9 |
#include <time.h> |
| 10 |
#include <qdebug.h> |
| 11 |
|
| 12 |
QT_BEGIN_NAMESPACE |
| 13 |
|
| 14 |
ProStringList UnixMakefileGenerator::libdirToFlags(const ProKey &key) |
| 15 |
{ |
| 16 |
ProStringList results; |
| 17 |
for (const auto &libdir : std::as_const(project->values(key))) { |
| 18 |
if (!project->isEmpty("QMAKE_LFLAGS_RPATH") && project->isActiveConfig("rpath_libdirs")) |
| 19 |
project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATH") + libdir; |
| 20 |
results.append("-L" + escapeFilePath(libdir)); |
| 21 |
} |
| 22 |
return results; |
| 23 |
} |
| 24 |
|
| 25 |
void |
| 26 |
UnixMakefileGenerator::init() |
| 27 |
{ |
| 28 |
ProStringList &configs = project->values("CONFIG"); |
| 29 |
if(project->isEmpty("ICON") && !project->isEmpty("RC_FILE")) |
| 30 |
project->values("ICON") = project->values("RC_FILE"); |
| 31 |
if(project->isEmpty("QMAKE_EXTENSION_PLUGIN")) |
| 32 |
project->values("QMAKE_EXTENSION_PLUGIN").append(project->first("QMAKE_EXTENSION_SHLIB")); |
| 33 |
|
| 34 |
project->values("QMAKE_ORIG_TARGET") = project->values("TARGET"); |
| 35 |
|
| 36 |
//version handling |
| 37 |
if (project->isEmpty("VERSION")) { |
| 38 |
project->values("VERSION").append( |
| 39 |
"1.0." + (project->isEmpty("VER_PAT") ? QString("0") : project->first("VER_PAT"))); |
| 40 |
} |
| 41 |
QStringList l = project->first("VERSION").toQString().split('.'); |
| 42 |
l << "0" << "0"; //make sure there are three |
| 43 |
project->values("VER_MAJ").append(l[0]); |
| 44 |
project->values("VER_MIN").append(l[1]); |
| 45 |
project->values("VER_PAT").append(l[2]); |
| 46 |
|
| 47 |
QString sroot = project->sourceRoot(); |
| 48 |
for (const ProString &iif : project->values("QMAKE_INTERNAL_INCLUDED_FILES")) { |
| 49 |
if (iif == project->cacheFile()) |
| 50 |
continue; |
| 51 |
if (iif.startsWith(sroot) && iif.at(sroot.size()) == QLatin1Char('/')) |
| 52 |
project->values("DISTFILES") += fileFixify(iif.toQString(), FileFixifyRelative); |
| 53 |
} |
| 54 |
|
| 55 |
/* this should probably not be here, but I'm using it to wrap the .t files */ |
| 56 |
if(project->first("TEMPLATE") == "app") |
| 57 |
project->values("QMAKE_APP_FLAG").append("1"); |
| 58 |
else if(project->first("TEMPLATE") == "lib") |
| 59 |
project->values("QMAKE_LIB_FLAG").append("1"); |
| 60 |
else if(project->first("TEMPLATE") == "subdirs") { |
| 61 |
MakefileGenerator::init(); |
| 62 |
if(project->isEmpty("MAKEFILE")) |
| 63 |
project->values("MAKEFILE").append("Makefile"); |
| 64 |
return; /* subdirs is done */ |
| 65 |
} |
| 66 |
|
| 67 |
project->values("QMAKE_ORIG_DESTDIR") = project->values("DESTDIR"); |
| 68 |
if((!project->isEmpty("QMAKE_LIB_FLAG") && !project->isActiveConfig("staticlib")) || |
| 69 |
(project->isActiveConfig("qt") && project->isActiveConfig("plugin"))) { |
| 70 |
if(configs.indexOf("dll") == -1) configs.append("dll"); |
| 71 |
} else if(!project->isEmpty("QMAKE_APP_FLAG") || project->isActiveConfig("dll")) { |
| 72 |
configs.removeAll("staticlib"); |
| 73 |
} |
| 74 |
if(!project->isEmpty("QMAKE_INCREMENTAL")) |
| 75 |
project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_INCREMENTAL"); |
| 76 |
else if(!project->isEmpty("QMAKE_LFLAGS_PREBIND") && |
| 77 |
!project->values("QMAKE_LIB_FLAG").isEmpty() && |
| 78 |
project->isActiveConfig("dll")) |
| 79 |
project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_PREBIND"); |
| 80 |
project->values("QMAKE_INCDIR") += project->values("QMAKE_INCDIR_POST"); |
| 81 |
project->values("QMAKE_RPATHDIR") += project->values("QMAKE_RPATHDIR_POST"); |
| 82 |
project->values("QMAKE_RPATHLINKDIR") += project->values("QMAKE_RPATHLINKDIR_POST"); |
| 83 |
if(!project->isEmpty("QMAKE_INCDIR")) |
| 84 |
project->values("INCLUDEPATH") += project->values("QMAKE_INCDIR"); |
| 85 |
// The order of the next two lines is relevant due to side effect on QMAKE_LFLAGS. |
| 86 |
ProStringList ldadd = project->values("QMAKE_LIBDIR_FLAGS") + libdirToFlags("QMAKE_LIBDIR"); |
| 87 |
ProStringList ldaddpost = libdirToFlags("QMAKE_LIBDIR_POST"); |
| 88 |
if (project->isActiveConfig("mac")) { |
| 89 |
if (!project->isEmpty("QMAKE_FRAMEWORKPATH")) { |
| 90 |
const ProStringList &fwdirs = project->values("QMAKE_FRAMEWORKPATH"); |
| 91 |
for (int i = 0; i < fwdirs.size(); ++i) |
| 92 |
project->values("QMAKE_FRAMEWORKPATH_FLAGS") += "-F" + escapeFilePath(fwdirs[i]); |
| 93 |
} |
| 94 |
ldadd += project->values("QMAKE_FRAMEWORKPATH_FLAGS"); |
| 95 |
} |
| 96 |
ProStringList &qmklibs = project->values("LIBS"); |
| 97 |
qmklibs = ldadd + qmklibs; |
| 98 |
ProStringList &qmklibspost = project->values("QMAKE_LIBS"); |
| 99 |
qmklibspost = ldaddpost + qmklibspost; |
| 100 |
if (!project->isEmpty("QMAKE_RPATHDIR") && !project->isEmpty("QMAKE_LFLAGS_RPATH")) { |
| 101 |
const ProStringList &rpathdirs = project->values("QMAKE_RPATHDIR"); |
| 102 |
for (int i = 0; i < rpathdirs.size(); ++i) { |
| 103 |
QString rpathdir = rpathdirs[i].toQString(); |
| 104 |
if (rpathdir.size() > 1 && rpathdir.at(0) == '$' && rpathdir.at(1) != '(') { |
| 105 |
rpathdir.replace(0, 1, "\\$$"); // Escape from make and the shell |
| 106 |
} else if (!rpathdir.startsWith('@') && fileInfo(rpathdir).isRelative()) { |
| 107 |
QString rpathbase = project->first("QMAKE_REL_RPATH_BASE").toQString(); |
| 108 |
if (rpathbase.isEmpty()) { |
| 109 |
fprintf(stderr, "Error: This platform does not support relative paths in QMAKE_RPATHDIR (%s)\n", |
| 110 |
rpathdir.toLatin1().constData()); |
| 111 |
continue; |
| 112 |
} |
| 113 |
if (rpathbase.startsWith('$')) |
| 114 |
rpathbase.replace(0, 1, "\\$$"); // Escape from make and the shell |
| 115 |
if (rpathdir == ".") |
| 116 |
rpathdir = rpathbase; |
| 117 |
else |
| 118 |
rpathdir.prepend(rpathbase + '/'); |
| 119 |
project->values("QMAKE_LFLAGS").insertUnique(project->values("QMAKE_LFLAGS_REL_RPATH")); |
| 120 |
} |
| 121 |
project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATH") + escapeFilePath(rpathdir); |
| 122 |
} |
| 123 |
} |
| 124 |
if (!project->isEmpty("QMAKE_RPATHLINKDIR")) { |
| 125 |
const ProStringList &rpathdirs = project->values("QMAKE_RPATHLINKDIR"); |
| 126 |
for (int i = 0; i < rpathdirs.size(); ++i) { |
| 127 |
if (!project->isEmpty("QMAKE_LFLAGS_RPATHLINK")) |
| 128 |
project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATHLINK") + escapeFilePath(QFileInfo(rpathdirs[i].toQString()).absoluteFilePath()); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
if(project->isActiveConfig("GNUmake") && !project->isEmpty("QMAKE_CFLAGS_DEPS")) |
| 133 |
include_deps = true; //do not generate deps |
| 134 |
|
| 135 |
MakefileGenerator::init(); |
| 136 |
|
| 137 |
if (project->isActiveConfig("objective_c")) |
| 138 |
project->values("QMAKE_BUILTIN_COMPILERS") << "OBJC" << "OBJCXX"; |
| 139 |
|
| 140 |
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) { |
| 141 |
QString compile_flag = var("QMAKE_COMPILE_FLAG"); |
| 142 |
if(compile_flag.isEmpty()) |
| 143 |
compile_flag = "-c"; |
| 144 |
|
| 145 |
if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) { |
| 146 |
QString pchFlags = var(ProKey("QMAKE_" + compiler + "FLAGS_USE_PRECOMPILE")); |
| 147 |
|
| 148 |
QString pchBaseName; |
| 149 |
if(!project->isEmpty("PRECOMPILED_DIR")) { |
| 150 |
pchBaseName = Option::fixPathToTargetOS(project->first("PRECOMPILED_DIR").toQString()); |
| 151 |
if(!pchBaseName.endsWith(Option::dir_sep)) |
| 152 |
pchBaseName += Option::dir_sep; |
| 153 |
} |
| 154 |
pchBaseName += project->first("QMAKE_ORIG_TARGET").toQString(); |
| 155 |
|
| 156 |
// replace place holders |
| 157 |
pchFlags.replace(QLatin1String("${QMAKE_PCH_INPUT}"), |
| 158 |
escapeFilePath(project->first("PRECOMPILED_HEADER").toQString())); |
| 159 |
pchFlags.replace(QLatin1String("${QMAKE_PCH_OUTPUT_BASE}"), escapeFilePath(pchBaseName)); |
| 160 |
if (project->isActiveConfig("icc_pch_style")) { |
| 161 |
// icc style |
| 162 |
pchFlags.replace(QLatin1String("${QMAKE_PCH_OUTPUT}"), |
| 163 |
escapeFilePath(pchBaseName + project->first("QMAKE_PCH_OUTPUT_EXT"))); |
| 164 |
const ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS"); |
| 165 |
for (const ProString &arch : pchArchs) { |
| 166 |
QString suffix = project->first("QMAKE_PCH_OUTPUT_EXT").toQString(); |
| 167 |
suffix.replace(QLatin1String("${QMAKE_PCH_ARCH}"), arch.toQString()); |
| 168 |
pchFlags.replace(QLatin1String("${QMAKE_PCH_OUTPUT_") + arch + QLatin1Char('}'), |
| 169 |
escapeFilePath(pchBaseName + suffix)); |
| 170 |
} |
| 171 |
} else { |
| 172 |
// gcc style (including clang_pch_style) |
| 173 |
QString headerSuffix; |
| 174 |
if (project->isActiveConfig("clang_pch_style")) |
| 175 |
headerSuffix = project->first("QMAKE_PCH_OUTPUT_EXT").toQString(); |
| 176 |
|
| 177 |
pchBaseName += project->first("QMAKE_PCH_OUTPUT_EXT").toQString(); |
| 178 |
pchBaseName += Option::dir_sep; |
| 179 |
|
| 180 |
ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler)); |
| 181 |
if (!language.isEmpty()) { |
| 182 |
pchFlags.replace(QLatin1String("${QMAKE_PCH_OUTPUT}"), |
| 183 |
escapeFilePath(pchBaseName + language + headerSuffix)); |
| 184 |
const ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS"); |
| 185 |
for (const ProString &arch : pchArchs) { |
| 186 |
QString file = pchBaseName + language + headerSuffix; |
| 187 |
file.replace(QLatin1String("${QMAKE_PCH_ARCH}"), arch.toQString()); |
| 188 |
if (project->isActiveConfig("clang_pch_style") |
| 189 |
&& (file.endsWith(QLatin1String(".pch")) |
| 190 |
|| file.endsWith(QLatin1String(".gch")))) { |
| 191 |
file.chop(4); // must omit header suffix for -include to recognize the PCH |
| 192 |
} |
| 193 |
pchFlags.replace(QLatin1String("${QMAKE_PCH_OUTPUT_") + arch + QLatin1Char('}'), |
| 194 |
escapeFilePath(file)); |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
if (!pchFlags.isEmpty()) |
| 200 |
compile_flag += " " + pchFlags; |
| 201 |
} |
| 202 |
|
| 203 |
QString compilerExecutable; |
| 204 |
if (compiler == "C" || compiler == "OBJC") { |
| 205 |
compilerExecutable = "$(CC)"; |
| 206 |
compile_flag += " $(CFLAGS)"; |
| 207 |
} else { |
| 208 |
compilerExecutable = "$(CXX)"; |
| 209 |
compile_flag += " $(CXXFLAGS)"; |
| 210 |
} |
| 211 |
|
| 212 |
compile_flag += " $(INCPATH)"; |
| 213 |
|
| 214 |
ProString compilerVariable = compiler; |
| 215 |
if (compilerVariable == "C") |
| 216 |
compilerVariable = ProString("CC"); |
| 217 |
|
| 218 |
const ProKey runComp("QMAKE_RUN_" + compilerVariable); |
| 219 |
if(project->isEmpty(runComp)) |
| 220 |
project->values(runComp).append(compilerExecutable + " " + compile_flag + " " + var("QMAKE_CC_O_FLAG") + "$obj $src"); |
| 221 |
const ProKey runCompImp("QMAKE_RUN_" + compilerVariable + "_IMP"); |
| 222 |
if(project->isEmpty(runCompImp)) |
| 223 |
project->values(runCompImp).append(compilerExecutable + " " + compile_flag + " " + var("QMAKE_CC_O_FLAG") + "\"$@\" \"$<\""); |
| 224 |
} |
| 225 |
|
| 226 |
if (project->isActiveConfig("mac") && !project->isEmpty("TARGET") && |
| 227 |
((project->isActiveConfig("build_pass") || project->isEmpty("BUILDS")))) { |
| 228 |
ProString bundle; |
| 229 |
if(project->isActiveConfig("bundle") && !project->isEmpty("QMAKE_BUNDLE_EXTENSION")) { |
| 230 |
bundle = project->first("TARGET"); |
| 231 |
if(!project->isEmpty("QMAKE_BUNDLE_NAME")) |
| 232 |
bundle = project->first("QMAKE_BUNDLE_NAME"); |
| 233 |
if(!bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION"))) |
| 234 |
bundle += project->first("QMAKE_BUNDLE_EXTENSION"); |
| 235 |
} else if(project->first("TEMPLATE") == "app" && project->isActiveConfig("app_bundle")) { |
| 236 |
bundle = project->first("TARGET"); |
| 237 |
if(!project->isEmpty("QMAKE_APPLICATION_BUNDLE_NAME")) |
| 238 |
bundle = project->first("QMAKE_APPLICATION_BUNDLE_NAME"); |
| 239 |
if(!bundle.endsWith(".app")) |
| 240 |
bundle += ".app"; |
| 241 |
if(project->isEmpty("QMAKE_BUNDLE_LOCATION")) |
| 242 |
project->values("QMAKE_BUNDLE_LOCATION").append("Contents/MacOS"); |
| 243 |
project->values("QMAKE_PKGINFO").append(project->first("DESTDIR") + bundle + "/Contents/PkgInfo"); |
| 244 |
} else if(project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") && |
| 245 |
((!project->isActiveConfig("plugin") && project->isActiveConfig("lib_bundle")) || |
| 246 |
(project->isActiveConfig("plugin") && project->isActiveConfig("plugin_bundle")))) { |
| 247 |
bundle = project->first("TARGET"); |
| 248 |
if(project->isActiveConfig("plugin")) { |
| 249 |
if(!project->isEmpty("QMAKE_PLUGIN_BUNDLE_NAME")) |
| 250 |
bundle = project->first("QMAKE_PLUGIN_BUNDLE_NAME"); |
| 251 |
if (project->isEmpty("QMAKE_BUNDLE_EXTENSION")) |
| 252 |
project->values("QMAKE_BUNDLE_EXTENSION").append(".plugin"); |
| 253 |
if (!bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION"))) |
| 254 |
bundle += project->first("QMAKE_BUNDLE_EXTENSION"); |
| 255 |
if(project->isEmpty("QMAKE_BUNDLE_LOCATION")) |
| 256 |
project->values("QMAKE_BUNDLE_LOCATION").append("Contents/MacOS"); |
| 257 |
} else { |
| 258 |
if(!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME")) |
| 259 |
bundle = project->first("QMAKE_FRAMEWORK_BUNDLE_NAME"); |
| 260 |
if (project->isEmpty("QMAKE_BUNDLE_EXTENSION")) |
| 261 |
project->values("QMAKE_BUNDLE_EXTENSION").append(".framework"); |
| 262 |
if (!bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION"))) |
| 263 |
bundle += project->first("QMAKE_BUNDLE_EXTENSION"); |
| 264 |
} |
| 265 |
} |
| 266 |
if(!bundle.isEmpty()) { |
| 267 |
project->values("QMAKE_BUNDLE") = ProStringList(bundle); |
| 268 |
} else { |
| 269 |
project->values("QMAKE_BUNDLE").clear(); |
| 270 |
project->values("QMAKE_BUNDLE_LOCATION").clear(); |
| 271 |
} |
| 272 |
} else { //no bundling here |
| 273 |
project->values("QMAKE_BUNDLE").clear(); |
| 274 |
project->values("QMAKE_BUNDLE_LOCATION").clear(); |
| 275 |
} |
| 276 |
|
| 277 |
init2(); |
| 278 |
ProString target = project->first("TARGET"); |
| 279 |
int slsh = target.lastIndexOf(Option::dir_sep); |
| 280 |
if (slsh != -1) |
| 281 |
target.chopFront(slsh + 1); |
| 282 |
project->values("LIB_TARGET").prepend(target); |
| 283 |
} |
| 284 |
|
| 285 |
QStringList |
| 286 |
&UnixMakefileGenerator::findDependencies(const QString &f) |
| 287 |
{ |
| 288 |
QStringList &ret = MakefileGenerator::findDependencies(f); |
| 289 |
if (doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) { |
| 290 |
ProString file = f; |
| 291 |
QString header_prefix; |
| 292 |
if(!project->isEmpty("PRECOMPILED_DIR")) |
| 293 |
header_prefix = project->first("PRECOMPILED_DIR").toQString(); |
| 294 |
header_prefix += project->first("QMAKE_ORIG_TARGET").toQString(); |
| 295 |
header_prefix += project->first("QMAKE_PCH_OUTPUT_EXT").toQString(); |
| 296 |
if (project->isActiveConfig("icc_pch_style")) { |
| 297 |
// icc style |
| 298 |
ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS"); |
| 299 |
if (pchArchs.isEmpty()) |
| 300 |
pchArchs << ProString(); // normal single-arch PCH |
| 301 |
for (const ProString &arch : std::as_const(pchArchs)) { |
| 302 |
auto pfx = header_prefix; |
| 303 |
if (!arch.isEmpty()) |
| 304 |
pfx.replace(QLatin1String("${QMAKE_PCH_ARCH}"), arch.toQString()); |
| 305 |
for (QStringList::Iterator it = Option::cpp_ext.begin(); |
| 306 |
it != Option::cpp_ext.end(); ++it) { |
| 307 |
if (file.endsWith(*it)) { |
| 308 |
ret += pfx; |
| 309 |
break; |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
} else { |
| 314 |
// gcc style (including clang_pch_style) |
| 315 |
QString header_suffix = project->isActiveConfig("clang_pch_style") |
| 316 |
? project->first("QMAKE_PCH_OUTPUT_EXT").toQString() : ""; |
| 317 |
header_prefix += Option::dir_sep + project->first("QMAKE_PRECOMP_PREFIX"); |
| 318 |
|
| 319 |
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) { |
| 320 |
if (project->isEmpty(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE"))) |
| 321 |
continue; |
| 322 |
|
| 323 |
ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler)); |
| 324 |
if (language.isEmpty()) |
| 325 |
continue; |
| 326 |
|
| 327 |
// Unfortunately we were not consistent about the C++ naming |
| 328 |
ProString extensionSuffix = compiler; |
| 329 |
if (extensionSuffix == "CXX") |
| 330 |
extensionSuffix = ProString("CPP"); |
| 331 |
|
| 332 |
for (const ProString &extension : project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) { |
| 333 |
if (!file.endsWith(extension.toQString())) |
| 334 |
continue; |
| 335 |
|
| 336 |
ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS"); |
| 337 |
if (pchArchs.isEmpty()) |
| 338 |
pchArchs << ProString(); // normal single-arch PCH |
| 339 |
for (const ProString &arch : std::as_const(pchArchs)) { |
| 340 |
QString precompiledHeader = header_prefix + language + header_suffix; |
| 341 |
if (!arch.isEmpty()) { |
| 342 |
precompiledHeader.replace(QLatin1String("${QMAKE_PCH_ARCH}"), |
| 343 |
arch.toQString()); |
| 344 |
} |
| 345 |
if (!ret.contains(precompiledHeader)) |
| 346 |
ret += precompiledHeader; |
| 347 |
} |
| 348 |
|
| 349 |
goto foundPrecompiledDependency; |
| 350 |
} |
| 351 |
} |
| 352 |
foundPrecompiledDependency: |
| 353 |
; // Hurray!! |
| 354 |
} |
| 355 |
} |
| 356 |
return ret; |
| 357 |
} |
| 358 |
|
| 359 |
ProString |
| 360 |
UnixMakefileGenerator::fixLibFlag(const ProString &lib) |
| 361 |
{ |
| 362 |
return escapeFilePath(lib); |
| 363 |
} |
| 364 |
|
| 365 |
bool |
| 366 |
UnixMakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags) |
| 367 |
{ |
| 368 |
QList<QMakeLocalFileName> libdirs, frameworkdirs; |
| 369 |
int libidx = 0, fwidx = 0; |
| 370 |
for (const ProString &dlib : project->values("QMAKE_DEFAULT_LIBDIRS")) |
| 371 |
libdirs.append(QMakeLocalFileName(dlib.toQString())); |
| 372 |
frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks")); |
| 373 |
frameworkdirs.append(QMakeLocalFileName("/Library/Frameworks")); |
| 374 |
ProStringList extens; |
| 375 |
extens << project->first("QMAKE_EXTENSION_SHLIB") << "a"; |
| 376 |
static const char * const lflags[] = { "LIBS", "LIBS_PRIVATE", |
| 377 |
"QMAKE_LIBS", "QMAKE_LIBS_PRIVATE", nullptr }; |
| 378 |
for (int i = 0; lflags[i]; i++) { |
| 379 |
ProStringList &l = project->values(lflags[i]); |
| 380 |
for (ProStringList::Iterator it = l.begin(); it != l.end(); ) { |
| 381 |
QString opt = (*it).toQString(); |
| 382 |
if(opt.startsWith("-")) { |
| 383 |
if(opt.startsWith("-L")) { |
| 384 |
QString lib = opt.mid(2); |
| 385 |
QMakeLocalFileName f(lib); |
| 386 |
int idx = libdirs.indexOf(f); |
| 387 |
if (idx >= 0 && idx < libidx) { |
| 388 |
it = l.erase(it); |
| 389 |
continue; |
| 390 |
} |
| 391 |
libdirs.insert(libidx++, f); |
| 392 |
} else if(opt.startsWith("-l")) { |
| 393 |
QString lib = opt.mid(2); |
| 394 |
for (const QMakeLocalFileName &libdir : std::as_const(libdirs)) { |
| 395 |
QString libBase = libdir.local() + '/' |
| 396 |
+ project->first("QMAKE_PREFIX_SHLIB") + lib; |
| 397 |
if (linkPrl && processPrlFile(libBase, true)) |
| 398 |
goto found; |
| 399 |
for (ProStringList::Iterator extit = extens.begin(); extit != extens.end(); ++extit) { |
| 400 |
if (exists(libBase + '.' + (*extit))) |
| 401 |
goto found; |
| 402 |
} |
| 403 |
} |
| 404 |
found: ; |
| 405 |
} else if (target_mode == TARG_MAC_MODE && opt.startsWith("-F")) { |
| 406 |
QMakeLocalFileName f(opt.mid(2)); |
| 407 |
if (!frameworkdirs.contains(f)) |
| 408 |
frameworkdirs.insert(fwidx++, f); |
| 409 |
} else if (target_mode == TARG_MAC_MODE && opt == "-framework") { |
| 410 |
if (linkPrl) { |
| 411 |
opt = (*++it).toQString(); |
| 412 |
static const QChar suffixMarker = ','; |
| 413 |
const int suffixPosition = opt.indexOf(suffixMarker); |
| 414 |
const bool hasSuffix = suffixPosition >= 0; |
| 415 |
QString frameworkName = opt; |
| 416 |
if (hasSuffix) { |
| 417 |
frameworkName.truncate(suffixPosition); |
| 418 |
opt.remove(suffixMarker); // Apply suffix by removing marker |
| 419 |
} |
| 420 |
for (const QMakeLocalFileName &dir : std::as_const(frameworkdirs)) { |
| 421 |
auto processPrlIfFound = [&](QString directory) { |
| 422 |
QString suffixedPrl = directory + opt; |
| 423 |
if (processPrlFile(suffixedPrl, true)) |
| 424 |
return true; |
| 425 |
if (hasSuffix) { |
| 426 |
QString unsuffixedPrl = directory + frameworkName; |
| 427 |
if (processPrlFile(unsuffixedPrl, true)) |
| 428 |
return true; |
| 429 |
} |
| 430 |
return false; |
| 431 |
}; |
| 432 |
QString frameworkDirectory = dir.local() + "/" + frameworkName + + ".framework/"; |
| 433 |
if (processPrlIfFound(frameworkDirectory + "Resources/") |
| 434 |
|| processPrlIfFound(frameworkDirectory)) |
| 435 |
break; |
| 436 |
} |
| 437 |
} else { |
| 438 |
if (opt.size() == 10) |
| 439 |
++it; |
| 440 |
// Skip |
| 441 |
} |
| 442 |
} |
| 443 |
} else if (linkPrl) { |
| 444 |
processPrlFile(opt, false); |
| 445 |
} |
| 446 |
|
| 447 |
ProStringList &prl_libs = project->values("QMAKE_CURRENT_PRL_LIBS"); |
| 448 |
for (int prl = 0; prl < prl_libs.size(); ++prl) |
| 449 |
it = l.insert(++it, prl_libs.at(prl)); |
| 450 |
prl_libs.clear(); |
| 451 |
++it; |
| 452 |
} |
| 453 |
|
| 454 |
if (mergeLflags) { |
| 455 |
QHash<ProKey, ProStringList> lflags; |
| 456 |
for(int lit = 0; lit < l.size(); ++lit) { |
| 457 |
ProKey arch("default"); |
| 458 |
ProString opt = l.at(lit); |
| 459 |
if (opt.startsWith('-')) { |
| 460 |
if (target_mode == TARG_MAC_MODE && opt.startsWith("-Xarch")) { |
| 461 |
if (opt.length() > 7) { |
| 462 |
arch = opt.mid(7).toKey(); |
| 463 |
opt = l.at(++lit); |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
if (opt.startsWith("-L") |
| 468 |
|| (target_mode == TARG_MAC_MODE && opt.startsWith("-F"))) { |
| 469 |
if (!lflags[arch].contains(opt)) |
| 470 |
lflags[arch].append(opt); |
| 471 |
} else if (opt.startsWith("-l") || opt == "-pthread") { |
| 472 |
// Make sure we keep the dependency order of libraries |
| 473 |
lflags[arch].removeAll(opt); |
| 474 |
lflags[arch].append(opt); |
| 475 |
} else if (target_mode == TARG_MAC_MODE |
| 476 |
&& (opt == "-framework" || opt == "-force_load")) { |
| 477 |
// Handle space separated options |
| 478 |
ProString dashOpt = opt; |
| 479 |
opt = l.at(++lit); |
| 480 |
if (opt.startsWith("-Xarch")) |
| 481 |
opt = l.at(++lit); // The user has done the right thing and prefixed each part |
| 482 |
for(int x = 0; x < lflags[arch].size(); ++x) { |
| 483 |
if (lflags[arch].at(x) == dashOpt && lflags[arch].at(++x) == opt) { |
| 484 |
lflags[arch].remove(x - 1, 2); |
| 485 |
break; |
| 486 |
} |
| 487 |
} |
| 488 |
lflags[arch].append(dashOpt); |
| 489 |
lflags[arch].append(opt); |
| 490 |
} else { |
| 491 |
lflags[arch].append(opt); |
| 492 |
} |
| 493 |
} else if(!opt.isNull()) { |
| 494 |
for (const ProString &ext : extens) { |
| 495 |
if (opt.size() > ext.size() && opt.endsWith(ext) |
| 496 |
&& opt.at(opt.size() - ext.size() - 1) == '.') { |
| 497 |
// Make sure we keep the dependency order of libraries |
| 498 |
lflags[arch].removeAll(opt); |
| 499 |
lflags[arch].append(opt); |
| 500 |
goto found2; |
| 501 |
} |
| 502 |
} |
| 503 |
if(!lflags[arch].contains(opt)) |
| 504 |
lflags[arch].append(opt); |
| 505 |
found2: ; |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
l = lflags.take("default"); |
| 510 |
|
| 511 |
// Process architecture specific options (Xarch) |
| 512 |
QHash<ProKey, ProStringList>::const_iterator archIterator = lflags.constBegin(); |
| 513 |
while (archIterator != lflags.constEnd()) { |
| 514 |
const ProStringList &archOptions = archIterator.value(); |
| 515 |
for (int i = 0; i < archOptions.size(); ++i) { |
| 516 |
l.append(QLatin1String("-Xarch_") + archIterator.key()); |
| 517 |
l.append(archOptions.at(i)); |
| 518 |
} |
| 519 |
++archIterator; |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
return false; |
| 524 |
} |
| 525 |
|
| 526 |
#ifdef Q_OS_WIN // MinGW x-compiling for QNX |
| 527 |
QString UnixMakefileGenerator::installRoot() const |
| 528 |
{ |
| 529 |
/* |
| 530 |
We include a magic prefix on the path to bypass mingw-make's "helpful" |
| 531 |
intervention in the environment, recognising variables that look like |
| 532 |
paths and adding the msys system root as prefix, which we don't want. |
| 533 |
Once this hack has smuggled INSTALL_ROOT into make's variable space, we |
| 534 |
can trivially strip the magic prefix back off to get the path we meant. |
| 535 |
*/ |
| 536 |
return QStringLiteral("$(INSTALL_ROOT:@msyshack@%=%)"); |
| 537 |
} |
| 538 |
#endif |
| 539 |
|
| 540 |
QString |
| 541 |
UnixMakefileGenerator::defaultInstall(const QString &t) |
| 542 |
{ |
| 543 |
if(t != "target" || project->first("TEMPLATE") == "subdirs") |
| 544 |
return QString(); |
| 545 |
|
| 546 |
enum { NoBundle, SolidBundle, SlicedBundle } bundle = NoBundle; |
| 547 |
bool isAux = (project->first("TEMPLATE") == "aux"); |
| 548 |
const QString root = installRoot(); |
| 549 |
ProStringList &uninst = project->values(ProKey(t + ".uninstall")); |
| 550 |
QString ret, destdir = project->first("DESTDIR").toQString(); |
| 551 |
if(!destdir.isEmpty() && destdir.right(1) != Option::dir_sep) |
| 552 |
destdir += Option::dir_sep; |
| 553 |
QString targetdir = fileFixify(project->first("target.path").toQString(), FileFixifyAbsolute); |
| 554 |
if(targetdir.right(1) != Option::dir_sep) |
| 555 |
targetdir += Option::dir_sep; |
| 556 |
|
| 557 |
ProStringList links; |
| 558 |
QString target="$(TARGET)"; |
| 559 |
const ProStringList &targets = project->values(ProKey(t + ".targets")); |
| 560 |
if(!project->isEmpty("QMAKE_BUNDLE")) { |
| 561 |
target = project->first("QMAKE_BUNDLE").toQString(); |
| 562 |
bundle = project->isActiveConfig("sliced_bundle") ? SlicedBundle : SolidBundle; |
| 563 |
} else if(project->first("TEMPLATE") == "app") { |
| 564 |
target = "$(QMAKE_TARGET)"; |
| 565 |
} else if(project->first("TEMPLATE") == "lib") { |
| 566 |
if (!project->isActiveConfig("staticlib") |
| 567 |
&& !project->isActiveConfig("plugin") |
| 568 |
&& !project->isActiveConfig("unversioned_libname")) { |
| 569 |
if(project->isEmpty("QMAKE_HPUX_SHLIB")) { |
| 570 |
links << "$(TARGET0)" << "$(TARGET1)" << "$(TARGET2)"; |
| 571 |
} else { |
| 572 |
links << "$(TARGET0)"; |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
for(int i = 0; i < targets.size(); ++i) { |
| 577 |
QString src = targets.at(i).toQString(), |
| 578 |
dst = escapeFilePath(filePrefixRoot(root, targetdir + src.section('/', -1))); |
| 579 |
if(!ret.isEmpty()) |
| 580 |
ret += "\n\t"; |
| 581 |
ret += "$(QINSTALL) " + escapeFilePath(Option::fixPathToTargetOS(src, false)) + ' ' + dst; |
| 582 |
if(!uninst.isEmpty()) |
| 583 |
uninst.append("\n\t"); |
| 584 |
uninst.append("-$(DEL_FILE) " + dst); |
| 585 |
} |
| 586 |
|
| 587 |
{ |
| 588 |
QString src_targ = target; |
| 589 |
if(!destdir.isEmpty()) |
| 590 |
src_targ = Option::fixPathToTargetOS(destdir + target, false); |
| 591 |
QString plain_targ = filePrefixRoot(root, fileFixify(targetdir + target, FileFixifyAbsolute)); |
| 592 |
QString dst_targ = plain_targ; |
| 593 |
plain_targ = escapeFilePath(plain_targ); |
| 594 |
if (bundle != NoBundle) { |
| 595 |
QString suffix; |
| 596 |
if (project->first("TEMPLATE") == "lib") { |
| 597 |
if (!project->isActiveConfig("shallow_bundle")) |
| 598 |
suffix += "/Versions/" + project->first("QMAKE_FRAMEWORK_VERSION"); |
| 599 |
suffix += "/$(TARGET)"; |
| 600 |
} else { |
| 601 |
suffix = "/" + project->first("QMAKE_BUNDLE_LOCATION") + "/$(QMAKE_TARGET)"; |
| 602 |
} |
| 603 |
dst_targ += suffix; |
| 604 |
if (bundle == SolidBundle) { |
| 605 |
if (!ret.isEmpty()) |
| 606 |
ret += "\n\t"; |
| 607 |
ret += "$(DEL_FILE) -r " + plain_targ + "\n\t"; |
| 608 |
} else { |
| 609 |
src_targ += suffix; |
| 610 |
} |
| 611 |
} |
| 612 |
src_targ = escapeFilePath(src_targ); |
| 613 |
dst_targ = escapeFilePath(dst_targ); |
| 614 |
|
| 615 |
QString copy_cmd; |
| 616 |
if (bundle == SolidBundle) { |
| 617 |
copy_cmd += "$(QINSTALL) " + src_targ + ' ' + plain_targ; |
| 618 |
} else if (project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib")) { |
| 619 |
copy_cmd += "$(QINSTALL) " + src_targ + ' ' + dst_targ; |
| 620 |
} else if (!isAux) { |
| 621 |
if (bundle == SlicedBundle) { |
| 622 |
if (!ret.isEmpty()) |
| 623 |
ret += "\n\t"; |
| 624 |
ret += mkdir_p_asstring("\"`dirname " + dst_targ + "`\"", false); |
| 625 |
} |
| 626 |
copy_cmd += "$(QINSTALL_PROGRAM) " + src_targ + ' ' + dst_targ; |
| 627 |
} |
| 628 |
if(project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") |
| 629 |
&& project->values(ProKey(t + ".CONFIG")).indexOf("fix_rpath") != -1) { |
| 630 |
if (!ret.isEmpty()) |
| 631 |
ret += "\n\t"; |
| 632 |
if(!project->isEmpty("QMAKE_FIX_RPATH")) { |
| 633 |
ret += copy_cmd; |
| 634 |
ret += "\n\t-" + var("QMAKE_FIX_RPATH") + ' ' + dst_targ + ' ' + dst_targ; |
| 635 |
} else if(!project->isEmpty("QMAKE_LFLAGS_RPATH")) { |
| 636 |
ret += "-$(LINK) $(LFLAGS) " + var("QMAKE_LFLAGS_RPATH") + targetdir + " -o " + |
| 637 |
dst_targ + " $(OBJECTS) $(LIBS) $(OBJCOMP)"; |
| 638 |
} else { |
| 639 |
ret += copy_cmd; |
| 640 |
} |
| 641 |
} else if (!copy_cmd.isEmpty()) { |
| 642 |
if (!ret.isEmpty()) |
| 643 |
ret += "\n\t"; |
| 644 |
ret += copy_cmd; |
| 645 |
} |
| 646 |
|
| 647 |
if (isAux) { |
| 648 |
} else if (project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib")) { |
| 649 |
if(!project->isEmpty("QMAKE_RANLIB")) |
| 650 |
ret += QString("\n\t$(RANLIB) ") + dst_targ; |
| 651 |
} else if (!project->isActiveConfig("debug_info") && !project->isActiveConfig("nostrip") |
| 652 |
&& !project->isEmpty("QMAKE_STRIP")) { |
| 653 |
ret += "\n\t-$(STRIP)"; |
| 654 |
if (project->first("TEMPLATE") == "lib") { |
| 655 |
if (!project->isEmpty("QMAKE_STRIPFLAGS_LIB")) |
| 656 |
ret += " " + var("QMAKE_STRIPFLAGS_LIB"); |
| 657 |
} else if (project->first("TEMPLATE") == "app") { |
| 658 |
if (!project->isEmpty("QMAKE_STRIPFLAGS_APP")) |
| 659 |
ret += " " + var("QMAKE_STRIPFLAGS_APP"); |
| 660 |
} |
| 661 |
ret += ' ' + dst_targ; |
| 662 |
} |
| 663 |
if(!uninst.isEmpty()) |
| 664 |
uninst.append("\n\t"); |
| 665 |
if (bundle == SolidBundle) |
| 666 |
uninst.append("-$(DEL_FILE) -r " + plain_targ); |
| 667 |
else if (!isAux) |
| 668 |
uninst.append("-$(DEL_FILE) " + dst_targ); |
| 669 |
if (bundle == SlicedBundle) { |
| 670 |
int dstlen = project->first("DESTDIR").length(); |
| 671 |
for (const ProString &src : project->values("QMAKE_BUNDLED_FILES")) { |
| 672 |
ProString file = src.mid(dstlen); |
| 673 |
QString dst = escapeFilePath( |
| 674 |
filePrefixRoot(root, fileFixify(targetdir + file, FileFixifyAbsolute))); |
| 675 |
if (!ret.isEmpty()) |
| 676 |
ret += "\n\t"; |
| 677 |
ret += mkdir_p_asstring("\"`dirname " + dst + "`\"", false) + "\n\t"; |
| 678 |
ret += "-$(DEL_FILE) " + dst + "\n\t"; // Can't overwrite symlinks to directories |
| 679 |
ret += "$(QINSTALL) " + escapeFilePath(src) + " " + dst; |
| 680 |
if (!uninst.isEmpty()) |
| 681 |
uninst.append("\n\t"); |
| 682 |
uninst.append("-$(DEL_FILE) " + dst); |
| 683 |
} |
| 684 |
} |
| 685 |
if(!links.isEmpty()) { |
| 686 |
for(int i = 0; i < links.size(); ++i) { |
| 687 |
if (target_mode == TARG_UNIX_MODE || target_mode == TARG_MAC_MODE) { |
| 688 |
QString link = Option::fixPathToTargetOS(destdir + links[i], false); |
| 689 |
int lslash = link.lastIndexOf(Option::dir_sep); |
| 690 |
if(lslash != -1) |
| 691 |
link = link.right(link.size() - (lslash + 1)); |
| 692 |
QString dst_link = escapeFilePath( |
| 693 |
filePrefixRoot(root, fileFixify(targetdir + link, FileFixifyAbsolute))); |
| 694 |
ret += "\n\t-$(SYMLINK) $(TARGET) " + dst_link; |
| 695 |
if(!uninst.isEmpty()) |
| 696 |
uninst.append("\n\t"); |
| 697 |
uninst.append("-$(DEL_FILE) " + dst_link); |
| 698 |
} |
| 699 |
} |
| 700 |
} |
| 701 |
} |
| 702 |
if (isAux || project->first("TEMPLATE") == "lib") { |
| 703 |
QStringList types; |
| 704 |
types << "prl" << "libtool" << "pkgconfig"; |
| 705 |
for(int i = 0; i < types.size(); ++i) { |
| 706 |
const QString type = types.at(i); |
| 707 |
QString meta; |
| 708 |
if(type == "prl" && project->isActiveConfig("create_prl") && !project->isActiveConfig("no_install_prl") && |
| 709 |
!project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) |
| 710 |
meta = prlFileName(false); |
| 711 |
if (type == "libtool" && project->isActiveConfig("create_libtool")) |
| 712 |
meta = libtoolFileName(false); |
| 713 |
if(type == "pkgconfig" && project->isActiveConfig("create_pc")) |
| 714 |
meta = pkgConfigFileName(false); |
| 715 |
if(!meta.isEmpty()) { |
| 716 |
QString src_meta = meta; |
| 717 |
if(!destdir.isEmpty()) |
| 718 |
src_meta = Option::fixPathToTargetOS(destdir + meta, false); |
| 719 |
QString dst_meta = filePrefixRoot(root, fileFixify(targetdir + meta, FileFixifyAbsolute)); |
| 720 |
if(!uninst.isEmpty()) |
| 721 |
uninst.append("\n\t"); |
| 722 |
uninst.append("-$(DEL_FILE) " + escapeFilePath(dst_meta)); |
| 723 |
const QString dst_meta_dir = fileInfo(dst_meta).path(); |
| 724 |
if(!dst_meta_dir.isEmpty()) { |
| 725 |
if(!ret.isEmpty()) |
| 726 |
ret += "\n\t"; |
| 727 |
ret += mkdir_p_asstring(dst_meta_dir, true); |
| 728 |
} |
| 729 |
if (!ret.isEmpty()) |
| 730 |
ret += "\n\t"; |
| 731 |
ret += installMetaFile(ProKey("QMAKE_" + type.toUpper() + "_INSTALL_REPLACE"), src_meta, dst_meta); |
| 732 |
} |
| 733 |
} |
| 734 |
} |
| 735 |
return ret; |
| 736 |
} |
| 737 |
|
| 738 |
QString |
| 739 |
UnixMakefileGenerator::escapeFilePath(const QString &path) const |
| 740 |
{ |
| 741 |
QString ret = path; |
| 742 |
if(!ret.isEmpty()) { |
| 743 |
ret.replace(QLatin1Char(' '), QLatin1String("\\ ")) |
| 744 |
.replace(QLatin1Char('\t'), QLatin1String("\\\t")); |
| 745 |
debug_msg(2, "EscapeFilePath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData()); |
| 746 |
} |
| 747 |
return ret; |
| 748 |
} |
| 749 |
|
| 750 |
QT_END_NAMESPACE |