diff options
Diffstat (limited to 'src/engine/SCons/Tool/lex.py')
-rw-r--r-- | src/engine/SCons/Tool/lex.py | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/engine/SCons/Tool/lex.py b/src/engine/SCons/Tool/lex.py index 3331f6c..31f21a9 100644 --- a/src/engine/SCons/Tool/lex.py +++ b/src/engine/SCons/Tool/lex.py @@ -33,23 +33,60 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import os.path + +import string + import SCons.Action import SCons.Tool import SCons.Util LexAction = SCons.Action.Action("$LEXCOM", "$LEXCOMSTR") +def lexEmitter(target, source, env): + sourceBase, sourceExt = os.path.splitext(SCons.Util.to_String(source[0])) + + if sourceExt == ".lm": # If using Objective-C + target = [sourceBase + ".m"] # the extension is ".m". + + # This emitter essentially tries to add to the target all extra + # files generated by flex. + + # Different options that are used to trigger the creation of extra files. + fileGenOptions = ["--header-file=", "--tables-file="] + + for option in SCons.Util.CLVar(env.subst("$LEXFLAGS")): + for fileGenOption in fileGenOptions: + l = len(fileGenOption) + if option[:l] == fileGenOption: + # A file generating option is present, so add the + # file name to the target list. + fileName = string.strip(option[l:]) + target.append(fileName) + return (target, source) + def generate(env): """Add Builders and construction variables for lex to an Environment.""" c_file, cxx_file = SCons.Tool.createCFileBuilders(env) - c_file.add_action('.l', LexAction) - c_file.add_action('.lex', LexAction) - cxx_file.add_action('.ll', LexAction) + # C + c_file.add_action(".l", LexAction) + c_file.add_emitter(".l", lexEmitter) + + c_file.add_action(".lex", LexAction) + c_file.add_emitter(".lex", lexEmitter) + + # Objective-C + cxx_file.add_action(".lm", LexAction) + cxx_file.add_emitter(".lm", lexEmitter) + + # C++ + cxx_file.add_action(".ll", LexAction) + cxx_file.add_emitter(".ll", lexEmitter) + + env["LEX"] = env.Detect("flex") or "lex" + env["LEXFLAGS"] = SCons.Util.CLVar("") + env["LEXCOM"] = "$LEX $LEXFLAGS -t $SOURCES > $TARGET" - env['LEX'] = env.Detect('flex') or 'lex' - env['LEXFLAGS'] = SCons.Util.CLVar('') - env['LEXCOM'] = '$LEX $LEXFLAGS -t $SOURCES > $TARGET' - def exists(env): - return env.Detect(['flex', 'lex']) + return env.Detect(["flex", "lex"]) |