[Numpy-svn] r3290 - in trunk/numpy/distutils: . command fcompiler

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Oct 8 04:30:26 CDT 2006


Author: pearu
Date: 2006-10-08 04:30:17 -0500 (Sun, 08 Oct 2006)
New Revision: 3290

Modified:
   trunk/numpy/distutils/command/build_clib.py
   trunk/numpy/distutils/command/build_ext.py
   trunk/numpy/distutils/fcompiler/__init__.py
   trunk/numpy/distutils/fcompiler/gnu.py
   trunk/numpy/distutils/misc_util.py
Log:
numpy.distutils: use language flag or source file extension to select default f77 or f90 compiler.

Modified: trunk/numpy/distutils/command/build_clib.py
===================================================================
--- trunk/numpy/distutils/command/build_clib.py	2006-10-08 06:37:50 UTC (rev 3289)
+++ trunk/numpy/distutils/command/build_clib.py	2006-10-08 09:30:17 UTC (rev 3290)
@@ -46,9 +46,12 @@
             return
 
         # Make sure that library sources are complete.
+        languages = []
         for (lib_name, build_info) in self.libraries:
             if not all_strings(build_info.get('sources',[])):
                 self.run_command('build_src')
+            l = build_info.get('language',None)
+            if l and l not in languages: languages.append(l)
 
         from distutils.ccompiler import new_compiler
         self.compiler = new_compiler(compiler=self.compiler,
@@ -69,7 +72,8 @@
             self.fcompiler = new_fcompiler(compiler=self.fcompiler,
                                            verbose=self.verbose,
                                            dry_run=self.dry_run,
-                                           force=self.force)
+                                           force=self.force,
+                                           requiref90='f90' in languages)
             self.fcompiler.customize(self.distribution)
 
             libraries = self.libraries
@@ -124,12 +128,14 @@
                          'for fortran compiler: %s' \
                          % (config_fc))
                 from numpy.distutils.fcompiler import new_fcompiler
+                requiref90 = build_info.get('language','c')=='f90'
                 fcompiler = new_fcompiler(compiler=self.fcompiler.compiler_type,
                                           verbose=self.verbose,
                                           dry_run=self.dry_run,
-                                          force=self.force)
+                                          force=self.force,
+                                          requiref90=requiref90)
                 fcompiler.customize(config_fc)
-
+            
             macros = build_info.get('macros')
             include_dirs = build_info.get('include_dirs')
             extra_postargs = build_info.get('extra_compiler_args') or []

Modified: trunk/numpy/distutils/command/build_ext.py
===================================================================
--- trunk/numpy/distutils/command/build_ext.py	2006-10-08 06:37:50 UTC (rev 3289)
+++ trunk/numpy/distutils/command/build_ext.py	2006-10-08 09:30:17 UTC (rev 3290)
@@ -75,6 +75,13 @@
                     need_f_compiler = 1
                     break
 
+        requiref90 = 0
+        if need_f_compiler:
+            for ext in self.extensions:
+                if getattr(ext,'language','c')=='f90':
+                    requiref90 = 1
+                    break
+
         # Determine if C++ compiler is needed.
         need_cxx_compiler = 0
         for ext in self.extensions:
@@ -100,7 +107,8 @@
             self.fcompiler = new_fcompiler(compiler=self.fcompiler,
                                            verbose=self.verbose,
                                            dry_run=self.dry_run,
-                                           force=self.force)
+                                           force=self.force,
+                                           requiref90=requiref90)
             if self.fcompiler.get_version():
                 self.fcompiler.customize(self.distribution)
                 self.fcompiler.customize_cmd(self)

Modified: trunk/numpy/distutils/fcompiler/__init__.py
===================================================================
--- trunk/numpy/distutils/fcompiler/__init__.py	2006-10-08 06:37:50 UTC (rev 3289)
+++ trunk/numpy/distutils/fcompiler/__init__.py	2006-10-08 09:30:17 UTC (rev 3290)
@@ -104,6 +104,11 @@
     shared_lib_format = "%s%s"
     exe_extension = ""
 
+    # If compiler does not support compiling Fortran 90 then it can
+    # suggest using another compiler. For example, gnu would suggest
+    # gnu95 compiler type when there are F90 sources.
+    suggested_f90_compiler = None
+
     ######################################################################
     ## Methods that subclasses may redefine. But don't call these methods!
     ## They are private to FCompiler class and may return unexpected
@@ -589,13 +594,23 @@
     ('mac',('gnu','gnu95',)),
     )
 
-def _find_existing_fcompiler(compilers, osname=None, platform=None):
+def _find_existing_fcompiler(compilers, osname=None, platform=None, requiref90=None):
     for compiler in compilers:
         v = None
         try:
             c = new_fcompiler(plat=platform, compiler=compiler)
             c.customize()
             v = c.get_version()
