Combine all boot build stuff in a single scons tool
[senf.git] / senfscons / SENFSCons.py
1 import os.path, glob
2 import SCons.Options, SCons.Environment, SCons.Script.SConscript, SCons.Node.FS
3 import SCons.Defaults, SCons.Action
4 from SCons.Script import *
5
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 ]
9     for subdir in subdirs:
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 ]
13     includes = []
14     for d in [ '.' ] + subdirs:
15         for f in os.listdir(d):
16             ext = '.' + f.split('.',1)[-1]
17             p = os.path.join(d,f)
18             if ext in env['CPP_INCLUDE_EXTENSIONS'] \
19                and ext not in env['CPP_EXCLUDE_EXTENSIONS'] \
20                and p not in exclude:
21                 includes.append(p)
22     return ( sources, testSources, includes )
23
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 doclib/doxygen.sh. We
27     # thus have to provide all necessary definitions here manually via DOXYENV !
28
29     if type(doxyfile) is type(""):
30         doxyfile = env.File(doxyfile)
31
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"
36
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"',
42                                            '--tagfile' ],
43                               DOXYENV  = { 'TOPDIR'          : env.Dir('#').abspath,
44                                            'output_dir'      : 'doc',
45                                            'html_dir'        : 'html',
46                                            'html'            : 'NO',
47                                            'generate_tagfile': 'doc/${MODULE}.tag' },
48                               MODULE   = module )
49         env.Append(ALL_TAGFILES = tagfile[0].abspath)
50         env.Depends(tagfile, env.File('#/doclib/doxygen.sh'))
51
52     # Rule to generate HTML documentation
53     doc = env.Doxygen(doxyfile,
54                       DOXYOPTS = [ '--tagfiles', '"$ALL_TAGFILES"',
55                                    '--tagfile-name', '"${MODULE}.tag"',
56                                    '--html' ],
57                       MODULE   = module,
58                       DOXYENV  = { 'TOPDIR'          : env.Dir('#').abspath,
59                                    'tagfiles'        : '${ALL_TAGFILES}',
60                                    'output_dir'      : 'doc',
61                                    'html_dir'        : 'html',
62                                    'html'            : 'YES' } )
63     env.Depends(doc, env.File('#/doclib/doxygen.sh'))
64
65     # Copy the extra_sources (the images) into the documentation directory
66     # (need to exclude the 'clean' case otherwise there are multiple ways to clean the copies)
67     if not env.GetOption('clean'):
68         if extra_sources:
69             env.Depends(doc, env.CopyToDir(doc[0].dir, extra_sources))
70
71     # Install documentation into DOCINSTALLDIR
72     l = len(env.Dir('#').abspath)
73     env.Install(env.Dir('$DOCINSTALLDIR').Dir(doc[0].dir.get_path('#')), doc[0].dir)
74
75     # Useful aliases
76     env.Alias('all_docs', doc)
77     env.Clean('all_docs', doc)
78     env.Clean('all', doc)
79
80     return doc
81
82 def AllIncludesHH(env, headers):
83     headers.sort()
84     target = env.File("all_includes.hh")
85     file(target.abspath,"w").write("".join([ '#include "%s"\n' % f
86                                              for f in headers ]))
87     env.Clean('all', target)