Search for correct versioned lib .5 suffix

Always use the major version instead of requiring manual updates to the
file names.
This commit is contained in:
Peace-Maker 2023-06-28 18:34:14 +02:00
parent 68c8943e32
commit d75c37b872
2 changed files with 6 additions and 5 deletions

View File

@ -342,10 +342,10 @@ def _load_lib(path):
if os.path.exists(lib_file):
return ctypes.cdll.LoadLibrary(lib_file)
else:
# if we're on linux, try again with .so.4 extension
# if we're on linux, try again with .so.5 extension
if lib_file.endswith('.so'):
if os.path.exists(lib_file + '.4'):
return ctypes.cdll.LoadLibrary(lib_file + '.4')
if os.path.exists(lib_file + '.{}'.format(CS_VERSION_MAJOR)):
return ctypes.cdll.LoadLibrary(lib_file + '.{}'.format(CS_VERSION_MAJOR))
return None
_cs = None

View File

@ -10,6 +10,7 @@ from Cython.Distutils import build_ext
SYSTEM = sys.platform
VERSION = '5.0.0'
VERSION_PARTS = VERSION.split(".")
# adapted from commit e504b81 of Nguyen Tan Cong
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
@ -25,7 +26,7 @@ PYPACKAGE_DIR = os.path.join(ROOT_DIR, 'capstone')
CYPACKAGE_DIR = os.path.join(ROOT_DIR, 'pyx')
if SYSTEM == 'darwin':
VERSIONED_LIBRARY_FILE = "libcapstone.4.dylib"
VERSIONED_LIBRARY_FILE = "libcapstone.{}.dylib".format(VERSION_PARTS[0])
LIBRARY_FILE = "libcapstone.dylib"
STATIC_LIBRARY_FILE = 'libcapstone.a'
elif SYSTEM in ('win32', 'cygwin'):
@ -33,7 +34,7 @@ elif SYSTEM in ('win32', 'cygwin'):
LIBRARY_FILE = "capstone.dll"
STATIC_LIBRARY_FILE = None
else:
VERSIONED_LIBRARY_FILE = "libcapstone.so.4"
VERSIONED_LIBRARY_FILE = "libcapstone.so.{}".format(VERSION_PARTS[0])
LIBRARY_FILE = "libcapstone.so"
STATIC_LIBRARY_FILE = 'libcapstone.a'