summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2004-02-04 14:30:06 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2004-02-04 14:30:06 +0000
commitaa6fd3365a968a4c322dff8850466aabb96a1c53 (patch)
treee13e917d837bbf65b0d720c2e96b6e98f7b729a3
parentda3e21058bbbac8c8f53037c8932ca4e05ddb7b1 (diff)
downloadnumpy-aa6fd3365a968a4c322dff8850466aabb96a1c53.tar.gz
Got scipy_core to build on win32 with new build_src hooks
-rw-r--r--scipy_distutils/__init__.py9
-rw-r--r--scipy_distutils/ccompiler.py63
-rw-r--r--scipy_distutils/mingw32_support.py228
-rw-r--r--scipy_distutils/mingw32ccompiler.py211
-rw-r--r--scipy_distutils/misc_util.py2
-rw-r--r--scipy_distutils/system_info.py4
6 files changed, 285 insertions, 232 deletions
diff --git a/scipy_distutils/__init__.py b/scipy_distutils/__init__.py
index 4f629c23a..2dde7413e 100644
--- a/scipy_distutils/__init__.py
+++ b/scipy_distutils/__init__.py
@@ -7,3 +7,12 @@
# Need to do something here to get distutils subsumed...
from scipy_distutils_version import scipy_distutils_version as __version__
+
+import sys
+
+# Replace distutils.ccompiler with scipy_distutils.ccompiler
+assert not sys.modules.has_key('distutils.ccompiler'),\
+ 'distutils has been imported before scipy_distutils'
+import ccompiler
+sys.modules['distutils.ccompiler'] = ccompiler
+
diff --git a/scipy_distutils/ccompiler.py b/scipy_distutils/ccompiler.py
new file mode 100644
index 000000000..3e11f82b9
--- /dev/null
+++ b/scipy_distutils/ccompiler.py
@@ -0,0 +1,63 @@
+
+import re
+import os
+import sys
+
+from distutils.ccompiler import *
+from distutils import ccompiler
+
+import log
+
+if sys.platform == 'win32':
+ compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',
+ "Mingw32 port of GNU C Compiler for Win32"\
+ "(for MSC built Python)")
+ if os.environ.get('OSTYPE','')=='msys':
+ # On windows platforms, we want to default to mingw32 (gcc)
+ # because msvc can't build blitz stuff.
+ log.info('Setting mingw32 as default compiler for nt.')
+ ccompiler._default_compilers = (('nt', 'mingw32'),) \
+ + ccompiler._default_compilers
+
+_distutils_new_compiler = new_compiler
+def new_compiler (plat=None,
+ compiler=None,
+ verbose=0,
+ dry_run=0,
+ force=0):
+ # Try first C compilers from scipy_distutils.
+ if plat is None:
+ plat = os.name
+ try:
+ if compiler is None:
+ compiler = get_default_compiler(plat)
+ (module_name, class_name, long_description) = compiler_class[compiler]
+ except KeyError:
+ msg = "don't know how to compile C/C++ code on platform '%s'" % plat
+ if compiler is not None:
+ msg = msg + " with '%s' compiler" % compiler
+ raise DistutilsPlatformError, msg
+
+ module_name = "scipy_distutils." + module_name
+ try:
+ __import__ (module_name)
+ except ImportError, msg:
+ print msg
+ module_name = module_name[6:]
+ try:
+ __import__(module_name)
+ except ImportError:
+ raise DistutilsModuleError, \
+ "can't compile C/C++ code: unable to load module '%s'" % \
+ module_name
+ try:
+ module = sys.modules[module_name]
+ klass = vars(module)[class_name]
+ except KeyError:
+ raise DistutilsModuleError, \
+ ("can't compile C/C++ code: unable to find class '%s' " +
+ "in module '%s'") % (class_name, module_name)
+ print '*'*80
+ print module_name,klass
+ print '*'*80
+ return klass(None, dry_run, force)
diff --git a/scipy_distutils/mingw32_support.py b/scipy_distutils/mingw32_support.py
deleted file mode 100644
index f56cf45f6..000000000
--- a/scipy_distutils/mingw32_support.py
+++ /dev/null
@@ -1,228 +0,0 @@
-"""
-Support code for building Python extensions on Windows.
-
- # NT stuff
- # 1. Make sure libpython<version>.a exists for gcc. If not, build it.
- # 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
- # 3. Force windows to use g77
-
-"""
-
-import os, sys
-import distutils.ccompiler
-
-# I'd really like to pull this out of scipy and make it part of distutils...
-import scipy_distutils.command.build_flib as build_flib
-
-
-if sys.platform == 'win32':
- # NT stuff
- # 1. Make sure libpython<version>.a exists for gcc. If not, build it.
- # 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
- # 3. Force windows to use g77
-
- # 1. Build libpython<version> from .lib and .dll if they don't exist.
- import distutils.cygwinccompiler
- from distutils.version import StrictVersion
- from distutils.ccompiler import gen_preprocess_options, gen_lib_options
- from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
-
- from distutils.unixccompiler import UnixCCompiler
-
- # the same as cygwin plus some additional parameters
- class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):
- """ A modified MingW32 compiler compatible with an MSVC built Python.
-
- """
-
- compiler_type = 'mingw32'
-
- def __init__ (self,
- verbose=0,
- dry_run=0,
- force=0):
-
- distutils.cygwinccompiler.CygwinCCompiler.__init__ (self,
- verbose,dry_run, force)
-
- # we need to support 3.2 which doesn't match the standard
- # get_versions methods regex
- if self.gcc_version is None:
- import re
- out = os.popen('gcc' + ' -dumpversion','r')
- out_string = out.read()
- out.close()
- result = re.search('(\d+\.\d+)',out_string)
- if result:
- self.gcc_version = StrictVersion(result.group(1))
-
- # A real mingw32 doesn't need to specify a different entry point,
- # but cygwin 2.91.57 in no-cygwin-mode needs it.
- if self.gcc_version <= "2.91.57":
- entry_point = '--entry _DllMain@12'
- else:
- entry_point = ''
- if self.linker_dll == 'dllwrap':
- self.linker = 'dllwrap' + ' --driver-name g++'
- elif self.linker_dll == 'gcc':
- self.linker = 'g++'
-
- # **changes: eric jones 4/11/01
- # 1. Check for import library on Windows. Build if it doesn't exist.
- if not import_library_exists():
- build_import_library()
-
- # **changes: eric jones 4/11/01
- # 2. increased optimization and turned off all warnings
- # 3. also added --driver-name g++
- #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
- # compiler_so='gcc -mno-cygwin -mdll -O2 -w',
- # linker_exe='gcc -mno-cygwin',
- # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s'
- # % (self.linker, entry_point))
- if self.gcc_version <= "3.0.0":
- self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
- compiler_so='gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',
- linker_exe='g++ -mno-cygwin',
- linker_so='%s -mno-cygwin -mdll -static %s'
- % (self.linker, entry_point))
- else:
- self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
- compiler_so='gcc -O2 -w -Wstrict-prototypes',
- linker_exe='g++ ',
- linker_so='g++ -shared')
- # added for python2.3 support
- # we can't pass it through set_executables because pre 2.2 would fail
- self.compiler_cxx = ['g++']
-
- # Maybe we should also append -mthreads, but then the finished
- # dlls need another dll (mingwm10.dll see Mingw32 docs)
- # (-mthreads: Support thread-safe exception handling on `Mingw32')
-
- # no additional libraries needed
- self.dll_libraries=[]
-
- # __init__ ()
-
- def link(self,
- target_desc,
- objects,
- output_filename,
- output_dir,
- libraries,
- library_dirs,
- runtime_library_dirs,
- export_symbols = None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- build_temp=None,
- target_lang=None):
- args = (self,
- target_desc,
- objects,
- output_filename,
- output_dir,
- libraries,
- library_dirs,
- runtime_library_dirs,
- None, #export_symbols, we do this in our def-file
- debug,
- extra_preargs,
- extra_postargs,
- build_temp,
- target_lang)
- if self.gcc_version < "3.0.0":
- func = distutils.cygwinccompiler.CygwinCCompiler.link
- else:
- func = UnixCCompiler.link
- func(*args[:func.im_func.func_code.co_argcount])
-
- def object_filenames (self,
- source_filenames,
- strip_dir=0,
- output_dir=''):
- if output_dir is None: output_dir = ''
- print 'cygiwn_output_dir:', output_dir
- obj_names = []
- for src_name in source_filenames:
- # use normcase to make sure '.rc' is really '.rc' and not '.RC'
- (base, ext) = os.path.splitext (os.path.normcase(src_name))
-
- # added these lines to strip off windows drive letters
- # without it, .o files are placed next to .c files
- # instead of the build directory
- drv,base = os.path.splitdrive(base)
- if drv:
- base = base[1:]
-
- if ext not in (self.src_extensions + ['.rc','.res']):
- raise UnknownFileError, \
- "unknown file type '%s' (from '%s')" % \
- (ext, src_name)
- if strip_dir:
- base = os.path.basename (base)
- if ext == '.res' or ext == '.rc':
- # these need to be compiled to object files
- obj_names.append (os.path.join (output_dir,
- base + ext + self.obj_extension))
- else:
- print 'here', os.path.join (output_dir,
- base + self.obj_extension)
- print '...:', output_dir, base + self.obj_extension
- obj_names.append (os.path.join (output_dir,
- base + self.obj_extension))
- return obj_names
-
- # object_filenames ()
-
-
- # On windows platforms, we want to default to mingw32 (gcc)
- # because msvc can't build blitz stuff.
- # We should also check the version of gcc available...
- #distutils.ccompiler._default_compilers['nt'] = 'mingw32'
- distutils.ccompiler._default_compilers = (('nt', 'mingw32'),) + \
- distutils.ccompiler._default_compilers
- # reset the Mingw32 compiler in distutils to the one defined above
- distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler
-
- def import_library_exists():
- """ on windows platforms, make sure a gcc import library exists
- """
- if os.name == 'nt':
- lib_name = "libpython%d%d.a" % tuple(sys.version_info[:2])
- full_path = os.path.join(sys.prefix,'libs',lib_name)
- if not os.path.exists(full_path):
- return 0
- return 1
-
- def build_import_library():
- """ Build the import libraries for Mingw32-gcc on Windows
- """
- from scipy_distutils import lib2def
- #libfile, deffile = parse_cmd()
- #if deffile is None:
- # deffile = sys.stdout
- #else:
- # deffile = open(deffile, 'w')
- lib_name = "python%d%d.lib" % tuple(sys.version_info[:2])
- lib_file = os.path.join(sys.prefix,'libs',lib_name)
- def_name = "python%d%d.def" % tuple(sys.version_info[:2])
- def_file = os.path.join(sys.prefix,'libs',def_name)
- nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)
- nm_output = lib2def.getnm(nm_cmd)
- dlist, flist = lib2def.parse_nm(nm_output)
- lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))
-
- out_name = "libpython%d%d.a" % tuple(sys.version_info[:2])
- out_file = os.path.join(sys.prefix,'libs',out_name)
- dll_name = "python%d%d.dll" % tuple(sys.version_info[:2])
- args = (dll_name,def_file,out_file)
- cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args
- success = not os.system(cmd)
- # for now, fail silently
- if not success:
- print 'WARNING: failed to build import library for gcc. Linking will fail.'
- #if not success:
- # msg = "Couldn't find import library, and failed to build it."
- # raise DistutilsPlatformError, msg
diff --git a/scipy_distutils/mingw32ccompiler.py b/scipy_distutils/mingw32ccompiler.py
new file mode 100644
index 000000000..44656fe77
--- /dev/null
+++ b/scipy_distutils/mingw32ccompiler.py
@@ -0,0 +1,211 @@
+"""
+Support code for building Python extensions on Windows.
+
+ # NT stuff
+ # 1. Make sure libpython<version>.a exists for gcc. If not, build it.
+ # 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
+ # 3. Force windows to use g77
+
+"""
+
+import os
+import sys
+import log
+
+import scipy_distutils.ccompiler
+
+# NT stuff
+# 1. Make sure libpython<version>.a exists for gcc. If not, build it.
+# 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
+# 3. Force windows to use g77
+
+# 1. Build libpython<version> from .lib and .dll if they don't exist.
+import distutils.cygwinccompiler
+from distutils.version import StrictVersion
+from scipy_distutils.ccompiler import gen_preprocess_options, gen_lib_options
+from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
+
+from distutils.unixccompiler import UnixCCompiler
+
+# the same as cygwin plus some additional parameters
+class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):
+ """ A modified MingW32 compiler compatible with an MSVC built Python.
+
+ """
+
+ compiler_type = 'mingw32'
+
+ def __init__ (self,
+ verbose=0,
+ dry_run=0,
+ force=0):
+
+ distutils.cygwinccompiler.CygwinCCompiler.__init__ (self,
+ verbose,dry_run, force)
+
+ # we need to support 3.2 which doesn't match the standard
+ # get_versions methods regex
+ if self.gcc_version is None:
+ import re
+ out = os.popen('gcc' + ' -dumpversion','r')
+ out_string = out.read()
+ out.close()
+ result = re.search('(\d+\.\d+)',out_string)
+ if result:
+ self.gcc_version = StrictVersion(result.group(1))
+
+ # A real mingw32 doesn't need to specify a different entry point,
+ # but cygwin 2.91.57 in no-cygwin-mode needs it.
+ if self.gcc_version <= "2.91.57":
+ entry_point = '--entry _DllMain@12'
+ else:
+ entry_point = ''
+
+ if self.linker_dll == 'dllwrap':
+ self.linker = 'dllwrap --driver-name g++'
+ elif self.linker_dll == 'gcc':
+ self.linker = 'g++'
+
+ # **changes: eric jones 4/11/01
+ # 1. Check for import library on Windows. Build if it doesn't exist.
+
+ build_import_library()
+
+ # **changes: eric jones 4/11/01
+ # 2. increased optimization and turned off all warnings
+ # 3. also added --driver-name g++
+ #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
+ # compiler_so='gcc -mno-cygwin -mdll -O2 -w',
+ # linker_exe='gcc -mno-cygwin',
+ # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s'
+ # % (self.linker, entry_point))
+ if self.gcc_version <= "3.0.0":
+ self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
+ compiler_so='gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',
+ linker_exe='g++ -mno-cygwin',
+ linker_so='%s -mno-cygwin -mdll -static %s'
+ % (self.linker, entry_point))
+ else:
+ self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
+ compiler_so='gcc -O2 -w -Wstrict-prototypes',
+ linker_exe='g++ ',
+ linker_so='g++ -shared')
+ # added for python2.3 support
+ # we can't pass it through set_executables because pre 2.2 would fail
+ self.compiler_cxx = ['g++']
+
+ # Maybe we should also append -mthreads, but then the finished
+ # dlls need another dll (mingwm10.dll see Mingw32 docs)
+ # (-mthreads: Support thread-safe exception handling on `Mingw32')
+
+ # no additional libraries needed
+ self.dll_libraries=[]
+
+ # __init__ ()
+
+ def link(self,
+ target_desc,
+ objects,
+ output_filename,
+ output_dir,
+ libraries,
+ library_dirs,
+ runtime_library_dirs,
+ export_symbols = None,
+ debug=0,
+ extra_preargs=None,
+ extra_postargs=None,
+ build_temp=None,
+ target_lang=None):
+ args = (self,
+ target_desc,
+ objects,
+ output_filename,
+ output_dir,
+ libraries,
+ library_dirs,
+ runtime_library_dirs,
+ None, #export_symbols, we do this in our def-file
+ debug,
+ extra_preargs,
+ extra_postargs,
+ build_temp,
+ target_lang)
+ if self.gcc_version < "3.0.0":
+ func = distutils.cygwinccompiler.CygwinCCompiler.link
+ else:
+ func = UnixCCompiler.link
+ func(*args[:func.im_func.func_code.co_argcount])
+
+ def object_filenames (self,
+ source_filenames,
+ strip_dir=0,
+ output_dir=''):
+ if output_dir is None: output_dir = ''
+ print 'cygiwn_output_dir:', output_dir
+ obj_names = []
+ for src_name in source_filenames:
+ # use normcase to make sure '.rc' is really '.rc' and not '.RC'
+ (base, ext) = os.path.splitext (os.path.normcase(src_name))
+
+ # added these lines to strip off windows drive letters
+ # without it, .o files are placed next to .c files
+ # instead of the build directory
+ drv,base = os.path.splitdrive(base)
+ if drv:
+ base = base[1:]
+
+ if ext not in (self.src_extensions + ['.rc','.res']):
+ raise UnknownFileError, \
+ "unknown file type '%s' (from '%s')" % \
+ (ext, src_name)
+ if strip_dir:
+ base = os.path.basename (base)
+ if ext == '.res' or ext == '.rc':
+ # these need to be compiled to object files
+ obj_names.append (os.path.join (output_dir,
+ base + ext + self.obj_extension))
+ else:
+ print 'here', os.path.join (output_dir,
+ base + self.obj_extension)
+ print '...:', output_dir, base + self.obj_extension
+ obj_names.append (os.path.join (output_dir,
+ base + self.obj_extension))
+ return obj_names
+
+ # object_filenames ()
+
+
+def build_import_library():
+ """ Build the import libraries for Mingw32-gcc on Windows
+ """
+ if os.name != 'nt':
+ return
+ lib_name = "python%d%d.lib" % tuple(sys.version_info[:2])
+ lib_file = os.path.join(sys.prefix,'libs',lib_name)
+ if os.path.isfile(lib_file):
+ log.info('Skip building import library "%s"' % (lib_file))
+ return
+ log.info('Building import library "%s"' % (lib_file))
+
+ from scipy_distutils import lib2def
+
+ def_name = "python%d%d.def" % tuple(sys.version_info[:2])
+ def_file = os.path.join(sys.prefix,'libs',def_name)
+ nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)
+ nm_output = lib2def.getnm(nm_cmd)
+ dlist, flist = lib2def.parse_nm(nm_output)
+ lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))
+
+ out_name = "libpython%d%d.a" % tuple(sys.version_info[:2])
+ out_file = os.path.join(sys.prefix,'libs',out_name)
+ dll_name = "python%d%d.dll" % tuple(sys.version_info[:2])
+ args = (dll_name,def_file,out_file)
+ cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args
+ success = not os.system(cmd)
+ # for now, fail silently
+ if not success:
+ print 'WARNING: failed to build import library for gcc. Linking will fail.'
+ #if not success:
+ # msg = "Couldn't find import library, and failed to build it."
+ # raise DistutilsPlatformError, msg
diff --git a/scipy_distutils/misc_util.py b/scipy_distutils/misc_util.py
index 30441677d..6b7ebd25e 100644
--- a/scipy_distutils/misc_util.py
+++ b/scipy_distutils/misc_util.py
@@ -10,7 +10,7 @@ if sys.version[:3]<='2.1':
# Hooks for colored terminal output.
# See also http://www.livinglogic.de/Python/ansistyle
def terminal_has_colors():
- if sys.platform=='cygwin' and os.environ.has_key('NOCOLOR'):
+ if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):
# Avoid importing curses that causes illegal operation
# with a message:
# PYTHON2 caused an invalid page fault in
diff --git a/scipy_distutils/system_info.py b/scipy_distutils/system_info.py
index db5f16335..ef9d81978 100644
--- a/scipy_distutils/system_info.py
+++ b/scipy_distutils/system_info.py
@@ -275,7 +275,7 @@ class system_info:
def get_paths(self, section, key):
dirs = self.cp.get(section, key).split(os.pathsep)
- if os.environ.has_key(self.dir_env_var):
+ if self.dir_env_var and os.environ.has_key(self.dir_env_var):
dirs = os.environ[self.dir_env_var].split(os.pathsep) + dirs
default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)
dirs.extend(default_dirs)
@@ -862,5 +862,3 @@ def show_all():
if __name__ == "__main__":
show_all()
- print numpy_info().get_info()
- print numarray_info().get_info()