diff --git a/buildtool.cpp b/buildtool.cpp
index 42c6c3719ab8bfe7f756f3ef8b972c32b5984bc3..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.2, 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;
}
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()
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];
}
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('.');
}
}