Code

Remove working file phoebedom.h from tree.
[inkscape.git] / buildtool.cpp
index f912ebdeaf23d262c7b4cde3c4213218defdd49b..21a7a4aef8131d83b30a315530adc850e15a00d8 100644 (file)
@@ -38,7 +38,7 @@
  *
  */
 
-#define BUILDTOOL_VERSION  "BuildTool v0.7.7, 2007-2008 Bob Jamison"
+#define BUILDTOOL_VERSION  "BuildTool v0.8.1, 2007-2008 Bob Jamison"
 
 #include <stdio.h>
 #include <fcntl.h>
@@ -2862,6 +2862,99 @@ private:
 };
 
 
+//########################################################################
+//# F I L E L I S T
+//########################################################################
+/**
+ * This is a simpler, explicitly-named list of files
+ */
+class FileList
+{
+public:
+
+    /**
+     *
+     */
+    FileList()
+        {}
+
+    /**
+     *
+     */
+    FileList(const FileList &other)
+        { assign(other); }
+
+    /**
+     *
+     */
+    FileList &operator=(const FileList &other)
+        { assign(other); return *this; }
+
+    /**
+     *
+     */
+    virtual ~FileList()
+        {}
+
+    /**
+     *
+     */
+    String getDirectory()
+        { return directory; }
+        
+    /**
+     *
+     */
+    void setDirectory(const String &val)
+        { directory = val; }
+
+    /**
+     *
+     */
+    void setFiles(const std::vector<String> &val)
+        { files = val; }
+
+    /**
+     *
+     */
+    std::vector<String> getFiles()
+        { return files; }
+        
+    /**
+     *
+     */
+    unsigned int size()
+        { return files.size(); }
+        
+    /**
+     *
+     */
+    String operator[](int index)
+        { return files[index]; }
+        
+    /**
+     *
+     */
+    void clear()
+        {
+        directory = "";
+        files.clear();
+        }
+        
+
+private:
+
+    void assign(const FileList &other)
+        {
+        directory = other.directory;
+        files     = other.files;
+        }
+
+    String directory;
+    std::vector<String> files;
+};
+
+
 
 
 //########################################################################
@@ -2979,6 +3072,11 @@ protected:
      */
     void status(const char *fmt, ...);
 
+    /**
+     *  Show target status
+     */
+    void targetstatus(const char *fmt, ...);
+
     /**
      *  Print a printf()-like formatted trace message
      */
@@ -3071,6 +3169,12 @@ protected:
     bool parseFileSet(Element *elem,
                     MakeBase &propRef,
                     FileSet &fileSet);
+    /**
+     * Parse a <filelist> entry
+     */  
+    bool parseFileList(Element *elem,
+                    MakeBase &propRef,
+                    FileList &fileList);
 
     /**
      * Return this object's property list
@@ -3161,7 +3265,6 @@ void MakeBase::status(const char *fmt, ...)
 }
 
 
-
 /**
  *  Resolve another path relative to this one
  */
@@ -4075,6 +4178,49 @@ bool MakeBase::parseFileSet(Element *elem,
     return true;
 }
 
