[Numpy-svn] r4381 - branches/numpy.scons/numpy/distutils/scons/tools

numpy-svn@scip... numpy-svn@scip...
Mon Nov 5 01:12:34 CST 2007


Author: cdavid
Date: 2007-11-05 01:12:26 -0600 (Mon, 05 Nov 2007)
New Revision: 4381

Added:
   branches/numpy.scons/numpy/distutils/scons/tools/f77.py
   branches/numpy.scons/numpy/distutils/scons/tools/f90.py
   branches/numpy.scons/numpy/distutils/scons/tools/f95.py
   branches/numpy.scons/numpy/distutils/scons/tools/fortran.py
   branches/numpy.scons/numpy/distutils/scons/tools/gfortran.py
Log:
Add fortran related toolchain in scons tools

Added: branches/numpy.scons/numpy/distutils/scons/tools/f77.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/f77.py	2007-11-03 16:09:06 UTC (rev 4380)
+++ branches/numpy.scons/numpy/distutils/scons/tools/f77.py	2007-11-05 07:12:26 UTC (rev 4381)
@@ -0,0 +1,135 @@
+"""engine.SCons.Tool.f77
+
+Tool-specific initialization for the generic Posix f77 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# __COPYRIGHT__
+#
+# 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 SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+import fortran
+
+compilers = ['f77']
+
+#
+F77Suffixes = ['.f77']
+F77PPSuffixes = []
+if SCons.Util.case_sensitive_suffixes('.f77', '.F77'):
+    F77PPSuffixes.append('.F77')
+else:
+    F77Suffixes.append('.F77')
+
+#
+F77Scan = SCons.Scanner.Fortran.FortranScan("F77PATH")
+
+for suffix in F77Suffixes + F77PPSuffixes:
+    SCons.Tool.SourceFileScanner.add_scanner(suffix, F77Scan)
+del suffix
+
+#
+fVLG = fortran.VariableListGenerator
+
+F77Generator = fVLG('F77', 'FORTRAN', '_FORTRAND')
+F77FlagsGenerator = fVLG('F77FLAGS', 'FORTRANFLAGS')
+F77CommandGenerator = fVLG('F77COM', 'FORTRANCOM', '_F77COMD')
+F77CommandStrGenerator = fVLG('F77COMSTR', 'FORTRANCOMSTR', '_F77COMSTRD')
+F77PPCommandGenerator = fVLG('F77PPCOM', 'FORTRANPPCOM', '_F77PPCOMD')
+F77PPCommandStrGenerator = fVLG('F77PPCOMSTR', 'FORTRANPPCOMSTR', '_F77PPCOMSTRD')
+ShF77Generator = fVLG('SHF77', 'SHFORTRAN', 'F77', 'FORTRAN', '_FORTRAND')
+ShF77FlagsGenerator = fVLG('SHF77FLAGS', 'SHFORTRANFLAGS')
+ShF77CommandGenerator = fVLG('SHF77COM', 'SHFORTRANCOM', '_SHF77COMD')
+ShF77CommandStrGenerator = fVLG('SHF77COMSTR', 'SHFORTRANCOMSTR', '_SHF77COMSTRD')
+ShF77PPCommandGenerator = fVLG('SHF77PPCOM', 'SHFORTRANPPCOM', '_SHF77PPCOMD')
+ShF77PPCommandStrGenerator = fVLG('SHF77PPCOMSTR', 'SHFORTRANPPCOMSTR', '_SHF77PPCOMSTRD')
+
+del fVLG
+
+#
+F77Action = SCons.Action.Action('$_F77COMG ', '$_F77COMSTRG')
+F77PPAction = SCons.Action.Action('$_F77PPCOMG ', '$_F77PPCOMSTRG')
+ShF77Action = SCons.Action.Action('$_SHF77COMG ', '$_SHF77COMSTRG')
+ShF77PPAction = SCons.Action.Action('$_SHF77PPCOMG ', '$_SHF77PPCOMSTRG')
+
+def add_to_env(env):
+    """Add Builders and construction variables for f77 to an Environment."""
+    env.AppendUnique(FORTRANSUFFIXES = F77Suffixes + F77PPSuffixes)
+
+    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+    for suffix in F77Suffixes:
+        static_obj.add_action(suffix, F77Action)
+        shared_obj.add_action(suffix, ShF77Action)
+        static_obj.add_emitter(suffix, fortran.FortranEmitter)
+        shared_obj.add_emitter(suffix, fortran.ShFortranEmitter)
+
+    for suffix in F77PPSuffixes:
+        static_obj.add_action(suffix, F77PPAction)
+        shared_obj.add_action(suffix, ShF77PPAction)
+        static_obj.add_emitter(suffix, fortran.FortranEmitter)
+        shared_obj.add_emitter(suffix, fortran.ShFortranEmitter)
+
+    env['_F77G']            = F77Generator
+    env['_F77FLAGSG']       = F77FlagsGenerator
+    env['_F77COMG']         = F77CommandGenerator
+    env['_F77PPCOMG']       = F77PPCommandGenerator
+    env['_F77COMSTRG']      = F77CommandStrGenerator
+    env['_F77PPCOMSTRG']    = F77PPCommandStrGenerator
+
+    env['_SHF77G']          = ShF77Generator
+    env['_SHF77FLAGSG']     = ShF77FlagsGenerator
+    env['_SHF77COMG']       = ShF77CommandGenerator
+    env['_SHF77PPCOMG']     = ShF77PPCommandGenerator
+    env['_SHF77COMSTRG']    = ShF77CommandStrGenerator
+    env['_SHF77PPCOMSTRG']  = ShF77PPCommandStrGenerator
+
+    env['_F77INCFLAGS'] = '$( ${_concat(INCPREFIX, F77PATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+
+    env['_F77COMD']     = '$_F77G -o $TARGET -c $_F77FLAGSG $_F77INCFLAGS $SOURCES'
+    env['_F77PPCOMD']   = '$_F77G -o $TARGET -c $_F77FLAGSG $CPPFLAGS $_CPPDEFFLAGS $_F77INCFLAGS $SOURCES'
+    env['_SHF77COMD']   = '$_SHF77G -o $TARGET -c $_SHF77FLAGSG $_F77INCFLAGS $SOURCES'
+    env['_SHF77PPCOMD'] = '$_SHF77G -o $TARGET -c $_SHF77FLAGSG $CPPFLAGS $_CPPDEFFLAGS $_F77INCFLAGS $SOURCES'
+
+def generate(env):
+    fortran.add_to_env(env)
+
+    import f90
+    import f95
+    f90.add_to_env(env)
+    f95.add_to_env(env)
+
+    add_to_env(env)
+
+    env['_FORTRAND']        = env.Detect(compilers) or 'f77'
+
+def exists(env):
+    return env.Detect(compilers)

Added: branches/numpy.scons/numpy/distutils/scons/tools/f90.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/f90.py	2007-11-03 16:09:06 UTC (rev 4380)
+++ branches/numpy.scons/numpy/distutils/scons/tools/f90.py	2007-11-05 07:12:26 UTC (rev 4381)
@@ -0,0 +1,132 @@
+"""engine.SCons.Tool.f90
+
+Tool-specific initialization for the generic Posix f90 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# __COPYRIGHT__
+#
+# 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 SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+import fortran
+
+compilers = ['f90']
+
+#
+F90Suffixes = ['.f90']
+F90PPSuffixes = []
+if SCons.Util.case_sensitive_suffixes('.f90', '.F90'):
+    F90PPSuffixes.append('.F90')
+else:
+    F90Suffixes.append('.F90')
+
+#
+F90Scan = SCons.Scanner.Fortran.FortranScan("F90PATH")
+
+for suffix in F90Suffixes + F90PPSuffixes:
+    SCons.Tool.SourceFileScanner.add_scanner(suffix, F90Scan)
+del suffix
+
+#
+fVLG = fortran.VariableListGenerator
+
+F90Generator = fVLG('F90', 'FORTRAN', '_FORTRAND')
+F90FlagsGenerator = fVLG('F90FLAGS', 'FORTRANFLAGS')
+F90CommandGenerator = fVLG('F90COM', 'FORTRANCOM', '_F90COMD')
+F90CommandStrGenerator = fVLG('F90COMSTR', 'FORTRANCOMSTR', '_F90COMSTRD')
+F90PPCommandGenerator = fVLG('F90PPCOM', 'FORTRANPPCOM', '_F90PPCOMD')
+F90PPCommandStrGenerator = fVLG('F90PPCOMSTR', 'FORTRANPPCOMSTR', '_F90PPCOMSTRD')
+ShF90Generator = fVLG('SHF90', 'SHFORTRAN', 'F90', 'FORTRAN', '_FORTRAND')
+ShF90FlagsGenerator = fVLG('SHF90FLAGS', 'SHFORTRANFLAGS')
+ShF90CommandGenerator = fVLG('SHF90COM', 'SHFORTRANCOM', '_SHF90COMD')
+ShF90CommandStrGenerator = fVLG('SHF90COMSTR', 'SHFORTRANCOMSTR', '_SHF90COMSTRD')
+ShF90PPCommandGenerator = fVLG('SHF90PPCOM', 'SHFORTRANPPCOM', '_SHF90PPCOMD')
+ShF90PPCommandStrGenerator = fVLG('SHF90PPCOMSTR', 'SHFORTRANPPCOMSTR', '_SHF90PPCOMSTRD')
+
+del fVLG
+
+#
+F90Action = SCons.Action.Action('$_F90COMG ', '$_F90COMSTRG')
+F90PPAction = SCons.Action.Action('$_F90PPCOMG ', '$_F90PPCOMSTRG')
+ShF90Action = SCons.Action.Action('$_SHF90COMG ', '$_SHF90COMSTRG')
+ShF90PPAction = SCons.Action.Action('$_SHF90PPCOMG ', '$_SHF90PPCOMSTRG')
+
+def add_to_env(env):
+    """Add Builders and construction variables for f90 to an Environment."""
+    env.AppendUnique(FORTRANSUFFIXES = F90Suffixes + F90PPSuffixes)
+
+    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+    for suffix in F90Suffixes:
+        static_obj.add_action(suffix, F90Action)
+        shared_obj.add_action(suffix, ShF90Action)
+        static_obj.add_emitter(suffix, fortran.FortranEmitter)
+        shared_obj.add_emitter(suffix, fortran.ShFortranEmitter)
+
+    for suffix in F90PPSuffixes:
+        static_obj.add_action(suffix, F90PPAction)
+        shared_obj.add_action(suffix, ShF90PPAction)
+        static_obj.add_emitter(suffix, fortran.FortranEmitter)
+        shared_obj.add_emitter(suffix, fortran.ShFortranEmitter)
+  
+    env['_F90G']            = F90Generator
+    env['_F90FLAGSG']       = F90FlagsGenerator
+    env['_F90COMG']         = F90CommandGenerator
+    env['_F90COMSTRG']      = F90CommandStrGenerator
+    env['_F90PPCOMG']       = F90PPCommandGenerator
+    env['_F90PPCOMSTRG']    = F90PPCommandStrGenerator
+
+    env['_SHF90G']          = ShF90Generator
+    env['_SHF90FLAGSG']     = ShF90FlagsGenerator
+    env['_SHF90COMG']       = ShF90CommandGenerator
+    env['_SHF90COMSTRG']    = ShF90CommandStrGenerator
+    env['_SHF90PPCOMG']     = ShF90PPCommandGenerator
+    env['_SHF90PPCOMSTRG']  = ShF90PPCommandStrGenerator
+
+    env['_F90INCFLAGS'] = '$( ${_concat(INCPREFIX, F90PATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+    env['_F90COMD']     = '$_F90G -o $TARGET -c $_F90FLAGSG $_F90INCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_F90PPCOMD']   = '$_F90G -o $TARGET -c $_F90FLAGSG $CPPFLAGS $_CPPDEFFLAGS $_F90INCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_SHF90COMD']   = '$_SHF90G -o $TARGET -c $_SHF90FLAGSG $_F90INCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_SHF90PPCOMD'] = '$_SHF90G -o $TARGET -c $_SHF90FLAGSG $CPPFLAGS $_CPPDEFFLAGS $_F90INCFLAGS $_FORTRANMODFLAG $SOURCES'
+
+def generate(env):
+    fortran.add_to_env(env)
+
+    import f77
+    f77.add_to_env(env)
+
+    add_to_env(env)
+
+    env['_FORTRAND']        = env.Detect(compilers) or 'f90'
+
+def exists(env):
+    return env.Detect(compilers)

