|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the qmake application of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
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 QMap<QString, QMap<QString, QStringList> > QMakeMetaInfo::cache_vars; |
|
50 |
|
51 QMakeMetaInfo::QMakeMetaInfo() |
|
52 { |
|
53 |
|
54 } |
|
55 |
|
56 |
|
57 bool |
|
58 QMakeMetaInfo::readLib(QString lib) |
|
59 { |
|
60 clear(); |
|
61 QString meta_file = findLib(lib); |
|
62 |
|
63 if(cache_vars.contains(meta_file)) { |
|
64 vars = cache_vars[meta_file]; |
|
65 return true; |
|
66 } |
|
67 |
|
68 bool ret = false; |
|
69 if(!meta_file.isNull()) { |
|
70 if(meta_file.endsWith(Option::pkgcfg_ext)) { |
|
71 if((ret=readPkgCfgFile(meta_file))) |
|
72 meta_type = "pkgcfg"; |
|
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)) { |
|
77 QMakeProject proj; |
|
78 if(!proj.read(Option::fixPathToLocalOS(meta_file), QMakeProject::ReadProFile)) |
|
79 return false; |
|
80 meta_type = "qmake"; |
|
81 vars = proj.variables(); |
|
82 ret = true; |
|
83 } else { |
|
84 warn_msg(WarnLogic, "QMakeMetaInfo: unknown file format for %s", meta_file.toLatin1().constData()); |
|
85 } |
|
86 } |
|
87 if(ret) |
|
88 cache_vars.insert(meta_file, vars); |
|
89 return ret; |
|
90 } |
|
91 |
|
92 |
|
93 void |
|
94 QMakeMetaInfo::clear() |
|
95 { |
|
96 vars.clear(); |
|
97 } |
|
98 |
|
99 |
|
100 QString |
|
101 QMakeMetaInfo::findLib(QString lib) |
|
102 { |
|
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); |
|
107 |
|
108 QString ret; |
|
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(); |
|
113 } |
|
114 if(ret.isNull()) { |
|
115 for(int extn = 0; !extns[extn].isNull(); extn++) { |
|
116 if(QFile::exists(lib + extns[extn])) { |
|
117 ret = lib + extns[extn]; |
|
118 break; |
|
119 } |
|
120 } |
|
121 } |
|
122 if(ret.isNull()) |
|
123 debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.toLatin1().constData()); |
|
124 else |
|
125 debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.toLatin1().constData(), lib.toLatin1().constData()); |
|
126 return ret; |
|
127 } |
|
128 |
|
129 |
|
130 bool |
|
131 QMakeMetaInfo::readLibtoolFile(const QString &f) |
|
132 { |
|
133 /* I can just run the .la through the .pro parser since they are compatible.. */ |
|
134 QMakeProject proj; |
|
135 if(!proj.read(Option::fixPathToLocalOS(f), QMakeProject::ReadProFile)) |
|
136 return false; |
|
137 QString dirf = Option::fixPathToTargetOS(f).section(Option::dir_sep, 0, -2); |
|
138 if(dirf == f) |
|
139 dirf = ""; |
|
140 else if(!dirf.isEmpty() && !dirf.endsWith(Option::output_dir)) |
|
141 dirf += Option::dir_sep; |
|
142 QMap<QString, QStringList> &v = proj.variables(); |
|
143 for(QMap<QString, QStringList>::Iterator it = v.begin(); it != v.end(); ++it) { |
|
144 QStringList lst = it.value(); |
|
145 if(lst.count() == 1 && (lst.first().startsWith("'") || lst.first().startsWith("\"")) && |
|
146 lst.first().endsWith(QString(lst.first()[0]))) |
|
147 lst = QStringList(lst.first().mid(1, lst.first().length() - 2)); |
|
148 if(!vars.contains("QMAKE_PRL_TARGET") && |
|
149 (it.key() == "dlname" || it.key() == "library_names" || it.key() == "old_library")) { |
|
150 QString dir = v["libdir"].first(); |
|
151 if((dir.startsWith("'") || dir.startsWith("\"")) && dir.endsWith(QString(dir[0]))) |
|
152 dir = dir.mid(1, dir.length() - 2); |
|
153 dir = dir.trimmed(); |
|
154 if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep)) |
|
155 dir += Option::dir_sep; |
|
156 if(lst.count() == 1) |
|
157 lst = lst.first().split(" "); |
|
158 for(QStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) { |
|
159 bool found = false; |
|
160 QString dirs[] = { "", dir, dirf, dirf + ".libs" + QDir::separator(), "(term)" }; |
|
161 for(int i = 0; !found && dirs[i] != "(term)"; i++) { |
|
162 if(QFile::exists(dirs[i] + (*lst_it))) { |
|
163 QString targ = dirs[i] + (*lst_it); |
|
164 if(QDir::isRelativePath(targ)) |
|
165 targ.prepend(qmake_getpwd() + QDir::separator()); |
|
166 vars["QMAKE_PRL_TARGET"] << targ; |
|
167 found = true; |
|
168 } |
|
169 } |
|
170 if(found) |
|
171 break; |
|
172 } |
|
173 } else if(it.key() == "dependency_libs") { |
|
174 if(lst.count() == 1) { |
|
175 QString dep = lst.first(); |
|
176 if((dep.startsWith("'") || dep.startsWith("\"")) && dep.endsWith(QString(dep[0]))) |
|
177 dep = dep.mid(1, dep.length() - 2); |
|
178 lst = dep.trimmed().split(" "); |
|
179 } |
|
180 QMakeProject *conf = NULL; |
|
181 for(QStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) { |
|
182 if((*lit).startsWith("-R")) { |
|
183 if(!conf) { |
|
184 conf = new QMakeProject; |
|
185 conf->read(QMakeProject::ReadAll ^ QMakeProject::ReadProFile); |
|
186 } |
|
187 if(!conf->isEmpty("QMAKE_LFLAGS_RPATH")) |
|
188 (*lit) = conf->first("QMAKE_LFLAGS_RPATH") + (*lit).mid(2); |
|
189 } |
|
190 } |
|
191 if(conf) |
|
192 delete conf; |
|
193 vars["QMAKE_PRL_LIBS"] += lst; |
|
194 } |
|
195 } |
|
196 return true; |
|
197 } |
|
198 |
|
199 bool |
|
200 QMakeMetaInfo::readPkgCfgFile(const QString &f) |
|
201 { |
|
202 fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.toLatin1().constData()); |
|
203 return false; |
|
204 } |
|
205 |
|
206 QT_END_NAMESPACE |