From: stevenknight Date: Thu, 29 Aug 2002 03:22:52 +0000 (+0000) Subject: Dynamically check for the existence of utilities. (sam th) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=81284e15a527ace92021e1026ad95d1aa25b844b;p=scons.git Dynamically check for the existence of utilities. (sam th) git-svn-id: http://scons.tigris.org/svn/scons/trunk@451 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 74b56213..32479f9f 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -46,6 +46,11 @@ RELEASE 0.09 - 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 diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py index d8fefbd2..2b35a2ea 100644 --- a/src/engine/SCons/Platform/__init__.py +++ b/src/engine/SCons/Platform/__init__.py @@ -89,7 +89,7 @@ def DefaultToolList(name = platform_default()): """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): diff --git a/src/engine/SCons/Tool/ToolTests.py b/src/engine/SCons/Tool/ToolTests.py index a7e03e87..cfd84b32 100644 --- a/src/engine/SCons/Tool/ToolTests.py +++ b/src/engine/SCons/Tool/ToolTests.py @@ -32,10 +32,12 @@ import SCons.Tool 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'] diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 08ab5c2a..d791526f 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -67,6 +67,7 @@ def Tool(name, platform = None): file.close() spec = ToolSpec(name) spec.__call__ = sys.modules[full_name].generate + spec.exists = sys.modules[full_name].exists return spec def createObjBuilders(env): @@ -123,3 +124,34 @@ def createCFileBuilders(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) diff --git a/src/engine/SCons/Tool/ar.py b/src/engine/SCons/Tool/ar.py index ab870b63..da664135 100644 --- a/src/engine/SCons/Tool/ar.py +++ b/src/engine/SCons/Tool/ar.py @@ -56,4 +56,5 @@ def generate(env, platform): env['SHLINKFLAGS'] = '$LINKFLAGS -shared' env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS' - +def exists(): + return SCons.Util.WhereIs('ar') diff --git a/src/engine/SCons/Tool/dvipdf.py b/src/engine/SCons/Tool/dvipdf.py index 230ce92c..6de52f1c 100644 --- a/src/engine/SCons/Tool/dvipdf.py +++ b/src/engine/SCons/Tool/dvipdf.py @@ -47,3 +47,6 @@ def generate(env, platform): env['DVIPDF'] = 'dvipdf' env['DVIPDFFLAGS'] = '' env['PDFCOM'] = '$DVIPDF $DVIPDFFLAGS $SOURCES $TARGET' + +def exists(): + return SCons.Util.WhereIs('dvipdf') diff --git a/src/engine/SCons/Tool/dvips.py b/src/engine/SCons/Tool/dvips.py index 098cba73..7da853dd 100644 --- a/src/engine/SCons/Tool/dvips.py +++ b/src/engine/SCons/Tool/dvips.py @@ -49,3 +49,6 @@ def generate(env, platform): env['DVIPS'] = 'dvips' env['DVIPSFLAGS'] = '' env['PSCOM'] = '$DVIPS $DVIPSFLAGS -o $TARGET $SOURCES' + +def exists(): + return SCons.Util.WhereIs('dvips') diff --git a/src/engine/SCons/Tool/g++.py b/src/engine/SCons/Tool/g++.py index f631b0b0..3c6dd365 100644 --- a/src/engine/SCons/Tool/g++.py +++ b/src/engine/SCons/Tool/g++.py @@ -37,6 +37,15 @@ import os.path 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'): @@ -50,7 +59,7 @@ def generate(env, platform): 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' @@ -60,3 +69,6 @@ def generate(env, platform): env['INCSUFFIX'] = '' env['CXXFILESUFFIX'] = '.cc' + +def exists(): + return cxx diff --git a/src/engine/SCons/Tool/g77.py b/src/engine/SCons/Tool/g77.py index dbafcf27..1066c0f5 100644 --- a/src/engine/SCons/Tool/g77.py +++ b/src/engine/SCons/Tool/g77.py @@ -37,6 +37,15 @@ import os.path 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'] @@ -65,3 +74,6 @@ def generate(env, platform): 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 diff --git a/src/engine/SCons/Tool/gas.py b/src/engine/SCons/Tool/gas.py index 6fc3d8c0..36672a1a 100644 --- a/src/engine/SCons/Tool/gas.py +++ b/src/engine/SCons/Tool/gas.py @@ -37,6 +37,16 @@ import os.path 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'] @@ -55,7 +65,10 @@ def generate(env, platform): 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 diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py index d767b218..8eae17f7 100644 --- a/src/engine/SCons/Tool/gcc.py +++ b/src/engine/SCons/Tool/gcc.py @@ -37,6 +37,16 @@ import os.path 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'): @@ -50,7 +60,7 @@ def generate(env, platform): 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' @@ -61,3 +71,6 @@ def generate(env, platform): env['INCSUFFIX'] = '' env['CFILESUFFIX'] = '.c' + +def exists(): + return cc diff --git a/src/engine/SCons/Tool/gnulink.py b/src/engine/SCons/Tool/gnulink.py index 630d95af..3fc78b10 100644 --- a/src/engine/SCons/Tool/gnulink.py +++ b/src/engine/SCons/Tool/gnulink.py @@ -36,8 +36,16 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" 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 @@ -45,10 +53,13 @@ def generate(env, platform): 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 diff --git a/src/engine/SCons/Tool/icc.py b/src/engine/SCons/Tool/icc.py index 2d8afc91..df1eb00c 100644 --- a/src/engine/SCons/Tool/icc.py +++ b/src/engine/SCons/Tool/icc.py @@ -67,3 +67,5 @@ def generate(env, platform): env['CFILESUFFIX'] = '.c' env['CXXFILESUFFIX'] = '.cc' +def exists(): + return SCons.Util.WhereIs('icc') diff --git a/src/engine/SCons/Tool/ilink.py b/src/engine/SCons/Tool/ilink.py index 460a4685..323f808e 100644 --- a/src/engine/SCons/Tool/ilink.py +++ b/src/engine/SCons/Tool/ilink.py @@ -46,3 +46,6 @@ def generate(env, platform): env['LIBDIRSUFFIX']='' env['LIBLINKPREFIX']='' env['LIBLINKSUFFIX']='$LIBSUFFIX' + +def exists(): + return SCons.Util.WhereIs('ilink') diff --git a/src/engine/SCons/Tool/latex.py b/src/engine/SCons/Tool/latex.py index cb53ccf4..65235803 100644 --- a/src/engine/SCons/Tool/latex.py +++ b/src/engine/SCons/Tool/latex.py @@ -53,3 +53,6 @@ def generate(env, platform): env['LATEX'] = 'latex' env['LATEXFLAGS'] = '' env['LATEXCOM'] = '$LATEX $LATEXFLAGS $SOURCES' + +def exists(): + return SCons.Util.WhereIs('latex') diff --git a/src/engine/SCons/Tool/lex.py b/src/engine/SCons/Tool/lex.py index c8851e29..0dda1288 100644 --- a/src/engine/SCons/Tool/lex.py +++ b/src/engine/SCons/Tool/lex.py @@ -46,3 +46,6 @@ def generate(env, platform): env['LEX'] = 'lex' env['LEXFLAGS'] = '' env['LEXCOM'] = '$LEX $LEXFLAGS -t $SOURCES > $TARGET' + +def exists(): + return SCons.Util.WhereIs('lex') diff --git a/src/engine/SCons/Tool/lib.py b/src/engine/SCons/Tool/lib.py index 9683abf7..477bf9ee 100644 --- a/src/engine/SCons/Tool/lib.py +++ b/src/engine/SCons/Tool/lib.py @@ -43,4 +43,6 @@ def generate(env, platform): env['AR'] = 'lib' env['ARFLAGS'] = '/nologo' env['ARCOM'] = '$AR $ARFLAGS /OUT:$TARGET $SOURCES' - + +def exists(): + return SCons.Util.WhereIs('lib') diff --git a/src/engine/SCons/Tool/masm.py b/src/engine/SCons/Tool/masm.py index e88266da..9d95913f 100644 --- a/src/engine/SCons/Tool/masm.py +++ b/src/engine/SCons/Tool/masm.py @@ -59,3 +59,6 @@ def generate(env, platform): 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') diff --git a/src/engine/SCons/Tool/mslink.py b/src/engine/SCons/Tool/mslink.py index 5b458c05..1bc9ce3e 100644 --- a/src/engine/SCons/Tool/mslink.py +++ b/src/engine/SCons/Tool/mslink.py @@ -39,6 +39,7 @@ import string import SCons.Defaults import SCons.Errors import SCons.Action +import SCons.Util from SCons.Tool.msvc import get_msdev_paths @@ -150,3 +151,6 @@ def generate(env, platform): 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') diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index 54796e3c..33da2ece 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -221,3 +221,5 @@ def generate(env, platform): env['CFILESUFFIX'] = '.c' env['CXXFILESUFFIX'] = '.cc' +def exists(): + return SCons.Util.WhereIs('cl') diff --git a/src/engine/SCons/Tool/nasm.py b/src/engine/SCons/Tool/nasm.py index b757a53a..e341ddee 100644 --- a/src/engine/SCons/Tool/nasm.py +++ b/src/engine/SCons/Tool/nasm.py @@ -59,3 +59,6 @@ def generate(env, platform): 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') diff --git a/src/engine/SCons/Tool/pdflatex.py b/src/engine/SCons/Tool/pdflatex.py index 340622ce..1e9e733f 100644 --- a/src/engine/SCons/Tool/pdflatex.py +++ b/src/engine/SCons/Tool/pdflatex.py @@ -52,3 +52,6 @@ def generate(env, platform): env['PDFLATEX'] = 'pdflatex' env['PDFLATEXFLAGS'] = '' env['PDFLATEXCOM'] = '$PDFLATEX $PDFLATEXFLAGS $SOURCES $TARGET' + +def exists(): + return SCons.Util.WhereIs('pdflatex') diff --git a/src/engine/SCons/Tool/pdftex.py b/src/engine/SCons/Tool/pdftex.py index 1acc9cef..f7dc60c3 100644 --- a/src/engine/SCons/Tool/pdftex.py +++ b/src/engine/SCons/Tool/pdftex.py @@ -48,3 +48,6 @@ def generate(env, platform): env['PDFTEX'] = 'pdftex' env['PDFTEXFLAGS'] = '' env['PDFTEXCOM'] = '$PDFTEX $PDFTEXFLAGS $SOURCES $TARGET' + +def exists(): + return SCons.Util.WhereIs('pdftex') diff --git a/src/engine/SCons/Tool/tar.py b/src/engine/SCons/Tool/tar.py index fff9dff0..0acfd56a 100644 --- a/src/engine/SCons/Tool/tar.py +++ b/src/engine/SCons/Tool/tar.py @@ -35,12 +35,22 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" 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: @@ -49,7 +59,10 @@ def generate(env, platform): 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 diff --git a/src/engine/SCons/Tool/tex.py b/src/engine/SCons/Tool/tex.py index 10413aa6..9e0d9629 100644 --- a/src/engine/SCons/Tool/tex.py +++ b/src/engine/SCons/Tool/tex.py @@ -48,3 +48,6 @@ def generate(env, platform): env['TEX'] = 'tex' env['TEXFLAGS'] = '' env['TEXCOM'] = '$TEX $TEXFLAGS $SOURCES' + +def exists(): + return SCons.Util.WhereIs('tex') diff --git a/src/engine/SCons/Tool/yacc.py b/src/engine/SCons/Tool/yacc.py index 34abe771..bce4a39f 100644 --- a/src/engine/SCons/Tool/yacc.py +++ b/src/engine/SCons/Tool/yacc.py @@ -45,3 +45,6 @@ def generate(env, platform): env['YACC'] = 'yacc' env['YACCFLAGS'] = '' env['YACCCOM'] = '$YACC $YACCFLAGS -o $TARGET $SOURCES' + +def exists(): + return SCons.Util.WhereIs('yacc')