00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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, 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
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 }