3 # Thomas Nagy, 2006-2008 (ita)
8 from TaskGen
import taskgen
, before
, after
, feature
15 def add_marshal_file(self
, filename
, prefix
):
16 if not hasattr(self
, 'marshal_list'):
17 self
.marshal_list
= []
18 self
.meths
.append('process_marshal')
19 self
.marshal_list
.append((filename
, prefix
))
22 def process_marshal(self
):
23 for f
, prefix
in getattr(self
, 'marshal_list', []):
24 node
= self
.path
.find_resource(f
)
27 raise Utils
.WafError('file not found %r' % f
)
29 h_node
= node
.change_ext('.h')
30 c_node
= node
.change_ext('.c')
32 task
= self
.create_task('glib_genmarshal', node
, [h_node
, c_node
])
33 task
.env
.GLIB_GENMARSHAL_PREFIX
= prefix
34 self
.allnodes
.append(c_node
)
36 def genmarshal_func(self
):
38 bld
= self
.inputs
[0].__class
__.bld
40 get
= self
.env
.get_flat
41 cmd1
= "%s %s --prefix=%s --header > %s" % (
42 get('GLIB_GENMARSHAL'),
43 self
.inputs
[0].srcpath(self
.env
),
44 get('GLIB_GENMARSHAL_PREFIX'),
45 self
.outputs
[0].abspath(self
.env
)
48 ret
= bld
.exec_command(cmd1
)
51 #print self.outputs[1].abspath(self.env)
52 f
= open(self
.outputs
[1].abspath(self
.env
), 'wb')
53 c
= '''#include "%s"\n''' % self
.outputs
[0].name
57 cmd2
= "%s %s --prefix=%s --body >> %s" % (
58 get('GLIB_GENMARSHAL'),
59 self
.inputs
[0].srcpath(self
.env
),
60 get('GLIB_GENMARSHAL_PREFIX'),
61 self
.outputs
[1].abspath(self
.env
)
63 ret
= Utils
.exec_command(cmd2
)
71 def add_enums_from_template(self
, source
='', target
='', template
='', comments
=''):
72 if not hasattr(self
, 'enums_list'):
74 self
.meths
.append('process_enums')
75 self
.enums_list
.append({'source': source
,
85 'comments': comments
})
88 def add_enums(self
, source
='', target
='',
89 file_head
='', file_prod
='', file_tail
='', enum_prod
='',
90 value_head
='', value_prod
='', value_tail
='', comments
=''):
91 if not hasattr(self
, 'enums_list'):
93 self
.meths
.append('process_enums')
94 self
.enums_list
.append({'source': source
,
97 'file-head': file_head
,
98 'file-prod': file_prod
,
99 'file-tail': file_tail
,
100 'enum-prod': enum_prod
,
101 'value-head': value_head
,
102 'value-prod': value_prod
,
103 'value-tail': value_tail
,
104 'comments': comments
})
106 @before('apply_core')
107 def process_enums(self
):
108 for enum
in getattr(self
, 'enums_list', []):
109 task
= self
.create_task('glib_mkenums')
115 source_list
= self
.to_list(enum
['source'])
117 raise Utils
.WafError('missing source ' + str(enum
))
118 source_list
= [self
.path
.find_resource(k
) for k
in source_list
]
119 inputs
+= source_list
120 env
['GLIB_MKENUMS_SOURCE'] = [k
.srcpath(env
) for k
in source_list
]
123 if not enum
['target']:
124 raise Utils
.WafError('missing target ' + str(enum
))
125 tgt_node
= self
.path
.find_or_declare(enum
['target'])
126 if tgt_node
.name
.endswith('.c'):
127 self
.allnodes
.append(tgt_node
)
128 env
['GLIB_MKENUMS_TARGET'] = tgt_node
.abspath(env
)
133 if enum
['template']: # template, if provided
134 template_node
= self
.path
.find_resource(enum
['template'])
135 options
.append('--template %s' % (template_node
.abspath(env
)))
136 inputs
.append(template_node
)
137 params
= {'file-head' : '--fhead',
138 'file-prod' : '--fprod',
139 'file-tail' : '--ftail',
140 'enum-prod' : '--eprod',
141 'value-head' : '--vhead',
142 'value-prod' : '--vprod',
143 'value-tail' : '--vtail',
144 'comments': '--comments'}
145 for param
, option
in params
.iteritems():
147 options
.append('%s %r' % (option
, enum
[param
]))
149 env
['GLIB_MKENUMS_OPTIONS'] = ' '.join(options
)
151 # update the task instance
152 task
.set_inputs(inputs
)
153 task
.set_outputs(tgt_node
)
155 Task
.task_type_from_func('glib_genmarshal', func
=genmarshal_func
, vars=['GLIB_GENMARSHAL_PREFIX', 'GLIB_GENMARSHAL'],
156 color
='BLUE', before
='cc cxx')
157 Task
.simple_task_type('glib_mkenums',
158 '${GLIB_MKENUMS} ${GLIB_MKENUMS_OPTIONS} ${GLIB_MKENUMS_SOURCE} > ${GLIB_MKENUMS_TARGET}',
159 color
='PINK', before
='cc cxx')
162 glib_genmarshal
= conf
.find_program('glib-genmarshal', var
='GLIB_GENMARSHAL')
163 mk_enums_tool
= conf
.find_program('glib-mkenums', var
='GLIB_MKENUMS')