bison.py 1.2 KB

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