.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
.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.
.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 .
.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.
- 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
'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:
},
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',
},
prefix = '$OBJPREFIX',
suffix = '$OBJSUFFIX',
- src_builder = CFile)
+ src_builder = [CFile, CXXFile])
Program = SCons.Builder.Builder(name = 'Program',
action = '$LINKCOM',
'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',
'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',
'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',
'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',
--- /dev/null
+#!/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()