Temporary backwards-compatibility window properties
[profile/ivi/qtbase.git] / qmake / meta.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "meta.h"
43 #include "project.h"
44 #include "option.h"
45 #include <qdir.h>
46
47 QT_BEGIN_NAMESPACE
48
49 QHash<QString, ProValueMap> QMakeMetaInfo::cache_vars;
50
51 QMakeMetaInfo::QMakeMetaInfo(QMakeProject *_conf)
52     : conf(_conf)
53 {
54
55 }
56
57
58 bool
59 QMakeMetaInfo::readLib(QString lib)
60 {
61     clear();
62     QString meta_file = findLib(lib);
63
64     if(cache_vars.contains(meta_file)) {
65         vars = cache_vars[meta_file];
66         return true;
67     }
68
69     bool ret = false;
70     if(!meta_file.isNull()) {
71         if(meta_file.endsWith(Option::pkgcfg_ext)) {
72             if((ret=readPkgCfgFile(meta_file)))
73                 meta_type = "pkgcfg";
74         } else if(meta_file.endsWith(Option::libtool_ext)) {
75             if((ret=readLibtoolFile(meta_file)))
76                 meta_type = "libtool";
77         } else if(meta_file.endsWith(Option::prl_ext)) {
78             QMakeProject proj;
79             if (!proj.read(Option::normalizePath(meta_file), QMakeEvaluator::LoadProOnly))
80                 return false;
81             meta_type = "qmake";
82             vars = proj.variables();
83             ret = true;
84         } else {
85             warn_msg(WarnLogic, "QMakeMetaInfo: unknown file format for %s",
86                      QDir::toNativeSeparators(meta_file).toLatin1().constData());
87         }
88     }
89     if(ret)
90         cache_vars.insert(meta_file, vars);
91     return ret;
92 }
93
94
95 void
96 QMakeMetaInfo::clear()
97 {
98     vars.clear();
99 }
100
101
102 QString
103 QMakeMetaInfo::findLib(QString lib)
104 {
105     if((lib[0] == '\'' || lib[0] == '"') &&
106        lib[lib.length()-1] == lib[0])
107     lib = lib.mid(1, lib.length()-2);
108     lib = Option::normalizePath(lib);
109
110     QString ret;
111     QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString() };
112     for(int extn = 0; !extns[extn].isNull(); extn++) {
113         if(lib.endsWith(extns[extn]))
114             ret = QFile::exists(lib) ? lib : QString();
115     }
116     if(ret.isNull()) {
117         for(int extn = 0; !extns[extn].isNull(); extn++) {
118             if(QFile::exists(lib + extns[extn])) {
119                 ret = lib + extns[extn];
120                 break;
121             }
122         }
123     }
124     if(ret.isNull()) {
125         debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.toLatin1().constData());
126     } else {
127         debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.toLatin1().constData(), lib.toLatin1().constData());
128     }
129     return ret;
130 }
131
132
133 bool
134 QMakeMetaInfo::readLibtoolFile(const QString &f)
135 {
136     /* I can just run the .la through the .pro parser since they are compatible.. */
137     QMakeProject proj;
138     QString nf = Option::normalizePath(f);
139     if (!proj.read(nf, QMakeEvaluator::LoadProOnly))
140         return false;
141     QString dirf = nf.section(QLatin1Char('/'), 0, -2);
142     if(dirf == nf)
143         dirf = "";
144     else if(!dirf.isEmpty() && !dirf.endsWith(Option::output_dir))
145         dirf += QLatin1Char('/');
146     const ProValueMap &v = proj.variables();
147     for (ProValueMap::ConstIterator it = v.begin(); it != v.end(); ++it) {
148         ProStringList lst = it.value();
149         if(lst.count() == 1 && (lst.first().startsWith("'") || lst.first().startsWith("\"")) &&
150            lst.first().endsWith(QString(lst.first().at(0))))
151             lst = ProStringList(lst.first().mid(1, lst.first().length() - 2));
152         if(!vars.contains("QMAKE_PRL_TARGET") &&
153            (it.key() == "dlname" || it.key() == "library_names" || it.key() == "old_library")) {
154             ProString dir = v["libdir"].first();
155             if ((dir.startsWith('\'') || dir.startsWith('"')) && dir.endsWith(dir.at(0)))
156                 dir = dir.mid(1, dir.length() - 2);
157             dir = dir.trimmed();
158             if(!dir.isEmpty() && !dir.endsWith(QLatin1Char('/')))
159                 dir += QLatin1Char('/');
160             if(lst.count() == 1)
161                 lst = ProStringList(lst.first().toQString().split(" "));
162             for (ProStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) {
163                 bool found = false;
164                 QString dirs[] = { "", dir.toQString(), dirf, dirf + ".libs/", "(term)" };
165                 for(int i = 0; !found && dirs[i] != "(term)"; i++) {
166                     if(QFile::exists(dirs[i] + (*lst_it))) {
167                         QString targ = dirs[i] + (*lst_it);
168                         if(QDir::isRelativePath(targ))
169                             targ.prepend(qmake_getpwd() + QLatin1Char('/'));
170                         vars["QMAKE_PRL_TARGET"] << targ;
171                         found = true;
172                     }
173                 }
174                 if(found)
175                     break;
176             }
177         } else if(it.key() == "dependency_libs") {
178             if(lst.count() == 1) {
179                 ProString dep = lst.first();
180                 if ((dep.startsWith('\'') || dep.startsWith('"')) && dep.endsWith(dep.at(0)))
181                     dep = dep.mid(1, dep.length() - 2);
182                 lst = ProStringList(dep.trimmed().toQString().split(" "));
183             }
184             for (ProStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) {
185                 if((*lit).startsWith("-R")) {
186                     if(!conf->isEmpty("QMAKE_LFLAGS_RPATH"))
187                         (*lit) = conf->first("QMAKE_LFLAGS_RPATH") + (*lit).mid(2);
188                 }
189             }
190             vars["QMAKE_PRL_LIBS"] += lst;
191         }
192     }
193     return true;
194 }
195
196 bool
197 QMakeMetaInfo::readPkgCfgFile(const QString &f)
198 {
199     fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.toLatin1().constData());
200     return false;
201 }
202
203 QT_END_NAMESPACE