66from setuptools .extension import Library
77
88
9+ # Force linker to produce a shared library
910class build_ext (_build_ext ):
11+ if sys .platform .startswith ('linux' ):
12+ def get_ext_filename (self , fullname ):
13+ import setuptools .command .build_ext
14+ tmp = setuptools .command .build_ext .libtype
15+ setuptools .command .build_ext .libtype = 'shared'
16+ ret = _build_ext .get_ext_filename (self , fullname )
17+ setuptools .command .build_ext .libtype = tmp
18+ return ret
19+
1020 def setup_shlib_compiler (self ):
1121 _build_ext .setup_shlib_compiler (self )
12- if os .name == 'nt' :
13- # Currently setuptools Library linking on Windows is broken
14- # so we are monkeypatching it to be able to produce dll
22+ if sys .platform == 'win32' :
1523 from distutils .ccompiler import CCompiler
1624 mtd = CCompiler .link_shared_object .__get__ (self .shlib_compiler )
1725 self .shlib_compiler .link_shared_object = mtd
26+ elif sys .platform .startswith ('linux' ):
27+ from functools import partial
28+ c = self .shlib_compiler
29+ c .link_shared_object = partial (c .link , c .SHARED_LIBRARY )
1830
1931
2032def list_files (path ):
@@ -79,6 +91,11 @@ def list_files(path):
7991 compiler = new_compiler (compiler = get_default_compiler ())
8092 ext = compiler .static_lib_extension
8193
94+ if os .name == 'nt' :
95+ zlib_name = 'zlib'
96+ else :
97+ zlib_name = 'libz'
98+
8299 import tempfile
83100 from distutils .ccompiler import CompileError , LinkError
84101 tmp_dir = tempfile .mkdtemp ()
@@ -87,7 +104,7 @@ def list_files(path):
87104 f .write ("#include <zlib.h>\n int main() { inflate(0, 0); return 0; }" )
88105 try :
89106 for i , path in enumerate (fnmatch .filter (list_files (zlib_root ),
90- '*zlib*' + ext )):
107+ '*%s*%s' % ( zlib_name , ext ) )):
91108 tmp_dir_i = os .path .join (tmp_dir , str (i ))
92109 zlib_library = os .path .splitext (os .path .basename (path ))[0 ]
93110 zlib_library_dir = os .path .dirname (path )
@@ -115,7 +132,10 @@ def list_files(path):
115132 break
116133 library_dirs .append (zlib_library_dir )
117134else :
118- zlib_library = 'zlib'
135+ if os .name == 'nt' :
136+ zlib_library = 'zlib'
137+ else :
138+ zlib_library = 'z'
119139
120140
121141ale_c = Library ('ale_c' ,
0 commit comments