| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 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 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 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 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 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 | } | 
|---|
| 127 | return ret; | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | bool | 
|---|
| 132 | QMakeMetaInfo::readLibtoolFile(const QString &f) | 
|---|
| 133 | { | 
|---|
| 134 | /* I can just run the .la through the .pro parser since they are compatible.. */ | 
|---|
| 135 | QMakeProject proj; | 
|---|
| 136 | if(!proj.read(Option::fixPathToLocalOS(f), QMakeProject::ReadProFile)) | 
|---|
| 137 | return false; | 
|---|
| 138 | QString dirf = Option::fixPathToTargetOS(f).section(Option::dir_sep, 0, -2); | 
|---|
| 139 | if(dirf == f) | 
|---|
| 140 | dirf = ""; | 
|---|
| 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); | 
|---|
| 154 | dir = dir.trimmed(); | 
|---|
| 155 | if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep)) | 
|---|
| 156 | dir += Option::dir_sep; | 
|---|
| 157 | if(lst.count() == 1) | 
|---|
| 158 | lst = lst.first().split(" "); | 
|---|
| 159 | for(QStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) { | 
|---|
| 160 | bool found = false; | 
|---|
| 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; | 
|---|
| 168 | found = true; | 
|---|
| 169 | } | 
|---|
| 170 | } | 
|---|
| 171 | if(found) | 
|---|
| 172 | break; | 
|---|
| 173 | } | 
|---|
| 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(" "); | 
|---|
| 180 | } | 
|---|
| 181 | QMakeProject *conf = NULL; | 
|---|
| 182 | for(QStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) { | 
|---|
| 183 | if((*lit).startsWith("-R")) { | 
|---|
| 184 | if(!conf) { | 
|---|
| 185 | conf = new QMakeProject; | 
|---|
| 186 | conf->read(QMakeProject::ReadAll ^ QMakeProject::ReadProFile); | 
|---|
| 187 | } | 
|---|
| 188 | if(!conf->isEmpty("QMAKE_LFLAGS_RPATH")) | 
|---|
| 189 | (*lit) = conf->first("QMAKE_LFLAGS_RPATH") + (*lit).mid(2); | 
|---|
| 190 | } | 
|---|
| 191 | } | 
|---|
| 192 | if(conf) | 
|---|
| 193 | delete conf; | 
|---|
| 194 | vars["QMAKE_PRL_LIBS"] += lst; | 
|---|
| 195 | } | 
|---|
| 196 | } | 
|---|
| 197 | return true; | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 | bool | 
|---|
| 201 | QMakeMetaInfo::readPkgCfgFile(const QString &f) | 
|---|
| 202 | { | 
|---|
| 203 | fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.toLatin1().constData()); | 
|---|
| 204 | return false; | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | QT_END_NAMESPACE | 
|---|