Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

meta.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** 
00003 **
00004 ** Implementation of QMakeMetaInfo class.
00005 **
00006 ** Copyright (C) 1992-2003 Trolltech AS.  All rights reserved.
00007 **
00008 ** This file is part of qmake.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech AS of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00020 ** file in accordance with the Qt Commercial License Agreement provided
00021 ** with the Software.
00022 **
00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 **
00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00027 **   information about Qt Commercial License Agreements.
00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00030 **
00031 ** Contact info@trolltech.com if any conditions of this licensing are
00032 ** not clear to you.
00033 **
00034 **********************************************************************/
00035 
00036 #include "meta.h"
00037 #include "project.h"
00038 #include "option.h"
00039 #include <qdir.h>
00040 
00041 QMap<QString, QMap<QString, QStringList> > QMakeMetaInfo::cache_vars;
00042 
00043 QMakeMetaInfo::QMakeMetaInfo()
00044 {
00045     
00046 }
00047 
00048 
00049 bool
00050 QMakeMetaInfo::readLib(const QString &lib)
00051 {
00052     clear();
00053     QString meta_file = findLib(lib);
00054     
00055     if(cache_vars.contains(meta_file)) {
00056         vars = cache_vars[meta_file];
00057         return TRUE;
00058     }
00059 
00060     bool ret = FALSE;
00061     if(!meta_file.isNull()) {
00062         if(meta_file.endsWith(Option::pkgcfg_ext)) {
00063             if((ret=readPkgCfgFile(meta_file))) 
00064                 meta_type = "pkgcfg";
00065         } else if(meta_file.endsWith(Option::libtool_ext)) {
00066             if((ret=readLibtoolFile(meta_file))) 
00067                 meta_type = "libtool";
00068         } else if(meta_file.endsWith(Option::prl_ext)) {
00069             QMakeProject proj;
00070             if(!proj.read(Option::fixPathToLocalOS(meta_file), 
00071                           QDir::currentDirPath(), QMakeProject::ReadProFile))
00072                 return FALSE;
00073             meta_type = "qmake";
00074             vars = proj.variables();
00075             ret = TRUE;
00076         } else {
00077             warn_msg(WarnLogic, "QMakeMetaInfo: unknown file format for %s", meta_file.latin1());
00078         }
00079     }
00080     if(ret) 
00081         cache_vars.insert(meta_file, vars);
00082     return ret;
00083 }
00084 
00085 
00086 void
00087 QMakeMetaInfo::clear()
00088 {
00089     vars.clear();
00090 }
00091 
00092 
00093 QString
00094 QMakeMetaInfo::findLib(const QString &lib)
00095 {
00096     QString ret = QString::null;
00097     QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString::null };
00098     for(int extn = 0; !extns[extn].isNull(); extn++) {
00099         if(lib.endsWith(extns[extn]))
00100             ret = QFile::exists(lib) ? lib : QString::null;
00101     }
00102     if(ret.isNull()) {
00103         for(int extn = 0; !extns[extn].isNull(); extn++) {
00104             if(QFile::exists(lib + extns[extn])) {
00105                 ret = lib + extns[extn];
00106                 break;
00107             }
00108         }
00109     }
00110     if(ret.isNull())
00111         debug_msg(2, "QMakeMetaInfo: Cannot find info file for %s", lib.latin1());
00112     else
00113         debug_msg(2, "QMakeMetaInfo: Found info file %s for %s", ret.latin1(), lib.latin1());
00114     return ret;
00115 }
00116 
00117 
00118 bool
00119 QMakeMetaInfo::readLibtoolFile(const QString &f)
00120 {
00121     /* I can just run the .la through the .pro parser since they are compatible.. */
00122     QMakeProject proj;
00123     if(!proj.read(Option::fixPathToLocalOS(f), QDir::currentDirPath(), QMakeProject::ReadProFile))
00124         return FALSE;
00125     QString dirf = Option::fixPathToTargetOS(f).section(Option::dir_sep, 0, -2);
00126     if(dirf == f)
00127         dirf = "";
00128     else if(!dirf.isEmpty() && !dirf.endsWith(Option::output_dir))
00129         dirf += Option::dir_sep;
00130     QMap<QString, QStringList> &v = proj.variables();
00131     for(QMap<QString, QStringList>::Iterator it = v.begin(); it != v.end(); ++it) {
00132         QStringList lst = it.data();
00133         if(lst.count() == 1 && (lst.first().startsWith("'") || lst.first().startsWith("\"")) &&
00134            lst.first().endsWith(QString(lst.first()[0])))
00135             lst = lst.first().mid(1, lst.first().length() - 2);
00136         if(!vars.contains("QMAKE_PRL_TARGET") &&
00137            (it.key() == "dlname" || it.key() == "library_names" || it.key() == "old_library")) {
00138             QString dir = v["libdir"].first();
00139             if((dir.startsWith("'") || dir.startsWith("\"")) && dir.endsWith(QString(dir[0])))
00140                 dir = dir.mid(1, dir.length() - 2);
00141             dir = dir.stripWhiteSpace();
00142             if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep))
00143                 dir += Option::dir_sep;
00144             if(lst.count() == 1)
00145                 lst = QStringList::split(" ", lst.first());
00146             for(QStringList::Iterator lst_it = lst.begin(); lst_it != lst.end(); ++lst_it) {
00147                 bool found = FALSE;
00148                 QString dirs[] = { "", dir, dirf, dirf + ".libs" + QDir::separator(), "(term)" };
00149                 for(int i = 0; !found && dirs[i] != "(term)"; i++) {
00150                     if(QFile::exists(dirs[i] + (*lst_it))) {
00151                         QString targ = dirs[i] + (*lst_it);
00152                         if(QDir::isRelativePath(targ)) 
00153                             targ.prepend(QDir::currentDirPath() + QDir::separator());
00154                         vars["QMAKE_PRL_TARGET"] << targ;
00155                         found = TRUE;
00156                     }
00157                 }
00158                 if(found)
00159                     break;
00160             }
00161         } else if(it.key() == "dependency_libs") {
00162             if(lst.count() == 1) {
00163                 QString dep = lst.first();
00164                 if((dep.startsWith("'") || dep.startsWith("\"")) && dep.endsWith(QString(dep[0])))
00165                     dep = dep.mid(1, dep.length() - 2);
00166                 lst = QStringList::split(" ", dep.stripWhiteSpace());
00167             }
00168             QMakeProject *conf = NULL;
00169             for(QStringList::Iterator lit = lst.begin(); lit != lst.end(); ++lit) {
00170                 if((*lit).startsWith("-R")) {
00171                     if(!conf) {
00172                         conf = new QMakeProject;
00173                         conf->read(QMakeProject::ReadAll ^ QMakeProject::ReadProFile);
00174                     }
00175                     if(!conf->isEmpty("QMAKE_RPATH"))
00176                         (*lit) = conf->first("QMAKE_RPATH") + (*lit).mid(2);
00177                 }
00178             }
00179             if(conf)
00180                 delete conf;
00181             vars["QMAKE_PRL_LIBS"] += lst;
00182         }
00183     }
00184     return TRUE;
00185 }
00186 
00187 bool
00188 QMakeMetaInfo::readPkgCfgFile(const QString &f)
00189 {
00190     fprintf(stderr, "Must implement reading in pkg-config files (%s)!!!\n", f.latin1());
00191     return FALSE;
00192 }

Generated on Sat Nov 5 16:18:27 2005 for OPIE by  doxygen 1.4.2