source: trunk/qmake/generators/unix/unixmake.cpp@ 289

Last change on this file since 289 was 27, checked in by Dmitry A. Kuminov, 16 years ago

qmake: Added os2 mode (default on OS/2).

File size: 40.6 KB
Line 
1/****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
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 [email protected].
38** $QT_END_LICENSE$
39 **
40 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 **
43 ****************************************************************************/
44
45#include "unixmake.h"
46#include "option.h"
47#include <qregexp.h>
48#include <qfile.h>
49#include <qhash.h>
50#include <qdir.h>
51#include <time.h>
52#include <qdebug.h>
53
54QT_BEGIN_NAMESPACE
55
56void
57UnixMakefileGenerator::init()
58{
59 if(init_flag)
60 return;
61 init_flag = true;
62
63 if(project->isEmpty("QMAKE_EXTENSION_SHLIB")) {
64 if(project->isEmpty("QMAKE_CYGWIN_SHLIB")) {
65 project->values("QMAKE_EXTENSION_SHLIB").append("so");
66 } else {
67 project->values("QMAKE_EXTENSION_SHLIB").append("dll");
68 }
69 }
70
71 if(!project->isEmpty("QMAKE_FAILED_REQUIREMENTS")) /* no point */
72 return;
73
74 QStringList &configs = project->values("CONFIG");
75 if(project->isEmpty("ICON") && !project->isEmpty("RC_FILE"))
76 project->values("ICON") = project->values("RC_FILE");
77 if(project->isEmpty("QMAKE_EXTENSION_PLUGIN"))
78 project->values("QMAKE_EXTENSION_PLUGIN").append(project->first("QMAKE_EXTENSION_SHLIB"));
79 if(project->isEmpty("QMAKE_COPY_FILE"))
80 project->values("QMAKE_COPY_FILE").append("$(COPY)");
81 if(project->isEmpty("QMAKE_STREAM_EDITOR"))
82 project->values("QMAKE_STREAM_EDITOR").append("sed");
83 if(project->isEmpty("QMAKE_COPY_DIR"))
84 project->values("QMAKE_COPY_DIR").append("$(COPY) -R");
85 if(project->isEmpty("QMAKE_INSTALL_FILE"))
86 project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
87 if(project->isEmpty("QMAKE_INSTALL_DIR"))
88 project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
89 if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
90 project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
91 if(project->isEmpty("QMAKE_LIBTOOL"))
92 project->values("QMAKE_LIBTOOL").append("libtool --silent");
93 if(project->isEmpty("QMAKE_SYMBOLIC_LINK"))
94 project->values("QMAKE_SYMBOLIC_LINK").append("ln -sf");
95
96 /* this should probably not be here, but I'm using it to wrap the .t files */
97 if(project->first("TEMPLATE") == "app")
98 project->values("QMAKE_APP_FLAG").append("1");
99 else if(project->first("TEMPLATE") == "lib")
100 project->values("QMAKE_LIB_FLAG").append("1");
101 else if(project->first("TEMPLATE") == "subdirs") {
102 MakefileGenerator::init();
103 if(project->isEmpty("MAKEFILE"))
104 project->values("MAKEFILE").append("Makefile");
105 if(project->isEmpty("QMAKE_QMAKE"))
106 project->values("QMAKE_QMAKE").append("qmake");
107 if(project->values("QMAKE_INTERNAL_QMAKE_DEPS").indexOf("qmake_all") == -1)
108 project->values("QMAKE_INTERNAL_QMAKE_DEPS").append("qmake_all");
109 return; /* subdirs is done */
110 }
111
112 //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET
113 if(!project->isEmpty("TARGET")) {
114 project->values("TARGET") = escapeFilePaths(project->values("TARGET"));
115 QString targ = unescapeFilePath(project->first("TARGET"));
116 int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep));
117 if(slsh != -1) {
118 if(project->isEmpty("DESTDIR"))
119 project->values("DESTDIR").append("");
120 else if(project->first("DESTDIR").right(1) != Option::dir_sep)
121 project->values("DESTDIR") = QStringList(project->first("DESTDIR") + Option::dir_sep);
122 project->values("DESTDIR") = QStringList(project->first("DESTDIR") + targ.left(slsh+1));
123 project->values("TARGET") = QStringList(targ.mid(slsh+1));
124 }
125 }
126
127 project->values("QMAKE_ORIG_TARGET") = project->values("TARGET");
128 project->values("QMAKE_ORIG_DESTDIR") = project->values("DESTDIR");
129 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
130 if((!project->isEmpty("QMAKE_LIB_FLAG") && !project->isActiveConfig("staticlib")) ||
131 (project->isActiveConfig("qt") && project->isActiveConfig("plugin"))) {
132 if(configs.indexOf("dll") == -1) configs.append("dll");
133 } else if(!project->isEmpty("QMAKE_APP_FLAG") || project->isActiveConfig("dll")) {
134 configs.removeAll("staticlib");
135 }
136 if(!project->isEmpty("QMAKE_INCREMENTAL"))
137 project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_INCREMENTAL");
138 else if(!project->isEmpty("QMAKE_LFLAGS_PREBIND") &&
139 !project->values("QMAKE_LIB_FLAG").isEmpty() &&
140 project->isActiveConfig("dll"))
141 project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_PREBIND");
142 if(!project->isEmpty("QMAKE_INCDIR"))
143 project->values("INCLUDEPATH") += project->values("QMAKE_INCDIR");
144 if(!project->isEmpty("QMAKE_LIBDIR")) {
145 const QStringList &libdirs = project->values("QMAKE_LIBDIR");
146 for(int i = 0; i < libdirs.size(); ++i) {
147 if(!project->isEmpty("QMAKE_LFLAGS_RPATH") && project->isActiveConfig("rpath_libdirs"))
148 project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATH") + libdirs[i];
149 if (project->isActiveConfig("rvct_linker")) {
150 project->values("QMAKE_LIBDIR_FLAGS") += "--userlibpath " + escapeFilePath(libdirs[i]);
151 } else {
152 project->values("QMAKE_LIBDIR_FLAGS") += "-L" + escapeFilePath(libdirs[i]);
153 }
154 }
155 }
156 if(project->isActiveConfig("macx") && !project->isEmpty("QMAKE_FRAMEWORKPATH")) {
157 const QStringList &fwdirs = project->values("QMAKE_FRAMEWORKPATH");
158 for(int i = 0; i < fwdirs.size(); ++i) {
159 project->values("QMAKE_FRAMEWORKPATH_FLAGS") += "-F" + escapeFilePath(fwdirs[i]);
160 }
161 }
162 if(!project->isEmpty("QMAKE_RPATHDIR")) {
163 const QStringList &rpathdirs = project->values("QMAKE_RPATHDIR");
164 for(int i = 0; i < rpathdirs.size(); ++i) {
165 if(!project->isEmpty("QMAKE_LFLAGS_RPATH"))
166 project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATH") + escapeFilePath(QFileInfo(rpathdirs[i]).absoluteFilePath());
167 }
168 }
169
170 project->values("QMAKE_FILETAGS") << "SOURCES" << "GENERATED_SOURCES" << "TARGET" << "DESTDIR";
171 if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
172 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
173 for(int i = 0; i < quc.size(); ++i)
174 project->values("QMAKE_FILETAGS") += project->values(quc[i]+".input");
175 }
176
177 if(project->isActiveConfig("GNUmake") && !project->isEmpty("QMAKE_CFLAGS_DEPS"))
178 include_deps = true; //do not generate deps
179 if(project->isActiveConfig("compile_libtool"))
180 Option::obj_ext = ".lo"; //override the .o
181
182 MakefileGenerator::init();
183
184 QString comps[] = { "C", "CXX", "OBJC", "OBJCXX", QString() };
185 for(int i = 0; !comps[i].isNull(); i++) {
186 QString compile_flag = var("QMAKE_COMPILE_FLAG");
187 if(compile_flag.isEmpty())
188 compile_flag = "-c";
189
190 if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
191 QString pchFlags = var("QMAKE_" + comps[i] + "FLAGS_USE_PRECOMPILE");
192
193 QString pchBaseName;
194 if(!project->isEmpty("PRECOMPILED_DIR")) {
195 pchBaseName = Option::fixPathToTargetOS(project->first("PRECOMPILED_DIR"));
196 if(!pchBaseName.endsWith(Option::dir_sep))
197 pchBaseName += Option::dir_sep;
198 }
199 pchBaseName += project->first("QMAKE_ORIG_TARGET");
200
201 // replace place holders
202 pchFlags = pchFlags.replace("${QMAKE_PCH_INPUT}",
203 fileFixify(project->first("PRECOMPILED_HEADER")));
204 pchFlags = pchFlags.replace("${QMAKE_PCH_OUTPUT_BASE}", pchBaseName);
205 if (project->isActiveConfig("icc_pch_style")) {
206 // icc style
207 pchFlags = pchFlags.replace("${QMAKE_PCH_OUTPUT}",
208 pchBaseName + project->first("QMAKE_PCH_OUTPUT_EXT"));
209 }
210
211 if (!pchFlags.isEmpty())
212 compile_flag += " " + pchFlags;
213 }
214
215 QString cflags;
216 if(comps[i] == "OBJC" || comps[i] == "OBJCXX")
217 cflags += " $(CFLAGS)";
218 else
219 cflags += " $(" + comps[i] + "FLAGS)";
220 compile_flag += cflags + " $(INCPATH)";
221
222 QString compiler = comps[i];
223 if (compiler == "C")
224 compiler = "CC";
225
226 QString runComp = "QMAKE_RUN_" + compiler;
227 if(project->isEmpty(runComp))
228 project->values(runComp).append("$(" + compiler + ") " + compile_flag + " -o $obj $src");
229 QString runCompImp = "QMAKE_RUN_" + compiler + "_IMP";
230 if(project->isEmpty(runCompImp))
231 project->values(runCompImp).append("$(" + compiler + ") " + compile_flag + " -o \"$@\" \"$<\"");
232 }
233
234 if(project->isActiveConfig("macx") && !project->isEmpty("TARGET") && !project->isActiveConfig("compile_libtool") &&
235 ((project->isActiveConfig("build_pass") || project->isEmpty("BUILDS")))) {
236 QString bundle;
237 if(project->isActiveConfig("bundle") && !project->isEmpty("QMAKE_BUNDLE_EXTENSION")) {
238 bundle = unescapeFilePath(project->first("TARGET"));
239 if(!project->isEmpty("QMAKE_BUNDLE_NAME"))
240 bundle = unescapeFilePath(project->first("QMAKE_BUNDLE_NAME"));
241 if(!bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION")))
242 bundle += project->first("QMAKE_BUNDLE_EXTENSION");
243 } else if(project->first("TEMPLATE") == "app" && project->isActiveConfig("app_bundle")) {
244 bundle = unescapeFilePath(project->first("TARGET"));
245 if(!project->isEmpty("QMAKE_APPLICATION_BUNDLE_NAME"))
246 bundle = unescapeFilePath(project->first("QMAKE_APPLICATION_BUNDLE_NAME"));
247 if(!bundle.endsWith(".app"))
248 bundle += ".app";
249 if(project->isEmpty("QMAKE_BUNDLE_LOCATION"))
250 project->values("QMAKE_BUNDLE_LOCATION").append("Contents/MacOS");
251 project->values("QMAKE_PKGINFO").append(project->first("DESTDIR") + bundle + "/Contents/PkgInfo");
252 project->values("QMAKE_BUNDLE_RESOURCE_FILE").append(project->first("DESTDIR") + bundle + "/Contents/Resources/empty.lproj");
253 } else if(project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") &&
254 ((!project->isActiveConfig("plugin") && project->isActiveConfig("lib_bundle")) ||
255 (project->isActiveConfig("plugin") && project->isActiveConfig("plugin_bundle")))) {
256 bundle = unescapeFilePath(project->first("TARGET"));
257 if(project->isActiveConfig("plugin")) {
258 if(!project->isEmpty("QMAKE_PLUGIN_BUNDLE_NAME"))
259 bundle = unescapeFilePath(project->first("QMAKE_PLUGIN_BUNDLE_NAME"));
260 if(!project->isEmpty("QMAKE_BUNDLE_EXTENSION") && !bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION")))
261 bundle += project->first("QMAKE_BUNDLE_EXTENSION");
262 else if(!bundle.endsWith(".plugin"))
263 bundle += ".plugin";
264 if(!project->isEmpty("QMAKE_BUNDLE_LOCATION"))
265 project->values("QMAKE_BUNDLE_LOCATION").append("Contents/MacOS");
266 } else {
267 if(!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME"))
268 bundle = unescapeFilePath(project->first("QMAKE_FRAMEWORK_BUNDLE_NAME"));
269 if(!project->isEmpty("QMAKE_BUNDLE_EXTENSION") && !bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION")))
270 bundle += project->first("QMAKE_BUNDLE_EXTENSION");
271 else if(!bundle.endsWith(".framework"))
272 bundle += ".framework";
273 }
274 }
275 if(!bundle.isEmpty()) {
276 project->values("QMAKE_BUNDLE") = QStringList(bundle);
277 project->values("ALL_DEPS") += project->first("QMAKE_PKGINFO");
278 project->values("ALL_DEPS") += project->first("QMAKE_BUNDLE_RESOURCE_FILE");
279 } else {
280 project->values("QMAKE_BUNDLE").clear();
281 project->values("QMAKE_BUNDLE_LOCATION").clear();
282 }
283 } else { //no bundling here
284 project->values("QMAKE_BUNDLE").clear();
285 project->values("QMAKE_BUNDLE_LOCATION").clear();
286 }
287
288 if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES"))
289 project->values("DISTFILES") += project->values("QMAKE_INTERNAL_INCLUDED_FILES");
290 project->values("DISTFILES") += project->projectFile();
291
292 init2();
293 project->values("QMAKE_INTERNAL_PRL_LIBS") << "QMAKE_LIBDIR_FLAGS" << "QMAKE_FRAMEWORKPATH_FLAGS" << "QMAKE_LIBS";
294 if(!project->isEmpty("QMAKE_MAX_FILES_PER_AR")) {
295 bool ok;
296 int max_files = project->first("QMAKE_MAX_FILES_PER_AR").toInt(&ok);
297 QStringList ar_sublibs, objs = project->values("OBJECTS");
298 if(ok && max_files > 5 && max_files < (int)objs.count()) {
299 QString lib;
300 for(int i = 0, obj_cnt = 0, lib_cnt = 0; i != objs.size(); ++i) {
301 if((++obj_cnt) >= max_files) {
302 if(lib_cnt) {
303 lib.sprintf("lib%s-tmp%d.a",
304 project->first("QMAKE_ORIG_TARGET").toLatin1().constData(), lib_cnt);
305 ar_sublibs << lib;
306 obj_cnt = 0;
307 }
308 lib_cnt++;
309 }
310 }
311 }
312 if(!ar_sublibs.isEmpty()) {
313 project->values("QMAKE_AR_SUBLIBS") = ar_sublibs;
314 project->values("QMAKE_INTERNAL_PRL_LIBS") << "QMAKE_AR_SUBLIBS";
315 }
316 }
317
318 if(project->isActiveConfig("compile_libtool")) {
319 const QString libtoolify[] = { "QMAKE_RUN_CC", "QMAKE_RUN_CC_IMP",
320 "QMAKE_RUN_CXX", "QMAKE_RUN_CXX_IMP",
321 "QMAKE_LINK_THREAD", "QMAKE_LINK", "QMAKE_AR_CMD", "QMAKE_LINK_SHLIB_CMD",
322 QString() };
323 for(int i = 0; !libtoolify[i].isNull(); i++) {
324 QStringList &l = project->values(libtoolify[i]);
325 if(!l.isEmpty()) {
326 QString libtool_flags, comp_flags;
327 if(libtoolify[i].startsWith("QMAKE_LINK") || libtoolify[i] == "QMAKE_AR_CMD") {
328 libtool_flags += " --mode=link";
329 if(project->isActiveConfig("staticlib")) {
330 libtool_flags += " -static";
331 } else {
332 if(!project->isEmpty("QMAKE_LIB_FLAG")) {
333 int maj = project->first("VER_MAJ").toInt();
334 int min = project->first("VER_MIN").toInt();
335 int pat = project->first("VER_PAT").toInt();
336 comp_flags += " -version-info " + QString::number(10*maj + min) +
337 ":" + QString::number(pat) + ":0";
338 if(libtoolify[i] != "QMAKE_AR_CMD") {
339 QString rpath = Option::output_dir;
340 if(!project->isEmpty("DESTDIR")) {
341 rpath = project->first("DESTDIR");
342 if(QDir::isRelativePath(rpath))
343 rpath.prepend(Option::output_dir + Option::dir_sep);
344 }
345 comp_flags += " -rpath " + Option::fixPathToTargetOS(rpath, false);
346 }
347 }
348 }
349 if(project->isActiveConfig("plugin"))
350 libtool_flags += " -module";
351 } else {
352 libtool_flags += " --mode=compile";
353 }
354 l.first().prepend("$(LIBTOOL)" + libtool_flags + " ");
355 if(!comp_flags.isEmpty())
356 l.first() += comp_flags;
357 }
358 }
359 }
360}
361
362void
363UnixMakefileGenerator::processPrlVariable(const QString &var, const QStringList &l)
364{
365 if(var == "QMAKE_PRL_LIBS") {
366 project->values("QMAKE_CURRENT_PRL_LIBS") += l;
367 } else
368 MakefileGenerator::processPrlVariable(var, l);
369}
370
371QStringList
372&UnixMakefileGenerator::findDependencies(const QString &file)
373{
374 QStringList &ret = MakefileGenerator::findDependencies(file);
375 // Note: The QMAKE_IMAGE_COLLECTION file have all images
376 // as dependency, so don't add precompiled header then
377 if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")
378 && file != project->first("QMAKE_IMAGE_COLLECTION")) {
379 QString header_prefix;
380 if(!project->isEmpty("PRECOMPILED_DIR"))
381 header_prefix = project->first("PRECOMPILED_DIR");
382 header_prefix += project->first("QMAKE_ORIG_TARGET") + project->first("QMAKE_PCH_OUTPUT_EXT");
383 if (project->isActiveConfig("icc_pch_style")) {
384 // icc style
385 for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
386 if(file.endsWith(*it)) {
387 ret += header_prefix;
388 break;
389 }
390 }
391 } else {
392 // gcc style
393 header_prefix += Option::dir_sep + project->first("QMAKE_PRECOMP_PREFIX");
394 for(QStringList::Iterator it = Option::c_ext.begin(); it != Option::c_ext.end(); ++it) {
395 if(file.endsWith(*it)) {
396 if(!project->isEmpty("QMAKE_CFLAGS_PRECOMPILE")) {
397 QString precomp_c_h = header_prefix + "c";
398 if(!ret.contains(precomp_c_h))
399 ret += precomp_c_h;
400 }
401 if(project->isActiveConfig("objective_c")) {
402 if(!project->isEmpty("QMAKE_OBJCFLAGS_PRECOMPILE")) {
403 QString precomp_objc_h = header_prefix + "objective-c";
404 if(!ret.contains(precomp_objc_h))
405 ret += precomp_objc_h;
406 }
407 if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) {
408 QString precomp_objcpp_h = header_prefix + "objective-c++";
409 if(!ret.contains(precomp_objcpp_h))
410 ret += precomp_objcpp_h;
411 }
412 }
413 break;
414 }
415 }
416 for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
417 if(file.endsWith(*it)) {
418 if(!project->isEmpty("QMAKE_CXXFLAGS_PRECOMPILE")) {
419 QString precomp_cpp_h = header_prefix + "c++";
420 if(!ret.contains(precomp_cpp_h))
421 ret += precomp_cpp_h;
422 }
423 if(project->isActiveConfig("objective_c")) {
424 if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) {
425 QString precomp_objcpp_h = header_prefix + "objective-c++";
426 if(!ret.contains(precomp_objcpp_h))
427 ret += precomp_objcpp_h;
428 }
429 }
430 break;
431 }
432 }
433 }
434 }
435 return ret;
436}
437
438bool
439UnixMakefileGenerator::findLibraries()
440{
441 QList<QMakeLocalFileName> libdirs, frameworkdirs;
442 frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks"));
443 frameworkdirs.append(QMakeLocalFileName("/Library/Frameworks"));
444 const QString lflags[] = { "QMAKE_LIBDIR_FLAGS", "QMAKE_FRAMEWORKPATH_FLAGS", "QMAKE_LFLAGS", "QMAKE_LIBS", QString() };
445 for(int i = 0; !lflags[i].isNull(); i++) {
446 QStringList &l = project->values(lflags[i]);
447 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
448 bool do_suffix = true;
449 QString stub, dir, extn, opt = (*it).trimmed();
450 if(opt.startsWith("-")) {
451 if(opt.startsWith("-L")) {
452 QMakeLocalFileName f(opt.right(opt.length()-2));
453 if(!libdirs.contains(f))
454 libdirs.append(f);
455 } else if(opt.startsWith("-l")) {
456 if (project->isActiveConfig("rvct_linker")) {
457 (*it) = "lib" + opt.mid(2) + ".so";
458 } else {
459 stub = opt.mid(2);
460 }
461 } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) {
462 frameworkdirs.append(QMakeLocalFileName(opt.right(opt.length()-2)));
463 } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) {
464 if(opt.length() > 11) {
465 opt = opt.mid(11);
466 } else {
467 ++it;
468 opt = (*it);
469 }
470 do_suffix = false;
471 extn = "";
472 dir = "/System/Library/Frameworks/" + opt + ".framework/";
473 stub = opt;
474 }
475 } else {
476 extn = dir = "";
477 stub = opt;
478 int slsh = opt.lastIndexOf(Option::dir_sep);
479 if(slsh != -1) {
480 dir = opt.left(slsh);
481 stub = opt.mid(slsh+1);
482 }
483 QRegExp stub_reg("^.*lib(" + stub + "[^./=]*)\\.(.*)$");
484 if(stub_reg.exactMatch(stub)) {
485 stub = stub_reg.cap(1);
486 extn = stub_reg.cap(2);
487 }
488 }
489 if(!stub.isEmpty()) {
490 if(do_suffix && !project->isEmpty("QMAKE_" + stub.toUpper() + "_SUFFIX"))
491 stub += project->first("QMAKE_" + stub.toUpper() + "_SUFFIX");
492 bool found = false;
493 QStringList extens;
494 if(!extn.isNull())
495 extens << extn;
496 else
497 extens << project->values("QMAKE_EXTENSION_SHLIB").first() << "a";
498 for(QStringList::Iterator extit = extens.begin(); extit != extens.end(); ++extit) {
499 if(dir.isNull()) {
500 QString lib_stub;
501 for(QList<QMakeLocalFileName>::Iterator dep_it = libdirs.begin(); dep_it != libdirs.end(); ++dep_it) {
502 if(exists((*dep_it).local() + Option::dir_sep + "lib" + stub +
503 "." + (*extit))) {
504 lib_stub = stub;
505 break;
506 }
507 }
508 if(!lib_stub.isNull()) {
509 (*it) = "-l" + lib_stub;
510 found = true;
511 break;
512 }
513 } else {
514 if(exists("lib" + stub + "." + (*extit))) {
515 (*it) = "lib" + stub + "." + (*extit);
516 found = true;
517 break;
518 }
519 }
520 }
521 if(!found && project->isActiveConfig("compile_libtool")) {
522 for(int dep_i = 0; dep_i < libdirs.size(); ++dep_i) {
523 if(exists(libdirs[dep_i].local() + Option::dir_sep + "lib" + stub + Option::libtool_ext)) {
524 (*it) = libdirs[dep_i].real() + Option::dir_sep + "lib" + stub + Option::libtool_ext;
525 found = true;
526 break;
527 }
528 }
529 }
530 }
531 }
532 }
533 return false;
534}
535
536QString linkLib(const QString &file, const QString &libName) {
537 QString ret;
538 QRegExp reg("^.*lib(" + QRegExp::escape(libName) + "[^./=]*).*$");
539 if(reg.exactMatch(file))
540 ret = "-l" + reg.cap(1);
541 return ret;
542}
543
544void
545UnixMakefileGenerator::processPrlFiles()
546{
547 QList<QMakeLocalFileName> libdirs, frameworkdirs;
548 frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks"));
549 frameworkdirs.append(QMakeLocalFileName("/Library/Frameworks"));
550 const QString lflags[] = { "QMAKE_LIBDIR_FLAGS", "QMAKE_FRAMEWORKPATH_FLAGS", "QMAKE_LFLAGS", "QMAKE_LIBS", QString() };
551 for(int i = 0; !lflags[i].isNull(); i++) {
552 QStringList &l = project->values(lflags[i]);
553 for(int lit = 0; lit < l.size(); ++lit) {
554 QString opt = l.at(lit).trimmed();
555 if(opt.startsWith("-")) {
556 if(opt.startsWith("-L")) {
557 QMakeLocalFileName l(opt.right(opt.length()-2));
558 if(!libdirs.contains(l))
559 libdirs.append(l);
560 } else if(opt.startsWith("-l")) {
561 QString lib = opt.right(opt.length() - 2);
562 for(int dep_i = 0; dep_i < libdirs.size(); ++dep_i) {
563 const QMakeLocalFileName &lfn = libdirs[dep_i];
564 if(!project->isActiveConfig("compile_libtool")) { //give them the .libs..
565 QString la = lfn.local() + Option::dir_sep + "lib" + lib + Option::libtool_ext;
566 if(exists(la) && QFile::exists(lfn.local() + Option::dir_sep + ".libs")) {
567 QString dot_libs = lfn.real() + Option::dir_sep + ".libs";
568 l.append("-L" + dot_libs);
569 libdirs.append(QMakeLocalFileName(dot_libs));
570 }
571 }
572
573 QString prl = lfn.local() + Option::dir_sep + "lib" + lib;
574 if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX"))
575 prl += project->first("QMAKE_" + lib.toUpper() + "_SUFFIX");
576 if(processPrlFile(prl)) {
577 if(prl.startsWith(lfn.local()))
578 prl.replace(0, lfn.local().length(), lfn.real());
579 opt = linkLib(prl, lib);
580 break;
581 }
582 }
583 } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) {
584 QMakeLocalFileName f(opt.right(opt.length()-2));
585 if(!frameworkdirs.contains(f))
586 frameworkdirs.append(f);
587 } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) {
588 if(opt.length() > 11)
589 opt = opt.mid(11);
590 else
591 opt = l.at(++lit);
592 opt = opt.trimmed();
593 const QList<QMakeLocalFileName> dirs = frameworkdirs + libdirs;
594 for(int dep_i = 0; dep_i < dirs.size(); ++dep_i) {
595 QString prl = dirs[dep_i].local() + "/" + opt + ".framework/" + opt + Option::prl_ext;
596 if(processPrlFile(prl))
597 break;
598 }
599 }
600 } else if(!opt.isNull()) {
601 QString lib = opt;
602 processPrlFile(lib);
603#if 0
604 if(ret)
605 opt = linkLib(lib, "");
606#endif
607 if(!opt.isEmpty())
608 l.replaceInStrings(lib, opt);
609 }
610
611 QStringList &prl_libs = project->values("QMAKE_CURRENT_PRL_LIBS");
612 if(!prl_libs.isEmpty()) {
613 for(int prl = 0; prl < prl_libs.size(); ++prl)
614 l.insert(lit+prl+1, prl_libs.at(prl));
615 prl_libs.clear();
616 }
617 }
618
619 //merge them into a logical order
620 if(!project->isActiveConfig("no_smart_library_merge") && !project->isActiveConfig("no_lflags_merge")) {
621 QStringList lflags;
622 for(int lit = 0; lit < l.size(); ++lit) {
623 QString opt = l.at(lit).trimmed();
624 if(opt.startsWith("-")) {
625 if(opt.startsWith("-L") ||
626 (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F"))) {
627 if(lit == 0 || l.lastIndexOf(opt, lit-1) == -1)
628 lflags.append(opt);
629 } else if(opt.startsWith("-l")) {
630 if(lit == l.size()-1 || l.indexOf(opt, lit+1) == -1)
631 lflags.append(opt);
632 } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) {
633 if(opt.length() > 11)
634 opt = opt.mid(11);
635 else
636 opt = l.at(++lit);
637 bool found = false;
638 for(int x = lit+1; x < l.size(); ++x) {
639 QString xf = l.at(x);
640 if(xf.startsWith("-framework")) {
641 QString framework;
642 if(xf.length() > 11)
643 framework = xf.mid(11);
644 else
645 framework = l.at(++x);
646 if(framework == opt) {
647 found = true;
648 break;
649 }
650 }
651 }
652 if(!found) {
653 lflags.append("-framework");
654 lflags.append(opt);
655 }
656 } else {
657 lflags.append(opt);
658 }
659 } else if(!opt.isNull()) {
660 if(lit == 0 || l.lastIndexOf(opt, lit-1) == -1)
661 lflags.append(opt);
662 }
663 }
664 l = lflags;
665 }
666 }
667}
668
669QString
670UnixMakefileGenerator::defaultInstall(const QString &t)
671{
672 if(t != "target" || project->first("TEMPLATE") == "subdirs")
673 return QString();
674
675 bool bundle = false;
676 const QString root = "$(INSTALL_ROOT)";
677 QStringList &uninst = project->values(t + ".uninstall");
678 QString ret, destdir=project->first("DESTDIR");
679 QString targetdir = Option::fixPathToTargetOS(project->first("target.path"), false);
680 if(!destdir.isEmpty() && destdir.right(1) != Option::dir_sep)
681 destdir += Option::dir_sep;
682 targetdir = fileFixify(targetdir, FileFixifyAbsolute);
683 if(targetdir.right(1) != Option::dir_sep)
684 targetdir += Option::dir_sep;
685
686 QStringList links;
687 QString target="$(TARGET)";
688 QStringList &targets = project->values(t + ".targets");
689 if(!project->isEmpty("QMAKE_BUNDLE")) {
690 target = project->first("QMAKE_BUNDLE");
691 bundle = true;
692 } else if(project->first("TEMPLATE") == "app") {
693 target = "$(QMAKE_TARGET)";
694 } else if(project->first("TEMPLATE") == "lib") {
695 if(project->isEmpty("QMAKE_CYGWIN_SHLIB")) {
696 if(!project->isActiveConfig("staticlib") && !project->isActiveConfig("plugin")) {
697 if(project->isEmpty("QMAKE_HPUX_SHLIB")) {
698 links << "$(TARGET0)" << "$(TARGET1)" << "$(TARGET2)";
699 } else {
700 links << "$(TARGET0)";
701 }
702 }
703 }
704 }
705 for(int i = 0; i < targets.size(); ++i) {
706 QString src = targets.at(i),
707 dst = filePrefixRoot(root, targetdir + src.section('/', -1));
708 if(!ret.isEmpty())
709 ret += "\n\t";
710 ret += "-$(INSTALL_FILE) \"" + src + "\" \"" + dst + "\"";
711 if(!uninst.isEmpty())
712 uninst.append("\n\t");
713 uninst.append("-$(DEL_FILE) \"" + dst + "\"");
714 }
715
716 if(!bundle && project->isActiveConfig("compile_libtool")) {
717 QString src_targ = target;
718 if(src_targ == "$(TARGET)")
719 src_targ = "$(TARGETL)";
720 QString dst_dir = fileFixify(targetdir, FileFixifyAbsolute);
721 if(QDir::isRelativePath(dst_dir))
722 dst_dir = Option::fixPathToTargetOS(Option::output_dir + Option::dir_sep + dst_dir);
723 ret = "-$(LIBTOOL) --mode=install cp \"" + src_targ + "\" \"" + filePrefixRoot(root, dst_dir) + "\"";
724 uninst.append("-$(LIBTOOL) --mode=uninstall \"" + src_targ + "\"");
725 } else {
726 QString src_targ = target;
727 if(!destdir.isEmpty())
728 src_targ = Option::fixPathToTargetOS(destdir + target, false);
729 QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + target, FileFixifyAbsolute));
730 if(bundle) {
731 if(!ret.isEmpty())
732 ret += "\n\t";
733 ret += "$(DEL_FILE) -r \"" + dst_targ + "\"\n\t";
734 }
735 if(!ret.isEmpty())
736 ret += "\n\t";
737
738 QString copy_cmd("-");
739 if (bundle)
740 copy_cmd += "$(INSTALL_DIR)";
741 else if (project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib"))
742 copy_cmd += "$(INSTALL_FILE)";
743 else
744 copy_cmd += "$(INSTALL_PROGRAM)";
745 copy_cmd += " \"" + src_targ + "\" \"" + dst_targ + "\"";
746 if(project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib")
747 && project->values(t + ".CONFIG").indexOf("fix_rpath") != -1) {
748 if(!project->isEmpty("QMAKE_FIX_RPATH")) {
749 ret += copy_cmd;
750 ret += "\n\t-" + var("QMAKE_FIX_RPATH") + " \"" +
751 dst_targ + "\" \"" + dst_targ + "\"";
752 } else if(!project->isEmpty("QMAKE_LFLAGS_RPATH")) {
753 ret += "-$(LINK) $(LFLAGS) " + var("QMAKE_LFLAGS_RPATH") + targetdir + " -o \"" +
754 dst_targ + "\" $(OBJECTS) $(LIBS) $(OBJCOMP)";
755 } else {
756 ret += copy_cmd;
757 }
758 } else {
759 ret += copy_cmd;
760 }
761
762 if(project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib")) {
763 if(!project->isEmpty("QMAKE_RANLIB"))
764 ret += QString("\n\t$(RANLIB) \"") + dst_targ + "\"";
765 } else if(!project->isActiveConfig("debug") && !project->isActiveConfig("nostrip") && !project->isEmpty("QMAKE_STRIP")) {
766 ret += "\n\t-" + var("QMAKE_STRIP");
767 if(project->first("TEMPLATE") == "lib" && !project->isEmpty("QMAKE_STRIPFLAGS_LIB"))
768 ret += " " + var("QMAKE_STRIPFLAGS_LIB");
769 else if(project->first("TEMPLATE") == "app" && !project->isEmpty("QMAKE_STRIPFLAGS_APP"))
770 ret += " " + var("QMAKE_STRIPFLAGS_APP");
771 if(bundle)
772 ret = " \"" + dst_targ + "/Contents/MacOS/$(QMAKE_TARGET)\"";
773 else
774 ret += " \"" + dst_targ + "\"";
775 }
776 if(!uninst.isEmpty())
777 uninst.append("\n\t");
778 if(bundle)
779 uninst.append("-$(DEL_FILE) -r \"" + dst_targ + "\"");
780 else
781 uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
782 if(!links.isEmpty()) {
783 for(int i = 0; i < links.size(); ++i) {
784 if(Option::target_mode == Option::TARG_WIN_MODE ||
785 Option::target_mode == Option::TARG_OS2_MODE ||
786 Option::target_mode == Option::TARG_MAC9_MODE) {
787 } else if(Option::target_mode == Option::TARG_UNIX_MODE ||
788 Option::target_mode == Option::TARG_MACX_MODE) {
789 QString link = Option::fixPathToTargetOS(destdir + links[i], false);
790 int lslash = link.lastIndexOf(Option::dir_sep);
791 if(lslash != -1)
792 link = link.right(link.length() - (lslash + 1));
793 QString dst_link = filePrefixRoot(root, fileFixify(targetdir + link, FileFixifyAbsolute));
794 ret += "\n\t-$(SYMLINK) \"$(TARGET)\" \"" + dst_link + "\"";
795 if(!uninst.isEmpty())
796 uninst.append("\n\t");
797 uninst.append("-$(DEL_FILE) \"" + dst_link + "\"");
798 }
799 }
800 }
801 }
802 if(project->first("TEMPLATE") == "lib") {
803 QStringList types;
804 types << "prl" << "libtool" << "pkgconfig";
805 for(int i = 0; i < types.size(); ++i) {
806 const QString type = types.at(i);
807 QString meta;
808 if(type == "prl" && project->isActiveConfig("create_prl") && !project->isActiveConfig("no_install_prl") &&
809 !project->isEmpty("QMAKE_INTERNAL_PRL_FILE"))
810 meta = prlFileName(false);
811 if(type == "libtool" && project->isActiveConfig("create_libtool") && !project->isActiveConfig("compile_libtool"))
812 meta = libtoolFileName(false);
813 if(type == "pkgconfig" && project->isActiveConfig("create_pc"))
814 meta = pkgConfigFileName(false);
815 if(!meta.isEmpty()) {
816 QString src_meta = meta;
817 if(!destdir.isEmpty())
818 src_meta = Option::fixPathToTargetOS(destdir + meta, false);
819 QString dst_meta = filePrefixRoot(root, fileFixify(targetdir + meta, FileFixifyAbsolute));
820 if(!uninst.isEmpty())
821 uninst.append("\n\t");
822 uninst.append("-$(DEL_FILE) \"" + dst_meta + "\"");
823 const QString replace_rule("QMAKE_" + type.toUpper() + "_INSTALL_REPLACE");
824 const QString dst_meta_dir = fileInfo(dst_meta).path();
825 if(!dst_meta_dir.isEmpty()) {
826 if(!ret.isEmpty())
827 ret += "\n\t";
828 ret += mkdir_p_asstring(dst_meta_dir, true);
829 }
830 QString install_meta = "$(INSTALL_FILE) \"" + src_meta + "\" \"" + dst_meta + "\"";
831 if(project->isEmpty(replace_rule) || project->isActiveConfig("no_sed_meta_install")) {
832 if(!ret.isEmpty())
833 ret += "\n\t";
834 ret += "-" + install_meta;
835 } else {
836 if(!ret.isEmpty())
837 ret += "\n\t";
838 ret += "-$(SED)";
839 QStringList replace_rules = project->values(replace_rule);
840 for(int r = 0; r < replace_rules.size(); ++r) {
841 const QString match = project->first(replace_rules.at(r) + ".match"),
842 replace = project->first(replace_rules.at(r) + ".replace");
843 if(!match.isEmpty() /*&& match != replace*/)
844 ret += " -e \"s," + match + "," + replace + ",g\"";
845 }
846 ret += " \"" + src_meta + "\" >\"" + dst_meta + "\"";
847 //ret += " || " + install_meta;
848 }
849 }
850 }
851 }
852 return ret;
853}
854
855QString
856UnixMakefileGenerator::escapeFilePath(const QString &path) const
857{
858 QString ret = path;
859 if(!ret.isEmpty()) {
860 ret = unescapeFilePath(ret).replace(QLatin1Char(' '), QLatin1String("\\ "));
861 debug_msg(2, "EscapeFilePath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData());
862 }
863 return ret;
864}
865
866QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.