+/**
+ * Parse a <filelist> entry.  This is far simpler than FileSet,
+ * since no directory scanning is needed.  The file names are listed
+ * explicitly.
+ */  
+bool MakeBase::parseFileList(Element *elem,
+                          MakeBase &propRef,
+                          FileList &fileList)
+{
+    std::vector<String> fnames;
+    //Look for child tags, namely "file"
+    std::vector<Element *> children  = elem->getChildren();
+    for (unsigned int i=0 ; i<children.size() ; i++)
+        {
+        Element *child = children[i];
+        String tagName = child->getName();
+        if (tagName == "file")
+            {
+            String fname = child->getAttribute("name");
+            if (fname.size()==0)
+                {
+                error("<file> element requires name="" attribute");
+                return false;
+                }
+            fnames.push_back(fname);
+            }
+        else
+            {
+            error("tag <%s> not allowed in <fileset>", tagName.c_str());
+            return false;
+                       }
+        }
+
+    String dir;
+    //Get the base directory for reading file names
+    if (!propRef.getAttribute(elem, "dir", dir))
+        return false;
+    fileList.setDirectory(dir);
+    fileList.setFiles(fnames);
+
+    return true;
+}
+
 
 
 /**
@@ -5976,6 +6122,19 @@ protected:
         name = other.name;
         }
         
+    /**
+     *  Show task status
+     */
+    void taskstatus(const char *fmt, ...)
+        {
+        va_list args;
+        va_start(args,fmt);
+        fprintf(stdout, "    %s : ", name.c_str());
+        vfprintf(stdout, fmt, args);
+        fprintf(stdout, "\n");
+        va_end(args) ;
+        }
+
     String getAttribute(Element *elem, const String &attrName)
         {
         String str;
@@ -6011,16 +6170,22 @@ public:
         defines     = "";
         includes    = "";
         fileSet.clear();
+        excludeInc.clear();
         }
 
     virtual ~TaskCC()
         {}
 
-    virtual bool needsCompiling(const FileRec &depRec,
-              const String &src, const String &dest)
+    virtual bool isExcludedInc(const String &dirname)
         {
+        for (unsigned int i=0 ; i<excludeInc.size() ; i++)
+            {
+            String fname = excludeInc[i];
+            if (fname == dirname)
+                return true;
+                       }
         return false;
-        }
+               }
 
     virtual bool execute()
         {
@@ -6034,7 +6199,7 @@ public:
         String fullName = parent.resolve("build.dep");
         if (isNewerThan(parent.getURI().getPath(), fullName))
             {
-            status("          : regenerating C/C++ dependency cache");
+            taskstatus("regenerating C/C++ dependency cache");
             refreshCache = true;
             }
 
@@ -6070,6 +6235,10 @@ public:
         std::set<String>::iterator setIter;
         for (setIter=paths.begin() ; setIter!=paths.end() ; setIter++)
             {
+            String dirName = *setIter;
+            //check excludeInc to see if we dont want to include this dir
+            if (isExcludedInc(dirName))
+                continue;
             incs.append(" -I");
             String dname;
             if (source.size()>0)
@@ -6077,7 +6246,7 @@ public:
                 dname.append(source);
                 dname.append("/");
                 }
-            dname.append(*setIter);
+            dname.append(dirName);
             incs.append(parent.resolve(dname));
             }
         std::vector<String> cfiles;
@@ -6130,7 +6299,7 @@ public:
             //# First we check if the source is newer than the .o
             if (isNewerThan(srcFullName, destFullName))
                 {
-                status("          : compile of %s required by %s",
+                taskstatus("compile of %s required by source: %s",
                         destFullName.c_str(), srcFullName.c_str());
                 compileMe = true;
                 }
@@ -6153,7 +6322,7 @@ public:
                     //        destFullName.c_str(), depFullName.c_str());
                     if (depRequires)
                         {
-                        status("          : compile of %s required by %s",
+                        taskstatus("compile of %s required by included: %s",
                                 destFullName.c_str(), depFullName.c_str());
                         compileMe = true;
                         break;
@@ -6273,6 +6442,11 @@ public:
                     return false;
                 source = fileSet.getDirectory();
                 }
+            else if (tagName == "excludeinc")
+                {
+                if (!parseFileList(child, parent, excludeInc))
+                    return false;
+                }
             }
 
         return true;
@@ -6280,14 +6454,16 @@ public:
         
 protected:
 
-    String ccCommand;
-    String cxxCommand;
-    String source;
-    String dest;
-    String flags;
-    String defines;
-    String includes;
-    FileSet fileSet;
+    String   ccCommand;
+    String   cxxCommand;
+    String   source;
+    String   dest;
+    String   flags;
+    String   lastflags;
+    String   defines;
+    String   includes;
+    FileSet  fileSet;
+    FileList excludeInc;
     
 };
 
