~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to qmake/meta.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

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