diff --git a/buildtool.cpp b/buildtool.cpp
index 17b81898725135147b68eddcc9debfd891d21989..5d0eb429c0296bfcffc5ddc44747730b8a4fc10c 100644 (file)
--- a/buildtool.cpp
+++ b/buildtool.cpp
* To use this file, compile with:
* <pre>
* g++ -O3 buildtool.cpp -o btool.exe
- * (or whatever your compiler might be)
+ * (or whatever your compiler might be)
* Then
* btool
- * or
+ * or
* btool {target}
- *
+ *
* Note: if you are using MinGW, and a not very recent version of it,
* gettimeofday() might be missing. If so, just build this file with
* this command:
* g++ -O3 -DNEED_GETTIMEOFDAY buildtool.cpp -o btool.exe
- *
- */
+ *
+ */
-#define BUILDTOOL_VERSION "BuildTool v0.7.0, 2007 Bob Jamison"
+#define BUILDTOOL_VERSION "BuildTool v0.7.4, 2007 Bob Jamison"
#include <stdio.h>
#include <fcntl.h>
* The path to the file associated with this object
*/
URI uri;
+
+ /**
+ * If this prefix is seen in a substitution, use an environment
+ * variable.
+ * example: <property environment="env"/>
+ * ${env.JAVA_HOME}
+ */
+ String envPrefix;
+
+
/**
else if (ch == '}')
{
std::map<String, String>::iterator iter;
- iter = properties.find(trim(varname));
- if (iter != properties.end())
+ varname = trim(varname);
+ if (envPrefix.size() > 0 && varname.compare(0, envPrefix.size(), envPrefix) == 0)
{
- val.append(iter->second);
+ varname = varname.substr(envPrefix.size());
+ char *envstr = getenv(varname.c_str());
+ if (!envstr)
+ {
+ error("environment variable '%s' not defined", varname.c_str());
+ return false;
+ }
+ val.append(envstr);
}
else
{
- error("property ${%s} not found", varname.c_str());
- return false;
+ iter = properties.find(varname);
+ if (iter != properties.end())
+ {
+ val.append(iter->second);
+ }
+ else
+ {
+ error("property ${%s} not found", varname.c_str());
+ return false;
+ }
}
break;
}
subName.push_back((char)ch);
pos++;
}
- trace("subName:%s %s", subName.c_str(), prefix.c_str());
+ //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());
+ //trace("prefix override:%s", prefix.c_str());
}
else
{
String subVal = attrs[subName];
- trace("subVal:%s", subVal.c_str());
+ //trace("subVal:%s", subVal.c_str());
attrVal.append(subVal);
}
}
public:
TaskJavac(MakeBase &par) : Task(par)
- { type = TASK_JAVAC; name = "javac"; }
+ {
+ type = TASK_JAVAC; name = "javac";
+ command = "javac";
+ }
virtual ~TaskJavac()
{}
virtual bool execute()
{
+ std::vector<String> fileList;
+ if (!listFiles(srcdir, "", fileList))
+ {
+ return false;
+ }
+ String cmd = command;
+ cmd.append(" -d ");
+ cmd.append(destdir);
+ cmd.append(" -sourcepath ");
+ cmd.append(srcdir);
+ cmd.append(" ");
+ for (unsigned int i=0 ; i<fileList.size() ; i++)
+ {
+ String fname = fileList[i];
+ String srcName = fname;
+ if (fname.size()<6) //x.java
+ continue;
+ if (fname.compare(fname.size()-5, 5, ".java") != 0)
+ continue;
+ String baseName = fname.substr(0, fname.size()-5);
+ String destName = baseName;
+ destName.append(".class");
+
+ String fullSrc = srcdir;
+ fullSrc.append("/");
+ fullSrc.append(fname);
+ String fullDest = destdir;
+ fullDest.append("/");
+ fullDest.append(destName);
+ //trace("fullsrc:%s fulldest:%s", fullSrc.c_str(), fullDest.c_str());
+ if (!isNewerThan(fullSrc, fullDest))
+ continue;
+
+ String execCmd = cmd;
+ execCmd.append(fullSrc);
+
+ String outString, errString;
+ bool ret = executeCommand(execCmd.c_str(), "", outString, errString);
+ if (!ret)
+ {
+ error("<javac> command '%s' failed :\n %s",
+ execCmd.c_str(), errString.c_str());
+ return false;
+ }
+ }
return true;
}
virtual bool parse(Element *elem)
{
+ String s;
+ if (!parent.getAttribute(elem, "command", s))
+ return false;
+ if (s.size() > 0)
+ command = s;
+ if (!parent.getAttribute(elem, "srcdir", srcdir))
+ return false;
+ if (!parent.getAttribute(elem, "destdir", destdir))
+ return false;
+ if (srcdir.size() == 0 || destdir.size() == 0)
+ {
+ error("<javac> required both srcdir and destdir attributes to be set");
+ return false;
+ }
return true;
}
+
+private:
+
+ String command;
+ String srcdir;
+ String destdir;
+
};
type = TASK_LINK; name = "link";
command = "g++";
doStrip = false;
- stripCommand = "strip";
- objcopyCommand = "objcopy";
+ stripCommand = "strip";
+ objcopyCommand = "objcopy";
}
virtual ~TaskLink()
//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",
TaskPkgConfig(MakeBase &par) : Task(par)
{
- type = TASK_PKG_CONFIG; name = "pkg-config";
+ type = TASK_PKG_CONFIG;
+ name = "pkg-config";
}
virtual ~TaskPkgConfig()
PkgConfig pkgconfig;
pkgconfig.setPath(path);
pkgconfig.setPrefix(prefix);
- if (!pkgconfig.query(name))
+ if (!pkgconfig.query(pkgName))
{
error("<pkg-config> query failed for '%s", name.c_str());
return false;
}
}
- //trace("ret: %s", ret.c_str());
+ status(" : %s", ret.c_str());
parent.setProperty(propName, ret);
return true;
}
if (!parent.getAttribute(elem, "name", s))
return false;
if (s.size()>0)
- name = s;
+ pkgName = s;
else
{
error("<pkg-config> requires 'name=\"package\"' attribute");
private:
- String name;
+ String pkgName;
String prefix;
String propName;
String pkg_config_path;
String description;
- String envAlias;
-
//std::vector<Property> properties;
std::map<String, Target> targets;
specifiedTarget = "";
baseDir = "";
description = "";
- envAlias = "";
+ envPrefix = "";
properties.clear();
for (unsigned int i = 0 ; i < allTasks.size() ; i++)
delete allTasks[i];
}
}
- 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();
}
else if (attrName == "environment")
{
- if (envAlias.size() > 0)
+ if (envPrefix.size() > 0)
+ {
+ error("environment prefix can only be set once");
+ return false;
+ }
+ if (attrVal.find('.') != attrVal.npos)
{
- error("environment property can only be set once");
+ error("environment prefix cannot have a '.' in it");
return false;
}
- envAlias = attrVal;
+ envPrefix = attrVal;
+ envPrefix.push_back('.');
}
}
}
else if (arg.size()>2 && sequ(arg, "-D"))
{
- String s = arg.substr(2, s.size());
+ String s = arg.substr(2, arg.size());
String name, value;
if (!parseProperty(s, name, value))
{