@@ -6326,7 +6502,7 @@ public:
                {
                if (fileName.size()>0)
                    {
-                   status("          : %s to %s",
+                   taskstatus("%s to %s",
                         fileName.c_str(), toFileName.c_str());
                    String fullSource = parent.resolve(fileName);
                    String fullDest = parent.resolve(toFileName);
@@ -6339,12 +6515,12 @@ public:
                        }
                    if (!isNewerThan(fullSource, fullDest))
                        {
-                       status("          : skipped");
+                       taskstatus("skipped");
                        return true;
                        }
                    if (!copyFile(fullSource, fullDest))
                        return false;
-                   status("          : 1 file copied");
+                   taskstatus("1 file copied");
                    }
                return true;
                }
@@ -6356,7 +6532,7 @@ public:
                        return false;
                    String fileSetDir = fileSet.getDirectory();
 
-                   status("          : %s to %s",
+                   taskstatus("%s to %s",
                        fileSetDir.c_str(), toDirName.c_str());
 
                    int nrFiles = 0;
@@ -6407,13 +6583,13 @@ public:
                            return false;
                        nrFiles++;
                        }
-                   status("          : %d file(s) copied", nrFiles);
+                   taskstatus("%d file(s) copied", nrFiles);
                    }
                else //file source
                    {
                    //For file->dir we want only the basename of
                    //the source appended to the dest dir
-                   status("          : %s to %s", 
+                   taskstatus("%s to %s", 
                        fileName.c_str(), toDirName.c_str());
                    String baseName = fileName;
                    unsigned int pos = baseName.find_last_of('/');
@@ -6437,12 +6613,12 @@ public:
                        }
                    if (!isNewerThan(fullSource, fullDest))
                        {
-                       status("          : skipped");
+                       taskstatus("skipped");
                        return true;
                        }
                    if (!copyFile(fullSource, fullDest))
                        return false;
-                   status("          : 1 file copied");
+                   taskstatus("1 file copied");
                    }
                return true;
                }
@@ -6585,7 +6761,7 @@ public:
                 }
             case DEL_DIR:
                 {
-                status("          : %s", dirName.c_str());
+                taskstatus("%s", dirName.c_str());
                 String fullDir = parent.resolve(dirName);
                 if (!removeDirectory(fullDir))
                     return false;
@@ -6771,11 +6947,11 @@ public:
         fclose(f);
         if (!count)
             {
-            status("          : nothing to do");
+            taskstatus("nothing to do");
             return true;
                        }
 
-        status("          : compiling %d files", count);
+        taskstatus("compiling %d files", count);
 
         String execCmd = cmd;
         execCmd.append("@");
@@ -7001,7 +7177,7 @@ public:
 
     virtual bool execute()
         {
-        status("          : %s", fileName.c_str());
+        taskstatus("%s", fileName.c_str());
         String fullName = parent.resolve(fileName);
         if (!isNewerThan(parent.getURI().getPath(), fullName))
             {
@@ -7063,7 +7239,7 @@ public:
 
     virtual bool execute()
         {
-        status("          : %s", dirName.c_str());
+        taskstatus("%s", dirName.c_str());
         String fullDir = parent.resolve(dirName);
         //trace("fullDir:%s", fullDir.c_str());
         if (!createDirectory(fullDir))
@@ -7292,7 +7468,7 @@ public:
                 }
             
             }
-        status("          : %s", ret.c_str());
+        taskstatus("%s", ret.c_str());
         parent.setProperty(propName, ret);
         return true;
         }
@@ -8385,7 +8561,7 @@ bool Make::executeTarget(Target &target,
             }
         }
 
-    status("## Target : %s : %s", name.c_str(),
+    status("##### Target : %s\n##### %s", name.c_str(),
             target.getDescription().c_str());
 
     //Now let's do the tasks
@@ -8393,7 +8569,7 @@ bool Make::executeTarget(Target &target,
     for (unsigned int i=0 ; i<tasks.size() ; i++)
         {
         Task *task = tasks[i];
-        status("---- task : %s", task->getName().c_str());
+        status("--- %s / %s", name.c_str(), task->getName().c_str());
         if (!task->execute())
             {
             return false;