forked from cawka/ndn.cxx
diff --git a/waf-tools/sphinx_build.py b/waf-tools/sphinx_build.py
new file mode 100644
index 0000000..e1155d1
--- /dev/null
+++ b/waf-tools/sphinx_build.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+# encoding: utf-8
+# Hans-Martin von Gaudecker, 2012
+
+"""
+Create Sphinx documentation. Currently only LaTeX and HTML are supported.
+
+The source file **must** be the conf.py file used by Sphinx. Everything
+else has defaults, passing in the parameters is optional.
+
+Usage for getting both html and pdf docs:
+
+ ctx(features='sphinx', source='docs/conf.py')
+ ctx(features='sphinx', source='docs/conf.py', buildername='latex')
+
+Optional parameters and their defaults:
+
+ * buildername: html
+ * srcdir: confdir (the directory where conf.py lives)
+ * outdir: confdir/buildername (in the build directory tree)
+ * doctreedir: outdir/.doctrees
+ * type: pdflatex (only applies to 'latex' builder)
+
+"""
+
+
+import os
+from waflib import Task, TaskGen, Errors, Logs
+
+class RunSphinxBuild(Task.Task):
+ def scan(self):
+ """Use Sphinx' internal environment to find the dependencies."""
+ s = self.sphinx_instance
+ msg, dummy, iterator = s.env.update(s.config, s.srcdir, s.doctreedir, s)
+ s.info(msg)
+ dep_nodes = []
+ for docname in s.builder.status_iterator(iterator, "reading sources... "):
+ filename = docname + s.config.source_suffix
+ dep_nodes.append(self.srcdir.find_node(filename))
+ for dep in s.env.dependencies.values():
+ # Need the 'str' call because Sphinx might return Unicode strings.
+ [dep_nodes.append(self.srcdir.find_node(str(d))) for d in dep]
+ return (dep_nodes, [])
+
+ def run(self):
+ """Run the Sphinx build."""
+ self.sphinx_instance.build(force_all=False, filenames=None)
+ return None
+
+ def post_run(self):
+ """Add everything found in the output directory tree as an output.
+ Not elegant, but pragmatic."""
+ for n in self.outdir.ant_glob("**", quiet=True, remove=False):
+ if n not in self.outputs: self.set_outputs(n)
+ super(RunSphinxBuild, self).post_run()
+
+
+def _get_main_targets(tg, s):
+ """Return some easy targets known from the Sphinx build environment **s.env**."""
+ out_dir = tg.bld.root.find_node(s.outdir)
+ tgt_nodes = []
+ if s.builder.name == "latex":
+ for tgt_info in s.env.config.latex_documents:
+ tgt_nodes.append(out_dir.find_or_declare(tgt_info[1]))
+ elif s.builder.name == "html":
+ suffix = getattr(s.env.config, "html_file_suffix", ".html")
+ tgt_name = s.env.config.master_doc + suffix
+ tgt_nodes.append(out_dir.find_or_declare(tgt_name))
+ else:
+ raise Errors.WafError("Sphinx builder not implemented: %s" % s.builder.name)
+ return tgt_nodes
+
+
+@TaskGen.feature("sphinx")
+@TaskGen.before_method("process_source")
+def apply_sphinx(tg):
+ """Set up the task generator with a Sphinx instance and create a task."""
+
+ from sphinx.application import Sphinx
+
+ # Put together the configuration based on defaults and tg attributes.
+ conf = tg.path.find_node(tg.source)
+ confdir = conf.parent.abspath()
+ buildername = getattr(tg, "buildername", "html")
+ srcdir = getattr(tg, "srcdir", confdir)
+ outdir = tg.path.find_or_declare (getattr(tg, "outdir", os.path.join(conf.parent.get_bld().abspath(), buildername))).abspath ()
+
+ doctreedir = getattr(tg, "doctreedir", os.path.join(outdir, ".doctrees"))
+
+ # Set up the Sphinx instance.
+ s = Sphinx (srcdir, confdir, outdir, doctreedir, buildername, status=None)
+
+ # Get the main targets of the Sphinx build.
+ tgt_nodes = _get_main_targets(tg, s)
+
+ # Create the task and set the required attributes.
+ task = tg.create_task("RunSphinxBuild", src=conf, tgt=tgt_nodes)
+ task.srcdir = tg.bld.root.find_node(s.srcdir)
+ task.outdir = tg.bld.root.find_node(s.outdir)
+ task.sphinx_instance = s
+
+ # Build pdf if we have the LaTeX builder, allow for building with xelatex.
+ if s.builder.name == "latex":
+ compile_type = getattr(tg, "type", "pdflatex")
+ tg.bld(features="tex", type=compile_type, source=tgt_nodes, name="sphinx_pdf", prompt=0)
+
+ # Bypass the execution of process_source by setting the source to an empty list
+ tg.source = []
diff --git a/waf-tools/tinyxml.py b/waf-tools/tinyxml.py
new file mode 100644
index 0000000..3908b38
--- /dev/null
+++ b/waf-tools/tinyxml.py
@@ -0,0 +1,76 @@
+#! /usr/bin/env python
+# encoding: utf-8
+
+'''
+
+When using this tool, the wscript will look like:
+
+ def options(opt):
+ opt.tool_options('tinyxml', tooldir=["waf-tools"])
+
+ def configure(conf):
+ conf.load('compiler_cxx tiny')
+
+ def build(bld):
+ bld(source='main.cpp', target='app', use='TINYXML')
+
+Options are generated, in order to specify the location of tinyxml includes/libraries.
+
+
+'''
+import sys
+import re
+from waflib import Utils,Logs,Errors
+from waflib.Configure import conf
+TINYXML_DIR=['/usr','/usr/local','/opt/local','/sw']
+TINYXML_VERSION_FILE='tinyxml.h'
+TINYXML_VERSION_CODE='''
+#include <iostream>
+#include <tinyxml.h>
+int main() { std::cout << TIXML_MAJOR_VERSION << "." << TIXML_MINOR_VERSION << "." << TIXML_PATCH_VERSION; }
+'''
+
+def options(opt):
+ opt.add_option('--tinyxml',type='string',default='',dest='tinyxml_dir',help='''path to where TinyXML is installed, e.g. /usr/local''')
+@conf
+def __tinyxml_get_version_file(self,dir):
+ try:
+ return self.root.find_dir(dir).find_node('%s/%s' % ('include', TINYXML_VERSION_FILE))
+ except:
+ return None
+@conf
+def tinyxml_get_version(self,dir):
+ val=self.check_cxx(fragment=TINYXML_VERSION_CODE,includes=['%s/%s' % (dir, 'include')], execute=True, define_ret = True, mandatory=True)
+ return val
+@conf
+def tinyxml_get_root(self,*k,**kw):
+ root=k and k[0]or kw.get('path',None)
+ # Logs.pprint ('RED', ' %s' %root)
+ if root and self.__tinyxml_get_version_file(root):
+ return root
+ for dir in TINYXML_DIR:
+ if self.__tinyxml_get_version_file(dir):
+ return dir
+ if root:
+ self.fatal('TinyXML not found in %s'%root)
+ else:
+ self.fatal('TinyXML not found, please provide a --tinyxml argument (see help)')
+@conf
+def check_tinyxml(self,*k,**kw):
+ if not self.env['CXX']:
+ self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
+
+ var=kw.get('uselib_store','TINYXML')
+ self.start_msg('Checking TinyXML')
+ root = self.tinyxml_get_root(*k,**kw);
+ self.env.TINYXML_VERSION=self.tinyxml_get_version(root)
+
+ self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include");
+ self.env['LIB_%s'%var] = "tinyxml"
+ self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
+
+ self.end_msg(self.env.TINYXML_VERSION)
+ if Logs.verbose:
+ Logs.pprint('CYAN',' TinyXML include : %s'%self.env['INCLUDES_%s'%var])
+ Logs.pprint('CYAN',' TinyXML lib : %s'%self.env['LIB_%s'%var])
+ Logs.pprint('CYAN',' TinyXML libpath : %s'%self.env['LIBPATH_%s'%var])