blob: 5ace420a4cbedfec7f8dba59beb16dd7d482a71c [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
Christopher Dunnf9864232007-06-14 21:01:26 +000012from fnmatch import fnmatch
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000013import SCons
Christopher Dunnf9864232007-06-14 21:01:26 +000014
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000015def Doxyfile_emitter(target, source, env):
Christopher Dunnf9864232007-06-14 21:01:26 +000016 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000017 Modify the target and source lists to use the defaults if nothing
18 else has been specified.
19
20 Dependencies on external HTML documentation references are also
21 appended to the source list.
Christopher Dunnf9864232007-06-14 21:01:26 +000022 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000023 doxyfile_template = env.File(env['DOXYFILE_FILE'])
24 source.insert(0, doxyfile_template)
Christopher Dunnf9864232007-06-14 21:01:26 +000025
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000026 return target, source
Christopher Dunnf9864232007-06-14 21:01:26 +000027
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000028def Doxyfile_Builder(target, source, env):
29 """Input:
30 DOXYFILE_FILE
31 Path of the template file for the output doxyfile
Christopher Dunnf9864232007-06-14 21:01:26 +000032
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000033 DOXYFILE_DICT
34 A dictionnary of parameter to append to the generated doxyfile
Christopher Dunnf9864232007-06-14 21:01:26 +000035 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000036 subdir = os.path.split(source[0].abspath)[0]
37 doc_top_dir = os.path.split(target[0].abspath)[0]
38 doxyfile_path = source[0].abspath
39 doxy_file = file( target[0].abspath, 'wt' )
40 try:
41 # First, output the template file
42 try:
43 f = file(doxyfile_path, 'rt')
44 doxy_file.write( f.read() )
45 f.close()
46 doxy_file.write( '\n' )
47 doxy_file.write( '# Generated content:\n' )
48 except:
49 raise SCons.Errors.UserError, "Can't read doxygen template file '%s'" % doxyfile_path
50 # Then, the input files
51 doxy_file.write( 'INPUT = \\\n' )
52 for source in source:
53 if source.abspath != doxyfile_path: # skip doxyfile path, which is the first source
54 doxy_file.write( '"%s" \\\n' % source.abspath )
55 doxy_file.write( '\n' )
56 # Dot...
57 values_dict = { 'HAVE_DOT': env.get('DOT') and 'YES' or 'NO',
58 'DOT_PATH': env.get('DOT') and os.path.split(env['DOT'])[0] or '',
59 'OUTPUT_DIRECTORY': doc_top_dir,
60 'WARN_LOGFILE': target[0].abspath + '-warning.log'}
61 values_dict.update( env['DOXYFILE_DICT'] )
62 # Finally, output user dictionary values which override any of the previously set parameters.
63 for key, value in values_dict.iteritems():
64 doxy_file.write ('%s = "%s"\n' % (key, str(value)))
65 finally:
66 doxy_file.close()
Christopher Dunnf9864232007-06-14 21:01:26 +000067
68def generate(env):
69 """
70 Add builders and construction variables for the
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000071 Doxygen tool.
Christopher Dunnf9864232007-06-14 21:01:26 +000072 """
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000073 ## Doxyfile builder
74 def doxyfile_message (target, source, env):
75 return "creating Doxygen config file '%s'" % target[0]
Christopher Dunnf9864232007-06-14 21:01:26 +000076
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000077 doxyfile_variables = [
78 'DOXYFILE_DICT',
79 'DOXYFILE_FILE'
80 ]
Christopher Dunnf9864232007-06-14 21:01:26 +000081
Christopher Dunn060c45a2009-05-24 22:22:08 +000082 #doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message,
83 # doxyfile_variables )
84 doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message)
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")