[Distutils] Re: CygwinCCompiler, msvc hack, BCPPCompiler

Rene Liebscher R.Liebscher@gmx.de
Tue, 08 Aug 2000 14:47:34 +0200


This is a multi-part message in MIME format.
--------------6D75E882F1D3D7994C314311
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

(My first email was sent uncomplete, here comes the second part.)

Patch decription:
- Extension.py: 
  * ext.export_symbols is now always a list (added 'or []')
- build_ext.py: 
  * get_export_symbols() changed, adds now module init function
    if not given by the user

- bccp_compiler.py: 
  * changed some list.extend([...]) to list.append(...)
  * added '/g0' to compiler_options, so compiler doesn't
    stop after 100 warnings

- cygwin_compiler.py: 
  * use self.debug_print() for debug messages
  * uses now copy.copy() to copy lists
  * added 'shared_lib_extension=".dll"', ... , this is necessary if you
    want use the compiler class outside of the standard distutils build
    process. 
  * changed result type of check_config_h() from int to string  


kind regards

Rene Liebscher
--------------6D75E882F1D3D7994C314311
Content-Type: text/plain; charset=us-ascii;
 name="bcpp_cygwin.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="bcpp_cygwin.patch"

diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/bcppcompiler.py d.p/distutils/bcppcompiler.py
--- distutils.orig/distutils/bcppcompiler.py	Tue Aug  8 13:18:37 2000
+++ d.p/distutils/bcppcompiler.py	Tue Aug  8 14:27:43 2000
@@ -67,8 +67,8 @@
         self.lib = "tlib.exe"
 
         self.preprocess_options = None
-        self.compile_options = ['/tWM', '/O2', '/q']
-        self.compile_options_debug = ['/tWM', '/Od', '/q']
+        self.compile_options = ['/tWM', '/O2', '/q', '/g0']
+        self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']
 
         self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
         self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
@@ -232,7 +232,6 @@
             # either exchange python15.lib in the python libs directory against
             # a Borland-like one, or create one with name bcpp_python15.lib 
             # there and remove the pragmas from config.h  
-            #libraries.append ('mypylib')            
             libraries.append ('import32')
             libraries.append ('cw32mt')
 
@@ -257,7 +256,7 @@
             # name of dll file
             ld_args.extend([',',output_filename])
             # no map file and start libraries 
-            ld_args.extend([',', ','])
+            ld_args.append(',,')
 
             for lib in libraries:
                 # see if we find it and if there is a bcpp specific lib 
diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/build_ext.py d.p/distutils/command/build_ext.py
--- distutils.orig/distutils/command/build_ext.py	Thu Aug  3 11:00:01 2000
+++ d.p/distutils/command/build_ext.py	Tue Aug  8 14:26:06 2000
@@ -549,14 +549,10 @@
         the .pyd file (DLL) must export the module "init" function.
         """
 
-        # XXX what if 'export_symbols' defined but it doesn't contain
-        # "init" + module_name?  Should we add it? warn? or just carry
-        # on doing nothing?
-
-        if ext.export_symbols is None:
-            return ["init" + string.split(ext.name,'.')[-1]]
-        else:
-            return ext.export_symbols
+        initfunc_name = "init" + string.split(ext.name,'.')[-1]
+        if initfunc_name not in ext.export_symbols:
+            ext.export_symbols.append(initfunc_name)
+        return ext.export_symbols
 
     def get_libraries (self, ext):
         """Return the list of libraries to link against when building a
diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/cygwinccompiler.py d.p/distutils/cygwinccompiler.py
--- distutils.orig/distutils/cygwinccompiler.py	Thu Aug  3 10:59:58 2000
+++ d.p/distutils/cygwinccompiler.py	Tue Aug  8 14:08:44 2000
@@ -44,16 +44,19 @@
 
 __revision__ = "$Id: cygwinccompiler.py,v 1.4 2000/08/02 01:31:56 gward Exp $"
 
