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 = env.Glob("*.test.cc",strings=True)
9 for x in env.Glob("*.cc",strings=True)
10 if x not in testSources and x not in exclude ]
11 for subdir in subdirs:
12 testSources += env.Glob(os.path.join(subdir,"*.test.cc"),strings=True)
14 for x in env.Glob(os.path.join(subdir,"*.cc"),strings=True)
15 if x not in testSources and x not in exclude ]
17 for d in [ '' ] + [ x+'/' for x in subdirs ]:
18 for p in env.Glob("%s*" % d, strings=True) + env.Glob("%s*" % d, strings=True, ondisk=False):
19 ext = '.' + p.split('.',1)[-1]
20 if ext in env['CPP_INCLUDE_EXTENSIONS'] \
21 and ext not in env['CPP_EXCLUDE_EXTENSIONS'] \
24 includes = list(set(includes))
28 return ( sources, testSources, includes )
30 def Doxygen(env, doxyfile = "Doxyfile", extra_sources = [], output_directory = "doc"):
31 # There is one small problem we need to solve with this builder: The Doxygen builder reads
32 # the Doxyfile and thus depends on the environment variables set by site_scons/lib/doxygen.sh.
33 # We thus have to provide all necessary definitions here manually via DOXYENV !
35 if type(doxyfile) is type(""):
36 doxyfile = env.File(doxyfile)
38 # Module name is derived from the doxyfile path
39 # Utils/Console/Doxyfile -> Utils_Console
40 module = doxyfile.dir.get_path(env.Dir('#')).replace('/','_')
41 if module == '.' : module = "Main"
43 # Standard doc build vars and opts
44 def vars(env=env, **kw):
45 denv = { 'TOPDIR' : env.Dir('#').abspath,
46 'LIBDIR' : env.Dir('#/site_scons/lib').abspath,
47 'output_dir' : '$OUTPUT_DIRECTORY',
51 return { 'DOXYENV' : denv,
53 'OUTPUT_DIRECTORY': output_directory,
54 'DOXYGENCOM' : "site_scons/lib/doxygen.sh $DOXYOPTS $SOURCE",
56 opts = [ '--tagfile-name', '"${MODULE}.tag"',
57 '--output-dir', '$OUTPUT_DIRECTORY' ]
59 # Rule to generate tagfile
60 # (need to exclude the 'clean' case, otherwise we'll have duplicate nodes)
61 if not env.GetOption('clean'):
62 tagfile = env.Doxygen(doxyfile, DOXYOPTS = opts + [ '--tagfile' ],
63 **vars(generate_tagfile='${OUTPUT_DIRECTORY}/${MODULE}.tag'))
64 env.Append(ALL_TAGFILES = [ tagfile[0].abspath ])
65 env.Depends(tagfile, [ env.File('#/site_scons/lib/doxygen.sh'),
66 env.File('#/site_scons/lib/tag-munge.xsl') ])
68 env.Install(env.Dir('$DOCINSTALLDIR').Dir(tagfile[0].dir.get_path(env.Dir('#'))),
71 # Rule to generate HTML documentation
72 doc = env.Doxygen(doxyfile, DOXYOPTS = opts + [ '--tagfiles', '"$ALL_TAGFILES"', '--html' ],
73 **vars(html='YES', tagfiles='$ALL_TAGFILES'))
74 env.Depends(doc, [ env.File('#/site_scons/lib/doxygen.sh'),
75 env.File('#/site_scons/lib/html-munge.xsl') ])
77 # Copy the extra_sources (the images) into the documentation directory
78 # (need to exclude the 'clean' case otherwise there are multiple ways to clean the copies)
80 if env.GetOption('clean'):
81 env.Depends(doc, extra_sources)
83 env.Depends(tagfile, env.CopyToDir(doc[0].dir, extra_sources))
85 # Install documentation into DOCINSTALLDIR
86 env.InstallDir(env.Dir('$DOCINSTALLDIR').Dir(doc[0].dir.dir.get_path(env.Dir('#'))), doc[0].dir,
87 FILTER_SUFFIXES=['.html','.css','.png','.php','.idx'])
90 env.Alias('all_docs', doc)
91 env.Clean(env.Alias('all_docs'), doc)
92 env.Clean(env.Alias('all'), doc)
96 def AllIncludesHH(env, exclude=[]):
97 exclude = exclude + ['all_includes.hh']
98 headers = [ f for f in env.Glob("*.hh", source=True)
99 if f.name not in exclude and not f.name.endswith('.test.hh') ]
100 headers.sort(key=lambda x:x.name)
101 target = env.File("all_includes.hh")
102 env.Default(env.CreateFile(target,
103 env.Value("".join([ '#include <%s>\n' % f.srcnode().get_path(env.Dir('#'))
104 for f in headers ]))))
107 /** \mainpage ${TITLE}
114 {{ for name, title in SUBPAGES:
115 <dt><a href="../../${name}/doc/html/index.html">${name}</a></dt><dd>${title}</a></dd>
123 def IndexPage(env, name, title, text=""):
125 for dox in sorted(env.Glob("*/Mainpage.dox",strings=True)):
126 subtitle = ([None] + [ line.split('\\mainpage',1)[-1].strip() for line in file(dox)
127 if '\\mainpage' in line ])[-1]
129 SUBPAGES.append( (dox.split('/',1)[0], subtitle) )
130 file(name,"w").write(yaptu.process(
131 INDEXPAGE, globals(), { 'TITLE': title, 'TEXT': text, 'SUBPAGES': SUBPAGES }))
132 env.Clean('all',name)
133 env.Clean('all_docs',name)
136 ###########################################################################
137 # The following functions serve as simple macros for most SConscript files
139 # If you need to customize these rules, copy-and-paste the code into the
140 # SConscript file and adjust at will (don't forget to replace the
141 # parameters with their actual value. Parameters are marked with ((name)) )
143 def AutoRules(env, exclude=[], subdirs=[], doc_extra_sources = []):
146 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
147 subscripts = sorted(env.Glob("*/SConscript", strings=True))
148 doxyfile = env.Glob("Doxyfile")
151 if sources : env.Append(ALLOBJECTS = env.Object(sources))
152 if tests : env.BoostUnitTest('test', tests)
153 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
154 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
155 if subscripts : SConscript(subscripts)
158 def AutoPacketBundle(env, name, exclude=[], subdirs=[], doc_extra_sources=[]):
161 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
162 subscripts = sorted(env.Glob("*/SConscript", strings=True))
163 doxyfile = env.Glob("Doxyfile")
165 objects = env.Object(sources)
166 cobject = env.CombinedObject('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', objects, NAME=((name)))
167 sobundle = env.SharedLibrary('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', sources, NAME=((name)),
168 LIBS=[], SHLIBPREFIX='')
171 env.Default(sobundle)
172 env.Append(ALLOBJECTS = objects, PACKET_BUNDLES = cobject)
173 env.Install('$OBJINSTALLDIR', cobject)
174 env.Install('$OBJINSTALLDIR', sobundle)
176 if tests : env.BoostUnitTest('test', tests + cobject)
177 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
178 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
179 if subscripts : SConscript(subscripts)