third_party/waf: upgrade to waf 2.0.8
[vlendec/samba-autobuild/.git] / third_party / waf / waflib / Tools / bison.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # John O'Meara, 2006
4 # Thomas Nagy 2009-2018 (ita)
5
6 """
7 The **bison** program is a code generator which creates C or C++ files.
8 The generated files are compiled into object files.
9 """
10
11 from waflib import Task
12 from waflib.TaskGen import extension
13
14 class bison(Task.Task):
15         """Compiles bison files"""
16         color   = 'BLUE'
17         run_str = '${BISON} ${BISONFLAGS} ${SRC[0].abspath()} -o ${TGT[0].name}'
18         ext_out = ['.h'] # just to make sure
19
20 @extension('.y', '.yc', '.yy')
21 def big_bison(self, node):
22         """
23         Creates a bison task, which must be executed from the directory of the output file.
24         """
25         has_h = '-d' in self.env.BISONFLAGS
26
27         outs = []
28         if node.name.endswith('.yc'):
29                 outs.append(node.change_ext('.tab.cc'))
30                 if has_h:
31                         outs.append(node.change_ext('.tab.hh'))
32         else:
33                 outs.append(node.change_ext('.tab.c'))
34                 if has_h:
35                         outs.append(node.change_ext('.tab.h'))
36
37         tsk = self.create_task('bison', node, outs)
38         tsk.cwd = node.parent.get_bld()
39
40         # and the c/cxx file must be compiled too
41         self.source.append(outs[0])
42
43 def configure(conf):
44         """
45         Detects the *bison* program
46         """
47         conf.find_program('bison', var='BISON')
48         conf.env.BISONFLAGS = ['-d']
49