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 + env.Glob("*.c",strings=True)
11 if x not in testSources and x not in exclude ]
12 for subdir in subdirs:
13 testSources += env.Glob(os.path.join(subdir,"*.test.cc"),strings=True)
15 for x in env.Glob(os.path.join(subdir,"*.cc"),strings=True) \
16 + env.Glob(os.path.join(subdir,"*.c"),strings=True)
17 if x not in testSources and x not in exclude ]
19 for d in [ '' ] + [ x+'/' for x in subdirs ]:
20 for p in env.Glob("%s*" % d, strings=True) + env.Glob("%s*" % d, strings=True, ondisk=False):
21 ext = '.' + p.split('.',1)[-1]
22 if ext in env['CPP_INCLUDE_EXTENSIONS'] \
23 and ext not in env['CPP_EXCLUDE_EXTENSIONS'] \
26 includes = list(set(includes))
30 return ( sources, testSources, includes )
32 def Doxygen(env, doxyfile = "Doxyfile", extra_sources = [], output_directory = "doc"):
33 # There is one small problem we need to solve with this builder: The Doxygen builder reads
34 # the Doxyfile and thus depends on the environment variables set by site_scons/lib/doxygen.sh.
35 # We thus have to provide all necessary definitions here manually via DOXYENV !
37 if type(doxyfile) is type(""):
38 doxyfile = env.File(doxyfile)
40 # Module name is derived from the doxyfile path
41 # Utils/Console/Doxyfile -> Utils_Console
42 module = doxyfile.dir.get_path(env.Dir('#')).replace('/','_')
43 if module == '.' : module = "Main"
45 # Standard doc build vars and opts
46 def vars(env=env, **kw):
47 denv = { 'TOPDIR' : env.Dir('#').abspath,
48 'LIBDIR' : env.Dir('#/site_scons/lib').abspath,
49 'output_dir' : '$OUTPUT_DIRECTORY',
52 'DOXYGEN' : '$DOXYGEN' }
54 return { 'DOXYENV' : denv,
56 'OUTPUT_DIRECTORY': output_directory,
57 'DOXYGENCOM' : "site_scons/lib/doxygen.sh $DOXYOPTS $SOURCE",
59 opts = [ '--tagfile-name', '"${MODULE}.tag"',
60 '--output-dir', '$OUTPUT_DIRECTORY' ]
62 # Rule to generate tagfile
63 # (need to exclude the 'clean' case, otherwise we'll have duplicate nodes)
64 if not env.GetOption('clean'):
65 tagfile = env.Doxygen(doxyfile, DOXYOPTS = opts + [ '--tagfile' ],
66 **vars(generate_tagfile='${OUTPUT_DIRECTORY}/${MODULE}.tag'))
67 env.Append(ALL_TAGFILES = [ tagfile[0].abspath ])
68 env.Depends(tagfile, [ env.File('#/site_scons/lib/doxygen.sh'),
69 env.File('#/site_scons/lib/tag-munge.xsl') ])
71 env.Install(env.Dir('$DOCINSTALLDIR').Dir(tagfile[0].dir.get_path(env.Dir('#'))),
74 # Rule to generate HTML documentation
75 doc = env.Doxygen(doxyfile, DOXYOPTS = opts + [ '--tagfiles', '"$ALL_TAGFILES"', '--html' ],
76 **vars(html='YES', tagfiles='$ALL_TAGFILES'))
77 env.Depends(doc, [ env.File('#/site_scons/lib/doxygen.sh'),
78 env.File('#/site_scons/lib/html-munge.xsl') ])
80 # Copy the extra_sources (the images) into the documentation directory
81 # (need to exclude the 'clean' case otherwise there are multiple ways to clean the copies)
83 if env.GetOption('clean'):
84 env.Depends(doc, extra_sources)
86 env.Depends(tagfile, env.CopyToDir(doc[0].dir, extra_sources))
88 # Install documentation into DOCINSTALLDIR
89 env.InstallDir(env.Dir('$DOCINSTALLDIR').Dir(doc[0].dir.dir.get_path(env.Dir('#'))), doc[0].dir,
90 FILTER_SUFFIXES=['.html','.css','.png','.php','.idx'])
93 env.Alias('all_docs', doc)
94 env.Clean(env.Alias('all_docs'), doc)
95 env.Clean(env.Alias('all'), doc)
99 def AllIncludesHH(env, exclude=[]):
100 exclude = exclude + ['all_includes.hh']
101 headers = [ f for f in env.Glob("*.hh", source=True)
102 if f.name not in exclude and not f.name.endswith('.test.hh') ]
103 headers.sort(key=lambda x:x.name)
104 target = env.File("all_includes.hh")
105 allinch = env.CreateFile(target,
106 env.Value("".join([ '#include <%s>\n' % f.srcnode().get_path(env.Dir('#'))
107 for f in headers ])))
109 env.Depends(allinch, headers)
112 /** \mainpage ${TITLE}
119 {{ for name, title in SUBPAGES:
120 <dt><a href="../../${name}/doc/html/index.html">${name}</a></dt><dd>${title}</a></dd>
128 def IndexPage(env, name, title, text=""):
130 for dox in sorted(env.Glob("*/Mainpage.dox",strings=True)):
131 subtitle = ([None] + [ line.split('\\mainpage',1)[-1].strip() for line in file(dox)
132 if '\\mainpage' in line ])[-1]
134 SUBPAGES.append( (dox.split('/',1)[0], subtitle) )
135 file(name,"w").write(yaptu.process(
136 INDEXPAGE, globals(), { 'TITLE': title, 'TEXT': text, 'SUBPAGES': SUBPAGES }))
137 env.Clean('all',name)
138 env.Clean('all_docs',name)
140 ###########################################################################
141 # The following functions serve as simple macros for most SConscript files
143 # If you need to customize these rules, copy-and-paste the code into the
144 # SConscript file and adjust at will (don't forget to replace the
145 # parameters with their actual value. Parameters are marked with ((name)) )
147 def AutoRules(env, exclude=[], subdirs=[], doc_extra_sources = []):
150 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
151 subscripts = sorted(env.Glob("*/SConscript", strings=True))
152 doxyfile = env.Glob("Doxyfile")
155 if sources : env.Append(ALLOBJECTS = env.Object(sources))
156 if tests : env.BoostUnitTest('test', tests)
157 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
158 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
159 if subscripts : SConscript(subscripts)
162 def AutoPacketBundle(env, name, exclude=[], subdirs=[], doc_extra_sources=[]):
165 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
166 subscripts = sorted(env.Glob("*/SConscript", strings=True))
167 doxyfile = env.Glob("Doxyfile")
169 objects = env.Object(sources)
170 cobject = env.CombinedObject('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', objects, NAME=((name)))
171 sobundle = env.SharedLibrary('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', sources, NAME=((name)),
172 LIBS=[], SHLIBPREFIX='')
175 env.Default(sobundle)
176 env.Append(ALLOBJECTS = objects, PACKET_BUNDLES = cobject)
177 env.Install('$OBJINSTALLDIR', cobject)
178 env.Install('$OBJINSTALLDIR', sobundle)
180 if tests : env.BoostUnitTest('test', tests + cobject)
181 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
182 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
183 if subscripts : SConscript(subscripts)
186 def BuildExample(env, sconstruct):
187 dir = env.File( ((sconstruct)) ).dir
188 example = env.Command( dir.File('.example.phony'), env.Alias('default'),
189 [ '$SCONS -C $EXAMPLEDIR' ],
190 CONCURRENCY_LEVEL=1, EXAMPLEDIR=dir )
191 env.Alias('examples', example)
193 if env.GetOption('clean') and ('all' in BUILD_TARGETS or 'examples' in BUILD_TARGETS):
194 env.Clone(CONCURRENCY_LEVEL=1, EXAMPLEDIR=dir).Execute([ '$SCONS -C $EXAMPLEDIR -c' ])