| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: meta.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of QMakeMetaInfo class.
|
|---|
| 5 | **
|
|---|
| 6 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
|---|
| 7 | **
|
|---|
| 8 | ** This file is part of qmake.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 11 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 12 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 13 | **
|
|---|
| 14 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 15 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 16 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 17 | ** packaging of this file.
|
|---|
| 18 | **
|
|---|
| 19 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 20 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 21 | ** with the Software.
|
|---|
| 22 | **
|
|---|
| 23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 25 | **
|
|---|
| 26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 27 | ** information about Qt Commercial License Agreements.
|
|---|
| 28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 30 | **
|
|---|
| 31 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 32 | ** not clear to you.
|
|---|
| 33 | **
|
|---|
| 34 | **********************************************************************/
|
|---|
| 35 |
|
|---|
| 36 | #include "meta.h"
|
|---|
| 37 | #include "project.h"
|
|---|
| 38 | #include "option.h"
|
|---|
| 39 | #include <qdir.h>
|
|---|
| 40 |
|
|---|
| 41 | QMap<QString, QMap<QString, QStringList> > QMakeMetaInfo::cache_vars;
|
|---|
| 42 |
|
|---|
| 43 | QMakeMetaInfo::QMakeMetaInfo()
|
|---|
| 44 | {
|
|---|
| 45 |
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | bool
|
|---|
| 50 | QMakeMetaInfo::readLib(const QString &lib)
|
|---|
| 51 | {
|
|---|
| 52 | clear();
|
|---|
| 53 | QString meta_file = findLib(lib);
|
|---|
| 54 |
|
|---|
| 55 | if(cache_vars.contains(meta_file)) {
|
|---|
| 56 | vars = cache_vars[meta_file];
|
|---|
| 57 | return TRUE;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | bool ret = FALSE;
|
|---|
| 61 | if(!meta_file.isNull()) {
|
|---|
| 62 | if(meta_file.endsWith(Option::pkgcfg_ext)) {
|
|---|
| 63 | if((ret=readPkgCfgFile(meta_file)))
|
|---|
| 64 | meta_type = "pkgcfg";
|
|---|
| 65 | } else if(meta_file.endsWith(Option::libtool_ext)) {
|
|---|
| 66 | if((ret=readLibtoolFile(meta_file)))
|
|---|
| 67 | meta_type = "libtool";
|
|---|
| 68 | } else if(meta_file.endsWith(Option::prl_ext)) {
|
|---|
| 69 | QMakeProject proj;
|
|---|
| 70 | if(!proj.read(Option::fixPathToLocalOS(meta_file),
|
|---|
| 71 | QDir::currentDirPath(), QMakeProject::ReadProFile))
|
|---|
| 72 | return FALSE;
|
|---|
| 73 | meta_type = "qmake";
|
|---|
| 74 | vars = proj.variables();
|
|---|
| 75 | ret = TRUE;
|
|---|
| 76 | } else {
|
|---|
| 77 | warn_msg(WarnLogic, "QMakeMetaInfo: unknown file format for %s", meta_file.latin1());
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 | if(ret)
|
|---|
| 81 | cache_vars.insert(meta_file, vars);
|
|---|
| 82 | return ret;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | void
|
|---|
| 87 | QMakeMetaInfo::clear()
|
|---|
| 88 | {
|
|---|
| 89 | vars.clear();
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | QString
|
|---|
| 94 | QMakeMetaInfo::findLib(const QString &lib)
|
|---|
| 95 | {
|
|---|
| 96 | QString ret = QString::null;
|
|---|
| 97 | QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString::null };
|
|---|
| 98 | for(int extn = 0; !extns[extn].isNull(); extn++) {
|
|---|
| 99 | if(lib.endsWith(extns[extn]))
|
|---|
| 100 | ret = QFile::exists(lib) ? lib : QString::null;
|
|---|
| 101 | }
|
|---|
| 102 | if(ret.isNull()) {
|
|---|
| 103 | for(int extn = 0; !extns[extn].isNull(); extn++) {
|
|---|
| 104 | if(QFile::exists(lib + extns[extn])) {
|
|---|
| 105 | ret = lib + extns[extn];
|
|---|
| 106 | break;
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | if(ret.isNull())
|
|---|
| 111 | debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.latin1());
|
|---|
| 112 | else
|
|---|
| 113 | debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.latin1(), lib.latin1());
|
|---|
| 114 | return ret;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | bool
|
|---|
| 119 | QMakeMetaInfo::readLibtoolFile(const QString &f)
|
|---|
| 120 | {
|
|---|
| 121 | /* I can just run the .la through the .pro parser since they are compatible.. */
|
|---|
| 122 | QMakeProject proj;
|
|---|
| 123 | if(!proj.read(Option::fixPathToLocalOS(f), QDir::currentDirPath(), QMakeProject::ReadProFile))
|
|---|
| 124 | return FALSE;
|
|---|
| 125 | QString dirf = Option::fixPathToTargetOS(f).section(Option::dir_sep, 0, -2);
|
|---|
| 126 | if(dirf == f)
|
|---|
| 127 | dirf = "";
|
|---|
| 128 | else if(!dirf.isEmpty() && !dirf.endsWith(Option::output_dir))
|
|---|
| 129 | dirf += Option::dir_sep;
|
|---|
| 130 | QMap<QString, QStringList> &v = proj.variables();
|
|---|
| 131 | for(QMap<QString, QStringList>::Iterator it = v.begin(); it != v.end(); ++it) {
|
|---|
| 132 | QStringList lst = it.data();
|
|---|
| 133 | if(lst.count() == 1 && (lst.first().startsWith("'") || lst.first().startsWith("\"")) &&
|
|---|
| 134 | lst.first().endsWith(QString(lst.first()[0])))
|
|---|
| 135 | lst = lst.first().mid(1, lst.first().length() - 2);
|
|---|
| 136 | if(!vars.contains("QMAKE_PRL_TARGET") &&
|
|---|
| 137 | (it.key() == "dlname" || it.key() == "library_names" || it.key() == "old_library")) {
|
|---|
| 138 | QString dir = v["libdir"].first();
|
|---|
| 139 | if((dir.startsWith("'") || dir.startsWith("\"")) && dir.endsWith(QString(dir[0])))
|
|---|
| 140 | dir = dir.mid(1, dir.length() - 2);
|
|---|
| 141 | dir = dir.stripWhiteSpace();
|
|---|
| 142 | if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep))
|
|---|
| 143 | dir += Option::dir_sep;
|
|---|
| 144 | if(lst.count() == 1)
|
|---|
| 145 | lst = QStringList::split(" ", lst.first());
|
|---|
| 146 | for(QStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) {
|
|---|
| 147 | bool found = FALSE;
|
|---|
| 148 | QString dirs[] = { "", dir, dirf, dirf + ".libs" + QDir::separator(), "(term)" };
|
|---|
| 149 | for(int i = 0; !found && dirs[i] != "(term)"; i++) {
|
|---|
| 150 | if(QFile::exists(dirs[i] + (*lst_it))) {
|
|---|
| 151 | QString targ = dirs[i] + (*lst_it);
|
|---|
| 152 | if(QDir::isRelativePath(targ))
|
|---|
| 153 | targ.prepend(QDir::currentDirPath() + QDir::separator());
|
|---|
| 154 | vars["QMAKE_PRL_TARGET"] << targ;
|
|---|
| 155 | found = TRUE;
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | if(found)
|
|---|
| 159 | break;
|
|---|
| 160 | }
|
|---|
| 161 | } else if(it.key() == "dependency_libs") {
|
|---|
| 162 | if(lst.count() == 1) {
|
|---|
| 163 | QString dep = lst.first();
|
|---|
| 164 | if((dep.startsWith("'") || dep.startsWith("\"")) && dep.endsWith(QString(dep[0])))
|
|---|
| 165 | dep = dep.mid(1, dep.length() - 2);
|
|---|
| 166 | lst = QStringList::split(" ", dep.stripWhiteSpace());
|
|---|
| 167 | }
|
|---|
| 168 | QMakeProject *conf = NULL;
|
|---|
| 169 | for(QStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) {
|
|---|
| 170 | if((*lit).startsWith("-R")) {
|
|---|
| 171 | if(!conf) {
|
|---|
| 172 | conf = new QMakeProject;
|
|---|
| 173 | conf->read(QMakeProject::ReadAll ^ QMakeProject::ReadProFile);
|
|---|
| 174 | }
|
|---|
| 175 | if(!conf->isEmpty("QMAKE_RPATH"))
|
|---|
| 176 | (*lit) = conf->first("QMAKE_RPATH") + (*lit).mid(2);
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | if(conf)
|
|---|
| 180 | delete conf;
|
|---|
| 181 | vars["QMAKE_PRL_LIBS"] += lst;
|
|---|
| 182 | }
|
|---|
| 183 | }
|
|---|
| 184 | return TRUE;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | bool
|
|---|
| 188 | QMakeMetaInfo::readPkgCfgFile(const QString &f)
|
|---|
| 189 | {
|
|---|
| 190 | fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.latin1());
|
|---|
| 191 | return FALSE;
|
|---|
| 192 | }
|
|---|