Index: Lib/distutils/ccompiler.py =================================================================== --- Lib/distutils/ccompiler.py (revision 66567) +++ Lib/distutils/ccompiler.py (working copy) @@ -73,6 +73,7 @@ static_lib_format = None # format string shared_lib_format = None # prob. same as static_lib_format exe_extension = None # string + lib_types = ["static", "shared"] # list of strings # Default language settings. language_map is used to detect a source # file or Extension target language, checking source filenames. @@ -1002,11 +1003,19 @@ basename = os.path.basename (basename) return os.path.join(output_dir, basename + (self.exe_extension or '')) + def _join_lib_types(self): + a = [] + for lib_type in self.lib_types: + a.append('"%s"' % lib_type) + return ", ".join(a[:-1]) + " or " + a[-1] + def library_filename(self, libname, lib_type='static', # or 'shared' strip_dir=0, output_dir=''): assert output_dir is not None - if lib_type not in ("static", "shared", "dylib"): - raise ValueError, "'lib_type' must be \"static\", \"shared\" or \"dylib\"" + assert "static" in self.lib_types + assert "shared" in self.lib_types + if lib_type not in self.lib_types: + raise ValueError, "'lib_type' must be %s" % self._join_lib_types() fmt = getattr(self, lib_type + "_lib_format") ext = getattr(self, lib_type + "_lib_extension") Index: Lib/distutils/unixccompiler.py =================================================================== --- Lib/distutils/unixccompiler.py (revision 66567) +++ Lib/distutils/unixccompiler.py (working copy) @@ -137,8 +137,23 @@ obj_extension = ".o" static_lib_extension = ".a" shared_lib_extension = ".so" - dylib_lib_extension = ".dylib" - static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" + static_lib_format = shared_lib_format = "lib%s%s" + + # We're second-guessing the linker here, with not much hard + # data to go on: GCC seems to prefer the shared library, so I'm + # assuming that *all* Unix C compilers do. And of course I'm + # ignoring even GCC's "-static" option. So sue me. + + lib_types = ["shared", "static"] + if sys.platform[:6] == "darwin": + lib_types.insert(0, "dylib") + dylib_lib_extension = ".dylib" + dylib_lib_format = "lib%s%s" + elif sys.platform == "cygwin": + lib_types.insert(0, "implib") + implib_lib_extension = ".dll.a" + implib_lib_format = "lib%s%s" + if sys.platform == "cygwin": exe_extension = ".exe" @@ -296,24 +311,12 @@ return "-l" + lib def find_library_file(self, dirs, lib, debug=0): - shared_f = self.library_filename(lib, lib_type='shared') - dylib_f = self.library_filename(lib, lib_type='dylib') - static_f = self.library_filename(lib, lib_type='static') + for lib_type in self.lib_types: + filename = self.library_filename(lib, lib_type=lib_type) + for dir in dirs: + path = os.path.join(dir, filename) + if os.path.exists(path): + return path - for dir in dirs: - shared = os.path.join(dir, shared_f) - dylib = os.path.join(dir, dylib_f) - static = os.path.join(dir, static_f) - # We're second-guessing the linker here, with not much hard - # data to go on: GCC seems to prefer the shared library, so I'm - # assuming that *all* Unix C compilers do. And of course I'm - # ignoring even GCC's "-static" option. So sue me. - if os.path.exists(dylib): - return dylib - elif os.path.exists(shared): - return shared - elif os.path.exists(static): - return static - # Oops, didn't find it in *any* of 'dirs' return None