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