2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-29 13:30:32 +01:00
waf/waflib/Tools/bison.py

50 lines
1.2 KiB
Python
Raw Normal View History

2011-09-10 11:13:51 +02:00
#!/usr/bin/env python
# encoding: utf-8
# John O'Meara, 2006
2017-02-11 16:13:37 +01:00
# Thomas Nagy 2009-2017 (ita)
2011-09-10 11:13:51 +02:00
"""
The **bison** program is a code generator which creates C or C++ files.
The generated files are compiled into object files.
"""
from waflib import Task
from waflib.TaskGen import extension
class bison(Task.Task):
2016-06-25 20:10:04 +02:00
"""Compiles bison files"""
2011-09-10 11:13:51 +02:00
color = 'BLUE'
run_str = '${BISON} ${BISONFLAGS} ${SRC[0].abspath()} -o ${TGT[0].name}'
ext_out = ['.h'] # just to make sure
@extension('.y', '.yc', '.yy')
def big_bison(self, node):
"""
2016-06-25 20:10:04 +02:00
Creates a bison task, which must be executed from the directory of the output file.
2011-09-10 11:13:51 +02:00
"""
2016-06-25 23:54:12 +02:00
has_h = '-d' in self.env.BISONFLAGS
2011-09-10 11:13:51 +02:00
outs = []
if node.name.endswith('.yc'):
outs.append(node.change_ext('.tab.cc'))
if has_h:
outs.append(node.change_ext('.tab.hh'))
else:
outs.append(node.change_ext('.tab.c'))
if has_h:
outs.append(node.change_ext('.tab.h'))
tsk = self.create_task('bison', node, outs)
2016-01-02 01:54:52 +01:00
tsk.cwd = node.parent.get_bld()
2011-09-10 11:13:51 +02:00
# and the c/cxx file must be compiled too
self.source.append(outs[0])
def configure(conf):
"""
2016-06-25 20:10:04 +02:00
Detects the *bison* program
2011-09-10 11:13:51 +02:00
"""
conf.find_program('bison', var='BISON')
conf.env.BISONFLAGS = ['-d']