+            if requiref90 and c.compiler_f90 is None:
+                v = None
+                new_compiler = c.suggested_f90_compiler
+                if new_compiler:
+                    c = new_fcompiler(plat=platform, compiler=new_compiler)
+                    c.customize()
+                    v = c.get_version()
+            if requiref90 and c.compiler_f90 is None:
+                raise ValueError,'%s does not support compiling f90 codes, skipping.' \
+                      % (c.__class__.__name__)
         except DistutilsModuleError:
             pass
         except Exception, msg:
@@ -604,7 +619,7 @@
             return compiler
     return
 
-def get_default_fcompiler(osname=None, platform=None):
+def get_default_fcompiler(osname=None, platform=None, requiref90=None):
     """ Determine the default Fortran compiler to use for the given platform. """
     if osname is None:
         osname = os.name
@@ -622,7 +637,8 @@
         matching_compilers.append('gnu')
     compiler =  _find_existing_fcompiler(matching_compilers,
                                          osname=osname,
-                                         platform=platform)
+                                         platform=platform,
+                                         requiref90=requiref90)
     if compiler is not None:
         return compiler
     return matching_compilers[0]
@@ -631,7 +647,8 @@
                   compiler=None,
                   verbose=0,
                   dry_run=0,
-                  force=0):
+                  force=0,
+                  requiref90=0):
     """ Generate an instance of some FCompiler subclass for the supplied
     platform/compiler combination.
     """
@@ -639,7 +656,7 @@
         plat = os.name
     try:
         if compiler is None:
-            compiler = get_default_fcompiler(plat)
+            compiler = get_default_fcompiler(plat,requiref90=requiref90)
         (module_name, class_name, long_description) = fcompiler_class[compiler]
     except KeyError:
         msg = "don't know how to compile Fortran code on platform '%s'" % plat

Modified: trunk/numpy/distutils/fcompiler/gnu.py
===================================================================
--- trunk/numpy/distutils/fcompiler/gnu.py	2006-10-08 06:37:50 UTC (rev 3289)
+++ trunk/numpy/distutils/fcompiler/gnu.py	2006-10-08 09:30:17 UTC (rev 3290)
@@ -28,7 +28,7 @@
     executables = {
         'version_cmd'  : [fc_exe,"--version"],
         'compiler_f77' : [fc_exe, "-g", "-Wall","-fno-second-underscore"],
-        'compiler_f90' : None,
+        'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes
         'compiler_fix' : None,
         'linker_so'    : [fc_exe, "-g", "-Wall"],
         'archiver'     : ["ar", "-cr"],
@@ -50,6 +50,8 @@
 
     g2c = 'g2c'
 
+    suggested_f90_compiler = 'gnu95'
+
     #def get_linker_so(self):
     #    # win32 linking should be handled by standard linker
     #    # Darwin g77 cannot be used as a linker.

Modified: trunk/numpy/distutils/misc_util.py
===================================================================
--- trunk/numpy/distutils/misc_util.py	2006-10-08 06:37:50 UTC (rev 3289)
+++ trunk/numpy/distutils/misc_util.py	2006-10-08 09:30:17 UTC (rev 3290)
@@ -19,7 +19,7 @@
            'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',
            'get_script_files', 'get_lib_source_files', 'get_data_files',
            'dot_join', 'get_frame', 'minrelpath','njoin',
-           'is_sequence', 'is_string', 'as_list', 'gpaths']
+           'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language']
 
 def allpath(name):
     "Convert a /-separated pathname to one using the OS's path separator."
@@ -308,6 +308,18 @@
     else:
         return [seq]
 
+def get_language(sources):
+    """ Determine language value (c,f77,f90) from sources """
+    language = 'c'
+    for source in sources:
+        if isinstance(source, str):
+            if f90_ext_match(source):
+                language = 'f90'
+                break
+            elif fortran_ext_match(source):
+                language = 'f77'
+    return language
+
 def has_f_sources(sources):
     """ Return True if sources contains Fortran files """
     for source in sources:
@@ -1018,6 +1030,10 @@
         ext_args['name'] = dot_join(self.name,name)
         ext_args['sources'] = sources
 
+        language = ext_args.get('language',None)
+        if language is None:
+            ext_args['language'] = get_language(sources)
+
         if ext_args.has_key('extra_info'):
             extra_info = ext_args['extra_info']
             del ext_args['extra_info']
@@ -1076,11 +1092,16 @@
           include_dirs
           extra_compiler_args
           f2py_options
+          language
         """
         build_info = copy.copy(build_info)
         name = name #+ '__OF__' + self.name
         build_info['sources'] = sources
 
+        language = build_info.get('language',None)
+        if language is None:
+            build_info['language'] = get_language(sources)
+
         self._fix_paths_dict(build_info)
 
         self.libraries.append((name,build_info))
@@ -1379,7 +1400,11 @@
 def dict_append(d, **kws):
     for k, v in kws.items():
         if d.has_key(k):
-            d[k].extend(v)
+            ov = d[k]
+            if isinstance(ov,str):
+                d[k] = v
+            else:
+                d[k].extend(v)
         else:
             d[k] = v
 



More information about the Numpy-svn mailing list