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 = []):
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 # Rule to generate tagfile
38 # (need to exclude the 'clean' case, otherwise we'll have duplicate nodes)
39 if not env.GetOption('clean'):
40 tagfile = env.Doxygen(doxyfile,
41 DOXYOPTS = [ '--tagfile-name', '"${MODULE}.tag"',
43 DOXYENV = { 'TOPDIR' : env.Dir('#').abspath,
44 'LIBDIR' : env.Dir('#/site_scons/lib').abspath,
48 'generate_tagfile': 'doc/${MODULE}.tag' },
50 env.Append(ALL_TAGFILES = [ tagfile[0].abspath ])
51 env.Depends(tagfile, [ env.File('#/site_scons/lib/doxygen.sh'),
52 env.File('#/site_scons/lib/tag-munge.xsl') ])
54 env.Install(env.Dir('$DOCINSTALLDIR').Dir(tagfile[0].dir.get_path(env.Dir('#'))),
57 # Rule to generate HTML documentation
58 doc = env.Doxygen(doxyfile,
59 DOXYOPTS = [ '--tagfiles', '"$ALL_TAGFILES"',
60 '--tagfile-name', '"${MODULE}.tag"',
63 DOXYENV = { 'TOPDIR' : env.Dir('#').abspath,
64 'LIBDIR' : env.Dir('#/site_scons/lib').abspath,
65 'tagfiles' : '${ALL_TAGFILES}',
69 env.Depends(doc, [ env.File('#/site_scons/lib/doxygen.sh'),
70 env.File('#/site_scons/lib/html-munge.xsl') ])
72 # Copy the extra_sources (the images) into the documentation directory
73 # (need to exclude the 'clean' case otherwise there are multiple ways to clean the copies)
75 if env.GetOption('clean'):
76 env.Depends(doc, extra_sources)
78 env.Depends(doc, env.CopyToDir(doc[0].dir, extra_sources))
80 # Install documentation into DOCINSTALLDIR
81 env.InstallDir(env.Dir('$DOCINSTALLDIR').Dir(doc[0].dir.dir.get_path(env.Dir('#'))), doc[0].dir,
82 FILTER_SUFFIXES=['.html','.css','.png','.php','.idx'])
85 env.Alias('all_docs', doc)
86 env.Clean(env.Alias('all_docs'), doc)
87 env.Clean(env.Alias('all'), doc)
91 def AllIncludesHH(env, exclude=[]):
92 exclude = exclude[:] + ['all_includes.hh'] # Make a copy !!
93 headers = [ f for f in glob.glob("*.hh")
94 if f not in exclude and not f.endswith('.test.hh') ]
96 target = env.File("all_includes.hh")
97 file(target.abspath,"w").write("".join([ '#include "%s"\n' % f
99 env.Clean(env.Alias('all'), target)
101 ###########################################################################
102 # The following functions serve as simple macros for most SConscript files
104 # If you need to customize these rules, copy-and-paste the code into the
105 # SConscript file and adjust at will (don't forget to replace the
106 # parameters with their actual value. Parameters are marked with ((name)) )
108 def AutoRules(env, exclude=[], subdirs=[], doc_extra_sources = []):
111 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
112 subscripts = env.Glob("*/SConscript")
113 doxyfile = env.Glob("Doxyfile")
115 if sources : env.Append(ALLOBJECTS = env.Object(sources))
116 if tests : env.BoostUnitTest('test', tests)
117 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
118 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
119 if subscripts : SConscript(subscripts)
122 def AutoPacketBundle(env, name, exclude=[], subdirs=[], doc_extra_sources=[]):
125 sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
126 subscripts = env.Glob("*/SConscript")
127 doxyfile = env.Glob("Doxyfile")
129 objects = env.Object(sources)
130 cobject = env.CombinedObject('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', objects, NAME=((name)))
133 env.Append(ALLOBJECTS = objects, PACKET_BUNDLES = cobject)
134 env.Install('$OBJINSTALLDIR', cobject)
136 if tests : env.BoostUnitTest('test', tests + cobject)
137 if includes : env.InstallSubdir('$INCLUDEINSTALLDIR', includes)
138 if doxyfile : SENFSCons.Doxygen(env, extra_sources=((doc_extra_sources)) )
139 if subscripts : SConscript(subscripts)