[PATCH v2 04/15] waf: Allow to only generate lex and yacc.

Christian Mauderer christian.mauderer at embedded-brains.de
Thu Aug 2 08:55:36 UTC 2018


In some applications, it's usefull if the files generated by lex or yacc
are not build automatically. With that it is for example possible to
create a wrapper source file that sets some defines before the generated
code is parsed.
---
 builder.py    | 12 ++++++++----
 waf_libbsd.py | 26 ++++++++++++++------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/builder.py b/builder.py
index b0d6374e..78f592c7 100755
--- a/builder.py
+++ b/builder.py
@@ -547,15 +547,17 @@ class RouteKeywordsFragmentComposer(BuildSystemFragmentComposer):
 
 class LexFragmentComposer(BuildSystemFragmentComposer):
 
-    def __init__(self, sym, dep, cflags = None, includes = None):
+    def __init__(self, sym, dep, cflags = None, includes = None, build = True):
         self.sym = sym
         self.dep = dep
         self.cflags, self.includes = _cflagsIncludes(cflags, includes)
+        self.build = build
 
     def compose(self, path):
         d = { 'file': path,
               'sym': self.sym,
-              'dep': self.dep }
+              'dep': self.dep,
+              'build': self.build }
         if None not in self.cflags:
             d['cflags'] = self.cflags
         if None not in self.includes:
@@ -564,15 +566,17 @@ class LexFragmentComposer(BuildSystemFragmentComposer):
 
 class YaccFragmentComposer(BuildSystemFragmentComposer):
 
-    def __init__(self, sym, header, cflags = None, includes = None):
+    def __init__(self, sym, header, cflags = None, includes = None, build = True):
         self.sym = sym
         self.header = header
         self.cflags, self.includes = _cflagsIncludes(cflags, includes)
+        self.build = build
 
     def compose(self, path):
         d = { 'file': path,
               'sym': self.sym,
-              'header': self.header }
+              'header': self.header,
+              'build': self.build }
         if None not in self.cflags:
             d['cflags'] = self.cflags
         if None not in self.includes:
diff --git a/waf_libbsd.py b/waf_libbsd.py
index bbc8b42c..597e882e 100644
--- a/waf_libbsd.py
+++ b/waf_libbsd.py
@@ -361,12 +361,13 @@ class Builder(builder.ModuleManager):
                     bld(target = lex['file'][:-2]+ '.c',
                         source = lex['file'],
                         rule = lex_rule)
-                bld.objects(target = 'lex_%s' % (lex['sym']),
-                            features = 'c',
-                            cflags = cflags,
-                            includes = lexIncludes + includes,
-                            defines = defines + lexDefines,
-                            source = lex['file'][:-2] + '.c')
+                if lex['build']:
+                    bld.objects(target = 'lex_%s' % (lex['sym']),
+                                features = 'c',
+                                cflags = cflags,
+                                includes = lexIncludes + includes,
+                                defines = defines + lexDefines,
+                                source = lex['file'][:-2] + '.c')
                 libbsd_use += ['lex_%s' % (lex['sym'])]
 
         #
@@ -398,12 +399,13 @@ class Builder(builder.ModuleManager):
                     bld(target = yaccFile[:-2] + '.c',
                         source = yaccFile,
                         rule = yacc_rule)
-                bld.objects(target = 'yacc_%s' % (yaccSym),
-                            features = 'c',
-                            cflags = cflags,
-                            includes = yaccIncludes + includes,
-                            defines = defines + yaccDefines,
-                            source = yaccFile[:-2] + '.c')
+                if yacc['build']:
+                    bld.objects(target = 'yacc_%s' % (yaccSym),
+                                features = 'c',
+                                cflags = cflags,
+                                includes = yaccIncludes + includes,
+                                defines = defines + yaccDefines,
+                                source = yaccFile[:-2] + '.c')
                 libbsd_use += ['yacc_%s' % (yaccSym)]
 
         #
-- 
2.13.7




More information about the devel mailing list