diff --git a/buildtool.cpp b/buildtool.cpp
index 39ae5be6ef87214665a371ed77809106453d419a..94a430da38fcfb06f2f44c389d0e07a985ae5e3b 100644 (file)
--- a/buildtool.cpp
+++ b/buildtool.cpp
*
*/
-#define BUILDTOOL_VERSION "BuildTool v0.6.13, 2007 Bob Jamison"
+#define BUILDTOOL_VERSION "BuildTool v0.7.1, 2007 Bob Jamison"
#include <stdio.h>
#include <fcntl.h>
void getLineAndColumn(int pos, int *lineNr, int *colNr);
- void error(char *fmt, ...);
+ void error(const char *fmt, ...);
int peek(int pos);
typedef struct
{
- char *escaped;
+ const char *escaped;
char value;
} EntityEntry;
}
-void Parser::error(char *fmt, ...)
+void Parser::error(const char *fmt, ...)
{
int lineNr;
int colNr;
if (ch!='<')
return p0;
- int line, col;
+ //int line, col;
//getLineAndColumn(p, &line, &col);
p++;
int peek(int p);
- int match(int p, char *key);
+ int match(int p, const char *key);
int parseScheme(int p);
typedef struct
{
- int ival;
- char *sval;
- int port;
+ int ival;
+ const char *sval;
+ int port;
} LookupEntry;
LookupEntry schemes[] =
-int URI::match(int p0, char *key)
+int URI::match(int p0, const char *key)
{
int p = p0;
while (p < parselen)
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<String, String>::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<String, String>::iterator iter = properties.find(name);
+ if (iter == properties.end())
+ return false;
+ return true;
+ }
+
+
protected:
/**
/**
* Print a printf()-like formatted error message
*/
- void error(char *fmt, ...);
+ void error(const char *fmt, ...);
/**
* Print a printf()-like formatted trace message
*/
- void status(char *fmt, ...);
+ void status(const char *fmt, ...);
/**
* Print a printf()-like formatted trace message
*/
- void trace(char *fmt, ...);
+ void trace(const char *fmt, ...);
/**
* Check if a given string matches a given regex pattern
*/
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
virtual std::map<String, String> &getProperties()
{ return properties; }
- /**
- * Return a named property if found, else a null string
- */
- virtual String getProperty(const String &name)
- {
- String val;
- std::map<String, String>::iterator iter;
- iter = properties.find(name);
- if (iter != properties.end())
- val = iter->second;
- return val;
- }
-
std::map<String, String> properties;
/**
* Print a printf()-like formatted error message
*/
-void MakeBase::error(char *fmt, ...)
+void MakeBase::error(const char *fmt, ...)
{
va_list args;
va_start(args,fmt);
/**
* Print a printf()-like formatted trace message
*/
-void MakeBase::status(char *fmt, ...)
+void MakeBase::status(const char *fmt, ...)
{
va_list args;
va_start(args,fmt);
/**
* Print a printf()-like formatted trace message
*/
-void MakeBase::trace(char *fmt, ...)
+void MakeBase::trace(const char *fmt, ...)
{
va_list args;
va_start(args,fmt);
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<s.size() ; i++)
+ {
+ ret.push_back(tolower(s[i]));
+ }
+ return ret;
+}
+
+
/**
* Return the native format of the canonical
* path which we store
*
*/
PkgConfig()
- { init(); }
-
- /**
- *
- */
- PkgConfig(const String &namearg)
- { init(); name = namearg; }
+ { path="."; init(); }
/**
*
virtual String getName()
{ return name; }
+ /**
+ *
+ */
+ virtual String getPath()
+ { return path; }
+
+ /**
+ *
+ */
+ virtual void setPath(const String &val)
+ { path = val; }
+
+ /**
+ *
+ */
+ virtual String getPrefix()
+ { return prefix; }
+
+ /**
+ * Allow the user to override the prefix in the file
+ */
+ virtual void setPrefix(const String &val)
+ { prefix = val; }
+
/**
*
*/
virtual String getLibs()
{ return libs; }
+ /**
+ *
+ */
+ virtual String getAll()
+ {
+ String ret = cflags;
+ ret.append(" ");
+ ret.append(libs);
+ return ret;
+ }
+
/**
*
*/
virtual std::vector<String> &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 = "";
void assign(const PkgConfig &other)
{
name = other.name;
+ path = other.path;
+ prefix = other.prefix;
description = other.description;
cflags = other.cflags;
libs = other.libs;
void parseVersion();
+ bool parseLine(const String &lineBuf);
+
bool parse(const String &buf);
void dumpAttrs();
String name;
+ String path;
+
+ String prefix;
+
String description;
String cflags;
/**
* 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)
{
}
-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;
pos = getword(pos, attrName);
if (attrName.size() == 0)
continue;
+
pos = skipwhite(pos);
ch = get(pos);
if (ch != ':' && ch != '=')
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);
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 ; p<buf.size() ; p++)
+ {
+ int ch = buf[p];
+ if (ch == '\n' || ch == '\r')
+ {
+ if (!parseLine(line))
+ return false;
+ line.clear();
+ lineNr++;
+ }
+ else
+ {
+ line.push_back(ch);
+ }
+ }
+ if (line.size()>0)
+ {
+ if (!parseLine(line))
+ return false;
+ }
parseRequires();
parseVersion();
return true;
}
+
+
+
void PkgConfig::dumpAttrs()
{
//trace("### PkgConfig attributes for %s", fileName.c_str());
}
-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)
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;
}
/**
*
*/
- bool sequ(int pos, char *key);
+ bool sequ(int pos, const char *key);
/**
*
* Return whether the sequence of characters in the buffer
* beginning at pos match the key, for the length of the key
*/
-bool DepTool::sequ(int pos, char *key)
+bool DepTool::sequ(int pos, const char *key)
{
while (*key)
{
TASK_MAKEFILE,
TASK_MKDIR,
TASK_MSGFMT,
+ TASK_PKG_CONFIG,
TASK_RANLIB,
TASK_RC,
TASK_SHAREDLIB,
srcFullName.c_str());
fprintf(f, "#### COMMAND ###\n");
int col = 0;
- for (int i = 0 ; i < cmd.size() ; i++)
+ for (unsigned int i = 0 ; i < cmd.size() ; i++)
{
char ch = cmd[i];
if (isspace(ch) && col > 63)
//trace("skipped <makefile>");
return true;
}
+ String fullNative = getNativePath(fullName);
//trace("fullName:%s", fullName.c_str());
- FILE *f = fopen(fullName.c_str(), "w");
+ FILE *f = fopen(fullNative.c_str(), "w");
if (!f)
{
error("<makefile> could not open %s for writing : %s",
+/**
+ * Perform a Package-Config query similar to pkg-config
+ */
+class TaskPkgConfig : public Task
+{
+public:
+
+ typedef enum
+ {
+ PKG_CONFIG_QUERY_CFLAGS,
+ PKG_CONFIG_QUERY_LIBS,
+ PKG_CONFIG_QUERY_ALL
+ } QueryTypes;
+
+ TaskPkgConfig(MakeBase &par) : Task(par)
+ {
+ type = TASK_PKG_CONFIG;
+ name = "pkg-config";
+ }
+
+ virtual ~TaskPkgConfig()
+ {}
+
+ virtual bool execute()
+ {
+ String path = parent.resolve(pkg_config_path);
+ PkgConfig pkgconfig;
+ pkgconfig.setPath(path);
+ pkgconfig.setPrefix(prefix);
+ if (!pkgconfig.query(pkgName))
+ {
+ error("<pkg-config> 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("<pkg-config> unhandled query : %d", query);
+ return false;
+ }
+
+ }
+ status(" : %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)
+ pkgName = s;
+ else
+ {
+ error("<pkg-config> requires 'name=\"package\"' attribute");
+ return false;
+ }
+
+ //# PROPERTY
+ if (!parent.getAttribute(elem, "property", s))
+ return false;
+ if (s.size()>0)
+ propName = s;
+ else
+ {
+ error("<pkg-config> requires 'property=\"name\"' attribute");
+ return false;
+ }
+ if (parent.hasProperty(propName))
+ {
+ error("<pkg-config> 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")
+ query = PKG_CONFIG_QUERY_CFLAGS;
+ else if (s == "libs")
+ query = PKG_CONFIG_QUERY_LIBS;
+ else if (s == "both")
+ query = PKG_CONFIG_QUERY_ALL;
+ else
+ {
+ error("<pkg-config> requires 'query=\"type\"' attribute");
+ error("where type = cflags, libs, or both");
+ return false;
+ }
+ return true;
+ }
+
+private:
+
+ String pkgName;
+ String prefix;
+ String propName;
+ String pkg_config_path;
+ int query;
+
+};
+
+
+
+
/**
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")
}
}
- status("## Target : %s", name.c_str());
+ status("## Target : %s : %s", name.c_str(),
+ target.getDescription().c_str());
//Now let's do the tasks
std::vector<Task *> &tasks = target.getTasks();
/**
* Format an error message in printf() style
*/
-static void error(char *fmt, ...)
+static void error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
/**
* Compare a buffer with a key, for the length of the key
*/
-static bool sequ(const String &buf, char *key)
+static bool sequ(const String &buf, const char *key)
{
int len = buf.size();
for (int i=0 ; key[i] && i<len ; i++)