Automatic image file dependency generation patch

Robert Jørgensgaard Engdahl <[email protected]>
Newsgroups gmane.text.doxygen.devel
Message-ID <[email protected]>
This patch adds the HTML_IMAGE_DEPENDENCY_FILE_NAME and
LATEX_IMAGE_DEPENDENCY_FILE_NAME tags.  For each of these tags that
are defined, warnings about missing image files will be supressed (for
the related output type --- i.e. LaTeX or HTML), and a list of used
image files will be saved as prerequisite to a relevant make rule in a
make file named by the value of that tag.

For usage examples, see the included doxygen comments in the patch.

Please note that we included changes made to the file
optionsconfig.cpp although it is automatically generated from the
config.xml file.  We did this since that file is under revision
control (you might want to change that).

Regards Robert Jørgensgaard Engdahl and Anders Franz Terkelsen

p.s. We sent this patch previously, but since the sender address was
not on the mailing list the mail did not get through. I hope that we
are not offending anyone by sending this patch again.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first

_______________________________________________
Doxygen-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/doxygen-develop
doxygen_automatic-dependency-generation.patch (text/x-patch, 13.1 KB)
Index: src/imagedependencies.cpp
===================================================================
--- src/imagedependencies.cpp	(revision 0)
+++ src/imagedependencies.cpp	(revision 0)
@@ -0,0 +1,92 @@
+/******************************************************************************
+ *
+ * 
+ *
+ *
+ * Copyright (C) 2010 by Robert Jørgensgaard Engdahl and Anders Franz Terkelsen
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation under the terms of the GNU General Public License is hereby 
+ * granted. No representations are made about the suitability of this software 
+ * for any purpose. It is provided "as is" without express or implied warranty.
+ * See the GNU General Public License for more details.
+ *
+ * Documents produced by Doxygen are derivative works derived from the
+ * input used in their production; they are not affected by this license.
+ *
+ */
+
+#include "imagedependencies.h"
+#include "config.h"
+#include "ftextstream.h"
+
+std::auto_ptr<ImageDependencies> ImageDependencies::m_instance;
+
+void ImageDependencies::AddHtmlDependency(const QCString &relativePath,
+					  const QCString &fileName)
+{
+  m_htmlDependencyFile.AddDependency(relativePath,fileName);
+}
+
+void ImageDependencies::AddLatexDependency(const QCString &relativePath,
+					   const QCString &fileName)
+{
+  m_latexDependencyFile.AddDependency(relativePath,fileName);
+}
+
+ImageDependencies *ImageDependencies::instance()
+{
+  if (!m_instance.get())
+  {
+    m_instance.reset(new ImageDependencies()); 
+  }
+  return m_instance.get();
+}
+
+ImageDependencies::ImageDependencies()
+  : m_htmlDependencyFile("HTML_IMAGE_DEPENDENCY_FILE_NAME",
+			 "html",
+			 Config_getString("HTML_OUTPUT")),
+    m_latexDependencyFile("LATEX_IMAGE_DEPENDENCY_FILE_NAME",
+			  "latex",
+			  Config_getString("LATEX_OUTPUT"))
+{
+}
+
+
+ImageDependencies::DependencyFile::DependencyFile(const char* configPropertyName,
+						  const char* makeTarget,
+						  const QCString outputDirectory)
+  : m_fileHandle(0), 
+    m_outputDirectory(outputDirectory)
+{
+  QCString fileName = Config_getString(configPropertyName);
+  if (!fileName.isEmpty())
+  {
+    m_fileStream.reset(
+      new FTextStream(m_fileHandle = ::fopen(fileName.data(),"w")));
+    *m_fileStream << "doxygen_" << makeTarget << "_output = " 
+		  << m_outputDirectory << "\n\n";
+    *m_fileStream << makeTarget << " :";
+  }
+}
+
+ImageDependencies::DependencyFile::~DependencyFile()
+{
+  if(m_fileStream.get())
+  {
+    *m_fileStream << "\n";
+    m_fileStream.reset();
+    ::fclose(m_fileHandle);
+  }
+}
+
+
+void ImageDependencies::DependencyFile::AddDependency(const QCString &relativePath,
+						      const QCString &fileName)
+{
+  if (m_fileStream.get())
+  {
+    *m_fileStream << " " << m_outputDirectory << "/" << relativePath << fileName;
+  }
+}
Index: src/configoptions.cpp
===================================================================
--- src/configoptions.cpp	(revision 737)
+++ src/configoptions.cpp	(working copy)
@@ -1059,6 +1059,13 @@
                 );
   //----
   cs = cfg->addString(
+                 "HTML_IMAGE_DEPENDENCY_FILE_NAME",
+                 "The HTML_IMAGE_DEPENDENCY_FILE_NAME tag can be used to specify a Make dependency file for images being included in the html documentation."
+                );
+  cs->setWidgetType(ConfigString::File);
+  cs->addDependency("GENERATE_HTML");
+  //----
+  cs = cfg->addString(
                  "HTML_OUTPUT",
                  "The HTML_OUTPUT tag is used to specify where the HTML docs will be put.\n"
                  "If a relative path is entered the value of OUTPUT_DIRECTORY will be\n"
@@ -1497,6 +1504,13 @@
                 );
   //----
   cs = cfg->addString(
+                 "LATEX_IMAGE_DEPENDENCY_FILE_NAME",
+                 "The LATEX_IMAGE_DEPENDENCY_FILE_NAME tag can be used to specify a Make dependency file for images being included in the LaTex documentation."
+                );
+  cs->setWidgetType(ConfigString::File);
+  cs->addDependency("GENERATE_LATEX");
+  //----
+  cs = cfg->addString(
                  "LATEX_OUTPUT",
                  "The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.\n"
                  "If a relative path is entered the value of OUTPUT_DIRECTORY will be\n"
Index: src/docparser.cpp
===================================================================
--- src/docparser.cpp	(revision 737)
+++ src/docparser.cpp	(working copy)
@@ -307,7 +307,11 @@
   else
   {
     result=fileName;
-    if (result.left(5)!="http:" && result.left(6)!="https:")
+    if (result.left(5)!="http:" && result.left(6)!="https:" &&
+	(Config_getBool("GENERATE_HTML") &&
+	 Config_getString("HTML_IMAGE_DEPENDENCY_FILE_NAME").isEmpty()) &&
+	(Config_getBool("GENERATE_LATEX") &&
+	 Config_getString("LATEX_IMAGE_DEPENDENCY_FILE_NAME").isEmpty()))
     {
       warn_doc_error(g_fileName,doctokenizerYYlineno,
            "warning: image file %s is not found in IMAGE_PATH: "  
Index: src/htmldocvisitor.cpp
===================================================================
--- src/htmldocvisitor.cpp	(revision 737)
+++ src/htmldocvisitor.cpp	(working copy)
@@ -29,6 +29,7 @@
 #include "parserintf.h"
 #include "msc.h"
 #include "util.h"
+#include "imagedependencies.h"
 
 
 static const int NUM_HTML_LIST_TYPES = 4;
@@ -1177,6 +1178,11 @@
     {
       m_t << "<p><strong>";
     }
+
+    if (!img->name().isEmpty())
+    {
+      ImageDependencies::instance()->AddHtmlDependency(img->relPath(),img->name());
+    }
   }
   else // other format -> skip
   {
Index: src/imagedependencies.h
===================================================================
--- src/imagedependencies.h	(revision 0)
+++ src/imagedependencies.h	(revision 0)
@@ -0,0 +1,135 @@
+/******************************************************************************
+ *
+ * 
+ *
+ *
+ * Copyright (C) 2010 by Robert Jørgensgaard Engdahl and Anders Franz Terkelsen
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation under the terms of the GNU General Public License is hereby 
+ * granted. No representations are made about the suitability of this software 
+ * for any purpose. It is provided "as is" without express or implied warranty.
+ * See the GNU General Public License for more details.
+ *
+ * Documents produced by Doxygen are derivative works derived from the
+ * input used in their production; they are not affected by this license.
+ *
+ */
+
+#ifndef _IMAGEDEPENDENCIES_H
+#define _IMAGEDEPENDENCIES_H
+
+#include <memory>
+#include <cstdio>
+#include "ftextstream.h"
+
+class QCString;
+
+/*! @brief Singleton class for handling image dependencies.
+ *
+ *  This class generates makefiles named by the
+ *  HTML_IMAGE_DEPENDENCY_FILE_NAME and
+ *  LATEX_IMAGE_DEPENDENCY_FILE_NAME options in the Doxyfile.  These
+ *  makefiles contain make descriptions of the image dependencies for
+ *  HTML and LaTeX output; given by the make targets html and latex.
+ *
+ *  Furthermore, to ease the use of these generated makefiles, the
+ *  variables doxygen_html_output and doxygen_latex_output are
+ *  defined.  They contain the HTML_OUTPUT and LATEX_OUTPUT
+ *  directories, respectively.
+ *
+ *  An example of a generated makefile, html-images.d, for HTML output
+ *  follows:
+ *  
+\verbatim
+doxygen_html_output = /home/robert/src/mkrootfs2/doc/html
+
+html : /home/robert/src/mkrootfs2/doc/html/file_to_generate.png /home/robert/src/mkrootfs2/doc/html/another_file_to_generate.png
+\endverbatim
+ *
+ *  The above make file is included in a image generating make file,
+ *  like the following:
+ *  
+\verbatim
+-include html-images.d
+
+$(doxygen_html_output)/%.png : %.dia
+	dia --export=$@ -t png $<
+\endverbatim
+ *
+ *  The following snippet in your main make file will build all your
+ *  doxygen documentation, including png images extracted from your
+ *  dia diagrams.
+ *
+\verbatim
+.PHONY : doc
+doc : 
+	doxygen
+	make -f images.mak html 
+\endverbatim
+ */
+class ImageDependencies
+{    
+  public:
+    /*! @name Methods for adding dependencies
+     *  
+     *  These dependencies are image files being prerequisites of the
+     *  relevant make target.  @{
+     */
+    void AddHtmlDependency(const QCString &relativePath,const QCString &fileName);
+    void AddLatexDependency(const QCString &relativePath,const QCString &fileName);
+    /*! @} */
+
+    /*! @brief Instance accessor method.
+     *
+     *  @return Returns a pointer to the ImageDependencies singleton
+     *  instance.
+     */
+    static ImageDependencies *instance();
+
+  private:
+    /*! @brief Private singleton constructor.
+     *
+     *  Instantiates an inner class for each supported output format
+     *  (currently HTML and LaTeX).
+     */
+    ImageDependencies();
+
+    /*! @brief Inner class for handling a dependency file.
+     */
+    class DependencyFile
+    {
+      public:
+        /*! @brief Creates the initial part of the dependency file.
+	 *
+	 *  @param configPropertyName The config property name giving
+	 *  the dependency file name.
+	 *
+	 *  @param makeTarget The make target for which all
+	 *  dependencies are prerequisites.
+	 *
+	 *  @param outputDirectory The directory the image files
+	 *  should be created in.
+	 */
+        DependencyFile(const char *configPropertyName,
+		       const char *makeTarget,
+		       const QCString outputDirectory);
+        ~DependencyFile();
+
+         /*! @brief Private implementation of AddHtmlDependency() and
+	  *  AddLatexDependency().
+	  */
+         void AddDependency(const QCString &relativePath,
+			    const QCString &fileName);
+      private: 
+        std::auto_ptr<FTextStream> m_fileStream;
+        FILE * m_fileHandle;
+        const QCString m_outputDirectory;
+    };
+
+    DependencyFile m_htmlDependencyFile;
+    DependencyFile m_latexDependencyFile;
+    static std::auto_ptr<ImageDependencies> m_instance;
+};
+
+#endif // _IMAGEDEPENDENCIES_H
Index: src/htmldocvisitor.h
===================================================================
--- src/htmldocvisitor.h	(revision 737)
+++ src/htmldocvisitor.h	(working copy)
@@ -19,6 +19,7 @@
 #ifndef _HTMLDOCVISITOR_H
 #define _HTMLDOCVISITOR_H
 
+#include <fstream>
 #include "docvisitor.h"
 #include <qstack.h>
 #include <qcstring.h>
@@ -32,7 +33,7 @@
 {
   public:
     HtmlDocVisitor(FTextStream &t,CodeOutputInterface &ci,const char *langExt);
-    
+
     //--------------------------------------
     // visitor functions for leaf nodes
     //--------------------------------------
Index: src/config.xml
===================================================================
--- src/config.xml	(revision 737)
+++ src/config.xml	(working copy)
@@ -741,6 +741,10 @@
 If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
 generate HTML output. 
 ' defval='1'/>
+    <option type='string' id='HTML_IMAGE_DEPENDENCY_FILE_NAME' format='file' docs='
+The HTML_IMAGE_DEPENDENCY_FILE_NAME tag can be used to specify a
+Make dependency file for images being included in the html
+documentation. This tag disables warnings about missing image files for HTML.' defval='' depends='GENERATE_HTML' />
     <option type='string' id='HTML_OUTPUT' format='dir' docs='
 The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 
 If a relative path is entered the value of OUTPUT_DIRECTORY will be 
@@ -1006,6 +1010,10 @@
 If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
 generate Latex output. 
 ' defval='1'/>
+    <option type='string' id='LATEX_IMAGE_DEPENDENCY_FILE_NAME' format='file' docs='
+The LATEX_IMAGE_DEPENDENCY_FILE_NAME tag can be used to specify a
+Make dependency file for images being included in the LaTex
+documentation. This tag disables warnings about missing image files for LaTex.' defval='' depends='GENERATE_LATEX' />
     <option type='string' id='LATEX_OUTPUT' format='dir' docs='
 The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
 If a relative path is entered the value of OUTPUT_DIRECTORY will be 
Index: src/libdoxygen.pro.in
===================================================================
--- src/libdoxygen.pro.in	(revision 737)
+++ src/libdoxygen.pro.in	(working copy)
@@ -151,7 +151,8 @@
 		vhdldocgen.h \
 		vhdlscanner.h \
 		xmldocvisitor.h \
-                xmlgen.h
+                xmlgen.h \
+                imagedependencies.h
 
 SOURCES      =	ce_lex.cpp \
                 ce_parse.cpp \
@@ -237,6 +238,7 @@
 		xmldocvisitor.cpp \
                 xmlgen.cpp \
                 dbusxmlscanner.cpp \
+                imagedependencies.cpp \
 
 win32:TMAKE_CXXFLAGS       += -DQT_NODLL 
 win32-msvc:TMAKE_CXXFLAGS  += -Zm200
Index: src/latexdocvisitor.cpp
===================================================================
--- src/latexdocvisitor.cpp	(revision 737)
+++ src/latexdocvisitor.cpp	(working copy)
@@ -27,6 +27,7 @@
 #include "parserintf.h"
 #include "msc.h"
 #include "htmlattrib.h"
+#include "imagedependencies.h"
 
 static QCString escapeLabelName(const char *s)
 {
@@ -967,6 +968,11 @@
     {
       m_t << "\n\\caption{";
     }
+
+    if (!img->name().isEmpty())
+    {
+      ImageDependencies::instance()->AddLatexDependency(img->relPath(),img->name());
+    }
   }
   else // other format -> skip
   {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.