utility is available, which is much faster than fork()/exec(),
and fixes the -j option on several platforms.
+ From sam th:
+
+ - Dynamically check for the existence of utilities with which to
+ initialize Environments by default.
+
RELEASE 0.08 - Mon, 15 Jul 2002 12:08:51 -0500
"""Select a default tool list for the specified platform.
"""
module = platform_module(name)
- return module.tool_list()
+ return SCons.Tool.tool_list()
class PlatformSpec:
def __init__(self, name):
class ToolTestCase(unittest.TestCase):
def test_Tool(self):
"""Test the Tool() function"""
+ # FIXME - this might fail, since there might be no C++ compiler on the system.
+ # How do we handle this?
t = SCons.Tool.Tool('g++')
env= { 'BUILDERS' : {}, 'ENV' : {} }
t(env, 'foo')
- assert env['CXX'] == 'c++', env['CXX']
+ assert (env['CXX'] == 'c++' or env['CXX'] == 'g++'), env['CXX']
assert env['CXXFLAGS'] == '$CCFLAGS', env['CXXFLAGS']
assert env['INCPREFIX'] == '-I', env['INCPREFIX']
file.close()
spec = ToolSpec(name)
spec.__call__ = sys.modules[full_name].generate
+ spec.exists = sys.modules[full_name].exists
return spec
def createObjBuilders(env):
env['BUILDERS']['CXXFile'] = cxx_file
return (c_file, cxx_file)
+
+linkers = ['gnulink', 'mslink', 'ilink']
+c_compilers = ['gcc', 'msvc', 'icc']
+cxx_compilers = ['g++'] # only those that are seperate from the c compiler
+fortran_compilers = ['g77']
+assemblers = ['gas', 'nasm', 'masm']
+other_tools = ['ar', 'dvipdf', 'dvips',
+ 'latex', 'lex', 'lib',
+ 'pdflatex', 'pdftex',
+ 'tar', 'tex', 'yacc']
+
+def FindTool(tools):
+ for tool in tools:
+ t = Tool(tool)
+ if t.exists():
+ return tool
+ return None
+
+def _ToolExists(tool):
+ return Tool(tool).exists()
+
+def FindAllTools(tools):
+ return filter (_ToolExists, tools)
+
+def tool_list():
+ return [FindTool(linkers),
+ FindTool(c_compilers),
+ FindTool(cxx_compilers),
+ FindTool(fortran_compilers),
+ FindTool(assemblers)
+ ] + FindAllTools(other_tools)
env['SHLINKFLAGS'] = '$LINKFLAGS -shared'
env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
-
+def exists():
+ return SCons.Util.WhereIs('ar')
env['DVIPDF'] = 'dvipdf'
env['DVIPDFFLAGS'] = ''
env['PDFCOM'] = '$DVIPDF $DVIPDFFLAGS $SOURCES $TARGET'
+
+def exists():
+ return SCons.Util.WhereIs('dvipdf')
env['DVIPS'] = 'dvips'
env['DVIPSFLAGS'] = ''
env['PSCOM'] = '$DVIPS $DVIPSFLAGS -o $TARGET $SOURCES'
+
+def exists():
+ return SCons.Util.WhereIs('dvips')
import SCons.Defaults
import SCons.Tool
+import SCons.Util
+
+compilers = ['c++', 'g++']
+
+for i in compilers:
+ if SCons.Util.WhereIs(i):
+ cxx = i
+ break
+ cxx = None
CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
if os.path.normcase('.c') != os.path.normcase('.C'):
static_obj.add_action(suffix, SCons.Defaults.CXXAction)
shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
- env['CXX'] = 'c++'
+ env['CXX'] = cxx
env['CXXFLAGS'] = '$CCFLAGS'
env['CXXCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
env['SHCXX'] = '$CXX'
env['INCSUFFIX'] = ''
env['CXXFILESUFFIX'] = '.cc'
+
+def exists():
+ return cxx
import SCons.Defaults
import SCons.Tool
+import SCons.Util
+
+compilers = ['g77', 'f77']
+for i in compilers:
+ if SCons.Util.WhereIs(i):
+ compiler = i
+ break
+ compiler = None
+
F77Suffixes = ['.f', '.for', '.FOR']
F77PPSuffixes = ['.fpp', '.FPP']
env['SHF77FLAGS'] = '$F77FLAGS -fPIC'
env['SHF77COM'] = '$SHF77 $SHF77FLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES'
env['SHF77PPCOM'] = '$SHF77 $SHF77FLAGS $CPPFLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES'
+
+def exists():
+ return compiler
import SCons.Defaults
import SCons.Tool
+import SCons.Util
+
+assemblers = ['as', 'gas']
+
+for i in assemblers:
+ if SCons.Util.WhereIs(i):
+ as = i
+ break
+ as = None
+
ASSuffixes = ['.s', '.asm', '.ASM']
ASPPSuffixes = ['.spp', '.SPP']
for suffix in ASPPSuffixes:
static_obj.add_action(suffix, SCons.Defaults.ASPPAction)
- env['AS'] = 'as'
+ env['AS'] = as
env['ASFLAGS'] = ''
env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES'
env['ASPPCOM'] = '$CC $ASFLAGS $CPPFLAGS -o $TARGET $SOURCES'
+
+def exists():
+ return as
import SCons.Tool
import SCons.Defaults
+import SCons.Util
+
+compilers = ['cc', 'gcc']
+
+for i in compilers:
+ if SCons.Util.WhereIs(i):
+ cc = i
+ break
+ cc = None
+
CSuffixes = ['.c']
if os.path.normcase('.c') == os.path.normcase('.C'):
static_obj.add_action(suffix, SCons.Defaults.CAction)
shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
- env['CC'] = 'gcc'
+ env['CC'] = cc
env['CCFLAGS'] = ''
env['CCCOM'] = '$CC $CCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
env['SHCC'] = '$CC'
env['INCSUFFIX'] = ''
env['CFILESUFFIX'] = '.c'
+
+def exists():
+ return cc
import SCons.Defaults
import SCons.Util
+linkers = ['c++', 'cc', 'g++', 'gcc']
+
+for i in linkers:
+ if SCons.Util.WhereIs(i):
+ linker = i
+ break
+ linker = None
+
def generate(env, platform):
- """Add Builders and construction variables for ar to an Environment."""
+ """Add Builders and construction variables for gnulink to an Environment."""
env['BUILDERS']['SharedLibrary'] = SCons.Defaults.SharedLibrary
env['BUILDERS']['Program'] = SCons.Defaults.Program
env['SHLINKFLAGS'] = '$LINKFLAGS -shared'
env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
env['SHLIBEMITTER']= None
- env['LINK'] = 'c++'
+ env['LINK'] = linker
env['LINKFLAGS'] = ''
env['LINKCOM'] = '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
env['LIBDIRPREFIX']='-L'
env['LIBDIRSUFFIX']=''
env['LIBLINKPREFIX']='-l'
env['LIBLINKSUFFIX']=''
+
+def exists():
+ return linker
env['CFILESUFFIX'] = '.c'
env['CXXFILESUFFIX'] = '.cc'
+def exists():
+ return SCons.Util.WhereIs('icc')
env['LIBDIRSUFFIX']=''
env['LIBLINKPREFIX']=''
env['LIBLINKSUFFIX']='$LIBSUFFIX'
+
+def exists():
+ return SCons.Util.WhereIs('ilink')
env['LATEX'] = 'latex'
env['LATEXFLAGS'] = ''
env['LATEXCOM'] = '$LATEX $LATEXFLAGS $SOURCES'
+
+def exists():
+ return SCons.Util.WhereIs('latex')
env['LEX'] = 'lex'
env['LEXFLAGS'] = ''
env['LEXCOM'] = '$LEX $LEXFLAGS -t $SOURCES > $TARGET'
+
+def exists():
+ return SCons.Util.WhereIs('lex')
env['AR'] = 'lib'
env['ARFLAGS'] = '/nologo'
env['ARCOM'] = '$AR $ARFLAGS /OUT:$TARGET $SOURCES'
-
+
+def exists():
+ return SCons.Util.WhereIs('lib')
env['ASFLAGS'] = '/nologo'
env['ASCOM'] = '$AS $ASFLAGS /c /Fo$TARGET $SOURCES'
env['ASPPCOM'] = '$CC $ASFLAGS $CPPFLAGS /c /Fo$TARGET $SOURCES'
+
+def exists():
+ return SCons.Util.WhereIs('ml')
import SCons.Defaults
import SCons.Errors
import SCons.Action
+import SCons.Util
from SCons.Tool.msvc import get_msdev_paths
include_path, lib_path, exe_path = get_msdev_paths()
env['ENV']['LIB'] = lib_path
env['ENV']['PATH'] = exe_path
+
+def exists():
+ return SCons.Util.WhereIs('link')
env['CFILESUFFIX'] = '.c'
env['CXXFILESUFFIX'] = '.cc'
+def exists():
+ return SCons.Util.WhereIs('cl')
env['ASFLAGS'] = ''
env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES'
env['ASPPCOM'] = '$CC $ASFLAGS $CPPFLAGS -c -o $TARGET $SOURCES'
+
+def exists():
+ return SCons.Util.WhereIs('nasm')
env['PDFLATEX'] = 'pdflatex'
env['PDFLATEXFLAGS'] = ''
env['PDFLATEXCOM'] = '$PDFLATEX $PDFLATEXFLAGS $SOURCES $TARGET'
+
+def exists():
+ return SCons.Util.WhereIs('pdflatex')
env['PDFTEX'] = 'pdftex'
env['PDFTEXFLAGS'] = ''
env['PDFTEXCOM'] = '$PDFTEX $PDFTEXFLAGS $SOURCES $TARGET'
+
+def exists():
+ return SCons.Util.WhereIs('pdftex')
import SCons.Builder
import SCons.Node.FS
+import SCons.Util
+
+tars = ['gtar', 'tar']
+
+for i in tars:
+ if SCons.Util.WhereIs(i):
+ tar = i
+ break
+ tar = None
TarBuilder = SCons.Builder.Builder(action = '$TARCOM',
source_factory = SCons.Node.FS.default_fs.Entry,
suffix = '$TARSUFFIX',
multi = 1)
+
def generate(env, platform):
"""Add Builders and construction variables for tar to an Environment."""
try:
bld = TarBuilder
env['BUILDERS']['Tar'] = bld
- env['TAR'] = 'tar'
+ env['TAR'] = tar
env['TARFLAGS'] = '-c'
env['TARCOM'] = '$TAR $TARFLAGS -f $TARGET $SOURCES'
env['TARSUFFIX'] = '.tar'
+
+def exists():
+ return tar
env['TEX'] = 'tex'
env['TEXFLAGS'] = ''
env['TEXCOM'] = '$TEX $TEXFLAGS $SOURCES'
+
+def exists():
+ return SCons.Util.WhereIs('tex')
env['YACC'] = 'yacc'
env['YACCFLAGS'] = ''
env['YACCCOM'] = '$YACC $YACCFLAGS -o $TARGET $SOURCES'
+
+def exists():
+ return SCons.Util.WhereIs('yacc')