From: ishmal Date: Fri, 18 May 2007 14:03:12 +0000 (+0000) Subject: Add initial attempt at embedded pkg-config X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d4f9af2ec7299cda665714173eece343effbd72d;p=inkscape.git Add initial attempt at embedded pkg-config --- diff --git a/build.xml b/build.xml index a3fe9f31c..4aad4e437 100644 --- a/build.xml +++ b/build.xml @@ -63,6 +63,15 @@ + + + #include @@ -2918,6 +2918,39 @@ public: int getLine() { return line; } + + /** + * Set a property to a given value + */ + virtual void setProperty(const String &name, const String &val) + { + properties[name] = val; + } + + /** + * Return a named property is found, else a null string + */ + virtual String getProperty(const String &name) + { + String val; + std::map::iterator iter = properties.find(name); + if (iter != properties.end()) + val = iter->second; + return val; + } + + /** + * Return true if a named property is found, else false + */ + virtual bool hasProperty(const String &name) + { + std::map::iterator iter = properties.find(name); + if (iter == properties.end()) + return false; + return true; + } + + protected: /** @@ -2973,6 +3006,11 @@ protected: */ String trim(const String &s); + /** + * Return a lower case version of the given string + */ + String toLower(const String &s); + /** * Return the native format of the canonical * path which we store @@ -3030,19 +3068,6 @@ protected: virtual std::map &getProperties() { return properties; } - /** - * Return a named property if found, else a null string - */ - virtual String getProperty(const String &name) - { - String val; - std::map::iterator iter; - iter = properties.find(name); - if (iter != properties.end()) - val = iter->second; - return val; - } - std::map properties; @@ -3349,6 +3374,24 @@ String MakeBase::trim(const String &s) return res; } + +/** + * Return a lower case version of the given string + */ +String MakeBase::toLower(const String &s) +{ + if (s.size()==0) + return s; + + String ret; + for(unsigned int i=0; i &getRequireList() { return requireList; } + /** + * Read a file for its details + */ virtual bool readFile(const String &fileName); + /** + * Read a file for its details + */ + virtual bool query(const String &name); + private: void init() { + //do not set path or prefix here name = ""; description = ""; cflags = ""; @@ -4421,6 +4502,8 @@ private: void assign(const PkgConfig &other) { name = other.name; + path = other.path; + prefix = other.prefix; description = other.description; cflags = other.cflags; libs = other.libs; @@ -4446,12 +4529,18 @@ private: void parseVersion(); + bool parseLine(const String &lineBuf); + bool parse(const String &buf); void dumpAttrs(); String name; + String path; + + String prefix; + String description; String cflags; @@ -4495,6 +4584,7 @@ int PkgConfig::get(int pos) /** * Skip over all whitespace characters beginning at pos. Return * the position of the first non-whitespace character. + * Pkg-config is line-oriented, so check for newline */ int PkgConfig::skipwhite(int pos) { @@ -4604,15 +4694,12 @@ void PkgConfig::parseVersion() } -bool PkgConfig::parse(const String &buf) +bool PkgConfig::parseLine(const String &lineBuf) { - init(); - - parsebuf = (char *)buf.c_str(); - parselen = buf.size(); + parsebuf = (char *)lineBuf.c_str(); + parselen = lineBuf.size(); int pos = 0; - - + while (pos < parselen) { String attrName; @@ -4633,6 +4720,7 @@ bool PkgConfig::parse(const String &buf) pos = getword(pos, attrName); if (attrName.size() == 0) continue; + pos = skipwhite(pos); ch = get(pos); if (ch != ':' && ch != '=') @@ -4667,10 +4755,18 @@ bool PkgConfig::parse(const String &buf) subName.push_back((char)ch); pos++; } - //trace("subName:%s", subName.c_str()); - String subVal = attrs[subName]; - //trace("subVal:%s", subVal.c_str()); - attrVal.append(subVal); + trace("subName:%s %s", subName.c_str(), prefix.c_str()); + if (subName == "prefix" && prefix.size()>0) + { + attrVal.append(prefix); + trace("prefix override:%s", prefix.c_str()); + } + else + { + String subVal = attrs[subName]; + trace("subVal:%s", subVal.c_str()); + attrVal.append(subVal); + } } else attrVal.push_back((char)ch); @@ -4680,23 +4776,55 @@ bool PkgConfig::parse(const String &buf) attrVal = trim(attrVal); attrs[attrName] = attrVal; - if (attrName == "Name") + String attrNameL = toLower(attrName); + + if (attrNameL == "name") name = attrVal; - else if (attrName == "Description") + else if (attrNameL == "description") description = attrVal; - else if (attrName == "Cflags") + else if (attrNameL == "cflags") cflags = attrVal; - else if (attrName == "Libs") + else if (attrNameL == "libs") libs = attrVal; - else if (attrName == "Requires") + else if (attrNameL == "requires") requires = attrVal; - else if (attrName == "Version") + else if (attrNameL == "version") version = attrVal; //trace("name:'%s' value:'%s'", // attrName.c_str(), attrVal.c_str()); } + return true; +} + + +bool PkgConfig::parse(const String &buf) +{ + init(); + + String line; + int lineNr = 0; + for (unsigned int p=0 ; p0) + { + if (!parseLine(line)) + return false; + } parseRequires(); parseVersion(); @@ -4704,6 +4832,9 @@ bool PkgConfig::parse(const String &buf) return true; } + + + void PkgConfig::dumpAttrs() { //trace("### PkgConfig attributes for %s", fileName.c_str()); @@ -4715,9 +4846,9 @@ void PkgConfig::dumpAttrs() } -bool PkgConfig::readFile(const String &fileNameArg) +bool PkgConfig::readFile(const String &fname) { - fileName = fileNameArg; + fileName = getNativePath(fname); FILE *f = fopen(fileName.c_str(), "r"); if (!f) @@ -4741,13 +4872,30 @@ bool PkgConfig::readFile(const String &fileNameArg) return false; } - dumpAttrs(); + //dumpAttrs(); return true; } +bool PkgConfig::query(const String &pkgName) +{ + name = pkgName; + + String fname = path; + fname.append("/"); + fname.append(name); + fname.append(".pc"); + + if (!readFile(fname)) + return false; + + return true; +} + + + //######################################################################## @@ -6939,7 +7087,7 @@ public: { PKG_CONFIG_QUERY_CFLAGS, PKG_CONFIG_QUERY_LIBS, - PKG_CONFIG_QUERY_BOTH + PKG_CONFIG_QUERY_ALL } QueryTypes; TaskPkgConfig(MakeBase &par) : Task(par) @@ -6953,17 +7101,89 @@ public: virtual bool execute() { String path = parent.resolve(pkg_config_path); - //fill this in + PkgConfig pkgconfig; + pkgconfig.setPath(path); + pkgconfig.setPrefix(prefix); + if (!pkgconfig.query(name)) + { + error(" query failed for '%s", name.c_str()); + return false; + } + String ret; + switch (query) + { + case PKG_CONFIG_QUERY_CFLAGS: + { + ret = pkgconfig.getCflags(); + break; + } + case PKG_CONFIG_QUERY_LIBS: + { + ret = pkgconfig.getLibs(); + break; + } + case PKG_CONFIG_QUERY_ALL: + { + ret = pkgconfig.getAll(); + break; + } + default: + { + error(" unhandled query : %d", query); + return false; + } + + } + //trace("ret: %s", ret.c_str()); + parent.setProperty(propName, ret); return true; } virtual bool parse(Element *elem) { String s; + //# NAME + if (!parent.getAttribute(elem, "name", s)) + return false; + if (s.size()>0) + name = s; + else + { + error(" requires 'name=\"package\"' attribute"); + return false; + } + + //# PROPERTY + if (!parent.getAttribute(elem, "property", s)) + return false; + if (s.size()>0) + propName = s; + else + { + error(" requires 'property=\"name\"' attribute"); + return false; + } + if (parent.hasProperty(propName)) + { + error(" property '%s' is already defined", + propName.c_str()); + return false; + } + parent.setProperty(propName, "undefined"); + + //# PATH if (!parent.getAttribute(elem, "path", s)) return false; if (s.size()>0) pkg_config_path = s; + + //# PREFIX + if (!parent.getAttribute(elem, "prefix", s)) + return false; + if (s.size()>0) + prefix = s; + + //# QUERY if (!parent.getAttribute(elem, "query", s)) return false; if (s == "cflags") @@ -6971,7 +7191,7 @@ public: else if (s == "libs") query = PKG_CONFIG_QUERY_LIBS; else if (s == "both") - query = PKG_CONFIG_QUERY_BOTH; + query = PKG_CONFIG_QUERY_ALL; else { error(" requires 'query=\"type\"' attribute"); @@ -6983,6 +7203,9 @@ public: private: + String name; + String prefix; + String propName; String pkg_config_path; int query; @@ -7537,6 +7760,8 @@ Task *Task::createTask(Element *elem, int lineNr) task = new TaskMkDir(parent); else if (tagName == "msgfmt") task = new TaskMsgFmt(parent); + else if (tagName == "pkg-config") + task = new TaskPkgConfig(parent); else if (tagName == "ranlib") task = new TaskRanlib(parent); else if (tagName == "rc")