-import os,sys
+import os,sys,copy
 from distutils.unixccompiler import UnixCCompiler
 from distutils.file_util import write_file
 
 class CygwinCCompiler (UnixCCompiler):
 
     compiler_type = 'cygwin'
-    gcc_version = None
-    dllwrap_version = None
-    ld_version = None
+    obj_extension = ".o"
+    static_lib_extension = ".a"
+    shared_lib_extension = ".dll"
+    static_lib_format = "lib%s%s"
+    shared_lib_format = "%s%s"
+    exe_extension = ".exe"
    
     def __init__ (self,
                   verbose=0,
@@ -62,14 +65,16 @@
 
         UnixCCompiler.__init__ (self, verbose, dry_run, force)
 
-        if check_config_h()<=0:
+        check_result = check_config_h()
+        self.debug_print("Python's GCC status: %s" % check_result)
+        if check_result[:2] <> "OK":
             self.warn(
                 "Python's config.h doesn't seem to support your compiler. "
                 "Compiling may fail because of undefined preprocessor macros.")
         
         (self.gcc_version, self.ld_version, self.dllwrap_version) = \
             get_versions()
-        sys.stderr.write(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
+        self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
                          (self.gcc_version, 
                           self.ld_version, 
                           self.dllwrap_version) )
@@ -117,9 +122,9 @@
                             extra_postargs=None,
                             build_temp=None):
         
-        # use separate copies, so can modify the lists
-        extra_preargs = list(extra_preargs or [])
-        libraries = list(libraries or [])
+        # use separate copies, so we can modify the lists
+        extra_preargs = copy.copy(extra_preargs or [])
+        libraries = copy.copy(libraries or [])
         
         # Additional libraries
         libraries.extend(self.dll_libraries)
@@ -241,11 +246,11 @@
        compiling probably doesn't work.
     """
     # return values
-    #  2: OK, python was compiled with GCC
-    #  1: OK, python's config.h mentions __GCC__
-    #  0: uncertain, because we couldn't check it
-    # -1: probably not OK, because we didn't found it in config.h
-    # You could check check_config_h()>0 => OK
+    #  "OK, python was compiled with GCC"
+    #  "OK, python's config.h mentions __GCC__"
+    #  "uncertain, because we couldn't check it"
+    #  "not OK, because we didn't found __GCC__ in config.h"
+    # You could check check_config_h()[:2] == "OK"
 
     from distutils import sysconfig
     import string,sys
@@ -254,7 +259,7 @@
     if -1 == string.find(sys.version,"GCC"):
         pass # go to the next test
     else:
-        return 2
+        return "OK, python was compiled with GCC"
     
     try:
         # It would probably better to read single lines to search.
@@ -265,14 +270,14 @@
         
         # is somewhere a #ifdef __GNUC__ or something similar
         if -1 == string.find(s,"__GNUC__"):
-            return -1  
+            return "not OK, because we didn't found __GCC__ in config.h"
         else:
-            return 1
+            return "OK, python's config.h mentions __GCC__"
     except IOError:
         # if we can't read this file, we cannot say it is wrong
         # the compiler will complain later about this file as missing
         pass
-    return 0
+    return "uncertain, because we couldn't check it"
 
 def get_versions():
     """ Try to find out the versions of gcc, ld and dllwrap.
diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/extension.py d.p/distutils/extension.py
--- distutils.orig/distutils/extension.py	Thu Aug  3 10:59:58 2000
+++ d.p/distutils/extension.py	Tue Aug  8 14:26:26 2000
@@ -105,6 +105,6 @@
         self.extra_objects = extra_objects or []
         self.extra_compile_args = extra_compile_args or []
         self.extra_link_args = extra_link_args or []
-        self.export_symbols = export_symbols
+        self.export_symbols = export_symbols or []
 
 # class Extension

--------------6D75E882F1D3D7994C314311--