Code

another forgotten file added to POTFILES.in, Shift+G added to default keys scheme...
[inkscape.git] / buildtool.cpp
index 17b81898725135147b68eddcc9debfd891d21989..5d0eb429c0296bfcffc5ddc44747730b8a4fc10c 100644 (file)
  * 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>
@@ -2957,6 +2957,16 @@ protected:
      *    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;
+
+
 
 
     /**
@@ -3874,15 +3884,30 @@ bool MakeBase::getSubstitutions(const String &str, String &result)
                 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;
                     }
@@ -4755,16 +4780,16 @@ bool PkgConfig::parseLine(const String &lineBuf)
                         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);
                     }
                 }
@@ -6650,20 +6675,89 @@ class TaskJavac : public Task
 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;
+
 };
 
 
@@ -6679,8 +6773,8 @@ public:
         type = TASK_LINK; name = "link";
         command = "g++";
         doStrip = false;
-                stripCommand = "strip";
-                objcopyCommand = "objcopy";
+        stripCommand = "strip";
+        objcopyCommand = "objcopy";
         }
 
     virtual ~TaskLink()
@@ -6852,8 +6946,9 @@ public:
             //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",
@@ -7092,7 +7187,8 @@ public:
 
     TaskPkgConfig(MakeBase &par) : Task(par)
         {
-        type = TASK_PKG_CONFIG; name = "pkg-config";
+        type = TASK_PKG_CONFIG;
+        name = "pkg-config";
         }
 
     virtual ~TaskPkgConfig()
@@ -7104,7 +7200,7 @@ public:
         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;
@@ -7134,7 +7230,7 @@ public:
                 }
             
             }
-        //trace("ret: %s", ret.c_str());
+        status("          : %s", ret.c_str());
         parent.setProperty(propName, ret);
         return true;
         }
@@ -7146,7 +7242,7 @@ public:
         if (!parent.getAttribute(elem, "name", s))
             return false;
         if (s.size()>0)
-           name = s;
+           pkgName = s;
         else
             {
             error("<pkg-config> requires 'name=\"package\"' attribute");
@@ -7203,7 +7299,7 @@ public:
 
 private:
 
-    String name;
+    String pkgName;
     String prefix;
     String propName;
     String pkg_config_path;
@@ -8107,8 +8203,6 @@ private:
 
     String description;
     
-    String envAlias;
-
     //std::vector<Property> properties;
     
     std::map<String, Target> targets;
@@ -8136,7 +8230,7 @@ void Make::init()
     specifiedTarget = "";
     baseDir         = "";
     description     = "";
-    envAlias        = "";
+    envPrefix       = "";
     properties.clear();
     for (unsigned int i = 0 ; i < allTasks.size() ; i++)
         delete allTasks[i];
@@ -8229,7 +8323,8 @@ bool Make::executeTarget(Target &target,
             }
         }
 
-    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();
@@ -8516,12 +8611,18 @@ bool Make::parseProperty(Element *elem)
             }
         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('.');
             }
         }
 
@@ -8868,7 +8969,7 @@ static bool parseOptions(int argc, char **argv)
                 }
             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))
                    {