📄 winmakefile.cpp
字号:
/****************************************************************************
**
** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
**
** This file is part of the qmake application of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.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 GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** 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 "winmakefile.h"
#include "option.h"
#include "project.h"
#include "meta.h"
#include <qtextstream.h>
#include <qstring.h>
#include <qhash.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qdir.h>
#include <stdlib.h>
Win32MakefileGenerator::Win32MakefileGenerator() : MakefileGenerator()
{
}
int
Win32MakefileGenerator::findHighestVersion(const QString &d, const QString &stem)
{
QString bd = Option::fixPathToLocalOS(d, true);
if(!exists(bd))
return -1;
QString dllStem = stem + QTDLL_POSTFIX;
QMakeMetaInfo libinfo;
bool libInfoRead = libinfo.readLib(bd + Option::dir_sep + dllStem);
// If the library, for which we're trying to find the highest version
// number, is a static library
if (libInfoRead && libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib"))
return -1;
if(!project->variables()["QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE"].isEmpty())
return project->variables()["QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE"].first().toInt();
int biggest=-1;
if(!project->isActiveConfig("no_versionlink")) {
QDir dir(bd);
QStringList entries = dir.entryList();
QRegExp regx("((lib)?" + dllStem + "([0-9]*)).(a|lib|prl)$", Qt::CaseInsensitive);
for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
if(regx.exactMatch((*it))) {
if (!regx.cap(3).isEmpty()) {
bool ok = true;
int num = regx.cap(3).toInt(&ok);
biggest = qMax(biggest, (!ok ? -1 : num));
}
}
}
}
if(libInfoRead
&& !libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib")
&& !libinfo.isEmpty("QMAKE_PRL_VERSION"))
biggest = qMax(biggest, libinfo.first("QMAKE_PRL_VERSION").replace(".", "").toInt());
return biggest;
}
bool
Win32MakefileGenerator::findLibraries(const QString &where)
{
QStringList &l = project->variables()[where];
QList<QMakeLocalFileName> dirs;
{
QStringList &libpaths = project->variables()["QMAKE_LIBDIR"];
for(QStringList::Iterator libpathit = libpaths.begin();
libpathit != libpaths.end(); ++libpathit)
dirs.append(QMakeLocalFileName((*libpathit)));
}
for(QStringList::Iterator it = l.begin(); it != l.end();) {
QChar quote;
bool modified_opt = false, remove = false;
QString opt = (*it).trimmed();
if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0]) {
quote = opt[0];
opt = opt.mid(1, opt.length()-2);
}
if(opt.startsWith("/LIBPATH:")) {
dirs.append(QMakeLocalFileName(opt.mid(9)));
} else if(opt.startsWith("-L") || opt.startsWith("/L")) {
QString libpath = opt.mid(2);
dirs.append(QMakeLocalFileName(libpath));
modified_opt = true;
if (!quote.isNull()) {
libpath = quote + libpath + quote;
quote = QChar();
}
(*it) = "/LIBPATH:" + libpath;
} else if(opt.startsWith("-l") || opt.startsWith("/l")) {
QString lib = opt.right(opt.length() - 2), out;
if(!lib.isEmpty()) {
QString suffix;
if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX"))
suffix = project->first("QMAKE_" + lib.toUpper() + "_SUFFIX");
for(QList<QMakeLocalFileName>::Iterator it = dirs.begin();
it != dirs.end(); ++it) {
QString extension;
int ver = findHighestVersion((*it).local(), lib);
if(ver > 0)
extension += QString::number(ver);
extension += suffix;
extension += ".lib";
if(QMakeMetaInfo::libExists((*it).local() + Option::dir_sep + lib) ||
exists((*it).local() + Option::dir_sep + lib + extension)) {
out = (*it).real() + Option::dir_sep + lib + extension;
break;
}
}
}
if(out.isEmpty())
out = lib + ".lib";
modified_opt = true;
(*it) = out;
} else if(!exists(Option::fixPathToLocalOS(opt))) {
QList<QMakeLocalFileName> lib_dirs;
QString file = opt;
int slsh = file.lastIndexOf(Option::dir_sep);
if(slsh != -1) {
lib_dirs.append(QMakeLocalFileName(file.left(slsh+1)));
file = file.right(file.length() - slsh - 1);
} else {
lib_dirs = dirs;
}
if(file.endsWith(".lib")) {
file = file.left(file.length() - 4);
if(!file.at(file.length()-1).isNumber()) {
QString suffix;
if(!project->isEmpty("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX"))
suffix = project->first("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX");
for(QList<QMakeLocalFileName>::Iterator dep_it = lib_dirs.begin(); dep_it != lib_dirs.end(); ++dep_it) {
QString lib_tmpl(file + "%1" + suffix + ".lib");
int ver = findHighestVersion((*dep_it).local(), file);
if(ver != -1) {
if(ver)
lib_tmpl = lib_tmpl.arg(ver);
else
lib_tmpl = lib_tmpl.arg("");
if(slsh != -1) {
QString dir = (*dep_it).real();
if(!dir.endsWith(Option::dir_sep))
dir += Option::dir_sep;
lib_tmpl.prepend(dir);
}
modified_opt = true;
(*it) = lib_tmpl;
break;
}
}
}
}
}
if(remove) {
it = l.erase(it);
} else {
if(!quote.isNull() && modified_opt)
(*it) = quote + (*it) + quote;
++it;
}
}
return true;
}
void
Win32MakefileGenerator::processPrlFiles()
{
QHash<QString, bool> processed;
QList<QMakeLocalFileName> libdirs;
{
QStringList &libpaths = project->variables()["QMAKE_LIBDIR"];
for(QStringList::Iterator libpathit = libpaths.begin(); libpathit != libpaths.end(); ++libpathit)
libdirs.append(QMakeLocalFileName((*libpathit)));
}
for(bool ret = false; true; ret = false) {
//read in any prl files included..
QStringList l_out;
QString where = "QMAKE_LIBS";
if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
where = project->first("QMAKE_INTERNAL_PRL_LIBS");
QStringList l = project->variables()[where];
for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
QString opt = (*it).trimmed();
if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0])
opt = opt.mid(1, opt.length()-2);
if(opt.startsWith("/")) {
if(opt.startsWith("/LIBPATH:"))
libdirs.append(QMakeLocalFileName(opt.mid(9)));
} else if(!processed.contains(opt)) {
if(processPrlFile(opt)) {
processed.insert(opt, true);
ret = true;
} else if(QDir::isRelativePath(opt) || opt.startsWith("-l")) {
QString tmp;
if (opt.startsWith("-l"))
tmp = opt.mid(2);
else
tmp = opt;
for(QList<QMakeLocalFileName>::Iterator it = libdirs.begin(); it != libdirs.end(); ++it) {
QString prl = (*it).local() + Option::dir_sep + tmp;
// the orignal is used as the key
QString orgprl = prl;
if(processed.contains(prl)) {
break;
} else if(processPrlFile(prl)) {
processed.insert(orgprl, true);
ret = true;
break;
}
}
}
}
if(!opt.isEmpty())
l_out.append(opt);
}
if(ret)
l = l_out;
else
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -