| OLD | NEW |
| (Empty) |
| 1 # Copyright 2009, Google Inc. | |
| 2 # All rights reserved. | |
| 3 # | |
| 4 # Redistribution and use in source and binary forms, with or without | |
| 5 # modification, are permitted provided that the following conditions are | |
| 6 # met: | |
| 7 # | |
| 8 # * Redistributions of source code must retain the above copyright | |
| 9 # notice, this list of conditions and the following disclaimer. | |
| 10 # * Redistributions in binary form must reproduce the above | |
| 11 # copyright notice, this list of conditions and the following disclaimer | |
| 12 # in the documentation and/or other materials provided with the | |
| 13 # distribution. | |
| 14 # * Neither the name of Google Inc. nor the names of its | |
| 15 # contributors may be used to endorse or promote products derived from | |
| 16 # this software without specific prior written permission. | |
| 17 # | |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | |
| 30 | |
| 31 import os.path | |
| 32 | |
| 33 Import('env') | |
| 34 | |
| 35 env.Append( | |
| 36 CPPPATH = [ | |
| 37 # Include path for generated headers. | |
| 38 env.Dir('$OBJ_ROOT/compiler/technique'), | |
| 39 # Include path for Antlr C runtime headers. | |
| 40 env.Dir('$ANTLRLIBC_DIR/include'), | |
| 41 ], | |
| 42 LIBPATH = [ | |
| 43 env.Dir('$ANTLRLIBC_DIR/lib'), | |
| 44 ], | |
| 45 LIBS = [ | |
| 46 'antlr3c', | |
| 47 ], | |
| 48 ) | |
| 49 | |
| 50 # Define a builder for Antlr grammars. | |
| 51 def TechniqueEmitter(target, source, env): | |
| 52 # TODO this path operation is horrible, please make '.base' work | |
| 53 base_name = os.path.splitext(source[0].abspath)[0] | |
| 54 generated_targets = [env.File(base_name + 'Lexer.c'), | |
| 55 env.File(base_name + 'Lexer.h'), | |
| 56 env.File(base_name + 'Parser.c'), | |
| 57 env.File(base_name + 'Parser.h'), ] | |
| 58 return generated_targets, source | |
| 59 | |
| 60 if env.Bit('windows'): | |
| 61 env.Append( | |
| 62 CCFLAGS=['/Wp64', '/TP'], | |
| 63 ) | |
| 64 else: | |
| 65 env.Append( | |
| 66 CCFLAGS = ['-x', 'c++'], | |
| 67 ) | |
| 68 | |
| 69 # To enable ANTLRworks debugging, replace | |
| 70 # org.antlr.Tool $SOURCE | |
| 71 # below, with | |
| 72 # org.antlr.Tool -debug $SOURCE | |
| 73 | |
| 74 env['BUILDERS']['Antlr'] = Builder( | |
| 75 action = ' '.join([ | |
| 76 '$JAVA_EXE', | |
| 77 '-cp $ANTLR_DIR/antlr-3.1.1.jar', | |
| 78 'org.antlr.Tool $SOURCE', | |
| 79 '-fo $TARGET.dir']), | |
| 80 emitter = TechniqueEmitter) | |
| 81 | |
| 82 # Generate the parser and lexer files | |
| 83 antlr_output_files = env.Antlr( env.File('Technique.g3pl') ) | |
| 84 # filter out only the C files from the generated files. | |
| 85 antlr_c_files = [f for f in antlr_output_files if f.suffix == '.c'] | |
| 86 | |
| 87 # Compile the resulting C and C++ files as C++ to build a library | |
| 88 inputs = [ | |
| 89 antlr_c_files, | |
| 90 'technique_error.cc', | |
| 91 'technique_parser.cc', | |
| 92 'technique_structures.cc', | |
| 93 ] | |
| 94 env.ComponentLibrary('technique', inputs) | |
| OLD | NEW |