1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the qmake application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
34
QMap<QString, QMap<QString, QStringList> > QMakeMetaInfo::cache_vars;
36
QMakeMetaInfo::QMakeMetaInfo()
43
QMakeMetaInfo::readLib(QString lib)
46
QString meta_file = findLib(lib);
48
if(cache_vars.contains(meta_file)) {
49
vars = cache_vars[meta_file];
54
if(!meta_file.isNull()) {
55
if(meta_file.endsWith(Option::pkgcfg_ext)) {
56
if((ret=readPkgCfgFile(meta_file)))
58
} else if(meta_file.endsWith(Option::libtool_ext)) {
59
if((ret=readLibtoolFile(meta_file)))
60
meta_type = "libtool";
61
} else if(meta_file.endsWith(Option::prl_ext)) {
63
if(!proj.read(Option::fixPathToLocalOS(meta_file), QMakeProject::ReadProFile))
66
vars = proj.variables();
69
warn_msg(WarnLogic, "QMakeMetaInfo: unknown file format for %s", meta_file.toLatin1().constData());
73
cache_vars.insert(meta_file, vars);
79
QMakeMetaInfo::clear()
86
QMakeMetaInfo::findLib(QString lib)
88
if((lib[0] == '\'' || lib[0] == '"') &&
89
lib[lib.length()-1] == lib[0])
90
lib = lib.mid(1, lib.length()-2);
91
lib = Option::fixPathToLocalOS(lib);
94
QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString() };
95
for(int extn = 0; !extns[extn].isNull(); extn++) {
96
if(lib.endsWith(extns[extn]))
97
ret = QFile::exists(lib) ? lib : QString();
100
for(int extn = 0; !extns[extn].isNull(); extn++) {
101
if(QFile::exists(lib + extns[extn])) {
102
ret = lib + extns[extn];
108
debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.toLatin1().constData());
110
debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.toLatin1().constData(), lib.toLatin1().constData());
116
QMakeMetaInfo::readLibtoolFile(const QString &f)
118
/* I can just run the .la through the .pro parser since they are compatible.. */
120
if(!proj.read(Option::fixPathToLocalOS(f), QMakeProject::ReadProFile))
122
QString dirf = Option::fixPathToTargetOS(f).section(Option::dir_sep, 0, -2);
125
else if(!dirf.isEmpty() && !dirf.endsWith(Option::output_dir))
126
dirf += Option::dir_sep;
127
QMap<QString, QStringList> &v = proj.variables();
128
for(QMap<QString, QStringList>::Iterator it = v.begin(); it != v.end(); ++it) {
129
QStringList lst = it.value();
130
if(lst.count() == 1 && (lst.first().startsWith("'") || lst.first().startsWith("\"")) &&
131
lst.first().endsWith(QString(lst.first()[0])))
132
lst = QStringList(lst.first().mid(1, lst.first().length() - 2));
133
if(!vars.contains("QMAKE_PRL_TARGET") &&
134
(it.key() == "dlname" || it.key() == "library_names" || it.key() == "old_library")) {
135
QString dir = v["libdir"].first();
136
if((dir.startsWith("'") || dir.startsWith("\"")) && dir.endsWith(QString(dir[0])))
137
dir = dir.mid(1, dir.length() - 2);
139
if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep))
140
dir += Option::dir_sep;
142
lst = lst.first().split(" ");
143
for(QStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) {
145
QString dirs[] = { "", dir, dirf, dirf + ".libs" + QDir::separator(), "(term)" };
146
for(int i = 0; !found && dirs[i] != "(term)"; i++) {
147
if(QFile::exists(dirs[i] + (*lst_it))) {
148
QString targ = dirs[i] + (*lst_it);
149
if(QDir::isRelativePath(targ))
150
targ.prepend(qmake_getpwd() + QDir::separator());
151
vars["QMAKE_PRL_TARGET"] << targ;
158
} else if(it.key() == "dependency_libs") {
159
if(lst.count() == 1) {
160
QString dep = lst.first();
161
if((dep.startsWith("'") || dep.startsWith("\"")) && dep.endsWith(QString(dep[0])))
162
dep = dep.mid(1, dep.length() - 2);
163
lst = dep.trimmed().split(" ");
165
QMakeProject *conf = NULL;
166
for(QStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) {
167
if((*lit).startsWith("-R")) {
169
conf = new QMakeProject;
170
conf->read(QMakeProject::ReadAll ^ QMakeProject::ReadProFile);
172
if(!conf->isEmpty("QMAKE_LFLAGS_RPATH"))
173
(*lit) = conf->first("QMAKE_LFLAGS_RPATH") + (*lit).mid(2);
178
vars["QMAKE_PRL_LIBS"] += lst;
185
QMakeMetaInfo::readPkgCfgFile(const QString &f)
187
fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.toLatin1().constData());