Skip to content

Commit d7e8140

Browse files
committed
Fixed *nix build
1 parent 4af6cb0 commit d7e8140

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

atari_py/ale_python_interface.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
def get_shared_lib_path():
1515
from distutils.ccompiler import get_default_compiler, new_compiler
1616
from distutils.sysconfig import get_config_var
17-
fname = 'ale_c'
17+
if os.name == 'nt':
18+
fname = 'ale_c'
19+
else:
20+
fname = 'libale_c'
1821
ext_suffix = get_config_var('EXT_SUFFIX')
1922
if ext_suffix is not None:
2023
fname += os.path.splitext(ext_suffix)[0]

setup.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@
66
from setuptools.extension import Library
77

88

9+
# Force linker to produce a shared library
910
class 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

2032
def 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>\nint 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)
117134
else:
118-
zlib_library = 'zlib'
135+
if os.name == 'nt':
136+
zlib_library = 'zlib'
137+
else:
138+
zlib_library = 'z'
119139

120140

121141
ale_c = Library('ale_c',

0 commit comments

Comments
 (0)