summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-03-07 19:31:55 (GMT)
committerSteven Knight <knight@baldmt.com>2002-03-07 19:31:55 (GMT)
commite23ae74447571c667d57d40a61d679732fe9ce83 (patch)
treeb2948193cfb5a17ba558ebb123bd7a4616931e7a
parentc233ea9e5d7f7a9f8ee369877ef1301b2702fbee (diff)
downloadSCons-e23ae74447571c667d57d40a61d679732fe9ce83.zip
SCons-e23ae74447571c667d57d40a61d679732fe9ce83.tar.gz
SCons-e23ae74447571c667d57d40a61d679732fe9ce83.tar.bz2
Add a CXXFile builder to turn .ll and .yy files into .cc.
-rw-r--r--doc/man/scons.129
-rw-r--r--src/CHANGES.txt3
-rw-r--r--src/engine/SCons/Builder.py6
-rw-r--r--src/engine/SCons/Defaults.py14
-rw-r--r--test/CXXFILESUFFIX.py83
5 files changed, 126 insertions, 9 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index 302b2eb..b1e7b66 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -602,14 +602,27 @@ env.Library(target = 'bar', source = 'bar.c foo.o')
.IP CFile
Builds a C source file given a lex (.l) or yacc (.y) input file.
-The hard-coded suffix .c is
-automatically added to the target
+The suffix specified by the $CFILESUFFIX construction variable
+(.c by default)
+is automatically added to the target
if it is not already present. Example:
.ES
env.CFile(target = 'foo.c', source = 'foo.l') # builds foo.c
env.CFile(target = 'bar', source = 'bar.y') # builds bar.c
.EE
+
+.IP CXXFile
+Builds a C++ source file given a lex (.ll) or yacc (.yy) input file.
+The suffix specified by the $CXXFILESUFFIX construction variable
+(.cc by default)
+is automatically added to the target
+if it is not already present. Example:
+
+.ES
+env.CXXFile(target = 'foo.cc', source = 'foo.ll') # builds foo.cc
+env.CXXFile(target = 'bar', source = 'bar.yy') # builds bar.cc
+.EE
.LP
C/C++ source files are automatically scanned for dependencies by
.B scons
@@ -743,7 +756,7 @@ The command line used to generate a static library from object files.
.IP BUILDERS
A list of the available builders.
-[CFile, Object, Program, Library] by default.
+[CFile, CXXFile, Object, Program, Library] by default.
.IP CC
The C compiler.
@@ -757,8 +770,7 @@ The command line used to compile a C source file to an object file.
.IP CFILESUFFIX
The suffix for C source files.
This is used by the internal CFile builder
-when generating destination files from Lex (.l) or YACC (.y)
-input files.
+when generating C files from Lex (.l) or YACC (.y) input files.
The default suffix, of course, is
.IR .c .
@@ -790,6 +802,13 @@ env = Environment(CPPPATH=include)
.IP CXX
The C++ compiler.
+.IP CXXFILESUFFIX
+The suffix for C++ source files.
+This is used by the internal CXXFile builder
+when generating C++ files from Lex (.ll) or YACC (.yy) input files.
+The default suffix is
+.IR .cc .
+
.IP CXXFLAGS
General options that are passed to the C++ compiler.
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 8b4269c..2acc69c 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -26,6 +26,9 @@ RELEASE 0.06 -
- Add a configurable CFILESUFFIX for the Builder of .l and .y files
into C files.
+ - Add a CXXFile Builder that turns .ll and .yy files into .cc files
+ (configurable via a CXXFILESUFFIX construction variable).
+
RELEASE 0.05 - Thu, 21 Feb 2002 16:50:03 -0600
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py
index 2c87b6a..efef969 100644
--- a/src/engine/SCons/Builder.py
+++ b/src/engine/SCons/Builder.py
@@ -326,7 +326,11 @@ class CompositeBuilder(BuilderBase):
'src_suffix' : last_suffix,
}
if self.sbuild[r]:
- kw['src_builder'] = self.sbuild[r][0]
+ sb = filter(lambda x, e=env, s=last_suffix:
+ e.subst(x.suffix) == s,
+ self.sbuild[r])
+ if sb:
+ kw['src_builder'] = sb[0]
# XXX We should be able to cache this
bld = apply(Builder, (), kw)
for tnode in tlist:
diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py
index baad55a..b0fa846 100644
--- a/src/engine/SCons/Defaults.py
+++ b/src/engine/SCons/Defaults.py
@@ -70,6 +70,12 @@ CFile = SCons.Builder.Builder(name = 'CFile',
},
suffix = '$CFILESUFFIX')
+CXXFile = SCons.Builder.Builder(name = 'CXXFile',
+ action = { '.ll' : '$LEXCOM',
+ '.yy' : '$YACCCOM',
+ },
+ suffix = '$CXXFILESUFFIX')
+
CPlusPlusAction = SCons.Action.Action('$CXXCOM')
Object = SCons.Builder.Builder(name = 'Object',
@@ -83,7 +89,7 @@ Object = SCons.Builder.Builder(name = 'Object',
},
prefix = '$OBJPREFIX',
suffix = '$OBJSUFFIX',
- src_builder = CFile)
+ src_builder = [CFile, CXXFile])
Program = SCons.Builder.Builder(name = 'Program',
action = '$LINKCOM',
@@ -209,6 +215,7 @@ def make_win32_env_from_paths(include, lib, path):
'CXX' : '$CC',
'CXXFLAGS' : '$CCFLAGS',
'CXXCOM' : '$CXX $CXXFLAGS $_INCFLAGS /c $SOURCES /Fo$TARGET',
+ 'CXXFILESUFFIX' : '.cc',
'LINK' : 'link',
'LINKFLAGS' : '/nologo',
'LINKCOM' : '$LINK $LINKFLAGS /OUT:$TARGET $_LIBDIRFLAGS $_LIBFLAGS $SOURCES',
@@ -221,7 +228,7 @@ def make_win32_env_from_paths(include, lib, path):
'YACC' : 'yacc',
'YACCFLAGS' : '',
'YACCCOM' : '$YACC $YACCFLAGS -o $TARGET $SOURCES',
- 'BUILDERS' : [CFile, Object, Program, Library],
+ 'BUILDERS' : [CFile, CXXFile, Object, Program, Library],
'SCANNERS' : [CScan],
'OBJPREFIX' : '',
'OBJSUFFIX' : '.obj',
@@ -269,6 +276,7 @@ if os.name == 'posix':
'CXX' : 'c++',
'CXXFLAGS' : '$CCFLAGS',
'CXXCOM' : '$CXX $CXXFLAGS $_INCFLAGS -c -o $TARGET $SOURCES',
+ 'CXXFILESUFFIX' : '.cc',
'LINK' : '$CXX',
'LINKFLAGS' : '',
'LINKCOM' : '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS',
@@ -283,7 +291,7 @@ if os.name == 'posix':
'YACC' : 'yacc',
'YACCFLAGS' : '',
'YACCCOM' : '$YACC $YACCFLAGS -o $TARGET $SOURCES',
- 'BUILDERS' : [CFile, Object, Program, Library],
+ 'BUILDERS' : [CFile, CXXFile, Object, Program, Library],
'SCANNERS' : [CScan],
'OBJPREFIX' : '',
'OBJSUFFIX' : '.o',
diff --git a/test/CXXFILESUFFIX.py b/test/CXXFILESUFFIX.py
new file mode 100644
index 0000000..3dde9af
--- /dev/null
+++ b/test/CXXFILESUFFIX.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2001, 2002 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import os
+import os.path
+import string
+import sys
+import TestSCons
+
+python = sys.executable
+
+if sys.platform == 'win32':
+ _exe = '.exe'
+else:
+ _exe = ''
+
+lex = None
+for dir in string.split(os.environ['PATH'], os.pathsep):
+ l = os.path.join(dir, 'lex' + _exe)
+ if os.path.exists(l):
+ lex = l
+ break
+
+test = TestSCons.TestSCons()
+
+test.no_result(not lex)
+
+test.write('SConstruct', """
+Environment().CXXFile(target = 'foo', source = 'foo.ll')
+Environment(CXXFILESUFFIX = '.xyz').CXXFile(target = 'bar', source = 'bar.ll')
+""")
+
+lex = r"""
+%%%%
+a printf("A%sA");
+b printf("B%sB");
+%%%%
+int
+yywrap()
+{
+ return 1;
+}
+
+main()
+{
+ yylex();
+}
+"""
+
+test.write('foo.ll', lex % ('foo.ll', 'foo.ll'))
+
+test.write('bar.ll', lex % ('bar.ll', 'bar.ll'))
+
+test.run(arguments = '.')
+
+test.fail_test(not os.path.exists(test.workpath('foo.cc')))
+
+test.fail_test(not os.path.exists(test.workpath('bar.xyz')))
+
+test.pass_test()