1 import os.path, glob, yaptu
2 import SCons.Options, SCons.Environment, SCons.Script.SConscript, SCons.Node.FS
3 import SCons.Defaults, SCons.Action
4 from SCons.Script import *
6 def Glob(env, exclude=[], subdirs=[]):
7 testSources = glob.glob("*.test.cc")
8 sources = [ x for x in glob.glob("*.cc") if x not in testSources and x not in exclude ]
10 testSources += glob.glob(os.path.join(subdir,"*.test.cc"))
11 sources += [ x for x in glob.glob(os.path.join(subdir,"*.cc"))
12 if x not in testSources and x not in exclude ]
14 for d in [ '.' ] + subdirs:
15 for f in os.listdir(d):
16 ext = '.' + f.split('.',1)[-1]
18 if ext in env['CPP_INCLUDE_EXTENSIONS'] \
19 and ext not in env['CPP_EXCLUDE_EXTENSIONS'] \
22 return ( sources, testSources, includes )
24 def Doxygen(env, doxyfile = "Doxyfile", extra_sources = [], output_directory = "doc"):
25 # There is one small problem we need to solve with this builder: The Doxygen builder reads
26 # the Doxyfile and thus depends on the environment variables set by site_scons/lib/doxygen.sh.
27 # We thus have to provide all necessary definitions here manually via DOXYENV !
29 if type(doxyfile) is type(""):
30 doxyfile = env.File(doxyfile)
32 # Module name is derived from the doxyfile path
33 # Utils/Console/Doxyfile -> Utils_Console
34 module = doxyfile.dir.get_path(env.Dir('#')).replace('/','_')
35 if module == '.' : module = "Main"
37 # Standard doc build vars and opts
38 def vars(env=env, **kw):
39 denv = { 'TOPDIR' : env.Dir('#').abspath,
40 'LIBDIR' : env.Dir('#/site_scons/lib').abspath,
41 'output_dir' : '$OUTPUT_DIRECTORY',
45 return { 'DOXYENV' : denv,
47 'OUTPUT_DIRECTORY': output_directory,
48 'DOXYGENCOM' : "site_scons/lib/doxygen.sh $DOXYOPTS $SOURCE",
50 opts = [ '--tagfile-name', '"${MODULE}.tag"',
51 '--output-dir', '$OUTPUT_DIRECTORY' ]
53 # Rule to generate tagfile
54 # (need to exclude the 'clean' case, otherwise we'll have duplicate nodes)
55 if not env.GetOption('clean'):
56 tagfile = env.Doxygen(doxyfile, DOXYOPTS = opts + [ '--tagfile' ],
57 **vars(generate_tagfile='${OUTPUT_DIRECTORY}/${MODULE}.tag'))
58 env.Append(ALL_TAGFILES = [ tagfile[0].abspath ])
59 env.Depends(tagfile, [ env.File('#/site_scons/lib/doxygen.sh'),
60 env.File('#/site_scons/lib/tag-munge.xsl') ])
62 env.Install(env.Dir('$DOCINSTALLDIR').Dir(tagfile[0].dir.get_path(env.Dir('#'))),
65 # Rule to generate HTML documentation
66 doc = env.Doxygen(doxyfile, DOXYOPTS = opts + [ '--tagfiles', '"$ALL_TAGFILES"', '--html' ],
67 **vars(html='YES', tagfiles='$ALL_TAGFILES'))
68 env.Depends(doc, [ env.File('#/site_scons/lib/doxygen.sh'),
69 env.File('#/site_scons/lib/html-munge.xsl') ])
71 # Copy the extra_sources (the images) into the documentation directory
72 # (need to exclude the 'clean' case otherwise there are multiple ways to clean the copies)
74 if env.GetOption('clean'):
75 env.Depends(doc, extra_sources)
77 env.Depends(tagfile, env.CopyToDir(doc[0].dir, extra_sources))
79 # Install documentation into DOCINSTALLDIR
80 env.InstallDir(env.Dir('$DOCINSTALLDIR').Dir(doc[0].dir.dir.get_path(env.Dir('#'))), doc[0].dir,
81 FILTER_SUFFIXES=['.html','.css','.png','.php','.idx'])
84 env.Alias('all_docs', doc)
85 env.Clean(env.Alias('all_docs'), doc)
86 env.Clean(env.Alias('all'), doc)
90 def AllIncludesHH(env, exclude=[]):
91 exclude = exclude[:] + ['all_includes.hh'] # Make a copy !!
92 headers = [ f for f in glob.glob("*.hh")
93 if f not in exclude and not f.endswith('.test.hh') ]
95 target = env.File("all_includes.hh")
96 file(target.abspath,"w").write("".join([ '#include "%s"\n' % f
98 env.Clean(env.Alias('all'), target)
102 /** \mainpage ${TITLE}
109 {{ for name, title in SUBPAGES:
110 <dt><a href="../../${name}/doc/html/index.html">${name}</a></dt><dd>${title}</a></dd>
118 def IndexPage(env, name, title, text=""):
120 for dox in sorted(glob.glob("*/Mainpage.dox")):
121 subtitle = ([None] + [ line.split('\\mainpage',1)[-1].strip() for line in file(dox)
122 if '\\mainpage' in line ])[-1]
124 SUBPAGES.append( (dox.split('/',1)[0], subtitle) )
125 file(name,"w").write(yaptu.process(
126 INDEXPAGE, globals(), { 'TITLE': title, 'TEXT': text, 'SUBPAGES': SUBPAGES }))
127 env.Clean('all',name)
128 env.Clean('all_docs',name)
131 ###########################################################################
132 # The following functions serve as simple macros for most SConscript files
134 # If you need to customize these rules, copy-and-paste the code into the
135 # SConscript file and adjust at will (don't forget to replace the
136 # parameters with their actual value. Parameters are marked with ((name)) )
138 def AutoRules(env, exclude=[], subdirs=[], doc_extra_sources = []):
141 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
142 subscripts = env.Glob("*/SConscript")
143 doxyfile = env.Glob("Doxyfile")
145 if sources : env.Append(ALLOBJECTS = env.Object(sources))
146 if tests : env.BoostUnitTest('test', tests)
147 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
148 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
149 if subscripts : SConscript(subscripts)
152 def AutoPacketBundle(env, name, exclude=[], subdirs=[], doc_extra_sources=[]):
155 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
156 subscripts = env.Glob("*/SConscript")
157 doxyfile = env.Glob("Doxyfile")
159 objects = env.Object(sources)
160 cobject = env.CombinedObject('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', objects, NAME=((name)))
163 env.Append(ALLOBJECTS = objects, PACKET_BUNDLES = cobject)
164 env.Install('$OBJINSTALLDIR', cobject)
166 if tests : env.BoostUnitTest('test', tests + cobject)
167 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
168 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
169 if subscripts : SConscript(subscripts)