diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /qmake/generators/unix | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'qmake/generators/unix')
-rw-r--r-- | qmake/generators/unix/unixmake.cpp | 865 | ||||
-rw-r--r-- | qmake/generators/unix/unixmake.h | 88 | ||||
-rw-r--r-- | qmake/generators/unix/unixmake2.cpp | 1478 |
3 files changed, 2431 insertions, 0 deletions
diff --git a/qmake/generators/unix/unixmake.cpp b/qmake/generators/unix/unixmake.cpp new file mode 100644 index 0000000..4970dc8 --- /dev/null +++ b/qmake/generators/unix/unixmake.cpp @@ -0,0 +1,865 @@ +/**************************************************************************** + ** + ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) + ** + ** This file is part of the qmake application of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ + ** + ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + ** + ****************************************************************************/ + +#include "unixmake.h" +#include "option.h" +#include <qregexp.h> +#include <qfile.h> +#include <qhash.h> +#include <qdir.h> +#include <time.h> +#include <qdebug.h> + +QT_BEGIN_NAMESPACE + +void +UnixMakefileGenerator::init() +{ + if(init_flag) + return; + init_flag = true; + + if(project->isEmpty("QMAKE_EXTENSION_SHLIB")) { + if(project->isEmpty("QMAKE_CYGWIN_SHLIB")) { + project->values("QMAKE_EXTENSION_SHLIB").append("so"); + } else { + project->values("QMAKE_EXTENSION_SHLIB").append("dll"); + } + } + + if(!project->isEmpty("QMAKE_FAILED_REQUIREMENTS")) /* no point */ + return; + + QStringList &configs = project->values("CONFIG"); + if(project->isEmpty("ICON") && !project->isEmpty("RC_FILE")) + project->values("ICON") = project->values("RC_FILE"); + if(project->isEmpty("QMAKE_EXTENSION_PLUGIN")) + project->values("QMAKE_EXTENSION_PLUGIN").append(project->first("QMAKE_EXTENSION_SHLIB")); + if(project->isEmpty("QMAKE_COPY_FILE")) + project->values("QMAKE_COPY_FILE").append("$(COPY)"); + if(project->isEmpty("QMAKE_STREAM_EDITOR")) + project->values("QMAKE_STREAM_EDITOR").append("sed"); + if(project->isEmpty("QMAKE_COPY_DIR")) + project->values("QMAKE_COPY_DIR").append("$(COPY) -R"); + if(project->isEmpty("QMAKE_INSTALL_FILE")) + project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)"); + if(project->isEmpty("QMAKE_INSTALL_DIR")) + project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)"); + if(project->isEmpty("QMAKE_INSTALL_PROGRAM")) + project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)"); + if(project->isEmpty("QMAKE_LIBTOOL")) + project->values("QMAKE_LIBTOOL").append("libtool --silent"); + if(project->isEmpty("QMAKE_SYMBOLIC_LINK")) + project->values("QMAKE_SYMBOLIC_LINK").append("ln -sf"); + + /* this should probably not be here, but I'm using it to wrap the .t files */ + if(project->first("TEMPLATE") == "app") + project->values("QMAKE_APP_FLAG").append("1"); + else if(project->first("TEMPLATE") == "lib") + project->values("QMAKE_LIB_FLAG").append("1"); + else if(project->first("TEMPLATE") == "subdirs") { + MakefileGenerator::init(); + if(project->isEmpty("MAKEFILE")) + project->values("MAKEFILE").append("Makefile"); + if(project->isEmpty("QMAKE_QMAKE")) + project->values("QMAKE_QMAKE").append("qmake"); + if(project->values("QMAKE_INTERNAL_QMAKE_DEPS").indexOf("qmake_all") == -1) + project->values("QMAKE_INTERNAL_QMAKE_DEPS").append("qmake_all"); + return; /* subdirs is done */ + } + + //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET + if(!project->isEmpty("TARGET")) { + project->values("TARGET") = escapeFilePaths(project->values("TARGET")); + QString targ = unescapeFilePath(project->first("TARGET")); + int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep)); + if(slsh != -1) { + if(project->isEmpty("DESTDIR")) + project->values("DESTDIR").append(""); + else if(project->first("DESTDIR").right(1) != Option::dir_sep) + project->values("DESTDIR") = QStringList(project->first("DESTDIR") + Option::dir_sep); + project->values("DESTDIR") = QStringList(project->first("DESTDIR") + targ.left(slsh+1)); + project->values("TARGET") = QStringList(targ.mid(slsh+1)); + } + } + + project->values("QMAKE_ORIG_TARGET") = project->values("TARGET"); + project->values("QMAKE_ORIG_DESTDIR") = project->values("DESTDIR"); + project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS")); + if((!project->isEmpty("QMAKE_LIB_FLAG") && !project->isActiveConfig("staticlib")) || + (project->isActiveConfig("qt") && project->isActiveConfig("plugin"))) { + if(configs.indexOf("dll") == -1) configs.append("dll"); + } else if(!project->isEmpty("QMAKE_APP_FLAG") || project->isActiveConfig("dll")) { + configs.removeAll("staticlib"); + } + if(!project->isEmpty("QMAKE_INCREMENTAL")) + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_INCREMENTAL"); + else if(!project->isEmpty("QMAKE_LFLAGS_PREBIND") && + !project->values("QMAKE_LIB_FLAG").isEmpty() && + project->isActiveConfig("dll")) + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_PREBIND"); + if(!project->isEmpty("QMAKE_INCDIR")) + project->values("INCLUDEPATH") += project->values("QMAKE_INCDIR"); + if(!project->isEmpty("QMAKE_LIBDIR")) { + const QStringList &libdirs = project->values("QMAKE_LIBDIR"); + for(int i = 0; i < libdirs.size(); ++i) { + if(!project->isEmpty("QMAKE_LFLAGS_RPATH") && project->isActiveConfig("rpath_libdirs")) + project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATH") + libdirs[i]; + if (project->isActiveConfig("rvct_linker")) { + project->values("QMAKE_LIBDIR_FLAGS") += "--userlibpath " + escapeFilePath(libdirs[i]); + } else { + project->values("QMAKE_LIBDIR_FLAGS") += "-L" + escapeFilePath(libdirs[i]); + } + } + } + if(project->isActiveConfig("macx") && !project->isEmpty("QMAKE_FRAMEWORKPATH")) { + const QStringList &fwdirs = project->values("QMAKE_FRAMEWORKPATH"); + for(int i = 0; i < fwdirs.size(); ++i) { + project->values("QMAKE_FRAMEWORKPATH_FLAGS") += "-F" + escapeFilePath(fwdirs[i]); + } + } + if(!project->isEmpty("QMAKE_RPATHDIR")) { + const QStringList &rpathdirs = project->values("QMAKE_RPATHDIR"); + for(int i = 0; i < rpathdirs.size(); ++i) { + if(!project->isEmpty("QMAKE_LFLAGS_RPATH")) + project->values("QMAKE_LFLAGS") += var("QMAKE_LFLAGS_RPATH") + escapeFilePath(QFileInfo(rpathdirs[i]).absoluteFilePath()); + } + } + + project->values("QMAKE_FILETAGS") << "SOURCES" << "GENERATED_SOURCES" << "TARGET" << "DESTDIR"; + if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) { + const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); + for(int i = 0; i < quc.size(); ++i) + project->values("QMAKE_FILETAGS") += project->values(quc[i]+".input"); + } + + if(project->isActiveConfig("GNUmake") && !project->isEmpty("QMAKE_CFLAGS_DEPS")) + include_deps = true; //do not generate deps + if(project->isActiveConfig("compile_libtool")) + Option::obj_ext = ".lo"; //override the .o + + MakefileGenerator::init(); + + QString comps[] = { "C", "CXX", "OBJC", "OBJCXX", QString() }; + for(int i = 0; !comps[i].isNull(); i++) { + QString compile_flag = var("QMAKE_COMPILE_FLAG"); + if(compile_flag.isEmpty()) + compile_flag = "-c"; + + if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) { + QString pchFlags = var("QMAKE_" + comps[i] + "FLAGS_USE_PRECOMPILE"); + + QString pchBaseName; + if(!project->isEmpty("PRECOMPILED_DIR")) { + pchBaseName = Option::fixPathToTargetOS(project->first("PRECOMPILED_DIR")); + if(!pchBaseName.endsWith(Option::dir_sep)) + pchBaseName += Option::dir_sep; + } + pchBaseName += project->first("QMAKE_ORIG_TARGET"); + + // replace place holders + pchFlags = pchFlags.replace("${QMAKE_PCH_INPUT}", + fileFixify(project->first("PRECOMPILED_HEADER"))); + pchFlags = pchFlags.replace("${QMAKE_PCH_OUTPUT_BASE}", pchBaseName); + if (project->isActiveConfig("icc_pch_style")) { + // icc style + pchFlags = pchFlags.replace("${QMAKE_PCH_OUTPUT}", + pchBaseName + project->first("QMAKE_PCH_OUTPUT_EXT")); + } + + if (!pchFlags.isEmpty()) + compile_flag += " " + pchFlags; + } + + QString cflags; + if(comps[i] == "OBJC" || comps[i] == "OBJCXX") + cflags += " $(CFLAGS)"; + else + cflags += " $(" + comps[i] + "FLAGS)"; + compile_flag += cflags + " $(INCPATH)"; + + QString compiler = comps[i]; + if (compiler == "C") + compiler = "CC"; + + QString runComp = "QMAKE_RUN_" + compiler; + if(project->isEmpty(runComp)) + project->values(runComp).append("$(" + compiler + ") " + compile_flag + " -o $obj $src"); + QString runCompImp = "QMAKE_RUN_" + compiler + "_IMP"; + if(project->isEmpty(runCompImp)) + project->values(runCompImp).append("$(" + compiler + ") " + compile_flag + " -o \"$@\" \"$<\""); + } + + if(project->isActiveConfig("macx") && !project->isEmpty("TARGET") && !project->isActiveConfig("compile_libtool") && + ((project->isActiveConfig("build_pass") || project->isEmpty("BUILDS")))) { + QString bundle; + if(project->isActiveConfig("bundle") && !project->isEmpty("QMAKE_BUNDLE_EXTENSION")) { + bundle = unescapeFilePath(project->first("TARGET")); + if(!project->isEmpty("QMAKE_BUNDLE_NAME")) + bundle = unescapeFilePath(project->first("QMAKE_BUNDLE_NAME")); + if(!bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION"))) + bundle += project->first("QMAKE_BUNDLE_EXTENSION"); + } else if(project->first("TEMPLATE") == "app" && project->isActiveConfig("app_bundle")) { + bundle = unescapeFilePath(project->first("TARGET")); + if(!project->isEmpty("QMAKE_APPLICATION_BUNDLE_NAME")) + bundle = unescapeFilePath(project->first("QMAKE_APPLICATION_BUNDLE_NAME")); + if(!bundle.endsWith(".app")) + bundle += ".app"; + if(project->isEmpty("QMAKE_BUNDLE_LOCATION")) + project->values("QMAKE_BUNDLE_LOCATION").append("Contents/MacOS"); + project->values("QMAKE_PKGINFO").append(project->first("DESTDIR") + bundle + "/Contents/PkgInfo"); + project->values("QMAKE_BUNDLE_RESOURCE_FILE").append(project->first("DESTDIR") + bundle + "/Contents/Resources/empty.lproj"); + } else if(project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") && + ((!project->isActiveConfig("plugin") && project->isActiveConfig("lib_bundle")) || + (project->isActiveConfig("plugin") && project->isActiveConfig("plugin_bundle")))) { + bundle = unescapeFilePath(project->first("TARGET")); + if(project->isActiveConfig("plugin")) { + if(!project->isEmpty("QMAKE_PLUGIN_BUNDLE_NAME")) + bundle = unescapeFilePath(project->first("QMAKE_PLUGIN_BUNDLE_NAME")); + if(!project->isEmpty("QMAKE_BUNDLE_EXTENSION") && !bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION"))) + bundle += project->first("QMAKE_BUNDLE_EXTENSION"); + else if(!bundle.endsWith(".plugin")) + bundle += ".plugin"; + if(!project->isEmpty("QMAKE_BUNDLE_LOCATION")) + project->values("QMAKE_BUNDLE_LOCATION").append("Contents/MacOS"); + } else { + if(!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME")) + bundle = unescapeFilePath(project->first("QMAKE_FRAMEWORK_BUNDLE_NAME")); + if(!project->isEmpty("QMAKE_BUNDLE_EXTENSION") && !bundle.endsWith(project->first("QMAKE_BUNDLE_EXTENSION"))) + bundle += project->first("QMAKE_BUNDLE_EXTENSION"); + else if(!bundle.endsWith(".framework")) + bundle += ".framework"; + } + } + if(!bundle.isEmpty()) { + project->values("QMAKE_BUNDLE") = QStringList(bundle); + project->values("ALL_DEPS") += project->first("QMAKE_PKGINFO"); + project->values("ALL_DEPS") += project->first("QMAKE_BUNDLE_RESOURCE_FILE"); + } else { + project->values("QMAKE_BUNDLE").clear(); + project->values("QMAKE_BUNDLE_LOCATION").clear(); + } + } else { //no bundling here + project->values("QMAKE_BUNDLE").clear(); + project->values("QMAKE_BUNDLE_LOCATION").clear(); + } + + if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES")) + project->values("DISTFILES") += project->values("QMAKE_INTERNAL_INCLUDED_FILES"); + project->values("DISTFILES") += project->projectFile(); + + init2(); + project->values("QMAKE_INTERNAL_PRL_LIBS") << "QMAKE_LIBDIR_FLAGS" << "QMAKE_FRAMEWORKPATH_FLAGS" << "QMAKE_LIBS"; + if(!project->isEmpty("QMAKE_MAX_FILES_PER_AR")) { + bool ok; + int max_files = project->first("QMAKE_MAX_FILES_PER_AR").toInt(&ok); + QStringList ar_sublibs, objs = project->values("OBJECTS"); + if(ok && max_files > 5 && max_files < (int)objs.count()) { + QString lib; + for(int i = 0, obj_cnt = 0, lib_cnt = 0; i != objs.size(); ++i) { + if((++obj_cnt) >= max_files) { + if(lib_cnt) { + lib.sprintf("lib%s-tmp%d.a", + project->first("QMAKE_ORIG_TARGET").toLatin1().constData(), lib_cnt); + ar_sublibs << lib; + obj_cnt = 0; + } + lib_cnt++; + } + } + } + if(!ar_sublibs.isEmpty()) { + project->values("QMAKE_AR_SUBLIBS") = ar_sublibs; + project->values("QMAKE_INTERNAL_PRL_LIBS") << "QMAKE_AR_SUBLIBS"; + } + } + + if(project->isActiveConfig("compile_libtool")) { + const QString libtoolify[] = { "QMAKE_RUN_CC", "QMAKE_RUN_CC_IMP", + "QMAKE_RUN_CXX", "QMAKE_RUN_CXX_IMP", + "QMAKE_LINK_THREAD", "QMAKE_LINK", "QMAKE_AR_CMD", "QMAKE_LINK_SHLIB_CMD", + QString() }; + for(int i = 0; !libtoolify[i].isNull(); i++) { + QStringList &l = project->values(libtoolify[i]); + if(!l.isEmpty()) { + QString libtool_flags, comp_flags; + if(libtoolify[i].startsWith("QMAKE_LINK") || libtoolify[i] == "QMAKE_AR_CMD") { + libtool_flags += " --mode=link"; + if(project->isActiveConfig("staticlib")) { + libtool_flags += " -static"; + } else { + if(!project->isEmpty("QMAKE_LIB_FLAG")) { + int maj = project->first("VER_MAJ").toInt(); + int min = project->first("VER_MIN").toInt(); + int pat = project->first("VER_PAT").toInt(); + comp_flags += " -version-info " + QString::number(10*maj + min) + + ":" + QString::number(pat) + ":0"; + if(libtoolify[i] != "QMAKE_AR_CMD") { + QString rpath = Option::output_dir; + if(!project->isEmpty("DESTDIR")) { + rpath = project->first("DESTDIR"); + if(QDir::isRelativePath(rpath)) + rpath.prepend(Option::output_dir + Option::dir_sep); + } + comp_flags += " -rpath " + Option::fixPathToTargetOS(rpath, false); + } + } + } + if(project->isActiveConfig("plugin")) + libtool_flags += " -module"; + } else { + libtool_flags += " --mode=compile"; + } + l.first().prepend("$(LIBTOOL)" + libtool_flags + " "); + if(!comp_flags.isEmpty()) + l.first() += comp_flags; + } + } + } +} + +void +UnixMakefileGenerator::processPrlVariable(const QString &var, const QStringList &l) +{ + if(var == "QMAKE_PRL_LIBS") { + project->values("QMAKE_CURRENT_PRL_LIBS") += l; + } else + MakefileGenerator::processPrlVariable(var, l); +} + +QStringList +&UnixMakefileGenerator::findDependencies(const QString &file) +{ + QStringList &ret = MakefileGenerator::findDependencies(file); + // Note: The QMAKE_IMAGE_COLLECTION file have all images + // as dependency, so don't add precompiled header then + if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER") + && file != project->first("QMAKE_IMAGE_COLLECTION")) { + QString header_prefix; + if(!project->isEmpty("PRECOMPILED_DIR")) + header_prefix = project->first("PRECOMPILED_DIR"); + header_prefix += project->first("QMAKE_ORIG_TARGET") + project->first("QMAKE_PCH_OUTPUT_EXT"); + if (project->isActiveConfig("icc_pch_style")) { + // icc style + for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) { + if(file.endsWith(*it)) { + ret += header_prefix; + break; + } + } + } else { + // gcc style + header_prefix += Option::dir_sep + project->first("QMAKE_PRECOMP_PREFIX"); + for(QStringList::Iterator it = Option::c_ext.begin(); it != Option::c_ext.end(); ++it) { + if(file.endsWith(*it)) { + if(!project->isEmpty("QMAKE_CFLAGS_PRECOMPILE")) { + QString precomp_c_h = header_prefix + "c"; + if(!ret.contains(precomp_c_h)) + ret += precomp_c_h; + } + if(project->isActiveConfig("objective_c")) { + if(!project->isEmpty("QMAKE_OBJCFLAGS_PRECOMPILE")) { + QString precomp_objc_h = header_prefix + "objective-c"; + if(!ret.contains(precomp_objc_h)) + ret += precomp_objc_h; + } + if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) { + QString precomp_objcpp_h = header_prefix + "objective-c++"; + if(!ret.contains(precomp_objcpp_h)) + ret += precomp_objcpp_h; + } + } + break; + } + } + for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) { + if(file.endsWith(*it)) { + if(!project->isEmpty("QMAKE_CXXFLAGS_PRECOMPILE")) { + QString precomp_cpp_h = header_prefix + "c++"; + if(!ret.contains(precomp_cpp_h)) + ret += precomp_cpp_h; + } + if(project->isActiveConfig("objective_c")) { + if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) { + QString precomp_objcpp_h = header_prefix + "objective-c++"; + if(!ret.contains(precomp_objcpp_h)) + ret += precomp_objcpp_h; + } + } + break; + } + } + } + } + return ret; +} + +bool +UnixMakefileGenerator::findLibraries() +{ + QList<QMakeLocalFileName> libdirs, frameworkdirs; + frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks")); + frameworkdirs.append(QMakeLocalFileName("/Library/Frameworks")); + const QString lflags[] = { "QMAKE_LIBDIR_FLAGS", "QMAKE_FRAMEWORKPATH_FLAGS", "QMAKE_LFLAGS", "QMAKE_LIBS", QString() }; + for(int i = 0; !lflags[i].isNull(); i++) { + QStringList &l = project->values(lflags[i]); + for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { + bool do_suffix = true; + QString stub, dir, extn, opt = (*it).trimmed(); + if(opt.startsWith("-")) { + if(opt.startsWith("-L")) { + QMakeLocalFileName f(opt.right(opt.length()-2)); + if(!libdirs.contains(f)) + libdirs.append(f); + } else if(opt.startsWith("-l")) { + if (project->isActiveConfig("rvct_linker")) { + (*it) = "lib" + opt.mid(2) + ".so"; + } else { + stub = opt.mid(2); + } + } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) { + frameworkdirs.append(QMakeLocalFileName(opt.right(opt.length()-2))); + } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) { + if(opt.length() > 11) { + opt = opt.mid(11); + } else { + ++it; + opt = (*it); + } + do_suffix = false; + extn = ""; + dir = "/System/Library/Frameworks/" + opt + ".framework/"; + stub = opt; + } + } else { + extn = dir = ""; + stub = opt; + int slsh = opt.lastIndexOf(Option::dir_sep); + if(slsh != -1) { + dir = opt.left(slsh); + stub = opt.mid(slsh+1); + } + QRegExp stub_reg("^.*lib(" + stub + "[^./=]*)\\.(.*)$"); + if(stub_reg.exactMatch(stub)) { + stub = stub_reg.cap(1); + extn = stub_reg.cap(2); + } + } + if(!stub.isEmpty()) { + if(do_suffix && !project->isEmpty("QMAKE_" + stub.toUpper() + "_SUFFIX")) + stub += project->first("QMAKE_" + stub.toUpper() + "_SUFFIX"); + bool found = false; + QStringList extens; + if(!extn.isNull()) + extens << extn; + else + extens << project->values("QMAKE_EXTENSION_SHLIB").first() << "a"; + for(QStringList::Iterator extit = extens.begin(); extit != extens.end(); ++extit) { + if(dir.isNull()) { + QString lib_stub; + for(QList<QMakeLocalFileName>::Iterator dep_it = libdirs.begin(); dep_it != libdirs.end(); ++dep_it) { + if(exists((*dep_it).local() + Option::dir_sep + "lib" + stub + + "." + (*extit))) { + lib_stub = stub; + break; + } + } + if(!lib_stub.isNull()) { + (*it) = "-l" + lib_stub; + found = true; + break; + } + } else { + if(exists("lib" + stub + "." + (*extit))) { + (*it) = "lib" + stub + "." + (*extit); + found = true; + break; + } + } + } + if(!found && project->isActiveConfig("compile_libtool")) { + for(int dep_i = 0; dep_i < libdirs.size(); ++dep_i) { + if(exists(libdirs[dep_i].local() + Option::dir_sep + "lib" + stub + Option::libtool_ext)) { + (*it) = libdirs[dep_i].real() + Option::dir_sep + "lib" + stub + Option::libtool_ext; + found = true; + break; + } + } + } + } + } + } + return false; +} + +QString linkLib(const QString &file, const QString &libName) { + QString ret; + QRegExp reg("^.*lib(" + QRegExp::escape(libName) + "[^./=]*).*$"); + if(reg.exactMatch(file)) + ret = "-l" + reg.cap(1); + return ret; +} + +void +UnixMakefileGenerator::processPrlFiles() +{ + QList<QMakeLocalFileName> libdirs, frameworkdirs; + frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks")); + frameworkdirs.append(QMakeLocalFileName("/Library/Frameworks")); + const QString lflags[] = { "QMAKE_LIBDIR_FLAGS", "QMAKE_FRAMEWORKPATH_FLAGS", "QMAKE_LFLAGS", "QMAKE_LIBS", QString() }; + for(int i = 0; !lflags[i].isNull(); i++) { + QStringList &l = project->values(lflags[i]); + for(int lit = 0; lit < l.size(); ++lit) { + QString opt = l.at(lit).trimmed(); + if(opt.startsWith("-")) { + if(opt.startsWith("-L")) { + QMakeLocalFileName l(opt.right(opt.length()-2)); + if(!libdirs.contains(l)) + libdirs.append(l); + } else if(opt.startsWith("-l")) { + QString lib = opt.right(opt.length() - 2); + for(int dep_i = 0; dep_i < libdirs.size(); ++dep_i) { + const QMakeLocalFileName &lfn = libdirs[dep_i]; + if(!project->isActiveConfig("compile_libtool")) { //give them the .libs.. + QString la = lfn.local() + Option::dir_sep + "lib" + lib + Option::libtool_ext; + if(exists(la) && QFile::exists(lfn.local() + Option::dir_sep + ".libs")) { + QString dot_libs = lfn.real() + Option::dir_sep + ".libs"; + l.append("-L" + dot_libs); + libdirs.append(QMakeLocalFileName(dot_libs)); + } + } + + QString prl = lfn.local() + Option::dir_sep + "lib" + lib; + if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX")) + prl += project->first("QMAKE_" + lib.toUpper() + "_SUFFIX"); + if(processPrlFile(prl)) { + if(prl.startsWith(lfn.local())) + prl.replace(0, lfn.local().length(), lfn.real()); + opt = linkLib(prl, lib); + break; + } + } + } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) { + QMakeLocalFileName f(opt.right(opt.length()-2)); + if(!frameworkdirs.contains(f)) + frameworkdirs.append(f); + } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) { + if(opt.length() > 11) + opt = opt.mid(11); + else + opt = l.at(++lit); + opt = opt.trimmed(); + const QList<QMakeLocalFileName> dirs = frameworkdirs + libdirs; + for(int dep_i = 0; dep_i < dirs.size(); ++dep_i) { + QString prl = dirs[dep_i].local() + "/" + opt + ".framework/" + opt + Option::prl_ext; + if(processPrlFile(prl)) + break; + } + } + } else if(!opt.isNull()) { + QString lib = opt; + processPrlFile(lib); +#if 0 + if(ret) + opt = linkLib(lib, ""); +#endif + if(!opt.isEmpty()) + l.replaceInStrings(lib, opt); + } + + QStringList &prl_libs = project->values("QMAKE_CURRENT_PRL_LIBS"); + if(!prl_libs.isEmpty()) { + for(int prl = 0; prl < prl_libs.size(); ++prl) + l.insert(lit+prl+1, prl_libs.at(prl)); + prl_libs.clear(); + } + } + + //merge them into a logical order + if(!project->isActiveConfig("no_smart_library_merge") && !project->isActiveConfig("no_lflags_merge")) { + QStringList lflags; + for(int lit = 0; lit < l.size(); ++lit) { + QString opt = l.at(lit).trimmed(); + if(opt.startsWith("-")) { + if(opt.startsWith("-L") || + (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F"))) { + if(lit == 0 || l.lastIndexOf(opt, lit-1) == -1) + lflags.append(opt); + } else if(opt.startsWith("-l")) { + if(lit == l.size()-1 || l.indexOf(opt, lit+1) == -1) + lflags.append(opt); + } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) { + if(opt.length() > 11) + opt = opt.mid(11); + else + opt = l.at(++lit); + bool found = false; + for(int x = lit+1; x < l.size(); ++x) { + QString xf = l.at(x); + if(xf.startsWith("-framework")) { + QString framework; + if(xf.length() > 11) + framework = xf.mid(11); + else + framework = l.at(++x); + if(framework == opt) { + found = true; + break; + } + } + } + if(!found) { + lflags.append("-framework"); + lflags.append(opt); + } + } else { + lflags.append(opt); + } + } else if(!opt.isNull()) { + if(lit == 0 || l.lastIndexOf(opt, lit-1) == -1) + lflags.append(opt); + } + } + l = lflags; + } + } +} + +QString +UnixMakefileGenerator::defaultInstall(const QString &t) +{ + if(t != "target" || project->first("TEMPLATE") == "subdirs") + return QString(); + + bool bundle = false; + const QString root = "$(INSTALL_ROOT)"; + QStringList &uninst = project->values(t + ".uninstall"); + QString ret, destdir=project->first("DESTDIR"); + QString targetdir = Option::fixPathToTargetOS(project->first("target.path"), false); + if(!destdir.isEmpty() && destdir.right(1) != Option::dir_sep) + destdir += Option::dir_sep; + targetdir = fileFixify(targetdir, FileFixifyAbsolute); + if(targetdir.right(1) != Option::dir_sep) + targetdir += Option::dir_sep; + + QStringList links; + QString target="$(TARGET)"; + QStringList &targets = project->values(t + ".targets"); + if(!project->isEmpty("QMAKE_BUNDLE")) { + target = project->first("QMAKE_BUNDLE"); + bundle = true; + } else if(project->first("TEMPLATE") == "app") { + target = "$(QMAKE_TARGET)"; + } else if(project->first("TEMPLATE") == "lib") { + if(project->isEmpty("QMAKE_CYGWIN_SHLIB")) { + if(!project->isActiveConfig("staticlib") && !project->isActiveConfig("plugin")) { + if(project->isEmpty("QMAKE_HPUX_SHLIB")) { + links << "$(TARGET0)" << "$(TARGET1)" << "$(TARGET2)"; + } else { + links << "$(TARGET0)"; + } + } + } + } + for(int i = 0; i < targets.size(); ++i) { + QString src = targets.at(i), + dst = filePrefixRoot(root, targetdir + src.section('/', -1)); + if(!ret.isEmpty()) + ret += "\n\t"; + ret += "-$(INSTALL_FILE) \"" + src + "\" \"" + dst + "\""; + if(!uninst.isEmpty()) + uninst.append("\n\t"); + uninst.append("-$(DEL_FILE) \"" + dst + "\""); + } + + if(!bundle && project->isActiveConfig("compile_libtool")) { + QString src_targ = target; + if(src_targ == "$(TARGET)") + src_targ = "$(TARGETL)"; + QString dst_dir = fileFixify(targetdir, FileFixifyAbsolute); + if(QDir::isRelativePath(dst_dir)) + dst_dir = Option::fixPathToTargetOS(Option::output_dir + Option::dir_sep + dst_dir); + ret = "-$(LIBTOOL) --mode=install cp \"" + src_targ + "\" \"" + filePrefixRoot(root, dst_dir) + "\""; + uninst.append("-$(LIBTOOL) --mode=uninstall \"" + src_targ + "\""); + } else { + QString src_targ = target; + if(!destdir.isEmpty()) + src_targ = Option::fixPathToTargetOS(destdir + target, false); + QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + target, FileFixifyAbsolute)); + if(bundle) { + if(!ret.isEmpty()) + ret += "\n\t"; + ret += "$(DEL_FILE) -r \"" + dst_targ + "\"\n\t"; + } + if(!ret.isEmpty()) + ret += "\n\t"; + + QString copy_cmd("-"); + if (bundle) + copy_cmd += "$(INSTALL_DIR)"; + else if (project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib")) + copy_cmd += "$(INSTALL_FILE)"; + else + copy_cmd += "$(INSTALL_PROGRAM)"; + copy_cmd += " \"" + src_targ + "\" \"" + dst_targ + "\""; + if(project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") + && project->values(t + ".CONFIG").indexOf("fix_rpath") != -1) { + if(!project->isEmpty("QMAKE_FIX_RPATH")) { + ret += copy_cmd; + ret += "\n\t-" + var("QMAKE_FIX_RPATH") + " \"" + + dst_targ + "\" \"" + dst_targ + "\""; + } else if(!project->isEmpty("QMAKE_LFLAGS_RPATH")) { + ret += "-$(LINK) $(LFLAGS) " + var("QMAKE_LFLAGS_RPATH") + targetdir + " -o \"" + + dst_targ + "\" $(OBJECTS) $(LIBS) $(OBJCOMP)"; + } else { + ret += copy_cmd; + } + } else { + ret += copy_cmd; + } + + if(project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib")) { + if(!project->isEmpty("QMAKE_RANLIB")) + ret += QString("\n\t$(RANLIB) \"") + dst_targ + "\""; + } else if(!project->isActiveConfig("debug") && !project->isActiveConfig("nostrip") && !project->isEmpty("QMAKE_STRIP")) { + ret += "\n\t-$(STRIP)"; + if(project->first("TEMPLATE") == "lib" && !project->isEmpty("QMAKE_STRIPFLAGS_LIB")) + ret += " " + var("QMAKE_STRIPFLAGS_LIB"); + else if(project->first("TEMPLATE") == "app" && !project->isEmpty("QMAKE_STRIPFLAGS_APP")) + ret += " " + var("QMAKE_STRIPFLAGS_APP"); + if(bundle) + ret = " \"" + dst_targ + "/Contents/MacOS/$(QMAKE_TARGET)\""; + else + ret += " \"" + dst_targ + "\""; + } + if(!uninst.isEmpty()) + uninst.append("\n\t"); + if(bundle) + uninst.append("-$(DEL_FILE) -r \"" + dst_targ + "\""); + else + uninst.append("-$(DEL_FILE) \"" + dst_targ + "\""); + if(!links.isEmpty()) { + for(int i = 0; i < links.size(); ++i) { + if(Option::target_mode == Option::TARG_WIN_MODE || + Option::target_mode == Option::TARG_MAC9_MODE) { + } else if(Option::target_mode == Option::TARG_UNIX_MODE || + Option::target_mode == Option::TARG_MACX_MODE) { + QString link = Option::fixPathToTargetOS(destdir + links[i], false); + int lslash = link.lastIndexOf(Option::dir_sep); + if(lslash != -1) + link = link.right(link.length() - (lslash + 1)); + QString dst_link = filePrefixRoot(root, fileFixify(targetdir + link, FileFixifyAbsolute)); + ret += "\n\t-$(SYMLINK) \"$(TARGET)\" \"" + dst_link + "\""; + if(!uninst.isEmpty()) + uninst.append("\n\t"); + uninst.append("-$(DEL_FILE) \"" + dst_link + "\""); + } + } + } + } + if(project->first("TEMPLATE") == "lib") { + QStringList types; + types << "prl" << "libtool" << "pkgconfig"; + for(int i = 0; i < types.size(); ++i) { + const QString type = types.at(i); + QString meta; + if(type == "prl" && project->isActiveConfig("create_prl") && !project->isActiveConfig("no_install_prl") && + !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) + meta = prlFileName(false); + if(type == "libtool" && project->isActiveConfig("create_libtool") && !project->isActiveConfig("compile_libtool")) + meta = libtoolFileName(false); + if(type == "pkgconfig" && project->isActiveConfig("create_pc")) + meta = pkgConfigFileName(false); + if(!meta.isEmpty()) { + QString src_meta = meta; + if(!destdir.isEmpty()) + src_meta = Option::fixPathToTargetOS(destdir + meta, false); + QString dst_meta = filePrefixRoot(root, fileFixify(targetdir + meta, FileFixifyAbsolute)); + if(!uninst.isEmpty()) + uninst.append("\n\t"); + uninst.append("-$(DEL_FILE) \"" + dst_meta + "\""); + const QString replace_rule("QMAKE_" + type.toUpper() + "_INSTALL_REPLACE"); + const QString dst_meta_dir = fileInfo(dst_meta).path(); + if(!dst_meta_dir.isEmpty()) { + if(!ret.isEmpty()) + ret += "\n\t"; + ret += mkdir_p_asstring(dst_meta_dir, true); + } + QString install_meta = "$(INSTALL_FILE) \"" + src_meta + "\" \"" + dst_meta + "\""; + if(project->isEmpty(replace_rule) || project->isActiveConfig("no_sed_meta_install")) { + if(!ret.isEmpty()) + ret += "\n\t"; + ret += "-" + install_meta; + } else { + if(!ret.isEmpty()) + ret += "\n\t"; + ret += "-$(SED)"; + QStringList replace_rules = project->values(replace_rule); + for(int r = 0; r < replace_rules.size(); ++r) { + const QString match = project->first(replace_rules.at(r) + ".match"), + replace = project->first(replace_rules.at(r) + ".replace"); + if(!match.isEmpty() /*&& match != replace*/) + ret += " -e \"s," + match + "," + replace + ",g\""; + } + ret += " \"" + src_meta + "\" >\"" + dst_meta + "\""; + //ret += " || " + install_meta; + } + } + } + } + return ret; +} + +QString +UnixMakefileGenerator::escapeFilePath(const QString &path) const +{ + QString ret = path; + if(!ret.isEmpty()) { + ret = unescapeFilePath(ret).replace(QLatin1Char(' '), QLatin1String("\\ ")); + debug_msg(2, "EscapeFilePath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData()); + } + return ret; +} + +QT_END_NAMESPACE diff --git a/qmake/generators/unix/unixmake.h b/qmake/generators/unix/unixmake.h new file mode 100644 index 0000000..a1c6233 --- /dev/null +++ b/qmake/generators/unix/unixmake.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UNIXMAKE_H +#define UNIXMAKE_H + +#include "makefile.h" + +QT_BEGIN_NAMESPACE + +class UnixMakefileGenerator : public MakefileGenerator +{ + bool init_flag, include_deps; + bool writeMakefile(QTextStream &); + QString libtoolFileName(bool fixify=true); + void writeLibtoolFile(); // for libtool + QString pkgConfigPrefix() const; + QString pkgConfigFileName(bool fixify=true); + QString pkgConfigFixPath(QString) const; + void writePkgConfigFile(); // for pkg-config + void writePrlFile(QTextStream &); + +public: + UnixMakefileGenerator(); + ~UnixMakefileGenerator(); + +protected: + virtual bool doPrecompiledHeaders() const { return project->isActiveConfig("precompile_header"); } + virtual bool doDepends() const { return !include_deps && !Option::mkfile::do_stub_makefile && MakefileGenerator::doDepends(); } + virtual QString defaultInstall(const QString &); + virtual void processPrlVariable(const QString &, const QStringList &); + virtual void processPrlFiles(); + + virtual bool findLibraries(); + virtual QString escapeFilePath(const QString &path) const; + virtual QStringList &findDependencies(const QString &); + virtual void init(); + + void writeMakeParts(QTextStream &); + +private: + void init2(); +}; + +inline UnixMakefileGenerator::~UnixMakefileGenerator() +{ } + +QT_END_NAMESPACE + +#endif // UNIXMAKE_H diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp new file mode 100644 index 0000000..9787075 --- /dev/null +++ b/qmake/generators/unix/unixmake2.cpp @@ -0,0 +1,1478 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "unixmake.h" +#include "option.h" +#include "meta.h" +#include <qregexp.h> +#include <qbytearray.h> +#include <qfile.h> +#include <qdir.h> +#include <qdatetime.h> +#include <qdebug.h> +#include <time.h> + +QT_BEGIN_NAMESPACE + +UnixMakefileGenerator::UnixMakefileGenerator() : MakefileGenerator(), init_flag(false), include_deps(false) +{ + +} + +void +UnixMakefileGenerator::writePrlFile(QTextStream &t) +{ + MakefileGenerator::writePrlFile(t); + // libtool support + + if(project->isActiveConfig("create_libtool") && project->first("TEMPLATE") == "lib") { //write .la + if(project->isActiveConfig("compile_libtool")) + warn_msg(WarnLogic, "create_libtool specified with compile_libtool can lead to conflicting .la\n" + "formats, create_libtool has been disabled\n"); + else + writeLibtoolFile(); + } + // pkg-config support + if(project->isActiveConfig("create_pc") && project->first("TEMPLATE") == "lib") + writePkgConfigFile(); +} + +bool +UnixMakefileGenerator::writeMakefile(QTextStream &t) +{ + + writeHeader(t); + if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) { + t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE")) << endl; + QStringList &qut = project->values("QMAKE_EXTRA_TARGETS"); + for(QStringList::ConstIterator it = qut.begin(); it != qut.end(); ++it) + t << *it << " "; + t << "first all clean install distclean uninstall qmake_all:" << "\n\t" + << "@echo \"Some of the required modules (" + << var("QMAKE_FAILED_REQUIREMENTS") << ") are not available.\"" << "\n\t" + << "@echo \"Skipped.\"" << endl << endl; + writeMakeQmake(t); + if(project->isEmpty("QMAKE_NOFORCE")) + t << "FORCE:" << endl << endl; + return true; + } + + if (project->values("TEMPLATE").first() == "app" || + project->values("TEMPLATE").first() == "lib") { + if(Option::mkfile::do_stub_makefile && MakefileGenerator::writeStubMakefile(t)) + return true; + writeMakeParts(t); + return MakefileGenerator::writeMakefile(t); + } else if(project->values("TEMPLATE").first() == "subdirs") { + MakefileGenerator::writeSubDirs(t); + return true; + } + return false; +} + +void +UnixMakefileGenerator::writeMakeParts(QTextStream &t) +{ + QString deps = fileFixify(Option::output.fileName()), target_deps, prl; + bool do_incremental = (project->isActiveConfig("incremental") && + !project->values("QMAKE_INCREMENTAL").isEmpty() && + (!project->values("QMAKE_APP_FLAG").isEmpty() || + (!project->isActiveConfig("staticlib")))), + src_incremental=false; + + t << "####### Compiler, tools and options" << endl << endl; + t << "CC = " << var("QMAKE_CC") << endl; + t << "CXX = " << var("QMAKE_CXX") << endl; + t << "DEFINES = " + << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ") + << varGlue("DEFINES","-D"," -D","") << endl; + t << "CFLAGS = " << var("QMAKE_CFLAGS") << " $(DEFINES)" << endl; + t << "CXXFLAGS = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)" << endl; + t << "INCPATH = " << "-I" << specdir(); + if(!project->isActiveConfig("no_include_pwd")) { + QString pwd = escapeFilePath(fileFixify(qmake_getpwd())); + if(pwd.isEmpty()) + pwd = "."; + t << " -I" << pwd; + } + { + const QStringList &incs = project->values("INCLUDEPATH"); + for(int i = 0; i < incs.size(); ++i) { + QString inc = escapeFilePath(incs.at(i)); + if(!inc.isEmpty()) + t << " " << "-I" << inc; + } + } + if(!project->isEmpty("QMAKE_FRAMEWORKPATH_FLAGS")) + t << " " << var("QMAKE_FRAMEWORKPATH_FLAGS"); + t << endl; + + if(!project->isActiveConfig("staticlib")) { + t << "LINK = " << var("QMAKE_LINK") << endl; + t << "LFLAGS = " << var("QMAKE_LFLAGS") << endl; + t << "LIBS = " << "$(SUBLIBS) " << var("QMAKE_FRAMEWORKDIR_FLAGS") << " " + << var("QMAKE_LIBDIR_FLAGS") << " " << var("QMAKE_LIBS") << endl; + } + + t << "AR = " << var("QMAKE_AR") << endl; + t << "RANLIB = " << var("QMAKE_RANLIB") << endl; + t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : var("QMAKE_QMAKE")) << endl; + t << "TAR = " << var("QMAKE_TAR") << endl; + t << "COMPRESS = " << var("QMAKE_GZIP") << endl; + if(project->isActiveConfig("compile_libtool")) + t << "LIBTOOL = " << var("QMAKE_LIBTOOL") << endl; + t << "COPY = " << var("QMAKE_COPY") << endl; + t << "SED = " << var("QMAKE_STREAM_EDITOR") << endl; + t << "COPY_FILE = " << var("QMAKE_COPY_FILE") << endl; + t << "COPY_DIR = " << var("QMAKE_COPY_DIR") << endl; + t << "STRIP = " << var("QMAKE_STRIP") << endl; + t << "INSTALL_FILE = " << var("QMAKE_INSTALL_FILE") << endl; + t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl; + t << "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl; + + t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl; + t << "SYMLINK = " << var("QMAKE_SYMBOLIC_LINK") << endl; + t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl; + t << "MOVE = " << var("QMAKE_MOVE") << endl; + t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl; + t << "MKDIR = " << var("QMAKE_MKDIR") << endl; + if(!project->isEmpty("QMAKE_MACOSX_DEPLOYMENT_TARGET")) + t << "export MACOSX_DEPLOYMENT_TARGET = " //exported to children processes + << project->first("QMAKE_MACOSX_DEPLOYMENT_TARGET") << endl; + t << endl; + + t << "####### Output directory" << endl << endl; + if (! project->values("OBJECTS_DIR").isEmpty()) + t << "OBJECTS_DIR = " << var("OBJECTS_DIR") << endl; + else + t << "OBJECTS_DIR = ./" << endl; + t << endl; + + /* files */ + t << "####### Files" << endl << endl; + t << "SOURCES = " << valList(escapeFilePaths(project->values("SOURCES"))) << " " + << valList(escapeFilePaths(project->values("GENERATED_SOURCES"))) << endl; + if(do_incremental) { + QStringList &objs = project->values("OBJECTS"), &incrs = project->values("QMAKE_INCREMENTAL"), incrs_out; + t << "OBJECTS = "; + for(QStringList::Iterator objit = objs.begin(); objit != objs.end(); ++objit) { + bool increment = false; + for(QStringList::Iterator incrit = incrs.begin(); incrit != incrs.end(); ++incrit) { + if((*objit).indexOf(QRegExp((*incrit), Qt::CaseSensitive, + QRegExp::Wildcard)) != -1) { + increment = true; + incrs_out.append((*objit)); + break; + } + } + if(!increment) + t << "\\\n\t\t" << (*objit); + } + if(incrs_out.count() == objs.count()) { //we just switched places, no real incrementals to be done! + t << escapeFilePaths(incrs_out).join(" \\\n\t\t") << endl; + } else if(!incrs_out.count()) { + t << endl; + } else { + src_incremental = true; + t << endl; + t << "INCREMENTAL_OBJECTS = " << escapeFilePaths(incrs_out).join(" \\\n\t\t") << endl; + } + } else { + t << "OBJECTS = " << valList(escapeFilePaths(project->values("OBJECTS"))) << endl; + } + if(do_incremental && !src_incremental) + do_incremental = false; + t << "DIST = " << valList(fileFixify(project->values("DISTFILES"))) << endl; + t << "QMAKE_TARGET = " << var("QMAKE_ORIG_TARGET") << endl; + t << "DESTDIR = " << var("DESTDIR") << endl; + if(project->isActiveConfig("compile_libtool")) + t << "TARGETL = " << var("TARGET_la") << endl; + t << "TARGET = " << escapeFilePath(var("TARGET")) << endl; + if(project->isActiveConfig("plugin")) { + t << "TARGETD = " << escapeFilePath(var("TARGET")) << endl; + } else if(!project->isActiveConfig("staticlib") && project->values("QMAKE_APP_FLAG").isEmpty()) { + t << "TARGETA = " << escapeFilePath(var("TARGETA")) << endl; + if(!project->isEmpty("QMAKE_BUNDLE")) { + t << "TARGETD = " << escapeFilePath(var("TARGET_x.y")) << endl; + t << "TARGET0 = " << escapeFilePath(var("TARGET_")) << endl; + } else if(project->isEmpty("QMAKE_HPUX_SHLIB")) { + t << "TARGETD = " << escapeFilePath(var("TARGET_x.y.z")) << endl; + t << "TARGET0 = " << escapeFilePath(var("TARGET_")) << endl; + t << "TARGET1 = " << escapeFilePath(var("TARGET_x")) << endl; + t << "TARGET2 = " << escapeFilePath(var("TARGET_x.y")) << endl; + } else { + t << "TARGETD = " << escapeFilePath(var("TARGET_x")) << endl; + t << "TARGET0 = " << escapeFilePath(var("TARGET_")) << endl; + } + } + writeExtraCompilerVariables(t); + writeExtraVariables(t); + t << endl; + + // blasted includes + QStringList &qeui = project->values("QMAKE_EXTRA_INCLUDES"); + QStringList::Iterator it; + for(it = qeui.begin(); it != qeui.end(); ++it) + t << "include " << (*it) << endl; + + /* rules */ + t << "first: all" << endl; + t << "####### Implicit rules" << endl << endl; + t << ".SUFFIXES: " << Option::obj_ext; + for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit) + t << " " << (*cit); + for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) + t << " " << (*cppit); + t << endl << endl; + for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) + t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl; + for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit) + t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl; + + if(include_deps) { + QString cmd=var("QMAKE_CFLAGS_DEPS") + " "; + cmd += varGlue("DEFINES","-D"," -D","") + varGlue("PRL_EXPORT_DEFINES"," -D"," -D",""); + if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH")) + cmd += " -I" + project->first("QMAKE_ABSOLUTE_SOURCE_PATH") + " "; + cmd += " $(INCPATH) " + varGlue("DEPENDPATH", "-I", " -I", ""); + QString odir; + if(!project->values("OBJECTS_DIR").isEmpty()) + odir = project->first("OBJECTS_DIR"); + t << "###### Dependencies" << endl << endl; + t << odir << ".deps/%.d: %.cpp\n\t"; + if(project->isActiveConfig("echo_depend_creation")) + t << "@echo Creating depend for $<" << "\n\t"; + t << mkdir_p_asstring("$(@D)") << "\n\t" + << "@$(CXX) " << cmd << " $< | sed \"s,^\\($(*F).o\\):," << odir << "\\1:,g\" >$@" << endl << endl; + + t << odir << ".deps/%.d: %.c\n\t"; + if(project->isActiveConfig("echo_depend_creation")) + t << "@echo Creating depend for $<" << "\n\t"; + t << mkdir_p_asstring("$(@D)") << "\n\t" + << "@$(CC) " << cmd << " $< | sed \"s,^\\($(*F).o\\):," << odir << "\\1:,g\" >$@" << endl << endl; + + QString src[] = { "SOURCES", "GENERATED_SOURCES", QString() }; + for(int x = 0; !src[x].isNull(); x++) { + QStringList &l = project->values(src[x]); + for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { + if(!(*it).isEmpty()) { + QString d_file; + for(QStringList::Iterator cit = Option::c_ext.begin(); + cit != Option::c_ext.end(); ++cit) { + if((*it).endsWith((*cit))) { + d_file = (*it).left((*it).length() - (*cit).length()); + break; + } + } + if(d_file.isEmpty()) { + for(QStringList::Iterator cppit = Option::cpp_ext.begin(); + cppit != Option::cpp_ext.end(); ++cppit) { + if((*it).endsWith((*cppit))) { + d_file = (*it).left((*it).length() - (*cppit).length()); + break; + } + } + } + if(!d_file.isEmpty()) { + d_file = odir + ".deps/" + d_file + ".d"; + QStringList deps = findDependencies((*it)).filter(QRegExp(Option::cpp_moc_ext + "$")); + if(!deps.isEmpty()) + t << d_file << ": " << deps.join(" ") << endl; + t << "-include " << d_file << endl; + project->values("QMAKE_DISTCLEAN") += d_file; + } + } + } + } + } + + t << "####### Build rules" << endl << endl; + if(!project->values("SUBLIBS").isEmpty()) { + QString libdir = "tmp/"; + if(!project->isEmpty("SUBLIBS_DIR")) + libdir = project->first("SUBLIBS_DIR"); + t << "SUBLIBS = "; + QStringList &l = project->values("SUBLIBS"); + for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) + t << libdir << "lib" << (*it) << ".a "; + t << endl << endl; + } + if(project->isActiveConfig("depend_prl") && !project->isEmpty("QMAKE_PRL_INTERNAL_FILES")) { + QStringList &l = project->values("QMAKE_PRL_INTERNAL_FILES"); + QStringList::Iterator it; + for(it = l.begin(); it != l.end(); ++it) { + QMakeMetaInfo libinfo; + if(libinfo.readLib((*it)) && !libinfo.isEmpty("QMAKE_PRL_BUILD_DIR")) { + QString dir; + int slsh = (*it).lastIndexOf(Option::dir_sep); + if(slsh != -1) + dir = (*it).left(slsh + 1); + QString targ = dir + libinfo.first("QMAKE_PRL_TARGET"); + target_deps += " " + targ; + t << targ << ":" << "\n\t" + << "@echo \"Creating '" << targ << "'\"" << "\n\t" + << "(cd " << libinfo.first("QMAKE_PRL_BUILD_DIR") << ";" + << "$(MAKE))" << endl; + } + } + } + if(!project->values("QMAKE_APP_FLAG").isEmpty()) { + QString destdir = project->first("DESTDIR"); + if(!project->isEmpty("QMAKE_BUNDLE")) { + QString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION"); + if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/")) + bundle_loc.prepend("/"); + if(!bundle_loc.endsWith("/")) + bundle_loc += "/"; + destdir += project->first("QMAKE_BUNDLE") + bundle_loc; + } + if(do_incremental) { + //incremental target + QString incr_target = var("TARGET") + "_incremental"; + if(incr_target.indexOf(Option::dir_sep) != -1) + incr_target = incr_target.right(incr_target.length() - + (incr_target.lastIndexOf(Option::dir_sep) + 1)); + QString incr_deps, incr_objs; + if(project->first("QMAKE_INCREMENTAL_STYLE") == "ld") { + QString incr_target_dir = var("OBJECTS_DIR") + incr_target + Option::obj_ext; + //actual target + t << incr_target_dir << ": $(OBJECTS)" << "\n\t" + << "ld -r -o "<< incr_target_dir << " $(OBJECTS)" << endl; + //communicated below + deps.prepend(incr_target_dir + " "); + incr_deps = "$(INCREMENTAL_OBJECTS)"; + if(!incr_objs.isEmpty()) + incr_objs += " "; + incr_objs += incr_target_dir; + } else { + //actual target + QString incr_target_dir = var("DESTDIR") + "lib" + incr_target + "." + + project->values("QMAKE_EXTENSION_SHLIB").first(); + QString incr_lflags = var("QMAKE_LFLAGS_SHLIB") + " "; + if(project->isActiveConfig("debug")) + incr_lflags += var("QMAKE_LFLAGS_DEBUG"); + else + incr_lflags += var("QMAKE_LFLAGS_RELEASE"); + t << incr_target_dir << ": $(INCREMENTAL_OBJECTS)" << "\n\t"; + if(!destdir.isEmpty()) + t << "\n\t" << mkdir_p_asstring(destdir) << "\n\t"; + t << "$(LINK) " << incr_lflags << " -o "<< incr_target_dir << + " $(INCREMENTAL_OBJECTS)" << endl; + //communicated below + if(!destdir.isEmpty()) { + if(!incr_objs.isEmpty()) + incr_objs += " "; + incr_objs += "-L" + destdir; + } else { + if(!incr_objs.isEmpty()) + incr_objs += " "; + incr_objs += "-L" + qmake_getpwd(); + } + if(!incr_objs.isEmpty()) + incr_objs += " "; + incr_objs += " -l" + incr_target; + deps.prepend(incr_target_dir + " "); + incr_deps = "$(OBJECTS)"; + } + t << "all: " << escapeDependencyPath(deps) << " " << valGlue(escapeDependencyPaths(project->values("ALL_DEPS")),""," "," ") << "$(TARGET)" + << endl << endl; + + //real target + t << var("TARGET") << ": " << var("PRE_TARGETDEPS") << " " << incr_deps << " " << target_deps + << " " << var("POST_TARGETDEPS") << "\n\t"; + if(!destdir.isEmpty()) + t << "\n\t" << mkdir_p_asstring(destdir) << "\n\t"; + if(!project->isEmpty("QMAKE_PRE_LINK")) + t << var("QMAKE_PRE_LINK") << "\n\t"; + t << "$(LINK) $(LFLAGS) -o $(TARGET) " << incr_deps << " " << incr_objs << " $(OBJCOMP) $(LIBS)"; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\n\t" << var("QMAKE_POST_LINK"); + t << endl << endl; + } else { + t << "all: " << escapeDependencyPath(deps) << " " << valGlue(escapeDependencyPaths(project->values("ALL_DEPS")),""," "," ") << "$(TARGET)" + << endl << endl; + + t << "$(TARGET): " << var("PRE_TARGETDEPS") << " $(OBJECTS) " + << target_deps << " " << var("POST_TARGETDEPS") << "\n\t"; + if(!destdir.isEmpty()) + t << mkdir_p_asstring(destdir) << "\n\t"; + if(!project->isEmpty("QMAKE_PRE_LINK")) + t << var("QMAKE_PRE_LINK") << "\n\t"; + t << "$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)"; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\n\t" << var("QMAKE_POST_LINK"); + t << endl << endl; + } + } else if(!project->isActiveConfig("staticlib")) { + QString destdir = unescapeFilePath(project->first("DESTDIR")), incr_deps; + if(!project->isEmpty("QMAKE_BUNDLE")) { + QString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION"); + if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/")) + bundle_loc.prepend("/"); + if(!bundle_loc.endsWith("/")) + bundle_loc += "/"; + destdir += project->first("QMAKE_BUNDLE") + bundle_loc; + } + destdir = escapeFilePath(destdir); + + if(do_incremental) { + QString s_ext = project->values("QMAKE_EXTENSION_SHLIB").first(); + QString incr_target = var("QMAKE_ORIG_TARGET").replace( + QRegExp("\\." + s_ext), "").replace(QRegExp("^lib"), "") + "_incremental"; + if(incr_target.indexOf(Option::dir_sep) != -1) + incr_target = incr_target.right(incr_target.length() - + (incr_target.lastIndexOf(Option::dir_sep) + 1)); + incr_target = escapeFilePath(incr_target); + + if(project->first("QMAKE_INCREMENTAL_STYLE") == "ld") { + QString incr_target_dir = escapeFilePath(var("OBJECTS_DIR") + incr_target + Option::obj_ext); + //actual target + const QString link_deps = "$(OBJECTS) "; + t << incr_target_dir << ": " << link_deps << "\n\t" + << "ld -r -o " << incr_target_dir << " " << link_deps << endl; + //communicated below + QStringList &cmd = project->values("QMAKE_LINK_SHLIB_CMD"); + cmd.first().replace("$(OBJECTS) ", "$(INCREMENTAL_OBJECTS)"); //ick + cmd.append(incr_target_dir); + deps.prepend(incr_target_dir + " "); + incr_deps = "$(INCREMENTAL_OBJECTS)"; + } else { + //actual target + QString incr_target_dir = escapeFilePath(destdir + "lib" + incr_target + "." + s_ext); + QString incr_lflags = var("QMAKE_LFLAGS_SHLIB") + " "; + if(!project->isEmpty("QMAKE_LFLAGS_INCREMENTAL")) + incr_lflags += var("QMAKE_LFLAGS_INCREMENTAL") + " "; + if(project->isActiveConfig("debug")) + incr_lflags += var("QMAKE_LFLAGS_DEBUG"); + else + incr_lflags += var("QMAKE_LFLAGS_RELEASE"); + t << incr_target_dir << ": $(INCREMENTAL_OBJECTS)" << "\n\t"; + if(!destdir.isEmpty()) + t << mkdir_p_asstring(destdir) << "\n\t"; + t << "$(LINK) " << incr_lflags << " -o "<< incr_target_dir << + " $(INCREMENTAL_OBJECTS)" << endl; + //communicated below + QStringList &cmd = project->values("QMAKE_LINK_SHLIB_CMD"); + if(!destdir.isEmpty()) + cmd.append(" -L" + destdir); + cmd.append(" -l" + incr_target); + deps.prepend(incr_target_dir + " "); + incr_deps = "$(OBJECTS)"; + } + + t << "all: " << " " << escapeDependencyPath(deps) << " " << valGlue(escapeDependencyPaths(project->values("ALL_DEPS")),""," "," ") + << " " << destdir << "$(TARGET)" << endl << endl; + + //real target + t << destdir << "$(TARGET): " << var("PRE_TARGETDEPS") << " " + << incr_deps << " $(SUBLIBS) " << target_deps << " " << var("POST_TARGETDEPS"); + } else { + t << "all: " << escapeDependencyPath(deps) << " " << valGlue(escapeDependencyPaths(project->values("ALL_DEPS")),""," "," ") << " " << + destdir << "$(TARGET)" << endl << endl; + t << destdir << "$(TARGET): " << var("PRE_TARGETDEPS") + << " $(OBJECTS) $(SUBLIBS) $(OBJCOMP) " << target_deps + << " " << var("POST_TARGETDEPS"); + } + if(!destdir.isEmpty()) + t << "\n\t" << mkdir_p_asstring(destdir); + if(!project->isEmpty("QMAKE_PRE_LINK")) + t << "\n\t" << var("QMAKE_PRE_LINK"); + + if(project->isActiveConfig("compile_libtool")) { + t << "\n\t" + << var("QMAKE_LINK_SHLIB_CMD"); + } else if(project->isActiveConfig("plugin")) { + t << "\n\t" + << "-$(DEL_FILE) $(TARGET)" << "\n\t" + << var("QMAKE_LINK_SHLIB_CMD"); + if(!destdir.isEmpty()) + t << "\n\t" + << "-$(MOVE) $(TARGET) " << destdir; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\n\t" << var("QMAKE_POST_LINK") << "\n\t"; + t << endl << endl; + } else if(!project->isEmpty("QMAKE_BUNDLE")) { + t << "\n\t" + << "-$(DEL_FILE) $(TARGET) $(TARGET0) $(DESTDIR)$(TARGET0)" << "\n\t" + << var("QMAKE_LINK_SHLIB_CMD") << "\n\t" + << mkdir_p_asstring("\"`dirname $(DESTDIR)$(TARGETD)`\"", false) << "\n\t" + << "-$(MOVE) $(TARGET) $(DESTDIR)$(TARGETD)" << "\n\t" + << mkdir_p_asstring("\"`dirname $(DESTDIR)$(TARGET0)`\"", false) << "\n\t" + << varGlue("QMAKE_LN_SHLIB","-"," "," Versions/" + + project->first("QMAKE_FRAMEWORK_VERSION") + + "/$(TARGET) $(DESTDIR)$(TARGET0)") << "\n\t" + << "-$(DEL_FILE) " << destdir << "Versions/Current" << "\n\t" + << varGlue("QMAKE_LN_SHLIB","-"," ", " " + project->first("QMAKE_FRAMEWORK_VERSION") + + " " + destdir + "Versions/Current") << "\n\t"; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\n\t" << var("QMAKE_POST_LINK"); + t << endl << endl; + } else if(project->isEmpty("QMAKE_HPUX_SHLIB")) { + t << "\n\t" + << "-$(DEL_FILE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2)" << "\n\t" + << var("QMAKE_LINK_SHLIB_CMD") << "\n\t"; + t << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET0)") << "\n\t" + << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET1)") << "\n\t" + << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET2)"); + if(!destdir.isEmpty()) + t << "\n\t" + << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t" + << "-$(DEL_FILE) " << destdir << "$(TARGET0)\n\t" + << "-$(DEL_FILE) " << destdir << "$(TARGET1)\n\t" + << "-$(DEL_FILE) " << destdir << "$(TARGET2)\n\t" + << "-$(MOVE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2) " << destdir; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\n\t" << var("QMAKE_POST_LINK"); + t << endl << endl; + } else { + t << "\n\t" + << "-$(DEL_FILE) $(TARGET) $(TARGET0)" << "\n\t" + << var("QMAKE_LINK_SHLIB_CMD") << "\n\t"; + t << varGlue("QMAKE_LN_SHLIB",""," "," $(TARGET) $(TARGET0)"); + if(!destdir.isEmpty()) + t << "\n\t" + << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t" + << "-$(DEL_FILE) " << destdir << "$(TARGET0)\n\t" + << "-$(MOVE) $(TARGET) $(TARGET0) " << destdir; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\n\t" << var("QMAKE_POST_LINK"); + t << endl << endl; + } + t << endl << endl; + + if (! project->isActiveConfig("plugin")) { + t << "staticlib: $(TARGETA)" << endl << endl; + t << "$(TARGETA): " << var("PRE_TARGETDEPS") << " $(OBJECTS) $(OBJCOMP)"; + if(do_incremental) + t << " $(INCREMENTAL_OBJECTS)"; + t << " " << var("POST_TARGETDEPS") << "\n\t" + << "-$(DEL_FILE) $(TARGETA) " << "\n\t" + << var("QMAKE_AR_CMD"); + if(do_incremental) + t << " $(INCREMENTAL_OBJECTS)"; + if(!project->isEmpty("QMAKE_RANLIB")) + t << "\n\t" << "$(RANLIB) $(TARGETA)"; + t << endl << endl; + } + } else { + QString destdir = project->first("DESTDIR"); + t << "all: " << escapeDependencyPath(deps) << " " << valGlue(escapeDependencyPaths(project->values("ALL_DEPS")),""," "," ") << destdir << "$(TARGET) " + << varGlue("QMAKE_AR_SUBLIBS", destdir, " " + destdir, "") << "\n\n" + << "staticlib: " << destdir << "$(TARGET)" << "\n\n"; + if(project->isEmpty("QMAKE_AR_SUBLIBS")) { + t << destdir << "$(TARGET): " << var("PRE_TARGETDEPS") + << " $(OBJECTS) $(OBJCOMP) " << var("POST_TARGETDEPS") << "\n\t"; + if(!destdir.isEmpty()) + t << mkdir_p_asstring(destdir) << "\n\t"; + t << "-$(DEL_FILE) $(TARGET)" << "\n\t" + << var("QMAKE_AR_CMD") << "\n"; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\t" << var("QMAKE_POST_LINK") << "\n"; + if(!project->isEmpty("QMAKE_RANLIB")) + t << "\t" << "$(RANLIB) $(TARGET)" << "\n"; + if(!destdir.isEmpty()) + t << "\t" << "-$(DEL_FILE) " << destdir << "$(TARGET)" << "\n" + << "\t" << "-$(MOVE) $(TARGET) " << destdir << "\n"; + } else { + int max_files = project->first("QMAKE_MAX_FILES_PER_AR").toInt(); + QStringList objs = project->values("OBJECTS") + project->values("OBJCOMP"), + libs = project->values("QMAKE_AR_SUBLIBS"); + libs.prepend("$(TARGET)"); + for(QStringList::Iterator libit = libs.begin(), objit = objs.begin(); + libit != libs.end(); ++libit) { + QStringList build; + for(int cnt = 0; cnt < max_files && objit != objs.end(); ++objit, cnt++) + build << (*objit); + QString ar; + if((*libit) == "$(TARGET)") { + t << destdir << "$(TARGET): " << var("PRE_TARGETDEPS") + << " " << var("POST_TARGETDEPS") << valList(build) << "\n\t"; + ar = project->values("QMAKE_AR_CMD").first(); + ar = ar.replace("$(OBJECTS)", build.join(" ")); + } else { + t << (*libit) << ": " << valList(build) << "\n\t"; + ar = "$(AR) " + (*libit) + " " + build.join(" "); + } + if(!destdir.isEmpty()) + t << mkdir_p_asstring(destdir) << "\n\t"; + t << "-$(DEL_FILE) " << (*libit) << "\n\t" + << ar << "\n"; + if(!project->isEmpty("QMAKE_POST_LINK")) + t << "\t" << var("QMAKE_POST_LINK") << "\n"; + if(!project->isEmpty("QMAKE_RANLIB")) + t << "\t" << "$(RANLIB) " << (*libit) << "\n"; + if(!destdir.isEmpty()) + t << "\t" << "-$(DEL_FILE) " << destdir << (*libit) << "\n" + << "\t" << "-$(MOVE) " << (*libit) << " " << destdir << "\n"; + } + } + t << endl << endl; + } + + writeMakeQmake(t); + if(project->isEmpty("QMAKE_FAILED_REQUIREMENTS") && !project->isActiveConfig("no_autoqmake")) { + QString meta_files; + if(project->isActiveConfig("create_libtool") && project->first("TEMPLATE") == "lib" && + !project->isActiveConfig("compile_libtool")) { //libtool + if(!meta_files.isEmpty()) + meta_files += " "; + meta_files += libtoolFileName(); + } + if(project->isActiveConfig("create_pc") && project->first("TEMPLATE") == "lib") { //pkg-config + if(!meta_files.isEmpty()) + meta_files += " "; + meta_files += pkgConfigFileName(); + } + if(!meta_files.isEmpty()) + t << escapeDependencyPath(meta_files) << ": " << "\n\t" + << "@$(QMAKE) -prl " << buildArgs() << " " << project->projectFile() << endl; + } + + if(!project->first("QMAKE_PKGINFO").isEmpty()) { + QString pkginfo = escapeFilePath(project->first("QMAKE_PKGINFO")); + QString destdir = escapeFilePath(project->first("DESTDIR") + project->first("QMAKE_BUNDLE") + "/Contents"); + t << pkginfo << ": " << "\n\t"; + if(!destdir.isEmpty()) + t << mkdir_p_asstring(destdir) << "\n\t"; + t << "@$(DEL_FILE) " << pkginfo << "\n\t" + << "@echo \"APPL" + << (project->isEmpty("QMAKE_PKGINFO_TYPEINFO") ? QString::fromLatin1("????") : project->first("QMAKE_PKGINFO_TYPEINFO").left(4)) + << "\" >" << pkginfo << endl; + } + if(!project->first("QMAKE_BUNDLE_RESOURCE_FILE").isEmpty()) { + QString resources = escapeFilePath(project->first("QMAKE_BUNDLE_RESOURCE_FILE")); + QString destdir = escapeFilePath(project->first("DESTDIR") + project->first("QMAKE_BUNDLE") + "/Contents/Resources"); + t << resources << ": " << "\n\t"; + t << mkdir_p_asstring(destdir) << "\n\t"; + t << "@touch " << resources << "\n\t" << endl; + } + if(!project->isEmpty("QMAKE_BUNDLE")) { + //copy the plist + QString info_plist = escapeFilePath(fileFixify(project->first("QMAKE_INFO_PLIST"))), + info_plist_out = escapeFilePath(project->first("QMAKE_INFO_PLIST_OUT")); + QString destdir = info_plist_out.section(Option::dir_sep, 0, -2); + t << info_plist_out << ": " << "\n\t"; + if(!destdir.isEmpty()) + t << mkdir_p_asstring(destdir) << "\n\t"; + if(project->first("TEMPLATE") == "app") { + QString icon = fileFixify(var("ICON")); + t << "@$(DEL_FILE) " << info_plist_out << "\n\t" + << "@sed " + << "-e \"s,@ICON@," << icon.section(Option::dir_sep, -1) << ",g\" " + << "-e \"s,@EXECUTABLE@," << var("QMAKE_ORIG_TARGET") << ",g\" " + << "-e \"s,@TYPEINFO@,"<< (project->isEmpty("QMAKE_PKGINFO_TYPEINFO") ? + QString::fromLatin1("????") : project->first("QMAKE_PKGINFO_TYPEINFO").left(4)) << ",g\" " + << "" << info_plist << " >" << info_plist_out << endl; + //copy the icon + if(!project->isEmpty("ICON")) { + QString dir = project->first("DESTDIR") + project->first("QMAKE_BUNDLE") + "/Contents/Resources/"; + const QString icon_path = escapeFilePath(dir + icon.section(Option::dir_sep, -1)); + t << icon_path << ": " << icon << "\n\t" + << mkdir_p_asstring(dir) << "\n\t" + << "@$(DEL_FILE) " << icon_path << "\n\t" + << "@$(COPY_FILE) " << escapeFilePath(icon) << " " << icon_path << endl; + } + } else { + t << "@$(DEL_FILE) " << info_plist_out << "\n\t" + << "@sed " + << "-e \"s,@LIBRARY@," << var("QMAKE_ORIG_TARGET") << ",g\" " + << "-e \"s,@SHORT_VERSION@," << project->first("VER_MAJ") << "." << project->first("VER_MIN") << ",g\" " + << "-e \"s,@TYPEINFO@," + << (project->isEmpty("QMAKE_PKGINFO_TYPEINFO") ? + QString::fromLatin1("????") : project->first("QMAKE_PKGINFO_TYPEINFO").left(4)) << ",g\" " + << "" << info_plist << " >" << info_plist_out << endl; + } + //copy other data + if(!project->isEmpty("QMAKE_BUNDLE_DATA")) { + QString bundle_dir = project->first("DESTDIR") + project->first("QMAKE_BUNDLE") + "/"; + const QStringList &bundle_data = project->values("QMAKE_BUNDLE_DATA"); + for(int i = 0; i < bundle_data.count(); i++) { + const QStringList &files = project->values(bundle_data[i] + ".files"); + QString path = bundle_dir; + if(!project->isEmpty(bundle_data[i] + ".version")) { + QString version = project->first(bundle_data[i] + ".version") + "/" + + project->first("QMAKE_FRAMEWORK_VERSION") + "/"; + t << Option::fixPathToLocalOS(path + project->first(bundle_data[i] + ".path")) << ": " << "\n\t" + << mkdir_p_asstring(path) << "\n\t" + << "@$(SYMLINK) " << version << project->first(bundle_data[i] + ".path") << " " << path << endl; + path += version; + } + path += project->first(bundle_data[i] + ".path"); + path = Option::fixPathToLocalOS(path); + for(int file = 0; file < files.count(); file++) { + QString src = fileFixify(files[file], FileFixifyAbsolute); + if (!QFile::exists(src)) + src = files[file]; + src = escapeFilePath(src); + const QString dst = escapeFilePath(path + Option::dir_sep + fileInfo(files[file]).fileName()); + t << dst << ": " << src << "\n\t" + << mkdir_p_asstring(path) << "\n\t"; + QFileInfo fi(fileInfo(files[file])); + if(fi.isDir()) + t << "@$(DEL_FILE) -r " << dst << "\n\t" + << "@$(COPY_DIR) " << src << " " << dst << endl; + else + t << "@$(DEL_FILE) " << dst << "\n\t" + << "@$(COPY_FILE) " << src << " " << dst << endl; + } + } + } + } + + QString ddir; + QString packageName(project->first("QMAKE_ORIG_TARGET")); + if(!project->isActiveConfig("no_dist_version")) + packageName += var("VERSION"); + if (project->isEmpty("QMAKE_DISTDIR")) + ddir = packageName; + else + ddir = project->first("QMAKE_DISTDIR"); + + QString ddir_c = escapeFilePath(fileFixify((project->isEmpty("OBJECTS_DIR") ? QString(".tmp/") : + project->first("OBJECTS_DIR")) + ddir)); + t << "dist: " << "\n\t" + << mkdir_p_asstring(ddir_c) << "\n\t" + << "$(COPY_FILE) --parents $(SOURCES) $(DIST) " << ddir_c << Option::dir_sep << " && "; + if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) { + const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); + for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { + const QStringList &var = project->values((*it)+".input"); + for(QStringList::ConstIterator var_it = var.begin(); var_it != var.end(); ++var_it) { + const QStringList &val = project->values((*var_it)); + if(val.isEmpty()) + continue; + t << "$(COPY_FILE) --parents " << val.join(" ") << " " << ddir_c << Option::dir_sep << " && "; + } + } + } + if(!project->isEmpty("TRANSLATIONS")) + t << "$(COPY_FILE) --parents " << var("TRANSLATIONS") << " " << ddir_c << Option::dir_sep << " && "; + t << "(cd `dirname " << ddir_c << "` && " + << "$(TAR) " << packageName << ".tar " << ddir << " && " + << "$(COMPRESS) " << packageName << ".tar) && " + << "$(MOVE) `dirname " << ddir_c << "`" << Option::dir_sep << packageName << ".tar.gz . && " + << "$(DEL_FILE) -r " << ddir_c + << endl << endl; + + t << endl; + + QString clean_targets = "compiler_clean " + var("CLEAN_DEPS"); + if(do_incremental) { + t << "incrclean:" << "\n"; + if(src_incremental) + t << "\t-$(DEL_FILE) $(INCREMENTAL_OBJECTS)" << "\n"; + t << endl; + } + + t << "clean:" << clean_targets << "\n\t"; + if(!project->isEmpty("OBJECTS")) { + if(project->isActiveConfig("compile_libtool")) + t << "-$(LIBTOOL) --mode=clean $(DEL_FILE) $(OBJECTS)" << "\n\t"; + else + t << "-$(DEL_FILE) $(OBJECTS)" << "\n\t"; + } + if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) { + QStringList precomp_files; + QString precomph_out_dir; + + if(!project->isEmpty("PRECOMPILED_DIR")) + precomph_out_dir = project->first("PRECOMPILED_DIR"); + precomph_out_dir += project->first("QMAKE_ORIG_TARGET") + project->first("QMAKE_PCH_OUTPUT_EXT"); + + if (project->isActiveConfig("icc_pch_style")) { + // icc style + QString pchBaseName = project->first("QMAKE_ORIG_TARGET"); + QString pchOutput; + if(!project->isEmpty("PRECOMPILED_DIR")) + pchOutput = project->first("PRECOMPILED_DIR"); + pchOutput += pchBaseName + project->first("QMAKE_PCH_OUTPUT_EXT"); + QString sourceFile = pchOutput + Option::cpp_ext.first(); + QString objectFile = createObjectList(QStringList(sourceFile)).first(); + + precomp_files << precomph_out_dir << sourceFile << objectFile; + } else { + // gcc style + precomph_out_dir += Option::dir_sep; + + QString header_prefix = project->first("QMAKE_PRECOMP_PREFIX"); + if(!project->isEmpty("QMAKE_CFLAGS_PRECOMPILE")) + precomp_files += precomph_out_dir + header_prefix + "c"; + if(!project->isEmpty("QMAKE_CXXFLAGS_PRECOMPILE")) + precomp_files += precomph_out_dir + header_prefix + "c++"; + if(project->isActiveConfig("objective_c")) { + if(!project->isEmpty("QMAKE_OBJCFLAGS_PRECOMPILE")) + precomp_files += precomph_out_dir + header_prefix + "objective-c"; + if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) + precomp_files += precomph_out_dir + header_prefix + "objective-c++"; + } + } + t << "-$(DEL_FILE) " << precomp_files.join(" ") << "\n\t"; + } + if(!project->isEmpty("IMAGES")) + t << varGlue("QMAKE_IMAGE_COLLECTION", "\t-$(DEL_FILE) ", " ", "") << "\n\t"; + if(src_incremental) + t << "-$(DEL_FILE) $(INCREMENTAL_OBJECTS)" << "\n\t"; + t << varGlue("QMAKE_CLEAN","-$(DEL_FILE) "," ","\n\t") + << "-$(DEL_FILE) *~ core *.core" << "\n" + << varGlue("CLEAN_FILES","\t-$(DEL_FILE) "," ","") << endl << endl; + t << "####### Sub-libraries" << endl << endl; + if (!project->values("SUBLIBS").isEmpty()) { + QString libdir = "tmp/"; + if(!project->isEmpty("SUBLIBS_DIR")) + libdir = project->first("SUBLIBS_DIR"); + QStringList &l = project->values("SUBLIBS"); + for(it = l.begin(); it != l.end(); ++it) + t << libdir << "lib" << (*it) << ".a" << ":\n\t" + << var(QString("MAKELIB") + (*it)) << endl << endl; + } + + QString destdir = project->first("DESTDIR"); + if(!destdir.isEmpty() && destdir.right(1) != Option::dir_sep) + destdir += Option::dir_sep; + t << "distclean: " << "clean\n"; + if(!project->isEmpty("QMAKE_BUNDLE")) { + QString bundlePath = escapeFilePath(destdir + project->first("QMAKE_BUNDLE")); + t << "\t-$(DEL_FILE) -r " << bundlePath << endl; + } else if(project->isActiveConfig("compile_libtool")) { + t << "\t-$(LIBTOOL) --mode=clean $(DEL_FILE) " << "$(TARGET)" << endl; + } else if(!project->isActiveConfig("staticlib") && project->values("QMAKE_APP_FLAG").isEmpty() && + !project->isActiveConfig("plugin")) { + t << "\t-$(DEL_FILE) " << destdir << "$(TARGET)" << " " << endl + << "\t-$(DEL_FILE) " << destdir << "$(TARGET0) " << destdir << "$(TARGET1) " + << destdir << "$(TARGET2) $(TARGETA)" << endl; + } else { + t << "\t-$(DEL_FILE) " << "$(TARGET)" << " " << endl; + } + t << varGlue("QMAKE_DISTCLEAN","\t-$(DEL_FILE) "," ","\n"); + { + QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName())); + if(!ofile.isEmpty()) + t << "\t-$(DEL_FILE) " << ofile << endl; + } + t << endl << endl; + + if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) { + QString pchInput = project->first("PRECOMPILED_HEADER"); + t << "###### Prefix headers" << endl; + QString comps[] = { "C", "CXX", "OBJC", "OBJCXX", QString() }; + for(int i = 0; !comps[i].isNull(); i++) { + QString pchFlags = var("QMAKE_" + comps[i] + "FLAGS_PRECOMPILE"); + if(pchFlags.isEmpty()) + continue; + + QString cflags; + if(comps[i] == "OBJC" || comps[i] == "OBJCXX") + cflags += " $(CFLAGS)"; + else + cflags += " $(" + comps[i] + "FLAGS)"; + + QString pchBaseName = project->first("QMAKE_ORIG_TARGET"); + QString pchOutput; + if(!project->isEmpty("PRECOMPILED_DIR")) + pchOutput = project->first("PRECOMPILED_DIR"); + pchOutput += pchBaseName + project->first("QMAKE_PCH_OUTPUT_EXT"); + + if (project->isActiveConfig("icc_pch_style")) { + // icc style + QString sourceFile = pchOutput + Option::cpp_ext.first(); + QString objectFile = createObjectList(QStringList(sourceFile)).first(); + t << pchOutput << ": " << pchInput << " " << findDependencies(pchInput).join(" \\\n\t\t") + << "\n\techo \"// Automatically generated, do not modify\" > " << sourceFile + << "\n\trm -f " << pchOutput; + + pchFlags = pchFlags.replace("${QMAKE_PCH_TEMP_SOURCE}", sourceFile) + .replace("${QMAKE_PCH_TEMP_OBJECT}", objectFile); + } else { + // gcc style + QString header_prefix = project->first("QMAKE_PRECOMP_PREFIX"); + + pchOutput += Option::dir_sep; + QString pchOutputDir = pchOutput, pchOutputFile; + + if(comps[i] == "C") { + pchOutputFile = "c"; + } else if(comps[i] == "CXX") { + pchOutputFile = "c++"; + } else if(project->isActiveConfig("objective_c")) { + if(comps[i] == "OBJC") + pchOutputFile = "objective-c"; + else if(comps[i] == "OBJCXX") + pchOutputFile = "objective-c++"; + } + if(pchOutputFile.isEmpty()) + continue; + pchOutput += header_prefix + pchOutputFile; + + t << pchOutput << ": " << pchInput << " " << findDependencies(pchInput).join(" \\\n\t\t") + << "\n\t" << mkdir_p_asstring(pchOutputDir); + } + pchFlags = pchFlags.replace("${QMAKE_PCH_INPUT}", pchInput) + .replace("${QMAKE_PCH_OUTPUT_BASE}", pchBaseName) + .replace("${QMAKE_PCH_OUTPUT}", pchOutput); + + QString compiler; + if(comps[i] == "C" || comps[i] == "OBJC" || comps[i] == "OBJCXX") + compiler = "$(CC)"; + else + compiler = "$(CXX)"; + + // compile command + t << "\n\t" << compiler << cflags << " $(INCPATH) " << pchFlags << endl << endl; + } + } + + writeExtraTargets(t); + writeExtraCompilerTargets(t); +} + +void UnixMakefileGenerator::init2() +{ + //version handling + if(project->isEmpty("VERSION")) + project->values("VERSION").append("1.0." + + (project->isEmpty("VER_PAT") ? QString("0") : + project->first("VER_PAT"))); + QStringList l = project->first("VERSION").split('.'); + l << "0" << "0"; //make sure there are three + project->values("VER_MAJ").append(l[0]); + project->values("VER_MIN").append(l[1]); + project->values("VER_PAT").append(l[2]); + if(project->isEmpty("QMAKE_FRAMEWORK_VERSION")) + project->values("QMAKE_FRAMEWORK_VERSION").append(project->values("VER_MAJ").first()); + + if (!project->values("QMAKE_APP_FLAG").isEmpty()) { + if(!project->isEmpty("QMAKE_BUNDLE")) { + QString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION"); + if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/")) + bundle_loc.prepend("/"); + if(!bundle_loc.endsWith("/")) + bundle_loc += "/"; + project->values("TARGET").first().prepend(project->first("QMAKE_BUNDLE") + bundle_loc); + } + if(!project->isEmpty("TARGET")) + project->values("TARGET").first().prepend(project->first("DESTDIR")); + if (!project->values("QMAKE_CYGWIN_EXE").isEmpty()) + project->values("TARGET_EXT").append(".exe"); + } else if (project->isActiveConfig("staticlib")) { + project->values("TARGET").first().prepend("lib"); + project->values("TARGET").first() += ".a"; + if(project->values("QMAKE_AR_CMD").isEmpty()) + project->values("QMAKE_AR_CMD").append("$(AR) $(TARGET) $(OBJECTS)"); + } else { + project->values("TARGETA").append(project->first("DESTDIR") + "lib" + project->first("TARGET") + ".a"); + if(project->isActiveConfig("compile_libtool")) + project->values("TARGET_la") = QStringList(project->first("DESTDIR") + "lib" + project->first("TARGET") + Option::libtool_ext); + + if (!project->values("QMAKE_AR_CMD").isEmpty()) + project->values("QMAKE_AR_CMD").first().replace("(TARGET)","(TARGETA)"); + else + project->values("QMAKE_AR_CMD").append("$(AR) $(TARGETA) $(OBJECTS)"); + if(project->isActiveConfig("compile_libtool")) { + project->values("TARGET") = project->values("TARGET_la"); + } else if(!project->isEmpty("QMAKE_BUNDLE")) { + QString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION"); + if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/")) + bundle_loc.prepend("/"); + if(!bundle_loc.endsWith("/")) + bundle_loc += "/"; + project->values("TARGET_").append(project->first("QMAKE_BUNDLE") + + bundle_loc + unescapeFilePath(project->first("TARGET"))); + project->values("TARGET_x.y").append(project->first("QMAKE_BUNDLE") + + "/Versions/" + + project->first("QMAKE_FRAMEWORK_VERSION") + + bundle_loc + unescapeFilePath(project->first("TARGET"))); + } else if(project->isActiveConfig("plugin")) { + QString prefix; + if(!project->isActiveConfig("no_plugin_name_prefix")) + prefix = "lib"; + project->values("TARGET_x.y.z").append(prefix + + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_PLUGIN")); + if(project->isActiveConfig("lib_version_first")) + project->values("TARGET_x").append(prefix + project->first("TARGET") + "." + + project->first("VER_MAJ") + "." + + project->first("QMAKE_EXTENSION_PLUGIN")); + else + project->values("TARGET_x").append(prefix + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_PLUGIN") + + "." + project->first("VER_MAJ")); + project->values("TARGET") = project->values("TARGET_x.y.z"); + } else if (!project->isEmpty("QMAKE_HPUX_SHLIB")) { + project->values("TARGET_").append("lib" + project->first("TARGET") + ".sl"); + if(project->isActiveConfig("lib_version_first")) + project->values("TARGET_x").append("lib" + project->first("VER_MAJ") + "." + + project->first("TARGET")); + else + project->values("TARGET_x").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ")); + project->values("TARGET") = project->values("TARGET_x"); + } else if (!project->isEmpty("QMAKE_AIX_SHLIB")) { + project->values("TARGET_").append("lib" + project->first("TARGET") + ".a"); + if(project->isActiveConfig("lib_version_first")) { + project->values("TARGET_x").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ") + "." + + project->first("QMAKE_EXTENSION_SHLIB")); + project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ") + + "." + project->first("VER_MIN") + "." + + project->first("QMAKE_EXTENSION_SHLIB")); + project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ") + "." + + project->first("VER_MIN") + "." + + project->first("VER_PAT") + "." + + project->first("QMAKE_EXTENSION_SHLIB")); + } else { + project->values("TARGET_x").append("lib" + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_SHLIB") + + "." + project->first("VER_MAJ")); + project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_SHLIB") + + "." + project->first("VER_MAJ") + + "." + project->first("VER_MIN")); + project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_SHLIB") + "." + + project->first("VER_MAJ") + "." + + project->first("VER_MIN") + "." + + project->first("VER_PAT")); + } + project->values("TARGET") = project->values("TARGET_x.y.z"); + } else { + project->values("TARGET_").append("lib" + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_SHLIB")); + if(project->isActiveConfig("lib_version_first")) { + project->values("TARGET_x").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ") + "." + + project->first("QMAKE_EXTENSION_SHLIB")); + project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ") + + "." + project->first("VER_MIN") + "." + + project->first("QMAKE_EXTENSION_SHLIB")); + project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + "." + + project->first("VER_MAJ") + "." + + project->first("VER_MIN") + "." + + project->first("VER_PAT") + "." + + project->values("QMAKE_EXTENSION_SHLIB").first()); + } else { + project->values("TARGET_x").append("lib" + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_SHLIB") + + "." + project->first("VER_MAJ")); + project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." + + project->first("QMAKE_EXTENSION_SHLIB") + + "." + project->first("VER_MAJ") + + "." + project->first("VER_MIN")); + project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + + "." + + project->values( + "QMAKE_EXTENSION_SHLIB").first() + "." + + project->first("VER_MAJ") + "." + + project->first("VER_MIN") + "." + + project->first("VER_PAT")); + } + project->values("TARGET") = project->values("TARGET_x.y.z"); + } + if(project->isEmpty("QMAKE_LN_SHLIB")) + project->values("QMAKE_LN_SHLIB").append("ln -s"); + if (!project->values("QMAKE_LFLAGS_SONAME").isEmpty()) { + QString soname; + if(project->isActiveConfig("plugin")) { + if(!project->values("TARGET").isEmpty()) + soname += project->first("TARGET"); + } else if(!project->isEmpty("QMAKE_BUNDLE")) { + soname += project->first("TARGET_x.y"); + } else if(!project->values("TARGET_x").isEmpty()) { + soname += project->first("TARGET_x"); + } + if(!soname.isEmpty()) { + if(project->isActiveConfig("absolute_library_soname") && + project->values("INSTALLS").indexOf("target") != -1 && + !project->isEmpty("target.path")) { + QString instpath = Option::fixPathToTargetOS(project->first("target.path")); + if(!instpath.endsWith(Option::dir_sep)) + instpath += Option::dir_sep; + soname.prepend(instpath); + } + project->values("QMAKE_LFLAGS_SONAME").first() += escapeFilePath(soname); + } + } + if (project->values("QMAKE_LINK_SHLIB_CMD").isEmpty()) + project->values("QMAKE_LINK_SHLIB_CMD").append( + "$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS) $(OBJCOMP)"); + } + if (!project->values("QMAKE_APP_FLAG").isEmpty()) { + project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_APP"); + project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_APP"); + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_APP"); + } else if (project->isActiveConfig("dll")) { + if(!project->isActiveConfig("plugin") || !project->isActiveConfig("plugin_no_share_shlib_cflags")) { + project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_SHLIB"); + project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_SHLIB"); + } + if (project->isActiveConfig("plugin")) { + project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_PLUGIN"); + project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_PLUGIN"); + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_PLUGIN"); + if(project->isActiveConfig("plugin_with_soname") && !project->isActiveConfig("compile_libtool")) + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SONAME"); + } else { + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SHLIB"); + if(!project->isEmpty("QMAKE_LFLAGS_COMPAT_VERSION")) { + if(project->isEmpty("COMPAT_VERSION")) + project->values("QMAKE_LFLAGS") += QString(project->first("QMAKE_LFLAGS_COMPAT_VERSION") + + project->first("VER_MAJ") + "." + + project->first("VER_MIN")); + else + project->values("QMAKE_LFLAGS") += QString(project->first("QMAKE_LFLAGS_COMPAT_VERSION") + + project->first("COMPATIBILITY_VERSION")); + } + if(!project->isEmpty("QMAKE_LFLAGS_VERSION")) { + project->values("QMAKE_LFLAGS") += QString(project->first("QMAKE_LFLAGS_VERSION") + + project->first("VER_MAJ") + "." + + project->first("VER_MIN") + "." + + project->first("VER_PAT")); + } + if(!project->isActiveConfig("compile_libtool")) + project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SONAME"); + } + } + + if(!project->isEmpty("QMAKE_BUNDLE")) { + QString plist = fileFixify(project->first("QMAKE_INFO_PLIST")); + if(plist.isEmpty()) + plist = specdir() + QDir::separator() + "Info.plist." + project->first("TEMPLATE"); + if(exists(Option::fixPathToLocalOS(plist))) { + if(project->isEmpty("QMAKE_INFO_PLIST")) + project->values("QMAKE_INFO_PLIST").append(plist); + project->values("QMAKE_INFO_PLIST_OUT").append(project->first("DESTDIR") + + project->first("QMAKE_BUNDLE") + + "/Contents/Info.plist"); + project->values("ALL_DEPS") += project->first("QMAKE_INFO_PLIST_OUT"); + if(!project->isEmpty("ICON") && project->first("TEMPLATE") == "app") + project->values("ALL_DEPS") += project->first("DESTDIR") + + project->first("QMAKE_BUNDLE") + + "/Contents/Resources/" + project->first("ICON").section('/', -1); + if(!project->isEmpty("QMAKE_BUNDLE_DATA")) { + QString bundle_dir = project->first("DESTDIR") + project->first("QMAKE_BUNDLE") + "/"; + QStringList &alldeps = project->values("ALL_DEPS"); + const QStringList &bundle_data = project->values("QMAKE_BUNDLE_DATA"); + for(int i = 0; i < bundle_data.count(); i++) { + const QStringList &files = project->values(bundle_data[i] + ".files"); + QString path = bundle_dir; + if(!project->isEmpty(bundle_data[i] + ".version")) { + alldeps += Option::fixPathToLocalOS(path + Option::dir_sep + + project->first(bundle_data[i] + ".path")); + path += project->first(bundle_data[i] + ".version") + "/" + + project->first("QMAKE_FRAMEWORK_VERSION") + "/"; + } + path += project->first(bundle_data[i] + ".path"); + path = Option::fixPathToLocalOS(path); + for(int file = 0; file < files.count(); file++) + alldeps += path + Option::dir_sep + fileInfo(files[file]).fileName(); + } + } + } + } +} + +QString +UnixMakefileGenerator::libtoolFileName(bool fixify) +{ + QString ret = var("TARGET"); + int slsh = ret.lastIndexOf(Option::dir_sep); + if(slsh != -1) + ret = ret.right(ret.length() - slsh - 1); + int dot = ret.indexOf('.'); + if(dot != -1) + ret = ret.left(dot); + ret += Option::libtool_ext; + if(!project->isEmpty("QMAKE_LIBTOOL_DESTDIR")) + ret.prepend(project->first("QMAKE_LIBTOOL_DESTDIR") + Option::dir_sep); + if(fixify) { + if(QDir::isRelativePath(ret) && !project->isEmpty("DESTDIR")) + ret.prepend(project->first("DESTDIR")); + ret = Option::fixPathToLocalOS(fileFixify(ret, qmake_getpwd(), Option::output_dir)); + } + return ret; +} + +void +UnixMakefileGenerator::writeLibtoolFile() +{ + QString fname = libtoolFileName(), lname = fname; + mkdir(fileInfo(fname).path()); + int slsh = lname.lastIndexOf(Option::dir_sep); + if(slsh != -1) + lname = lname.right(lname.length() - slsh - 1); + QFile ft(fname); + if(!ft.open(QIODevice::WriteOnly)) + return; + project->values("ALL_DEPS").append(fileFixify(fname)); + + QTextStream t(&ft); + t << "# " << lname << " - a libtool library file\n"; + t << "# Generated by qmake/libtool (" << qmake_version() << ") (Qt " + << QT_VERSION_STR << ") on: " << QDateTime::currentDateTime().toString(); + t << "\n"; + + t << "# The name that we can dlopen(3).\n" + << "dlname='" << var(project->isActiveConfig("plugin") ? "TARGET" : "TARGET_x") + << "'\n\n"; + + t << "# Names of this library.\n"; + t << "library_names='"; + if(project->isActiveConfig("plugin")) { + t << var("TARGET"); + } else { + if (project->isEmpty("QMAKE_HPUX_SHLIB")) + t << var("TARGET_x.y.z") << " "; + t << var("TARGET_x") << " " << var("TARGET_"); + } + t << "'\n\n"; + + t << "# The name of the static archive.\n" + << "old_library='" << lname.left(lname.length()-Option::libtool_ext.length()) << ".a'\n\n"; + + t << "# Libraries that this one depends upon.\n"; + QStringList libs; + if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) + libs = project->values("QMAKE_INTERNAL_PRL_LIBS"); + else + libs << "QMAKE_LIBS"; //obvious one + t << "dependency_libs='"; + for(QStringList::ConstIterator it = libs.begin(); it != libs.end(); ++it) + t << project->values((*it)).join(" ") << " "; + t << "'\n\n"; + + t << "# Version information for " << lname << "\n"; + int maj = project->first("VER_MAJ").toInt(); + int min = project->first("VER_MIN").toInt(); + int pat = project->first("VER_PAT").toInt(); + t << "current=" << (10*maj + min) << "\n" // best I can think of + << "age=0\n" + << "revision=" << pat << "\n\n"; + + t << "# Is this an already installed library.\n" + "installed=yes\n\n"; // ### + + t << "# Files to dlopen/dlpreopen.\n" + "dlopen=''\n" + "dlpreopen=''\n\n"; + + QString install_dir = project->first("QMAKE_LIBTOOL_LIBDIR"); + if(install_dir.isEmpty()) + install_dir = project->first("target.path"); + if(install_dir.isEmpty()) + install_dir = project->first("DESTDIR"); + t << "# Directory that this library needs to be installed in:\n" + "libdir='" << Option::fixPathToTargetOS(install_dir, false) << "'\n"; +} + +QString +UnixMakefileGenerator::pkgConfigFileName(bool fixify) +{ + QString ret = var("TARGET"); + int slsh = ret.lastIndexOf(Option::dir_sep); + if(slsh != -1) + ret = ret.right(ret.length() - slsh - 1); + if(ret.startsWith("lib")) + ret = ret.mid(3); + int dot = ret.indexOf('.'); + if(dot != -1) + ret = ret.left(dot); + ret += Option::pkgcfg_ext; + if(!project->isEmpty("QMAKE_PKGCONFIG_DESTDIR")) + ret.prepend(project->first("QMAKE_PKGCONFIG_DESTDIR") + Option::dir_sep); + if(fixify) { + if(QDir::isRelativePath(ret) && !project->isEmpty("DESTDIR")) + ret.prepend(project->first("DESTDIR")); + ret = Option::fixPathToLocalOS(fileFixify(ret, qmake_getpwd(), Option::output_dir)); + } + return ret; +} + +QString +UnixMakefileGenerator::pkgConfigPrefix() const +{ + if(!project->isEmpty("QMAKE_PKGCONFIG_PREFIX")) + return project->first("QMAKE_PKGCONFIG_PREFIX"); + return QLibraryInfo::location(QLibraryInfo::PrefixPath); +} + +QString +UnixMakefileGenerator::pkgConfigFixPath(QString path) const +{ + QString prefix = pkgConfigPrefix(); + if(path.startsWith(prefix)) + path = path.replace(prefix, "${prefix}"); + return path; +} + +void +UnixMakefileGenerator::writePkgConfigFile() +{ + QString fname = pkgConfigFileName(), lname = fname; + mkdir(fileInfo(fname).path()); + int slsh = lname.lastIndexOf(Option::dir_sep); + if(slsh != -1) + lname = lname.right(lname.length() - slsh - 1); + QFile ft(fname); + if(!ft.open(QIODevice::WriteOnly)) + return; + project->values("ALL_DEPS").append(fileFixify(fname)); + QTextStream t(&ft); + + QString prefix = pkgConfigPrefix(); + QString libDir = project->first("QMAKE_PKGCONFIG_LIBDIR"); + if(libDir.isEmpty()) + libDir = prefix + Option::dir_sep + "lib" + Option::dir_sep; + QString includeDir = project->first("QMAKE_PKGCONFIG_INCDIR"); + if(includeDir.isEmpty()) + includeDir = prefix + "/include"; + + t << "prefix=" << prefix << endl; + t << "exec_prefix=${prefix}\n" + << "libdir=" << pkgConfigFixPath(libDir) << "\n" + << "includedir=" << pkgConfigFixPath(includeDir) << endl; + // non-standard entry. Provides useful info normally only + // contained in the internal .qmake.cache file + t << varGlue("CONFIG", "qt_config=", " ", "") << endl; + + //extra PKGCONFIG variables + const QStringList &pkgconfig_vars = project->values("QMAKE_PKGCONFIG_VARIABLES"); + for(int i = 0; i < pkgconfig_vars.size(); ++i) { + QString var = project->first(pkgconfig_vars.at(i) + ".name"), + val = project->values(pkgconfig_vars.at(i) + ".value").join(" "); + if(var.isEmpty()) + continue; + if(val.isEmpty()) { + const QStringList &var_vars = project->values(pkgconfig_vars.at(i) + ".variable"); + for(int v = 0; v < var_vars.size(); ++v) { + const QStringList &vars = project->values(var_vars.at(v)); + for(int var = 0; var < vars.size(); ++var) { + if(!val.isEmpty()) + val += " "; + val += pkgConfigFixPath(vars.at(var)); + } + } + } + t << var << "=" << val << endl; + } + + t << endl; + + QString name = project->first("QMAKE_PKGCONFIG_NAME"); + if(name.isEmpty()) { + name = project->first("QMAKE_ORIG_TARGET").toLower(); + name.replace(0, 1, name[0].toUpper()); + } + t << "Name: " << name << endl; + QString desc = project->values("QMAKE_PKGCONFIG_DESCRIPTION").join(" "); + if(desc.isEmpty()) { + if(name.isEmpty()) { + desc = project->first("QMAKE_ORIG_TARGET").toLower(); + desc.replace(0, 1, desc[0].toUpper()); + } else { + desc = name; + } + if(project->first("TEMPLATE") == "lib") { + if(project->isActiveConfig("plugin")) + desc += " Plugin"; + else + desc += " Library"; + } else if(project->first("TEMPLATE") == "app") { + desc += " Application"; + } + } + t << "Description: " << desc << endl; + t << "Version: " << project->first("VERSION") << endl; + + // libs + QStringList libs; + if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) { + libs = project->values("QMAKE_INTERNAL_PRL_LIBS"); + } else { + libs << "QMAKE_LIBS"; //obvious one + } + libs << "QMAKE_LFLAGS_THREAD"; //not sure about this one, but what about things like -pthread? + t << "Libs: "; + QString pkgConfiglibDir; + QString pkgConfiglibName; + if (Option::target_mode == Option::TARG_MACX_MODE && project->isActiveConfig("lib_bundle")) { + pkgConfiglibDir = "-F${libdir}"; + QString bundle; + if (!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME")) + bundle = unescapeFilePath(project->first("QMAKE_FRAMEWORK_BUNDLE_NAME")); + else + bundle = unescapeFilePath(project->first("TARGET")); + int suffix = bundle.lastIndexOf(".framework"); + if (suffix != -1) + bundle = bundle.left(suffix); + pkgConfiglibName = "-framework " + bundle + " "; + } else { + pkgConfiglibDir = "-L${libdir}"; + pkgConfiglibName = "-l" + lname.left(lname.length()-Option::libtool_ext.length()); + } + t << pkgConfiglibDir << " " << pkgConfiglibName << " " << endl; + t << "Libs.private: "; + for(QStringList::ConstIterator it = libs.begin(); it != libs.end(); ++it) { + t << project->values((*it)).join(" ") << " "; + } + t << endl; + + // flags + // ### too many + t << "Cflags: " + // << var("QMAKE_CXXFLAGS") << " " + << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ") + << project->values("PRL_EXPORT_CXXFLAGS").join(" ") + << project->values("QMAKE_PKGCONFIG_CFLAGS").join(" ") + // << varGlue("DEFINES","-D"," -D"," ") + << " -I${includedir}" << endl; + + // requires + const QString requires = project->values("QMAKE_PKGCONFIG_REQUIRES").join(" "); + if (!requires.isEmpty()) { + t << "Requires: " << requires << endl; + } + + t << endl; +} + +QT_END_NAMESPACE |