Move debian and documentation specific parts of SConstruct into SConscript files
[senf.git] / senfscons / Doxygen.py
index 5e327fa..2b4530b 100644 (file)
@@ -254,7 +254,7 @@ def DoxyfileParse(env,file):
       return {}
    ENV = {}
    ENV.update(env.get("ENV",{}))
-   ENV['TOPDIR'] = env.Dir('#').abspath
+   ENV.update(env.get("DOXYENV", {}))
    parser = DoxyfileParser(file,ENV)
    try:
       parser.parse()
@@ -274,9 +274,22 @@ def DoxySourceScan(node, env, path):
    any files used to generate docs to the list of source files.
    """
    dep_add_keys = (
-      'LAYOUT_FILE', '@INCLUDE', 'HTML_HEADER', 'HTML_FOOTER', 'TAGFILES', 'INPUT_FILTER'
+      ('HTML', 'LAYOUT_FILE'), 
+      (None,   '@INCLUDE'), 
+      ('HTML', 'HTML_HEADER'), 
+      ('HTML', 'HTML_FOOTER'), 
+      (None,   'TAGFILES'), 
+      (None,   'INPUT_FILTER'),
    )
 
+   output_formats = {
+      "HTML"  : ("YES", "html"),
+      "LATEX" : ("YES", "latex"),
+      "RTF"   : ("NO",  "rtf"),
+      "MAN"   : ("YES", "man"),
+      "XML"   : ("NO",  "xml"),
+   }
+
    default_file_patterns = (
       '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx',
       '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++',
@@ -309,12 +322,12 @@ def DoxySourceScan(node, env, path):
                     and not reduce(lambda x, y: x or fnmatch(f, y), exclude_patterns, False) ):
                   sources.append(filename)
 
-   for key in dep_add_keys:
-      if data.has_key(key):
-         elt = data[key]
-         if type(elt) is type ("") : elt = [ elt ]
+   for fmt, key in dep_add_keys:
+      if data.has_key(key) and \
+             (fmt is None or data.get("GENERATE_%s" % fmt, output_formats[fmt][0]).upper() == "YES"):
+         elt = env.Flatten(env.subst_list(data[key]))
          sources.extend([ os.path.normpath(os.path.join(basedir,f))
-                          for f in elt ])
+                          for f in elt if f ])
 
    sources = map( lambda path: env.File(path), sources )
    return sources
@@ -337,7 +350,7 @@ def DoxyEmitter(source, target, env):
    data = DoxyfileParse(env, source[0].abspath)
 
    targets = []
-   if data.has_key("OUTPUT_DIRECTORY"):
+   if data.get("OUTPUT_DIRECTORY",""):
       out_dir = data["OUTPUT_DIRECTORY"]
       dir = env.Dir( os.path.join(source[0].dir.abspath, out_dir) )
       dir.sources = source
@@ -350,7 +363,7 @@ def DoxyEmitter(source, target, env):
    # add our output locations
    html_dir = None
    for (k, v) in output_formats.iteritems():
-      if data.get("GENERATE_" + k, v[0]).upper() == "YES":
+      if data.get("GENERATE_" + k, v[0]).upper() == "YES" and data.get(k + "_OUTPUT", v[1]):
          dir = env.Dir( os.path.join(source[0].dir.abspath, out_dir, data.get(k + "_OUTPUT", v[1])) )
          if k == "HTML" : html_dir = dir
          dir.sources = source
@@ -358,10 +371,10 @@ def DoxyEmitter(source, target, env):
          targets.append(node)
          if env.GetOption('clean'): targets.append(dir)
 
-   if data.has_key("GENERATE_TAGFILE") and html_dir:
+   if data.get("GENERATE_TAGFILE",""):
       targets.append(env.File( os.path.join(source[0].dir.abspath, data["GENERATE_TAGFILE"]) ))
 
-   if data.get("SEARCHENGINE","NO").upper() == "YES":
+   if data.get("SEARCHENGINE","NO").upper() == "YES" and html_dir:
       targets.append(env.File( os.path.join(html_dir.abspath, "search.idx") ))
 
    # don't clobber targets
@@ -391,53 +404,12 @@ def relpath(source, target):
                          target_elts[prefix_len:]))
 
 def DoxyGenerator(source, target, env, for_signature):
-
    data = DoxyfileParse(env, source[0].abspath)
-
-   actions = [ SCons.Action.Action("cd ${SOURCE.dir} && TOPDIR=%s ${DOXYGEN} ${SOURCE.file}"
-                                   % env.Dir('#').abspath) ]
-
-   # This will add automatic 'installdox' calls.
-   #
-   # For every referenced tagfile, the generator first checks for the
-   # existence of a construction variable '<name>_DOXY_URL' where
-   # '<name>' is the uppercased name of the tagfile sans extension
-   # (e.g. 'Utils.tag' -> 'UTILS_DOXY_URL'). If this variable exists,
-   # it must contain the url or path to the installed documentation
-   # corresponding to the tag file.
-   #
-   # Is the variable is not found and if a referenced tag file is a
-   # target within this same build, the generator will parse the
-   # 'Doxyfile' from which the tag file is built. It will
-   # automatically create the html directory from the information in
-   # that 'Doxyfile'.
-   #
-   # If for any referenced tagfile no url can be found, 'installdox'
-   # will *not* be called and a warning about the missing url is
-   # generated.
-
-   if data.get('GENERATE_HTML','YES').upper() == "YES":
-      output_dir = os.path.normpath(os.path.join( source[0].dir.abspath,
-                                                  data.get("OUTPUT_DIRECTORY","."),
-                                                  data.get("HTML_OUTPUT","html") ))
-      args = []
-      for tagfile in data.get('TAGFILES',[]):
-         url = env.get(os.path.splitext(os.path.basename(tagfile))[0].upper()+"_DOXY_URL", None)
-         if not url:
-            url = doxyNodeHtmlDir(
-               env,
-               env.File(os.path.normpath(os.path.join(str(source[0].dir), tagfile))))
-            if url : url = relpath(output_dir, url)
-         if not url:
-            print "WARNING:",source[0].abspath, ": missing tagfile url for", tagfile
-            args = None
-         if args is not None and url:
-            args.append("-l %s@%s" % ( os.path.basename(tagfile), url ))
-      if args:
-         actions.append(SCons.Action.Action('cd %s && ./installdox %s' % (output_dir, " ".join(args))))
-
-   actions.append(SCons.Action.Action([ "touch $TARGETS" ]))
-
+   actions = [ 
+      SCons.Action.Action("$DOXYGENCOM"),
+      SCons.Action.Action([ "touch $TARGETS" ]),
+      ]
+   
    return actions
 
 def generate(env):
@@ -452,12 +424,11 @@ def generate(env):
    )
 
    doxyfile_builder = env.Builder(
-      # scons 0.96.93 hang on the next line but I don't know hot to FIX the problem
       generator = DoxyGenerator,
       emitter = DoxyEmitter,
       target_factory = env.fs.Entry,
       single_source = True,
-      source_scanner =  doxyfile_scanner
+      source_scanner = doxyfile_scanner
    )
 
    env.Append(BUILDERS = {
@@ -465,7 +436,7 @@ def generate(env):
    })
 
    env.SetDefault(
-      DOXYGEN = 'doxygen',
+      DOXYGENCOM = 'cd ${SOURCE.dir} && doxygen ${SOURCE.file}'
    )
 
 def exists(env):