blob: 927fd29c990aff665d363a1ba2e27b9ce2611bee [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
Christopher Dunn060c45a2009-05-24 22:22:08 +000083 #doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message,
84 # doxyfile_variables )
85 doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message)
Christopher Dunnf9864232007-06-14 21:01:26 +000086
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000087 doxyfile_builder = SCons.Builder.Builder( action = doxyfile_action,
88 emitter = Doxyfile_emitter )
89
90 env['BUILDERS']['Doxyfile'] = doxyfile_builder
91 env['DOXYFILE_DICT'] = {}
92 env['DOXYFILE_FILE'] = 'doxyfile.in'
93
94 ## Doxygen builder
95 def Doxygen_emitter(target, source, env):
96 output_dir = str( source[0].dir )
97 if str(target[0]) == str(source[0]):
98 target = env.File( os.path.join( output_dir, 'html', 'index.html' ) )
99 return target, source
100
101 doxygen_action = SCons.Action.Action( [ '$DOXYGEN_COM'] )
102 doxygen_builder = SCons.Builder.Builder( action = doxygen_action,
103 emitter = Doxygen_emitter )
104 env['BUILDERS']['Doxygen'] = doxygen_builder
105 env['DOXYGEN_COM'] = '$DOXYGEN $DOXYGEN_FLAGS $SOURCE'
106 env['DOXYGEN_FLAGS'] = ''
107 env['DOXYGEN'] = 'doxygen'
108
109 dot_path = env.WhereIs("dot")
110 if dot_path:
111 env['DOT'] = dot_path
Christopher Dunnf9864232007-06-14 21:01:26 +0000112
113def exists(env):
114 """
115 Make sure doxygen exists.
116 """
117 return env.Detect("doxygen")