1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the qmake application of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
49 QMap<QString, QMap<QString, QStringList> > QMakeMetaInfo::cache_vars;
51 QMakeMetaInfo::QMakeMetaInfo()
58 QMakeMetaInfo::readLib(QString lib)
61 QString meta_file = findLib(lib);
63 if(cache_vars.contains(meta_file)) {
64 vars = cache_vars[meta_file];
69 if(!meta_file.isNull()) {
70 if(meta_file.endsWith(Option::pkgcfg_ext)) {
71 if((ret=readPkgCfgFile(meta_file)))
73 } else if(meta_file.endsWith(Option::libtool_ext)) {
74 if((ret=readLibtoolFile(meta_file)))
75 meta_type = "libtool";
76 } else if(meta_file.endsWith(Option::prl_ext)) {
78 if(!proj.read(Option::fixPathToLocalOS(meta_file), QMakeProject::ReadProFile))
81 vars = proj.variables();
84 warn_msg(WarnLogic, "QMakeMetaInfo: unknown file format for %s", meta_file.toLatin1().constData());
88 cache_vars.insert(meta_file, vars);
94 QMakeMetaInfo::clear()
101 QMakeMetaInfo::findLib(QString lib)
103 if((lib[0] == '\'' || lib[0] == '"') &&
104 lib[lib.length()-1] == lib[0])
105 lib = lib.mid(1, lib.length()-2);
106 lib = Option::fixPathToLocalOS(lib);
109 QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString() };
110 for(int extn = 0; !extns[extn].isNull(); extn++) {
111 if(lib.endsWith(extns[extn]))
112 ret = QFile::exists(lib) ? lib : QString();
115 for(int extn = 0; !extns[extn].isNull(); extn++) {
116 if(QFile::exists(lib + extns[extn])) {
117 ret = lib + extns[extn];
123 debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.toLatin1().constData());
125 debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.toLatin1().constData(), lib.toLatin1().constData());
132 QMakeMetaInfo::readLibtoolFile(const QString &f)
134 /* I can just run the .la through the .pro parser since they are compatible.. */
136 if(!proj.read(Option::fixPathToLocalOS(f), QMakeProject::ReadProFile))
138 QString dirf = Option::fixPathToTargetOS(f).section(Option::dir_sep, 0, -2);
141 else if(!dirf.isEmpty() && !dirf.endsWith(Option::output_dir))
142 dirf += Option::dir_sep;
143 QMap<QString, QStringList> &v = proj.variables();
144 for(QMap<QString, QStringList>::Iterator it = v.begin(); it != v.end(); ++it) {
145 QStringList lst = it.value();
146 if(lst.count() == 1 && (lst.first().startsWith("'") || lst.first().startsWith("\"")) &&
147 lst.first().endsWith(QString(lst.first()[0])))
148 lst = QStringList(lst.first().mid(1, lst.first().length() - 2));
149 if(!vars.contains("QMAKE_PRL_TARGET") &&
150 (it.key() == "dlname" || it.key() == "library_names" || it.key() == "old_library")) {
151 QString dir = v["libdir"].first();
152 if((dir.startsWith("'") || dir.startsWith("\"")) && dir.endsWith(QString(dir[0])))
153 dir = dir.mid(1, dir.length() - 2);
155 if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep))
156 dir += Option::dir_sep;
158 lst = lst.first().split(" ");
159 for(QStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) {
161 QString dirs[] = { "", dir, dirf, dirf + ".libs" + QDir::separator(), "(term)" };
162 for(int i = 0; !found && dirs[i] != "(term)"; i++) {
163 if(QFile::exists(dirs[i] + (*lst_it))) {
164 QString targ = dirs[i] + (*lst_it);
165 if(QDir::isRelativePath(targ))
166 targ.prepend(qmake_getpwd() + QDir::separator());
167 vars["QMAKE_PRL_TARGET"] << targ;
174 } else if(it.key() == "dependency_libs") {
175 if(lst.count() == 1) {
176 QString dep = lst.first();
177 if((dep.startsWith("'") || dep.startsWith("\"")) && dep.endsWith(QString(dep[0])))
178 dep = dep.mid(1, dep.length() - 2);
179 lst = dep.trimmed().split(" ");
181 QMakeProject *conf = NULL;
182 for(QStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) {
183 if((*lit).startsWith("-R")) {
185 conf = new QMakeProject;
186 conf->read(QMakeProject::ReadAll ^ QMakeProject::ReadProFile);
188 if(!conf->isEmpty("QMAKE_LFLAGS_RPATH"))
189 (*lit) = conf->first("QMAKE_LFLAGS_RPATH") + (*lit).mid(2);
194 vars["QMAKE_PRL_LIBS"] += lst;
201 QMakeMetaInfo::readPkgCfgFile(const QString &f)
203 fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.toLatin1().constData());