1 /****************************************************************************
3 ** Copyright (C) 2010 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 ** 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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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());
131 QMakeMetaInfo::readLibtoolFile(const QString
&f
)
133 /* I can just run the .la through the .pro parser since they are compatible.. */
135 if(!proj
.read(Option::fixPathToLocalOS(f
), QMakeProject::ReadProFile
))
137 QString dirf
= Option::fixPathToTargetOS(f
).section(Option::dir_sep
, 0, -2);
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);
154 if(!dir
.isEmpty() && !dir
.endsWith(Option::dir_sep
))
155 dir
+= Option::dir_sep
;
157 lst
= lst
.first().split(" ");
158 for(QStringList::Iterator lst_it
= lst
.begin(); lst_it
!= lst
.end(); ++lst_it
) {
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
;
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(" ");
180 QMakeProject
*conf
= NULL
;
181 for(QStringList::Iterator lit
= lst
.begin(); lit
!= lst
.end(); ++lit
) {
182 if((*lit
).startsWith("-R")) {
184 conf
= new QMakeProject
;
185 conf
->read(QMakeProject::ReadAll
^ QMakeProject::ReadProFile
);
187 if(!conf
->isEmpty("QMAKE_LFLAGS_RPATH"))
188 (*lit
) = conf
->first("QMAKE_LFLAGS_RPATH") + (*lit
).mid(2);
193 vars
["QMAKE_PRL_LIBS"] += lst
;
200 QMakeMetaInfo::readPkgCfgFile(const QString
&f
)
202 fprintf(stderr
, "Must implement reading in pkg-config files (%s)!!!\n", f
.toLatin1().constData());