blob: a03314e75db728c86d11777862536cc481c88b5a [file] [log] [blame]
Christopher Dunnf9864232007-06-14 21:01:26 +00001# Big issue:
2# emitter depends on doxyfile which is generated from doxyfile.in.
3# build fails after cleaning and relaunching the build.
4
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +00005# Todo:
6# Add helper function to environment like for glob
7# Easier passage of header/footer
8# Automatic deduction of index.html path based on custom parameters passed to doxyfile
9
Christopher Dunnf9864232007-06-14 21:01:26 +000010import os
11import os.path
12import glob
13from fnmatch import fnmatch
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000014import SCons
Christopher Dunnf9864232007-06-14 21:01:26 +000015
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000016def Doxyfile_emitter(target, source, env):
Christopher Dunnf9864232007-06-14 21:01:26 +000017 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000018 Modify the target and source lists to use the defaults if nothing
19 else has been specified.
20
21 Dependencies on external HTML documentation references are also
22 appended to the source list.
Christopher Dunnf9864232007-06-14 21:01:26 +000023 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000024 doxyfile_template = env.File(env['DOXYFILE_FILE'])
25 source.insert(0, doxyfile_template)
Christopher Dunnf9864232007-06-14 21:01:26 +000026
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000027 return target, source
Christopher Dunnf9864232007-06-14 21:01:26 +000028
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000029def Doxyfile_Builder(target, source, env):
30 """Input:
31 DOXYFILE_FILE
32 Path of the template file for the output doxyfile
Christopher Dunnf9864232007-06-14 21:01:26 +000033
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000034 DOXYFILE_DICT
35 A dictionnary of parameter to append to the generated doxyfile
Christopher Dunnf9864232007-06-14 21:01:26 +000036 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000037 subdir = os.path.split(source[0].abspath)[0]
38 doc_top_dir = os.path.split(target[0].abspath)[0]
39 doxyfile_path = source[0].abspath
40 doxy_file = file( target[0].abspath, 'wt' )
41 try:
42 # First, output the template file
43 try:
44 f = file(doxyfile_path, 'rt')
45 doxy_file.write( f.read() )
46 f.close()
47 doxy_file.write( '\n' )
48 doxy_file.write( '# Generated content:\n' )
49 except:
50 raise SCons.Errors.UserError, "Can't read doxygen template file '%s'" % doxyfile_path
51 # Then, the input files
52 doxy_file.write( 'INPUT = \\\n' )
53 for source in source:
54 if source.abspath != doxyfile_path: # skip doxyfile path, which is the first source
55 doxy_file.write( '"%s" \\\n' % source.abspath )
56 doxy_file.write( '\n' )
57 # Dot...
58 values_dict = { 'HAVE_DOT': env.get('DOT') and 'YES' or 'NO',
59 'DOT_PATH': env.get('DOT') and os.path.split(env['DOT'])[0] or '',
60 'OUTPUT_DIRECTORY': doc_top_dir,
61 'WARN_LOGFILE': target[0].abspath + '-warning.log'}
62 values_dict.update( env['DOXYFILE_DICT'] )
63 # Finally, output user dictionary values which override any of the previously set parameters.
64 for key, value in values_dict.iteritems():
65 doxy_file.write ('%s = "%s"\n' % (key, str(value)))
66 finally:
67 doxy_file.close()
Christopher Dunnf9864232007-06-14 21:01:26 +000068
69def generate(env):
70 """
71 Add builders and construction variables for the
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000072 Doxygen tool.
Christopher Dunnf9864232007-06-14 21:01:26 +000073 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000074 ## Doxyfile builder
75 def doxyfile_message (target, source, env):
76 return "creating Doxygen config file '%s'" % target[0]
Christopher Dunnf9864232007-06-14 21:01:26 +000077
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000078 doxyfile_variables = [
79 'DOXYFILE_DICT',
80 'DOXYFILE_FILE'
81 ]
Christopher Dunnf9864232007-06-14 21:01:26 +000082
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000083 doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message,
84 doxyfile_variables )
Christopher Dunnf9864232007-06-14 21:01:26 +000085
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000086 doxyfile_builder = SCons.Builder.Builder( action = doxyfile_action,
87 emitter = Doxyfile_emitter )
88
89 env['BUILDERS']['Doxyfile'] = doxyfile_builder
90 env['DOXYFILE_DICT'] = {}
91 env['DOXYFILE_FILE'] = 'doxyfile.in'
92
93 ## Doxygen builder
94 def Doxygen_emitter(target, source, env):
95 output_dir = str( source[0].dir )
96 if str(target[0]) == str(source[0]):
97 target = env.File( os.path.join( output_dir, 'html', 'index.html' ) )
98 return target, source
99
100 doxygen_action = SCons.Action.Action( [ '$DOXYGEN_COM'] )
101 doxygen_builder = SCons.Builder.Builder( action = doxygen_action,
102 emitter = Doxygen_emitter )
103 env['BUILDERS']['Doxygen'] = doxygen_builder
104 env['DOXYGEN_COM'] = '$DOXYGEN $DOXYGEN_FLAGS $SOURCE'
105 env['DOXYGEN_FLAGS'] = ''
106 env['DOXYGEN'] = 'doxygen'
107
108 dot_path = env.WhereIs("dot")
109 if dot_path:
110 env['DOT'] = dot_path
Christopher Dunnf9864232007-06-14 21:01:26 +0000111
112def exists(env):
113 """
114 Make sure doxygen exists.
115 """
116 return env.Detect("doxygen")