thirdparty:waf: New files for waf 1.9.10
[sfrench/samba-autobuild/.git] / third_party / waf / waflib / Tools / flex.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, 2006-2016 (ita)
9
10 """
11 The **flex** program is a code generator which creates C or C++ files.
12 The generated files are compiled into object files.
13 """
14
15 import os, re
16 from waflib import Task, TaskGen
17 from waflib.Tools import ccroot
18
19 def decide_ext(self, node):
20         if 'cxx' in self.features:
21                 return ['.lex.cc']
22         return ['.lex.c']
23
24 def flexfun(tsk):
25         env = tsk.env
26         bld = tsk.generator.bld
27         wd = bld.variant_dir
28         def to_list(xx):
29                 if isinstance(xx, str): return [xx]
30                 return xx
31         tsk.last_cmd = lst = []
32         lst.extend(to_list(env.FLEX))
33         lst.extend(to_list(env.FLEXFLAGS))
34         inputs = [a.path_from(tsk.get_cwd()) for a in tsk.inputs]
35         if env.FLEX_MSYS:
36                 inputs = [x.replace(os.sep, '/') for x in inputs]
37         lst.extend(inputs)
38         lst = [x for x in lst if x]
39         txt = bld.cmd_and_log(lst, cwd=wd, env=env.env or None, quiet=0)
40         tsk.outputs[0].write(txt.replace('\r\n', '\n').replace('\r', '\n')) # issue #1207
41
42 TaskGen.declare_chain(
43         name = 'flex',
44         rule = flexfun, # issue #854
45         ext_in = '.l',
46         decider = decide_ext,
47 )
48
49 # To support the following:
50 # bld(features='c', flexflags='-P/foo')
51 Task.classes['flex'].vars = ['FLEXFLAGS', 'FLEX']
52 ccroot.USELIB_VARS['c'].add('FLEXFLAGS')
53 ccroot.USELIB_VARS['cxx'].add('FLEXFLAGS')
54
55 def configure(conf):
56         """
57         Detect the *flex* program
58         """
59         conf.find_program('flex', var='FLEX')
60         conf.env.FLEXFLAGS = ['-t']
61
62         if re.search (r"\\msys\\[0-9.]+\\bin\\flex.exe$", conf.env.FLEX[0]):
63                 # this is the flex shipped with MSYS
64                 conf.env.FLEX_MSYS = True