Added: branches/numpy.scons/numpy/distutils/scons/tools/f95.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/f95.py	2007-11-03 16:09:06 UTC (rev 4380)
+++ branches/numpy.scons/numpy/distutils/scons/tools/f95.py	2007-11-05 07:12:26 UTC (rev 4381)
@@ -0,0 +1,135 @@
+"""engine.SCons.Tool.f95
+
+Tool-specific initialization for the generic Posix f95 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# __COPYRIGHT__
+#
+# 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 SCons.Defaults
+import SCons.Tool
+import SCons.Util
+import fortran
+
+compilers = ['f95']
+
+#
+F95Suffixes = ['.f95']
+F95PPSuffixes = []
+if SCons.Util.case_sensitive_suffixes('.f95', '.F95'):
+    F95PPSuffixes.append('.F95')
+else:
+    F95Suffixes.append('.F95')
+
+#
+F95Scan = SCons.Scanner.Fortran.FortranScan("F95PATH")
+
+for suffix in F95Suffixes + F95PPSuffixes:
+    SCons.Tool.SourceFileScanner.add_scanner(suffix, F95Scan)
+del suffix
+
+#
+fVLG = fortran.VariableListGenerator
+
+F95Generator = fVLG('F95', 'FORTRAN', '_FORTRAND')
+F95FlagsGenerator = fVLG('F95FLAGS', 'FORTRANFLAGS')
+F95CommandGenerator = fVLG('F95COM', 'FORTRANCOM', '_F95COMD')
+F95CommandStrGenerator = fVLG('F95COMSTR', 'FORTRANCOMSTR', '_F95COMSTRD')
+F95PPCommandGenerator = fVLG('F95PPCOM', 'FORTRANPPCOM', '_F95PPCOMD')
+F95PPCommandStrGenerator = fVLG('F95PPCOMSTR', 'FORTRANPPCOMSTR', '_F95PPCOMSTRD')
+ShF95Generator = fVLG('SHF95', 'SHFORTRAN', 'F95', 'FORTRAN', '_FORTRAND')
+ShF95FlagsGenerator = fVLG('SHF95FLAGS', 'SHFORTRANFLAGS')
+ShF95CommandGenerator = fVLG('SHF95COM', 'SHFORTRANCOM', '_SHF95COMD')
+ShF95CommandStrGenerator = fVLG('SHF95COMSTR', 'SHFORTRANCOMSTR', '_SHF95COMSTRD')
+ShF95PPCommandGenerator = fVLG('SHF95PPCOM', 'SHFORTRANPPCOM', '_SHF95PPCOMD')
+ShF95PPCommandStrGenerator = fVLG('SHF95PPCOMSTR', 'SHFORTRANPPCOMSTR', '_SHF95PPCOMSTRD')
+
+del fVLG
+
+#
+F95Action = SCons.Action.Action('$_F95COMG ', '$_F95COMSTRG')
+F95PPAction = SCons.Action.Action('$_F95PPCOMG ', '$_F95PPCOMSTRG')
+ShF95Action = SCons.Action.Action('$_SHF95COMG ', '$_SHF95COMSTRG')
+ShF95PPAction = SCons.Action.Action('$_SHF95PPCOMG ', '$_SHF95PPCOMSTRG')
+
+def add_to_env(env):
+    """Add Builders and construction variables for f95 to an Environment."""
+    env.AppendUnique(FORTRANSUFFIXES = F95Suffixes + F95PPSuffixes)
+
+    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+    for suffix in F95Suffixes:
+        static_obj.add_action(suffix, F95Action)
+        shared_obj.add_action(suffix, ShF95Action)
+        static_obj.add_emitter(suffix, fortran.FortranEmitter)
+        shared_obj.add_emitter(suffix, fortran.ShFortranEmitter)
+
+    for suffix in F95PPSuffixes:
+        static_obj.add_action(suffix, F95PPAction)
+        shared_obj.add_action(suffix, ShF95PPAction)
+        static_obj.add_emitter(suffix, fortran.FortranEmitter)
+        shared_obj.add_emitter(suffix, fortran.ShFortranEmitter)
+
+    env['_F95G']           = F95Generator
+    env['_F95FLAGSG']      = F95FlagsGenerator
+    env['_F95COMG']        = F95CommandGenerator
+    env['_F95COMSTRG']     = F95CommandStrGenerator
+    env['_F95PPCOMG']      = F95PPCommandGenerator
+    env['_F95PPCOMSTRG']   = F95PPCommandStrGenerator
+
+    env['_SHF95G']         = ShF95Generator
+    env['_SHF95FLAGSG']    = ShF95FlagsGenerator
+    env['_SHF95COMG']      = ShF95CommandGenerator
+    env['_SHF95COMSTRG']   = ShF95CommandStrGenerator
+    env['_SHF95PPCOMG']    = ShF95PPCommandGenerator
+    env['_SHF95PPCOMSTRG'] = ShF95PPCommandStrGenerator
+
+    env['_F95INCFLAGS'] = '$( ${_concat(INCPREFIX, F95PATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+
+    env['_F95COMD']     = '$_F95G -o $TARGET -c $_F95FLAGSG $_F95INCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_F95PPCOMD']   = '$_F95G -o $TARGET -c $_F95FLAGSG $CPPFLAGS $_CPPDEFFLAGS $_F95INCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_SHF95COMD']   = '$_SHF95G -o $TARGET -c $_SHF95FLAGSG $_F95INCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_SHF95PPCOMD'] = '$_SHF95G -o $TARGET -c $_SHF95FLAGSG $CPPFLAGS $_CPPDEFFLAGS $_F95INCFLAGS $_FORTRANMODFLAG $SOURCES'
+
+def generate(env):
+    fortran.add_to_env(env)
+
+    import f77
+    f77.add_to_env(env)
+
+    import f90
+    f90.add_to_env(env)
+
+    add_to_env(env)
+
+    env['_FORTRAND']        = env.Detect(compilers) or 'f95'
+
+def exists(env):
+    return env.Detect(compilers)

Added: branches/numpy.scons/numpy/distutils/scons/tools/fortran.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/fortran.py	2007-11-03 16:09:06 UTC (rev 4380)
+++ branches/numpy.scons/numpy/distutils/scons/tools/fortran.py	2007-11-05 07:12:26 UTC (rev 4381)
@@ -0,0 +1,187 @@
+"""SCons.Tool.fortran
+
+Tool-specific initialization for a generic Posix f77/f90 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# __COPYRIGHT__
+#
+# 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 re
+import string
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+
+compilers = ['f95', 'f90', 'f77']
+
+#
+#  Not yet sure how to deal with fortran pre-processor functions.
+#  Different compilers do this differently in modern fortran.  Some still
+#  rely on the c pre-processor, some (like cvf, ivf) have their own
+#  pre-processor technology and use intermediary suffixes (.i90)
+#
+FortranSuffixes = [".f", ".for", ".ftn", ]
+FortranPPSuffixes = ['.fpp', '.FPP']
+upper_case = [".F", ".FOR", ".FTN"]
+if SCons.Util.case_sensitive_suffixes('.f', '.F'):
+    FortranPPSuffixes.extend(upper_case)
+else:
+    FortranSuffixes.extend(upper_case)
+
+#
+FortranScan = SCons.Scanner.Fortran.FortranScan("FORTRANPATH")
+
+for suffix in FortranSuffixes + FortranPPSuffixes:
+    SCons.Tool.SourceFileScanner.add_scanner(suffix, FortranScan)
+del suffix
+
+#
+def _fortranEmitter(target, source, env):
+    node = source[0].rfile()
+    if not node.exists() and not node.is_derived():
+       print "Could not locate " + str(node.name)
+       return ([], [])
+    mod_regex = """(?i)^\s*MODULE\s+(?!PROCEDURE)(\w+)"""
+    cre = re.compile(mod_regex,re.M)
+    # Retrieve all USE'd module names
+    modules = cre.findall(node.get_contents())
+    # Remove unique items from the list
+    modules = SCons.Util.unique(modules)
+    # Convert module name to a .mod filename
+    suffix = env.subst('$FORTRANMODSUFFIX', target=target, source=source)
+    moddir = env.subst('$FORTRANMODDIR', target=target, source=source)
+    modules = map(lambda x, s=suffix: string.lower(x) + s, modules)
+    for m in modules:
+       target.append(env.fs.File(m, moddir))
+    return (target, source)
+
+def FortranEmitter(target, source, env):
+    target, source = _fortranEmitter(target, source, env)
+    return SCons.Defaults.StaticObjectEmitter(target, source, env)
+
+def ShFortranEmitter(target, source, env):
+    target, source = _fortranEmitter(target, source, env)
+    return SCons.Defaults.SharedObjectEmitter(target, source, env)
+
+class VariableListGenerator:
+    def __init__(self, *variablelist):
+        self.variablelist = variablelist
+    def __call__(self, env, target, source, for_signature=0):
+        for v in self.variablelist:
+            try: return env[v]
+            except KeyError: pass
+        return ''
+
+#
+FortranGenerator = VariableListGenerator('FORTRAN', 'F77', '_FORTRAND')
+FortranFlagsGenerator = VariableListGenerator('FORTRANFLAGS', 'F77FLAGS')
+FortranCommandGenerator = VariableListGenerator('FORTRANCOM', 'F77COM', '_FORTRANCOMD')
+FortranCommandStrGenerator = VariableListGenerator('FORTRANCOMSTR', 'F77COMSTR', '_FORTRANCOMSTRD')
+FortranPPCommandGenerator = VariableListGenerator('FORTRANPPCOM', 'F77PPCOM', '_FORTRANPPCOMD')
+FortranPPCommandStrGenerator = VariableListGenerator('FORTRANPPCOMSTR', 'F77PPCOMSTR', '_FORTRANPPCOMSTRD')
+ShFortranGenerator = VariableListGenerator('SHFORTRAN', 'SHF77', 'FORTRAN', 'F77', '_FORTRAND')
+ShFortranFlagsGenerator = VariableListGenerator('SHFORTRANFLAGS', 'SHF77FLAGS')
+ShFortranCommandGenerator = VariableListGenerator('SHFORTRANCOM', 'SHF77COM', '_SHFORTRANCOMD')
+ShFortranCommandStrGenerator = VariableListGenerator('SHFORTRANCOMSTR', 'SHF77COMSTR', '_SHFORTRANCOMSTRD')
+ShFortranPPCommandGenerator = VariableListGenerator('SHFORTRANPPCOM', 'SHF77PPCOM', '_SHFORTRANPPCOMD')
+ShFortranPPCommandStrGenerator = VariableListGenerator('SHFORTRANPPCOMSTR', 'SHF77PPCOMSTR', '_SHFORTRANPPCOMSTRD')
+
+#
+FortranAction = SCons.Action.Action('$_FORTRANCOMG ', '$_FORTRANCOMSTRG')
+FortranPPAction = SCons.Action.Action('$_FORTRANPPCOMG ', '$_FORTRANPPCOMSTRG')
+ShFortranAction = SCons.Action.Action('$_SHFORTRANCOMG ', '$_SHFORTRANCOMSTRG')
+ShFortranPPAction = SCons.Action.Action('$_SHFORTRANPPCOMG ', '$_SHFORTRANPPCOMSTRG')
+
+def add_to_env(env):
+    """Add Builders and construction variables for Fortran to an Environment."""
+
+    env['_FORTRANG']            = FortranGenerator
+    env['_FORTRANFLAGSG']       = FortranFlagsGenerator
+    env['_FORTRANCOMG']         = FortranCommandGenerator
+    env['_FORTRANCOMSTRG']      = FortranCommandStrGenerator
+    env['_FORTRANPPCOMG']       = FortranPPCommandGenerator
+    env['_FORTRANPPCOMSTRG']    = FortranPPCommandStrGenerator
+
+    env['_SHFORTRANG']          = ShFortranGenerator
+    env['_SHFORTRANFLAGSG']     = ShFortranFlagsGenerator
+    env['_SHFORTRANCOMG']       = ShFortranCommandGenerator
+    env['_SHFORTRANCOMSTRG']    = ShFortranCommandStrGenerator
+    env['_SHFORTRANPPCOMG']     = ShFortranPPCommandGenerator
+    env['_SHFORTRANPPCOMSTRG']  = ShFortranPPCommandStrGenerator
+
+    env['_FORTRANINCFLAGS'] = '$( ${_concat(INCPREFIX, FORTRANPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+
+    env['FORTRANMODPREFIX'] = ''     # like $LIBPREFIX
+    env['FORTRANMODSUFFIX'] = '.mod' # like $LIBSUFFIX
+
+    env['FORTRANMODDIR'] = ''          # where the compiler should place .mod files
+    env['FORTRANMODDIRPREFIX'] = ''    # some prefix to $FORTRANMODDIR - similar to $INCPREFIX
+    env['FORTRANMODDIRSUFFIX'] = ''    # some suffix to $FORTRANMODDIR - similar to $INCSUFFIX
+    env['_FORTRANMODFLAG'] = '$( ${_concat(FORTRANMODDIRPREFIX, FORTRANMODDIR, FORTRANMODDIRSUFFIX, __env__, RDirs)} $)'
+
+    env.AppendUnique(FORTRANSUFFIXES = FortranSuffixes + FortranPPSuffixes)
+
+    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+    for suffix in FortranSuffixes:
+        static_obj.add_action(suffix, FortranAction)
+        shared_obj.add_action(suffix, ShFortranAction)
+        static_obj.add_emitter(suffix, FortranEmitter)
+        shared_obj.add_emitter(suffix, ShFortranEmitter)
+
+    for suffix in FortranPPSuffixes:
+        static_obj.add_action(suffix, FortranPPAction)
+        shared_obj.add_action(suffix, ShFortranPPAction)
+        static_obj.add_emitter(suffix, FortranEmitter)
+        shared_obj.add_emitter(suffix, ShFortranEmitter)
+
+    env['_FORTRANCOMD']     = '$_FORTRANG -o $TARGET -c $_FORTRANFLAGSG $_FORTRANINCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_FORTRANPPCOMD']   = '$_FORTRANG -o $TARGET -c $_FORTRANFLAGSG $CPPFLAGS $_CPPDEFFLAGS $_FORTRANINCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_SHFORTRANCOMD']   = '$_SHFORTRANG -o $TARGET -c $_SHFORTRANFLAGSG $_FORTRANINCFLAGS $_FORTRANMODFLAG $SOURCES'
+    env['_SHFORTRANPPCOMD'] = '$_SHFORTRANG -o $TARGET -c $_SHFORTRANFLAGSG $CPPFLAGS $_CPPDEFFLAGS $_FORTRANINCFLAGS $_FORTRANMODFLAG $SOURCES'
+
+import f77
+import f90
+import f95
+
+def generate(env):
+    f77.add_to_env(env)
+    f90.add_to_env(env)
+    f95.add_to_env(env)
+
+    add_to_env(env)
+
+    env['_FORTRAND'] = env.Detect(compilers) or 'f77'
+
+def exists(env):
+    return env.Detect(compilers)

Added: branches/numpy.scons/numpy/distutils/scons/tools/gfortran.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/gfortran.py	2007-11-03 16:09:06 UTC (rev 4380)
+++ branches/numpy.scons/numpy/distutils/scons/tools/gfortran.py	2007-11-05 07:12:26 UTC (rev 4381)
@@ -0,0 +1,49 @@
+"""SCons.Tool.gfirtran
+
+Tool-specific initialization for gfortran, the GNU Fortran 95/Fortran 2003 compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# __COPYRIGHT__
+#
+# 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 string
+
+import SCons.Defaults
+
+import fortran
+
+def generate(env):
+    """Add Builders and construction variables for gfortran to an Environment."""
+    fortran.generate(env)
+
+    env['_FORTRAND'] = 'gfortran'
+
+def exists(env):
+    return env.Detect('ifort')



More information about the Numpy-svn mailing list