Fix setup.py to use setuptools and put the libcapstone.so in the right place.
This commit is contained in:
parent
b24d991e3c
commit
40a42b4939
|
@ -1,4 +1,4 @@
|
||||||
recursive-include src *
|
recursive-include capstone *
|
||||||
recursive-include prebuilt *
|
recursive-include prebuilt *
|
||||||
include LICENSE.TXT
|
include LICENSE.TXT
|
||||||
include README
|
include README
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
|
@ -9,8 +8,8 @@ import sys
|
||||||
from distutils import log
|
from distutils import log
|
||||||
from distutils import dir_util
|
from distutils import dir_util
|
||||||
from distutils.command.build_clib import build_clib
|
from distutils.command.build_clib import build_clib
|
||||||
from distutils.command.sdist import sdist
|
from setuptools.command.sdist import sdist
|
||||||
from distutils.core import setup
|
from setuptools import setup
|
||||||
from distutils.sysconfig import get_python_lib
|
from distutils.sysconfig import get_python_lib
|
||||||
|
|
||||||
# prebuilt libraries for Windows - for sdist
|
# prebuilt libraries for Windows - for sdist
|
||||||
|
@ -35,8 +34,6 @@ if "--user" in sys.argv:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
SETUP_DATA_FILES = []
|
|
||||||
|
|
||||||
# adapted from commit e504b81 of Nguyen Tan Cong
|
# adapted from commit e504b81 of Nguyen Tan Cong
|
||||||
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
|
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
|
||||||
is_64bits = sys.maxsize > 2**32
|
is_64bits = sys.maxsize > 2**32
|
||||||
|
@ -55,6 +52,8 @@ def copy_sources():
|
||||||
|
|
||||||
dir_util.copy_tree("../../arch", "src/arch/")
|
dir_util.copy_tree("../../arch", "src/arch/")
|
||||||
dir_util.copy_tree("../../include", "src/include/")
|
dir_util.copy_tree("../../include", "src/include/")
|
||||||
|
if SYSTEM == "win32":
|
||||||
|
dir_util.copy_tree("../../msvc/headers", "src/msvc/headers")
|
||||||
|
|
||||||
src.extend(glob.glob("../../*.[ch]"))
|
src.extend(glob.glob("../../*.[ch]"))
|
||||||
src.extend(glob.glob("../../*.mk"))
|
src.extend(glob.glob("../../*.mk"))
|
||||||
|
@ -77,6 +76,14 @@ class custom_sdist(sdist):
|
||||||
"""Reshuffle files for distribution."""
|
"""Reshuffle files for distribution."""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
for filename in (glob.glob("capstone/*.dll")
|
||||||
|
+ glob.glob("capstone/*.so")
|
||||||
|
+ glob.glob("capstone/*.dylib")):
|
||||||
|
try:
|
||||||
|
os.unlink(filename)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# if prebuilt libraries are existent, then do not copy source
|
# if prebuilt libraries are existent, then do not copy source
|
||||||
if os.path.exists(PATH_LIB64) and os.path.exists(PATH_LIB32):
|
if os.path.exists(PATH_LIB64) and os.path.exists(PATH_LIB32):
|
||||||
return sdist.run(self)
|
return sdist.run(self)
|
||||||
|
@ -108,17 +115,16 @@ class custom_build_clib(build_clib):
|
||||||
if SYSTEM in ("win32", "cygwin"):
|
if SYSTEM in ("win32", "cygwin"):
|
||||||
# if Windows prebuilt library is available, then include it
|
# if Windows prebuilt library is available, then include it
|
||||||
if is_64bits and os.path.exists(PATH_LIB64):
|
if is_64bits and os.path.exists(PATH_LIB64):
|
||||||
SETUP_DATA_FILES.append(PATH_LIB64)
|
shutil.copy(PATH_LIB64, "capstone")
|
||||||
return
|
return
|
||||||
elif os.path.exists(PATH_LIB32):
|
elif os.path.exists(PATH_LIB32):
|
||||||
SETUP_DATA_FILES.append(PATH_LIB32)
|
shutil.copy(PATH_LIB32, "capstone")
|
||||||
return
|
return
|
||||||
|
|
||||||
# build library from source if src/ is existent
|
# build library from source if src/ is existent
|
||||||
if not os.path.exists('src'):
|
if not os.path.exists('src'):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
for (lib_name, build_info) in libraries:
|
for (lib_name, build_info) in libraries:
|
||||||
log.info("building '%s' library", lib_name)
|
log.info("building '%s' library", lib_name)
|
||||||
|
|
||||||
|
@ -135,25 +141,25 @@ class custom_build_clib(build_clib):
|
||||||
os.system('cmake -DCMAKE_BUILD_TYPE=RELEASE -DCAPSTONE_BUILD_TESTS=0 -DCAPSTONE_BUILD_STATIC=0 -G "NMake Makefiles" ..')
|
os.system('cmake -DCMAKE_BUILD_TYPE=RELEASE -DCAPSTONE_BUILD_TESTS=0 -DCAPSTONE_BUILD_STATIC=0 -G "NMake Makefiles" ..')
|
||||||
os.system("nmake")
|
os.system("nmake")
|
||||||
os.chdir("..")
|
os.chdir("..")
|
||||||
SETUP_DATA_FILES.append("src/build/capstone.dll")
|
so = "src/build/capstone.dll"
|
||||||
elif SYSTEM == "cygwin":
|
elif SYSTEM == "cygwin":
|
||||||
os.chmod("make.sh", stat.S_IREAD|stat.S_IEXEC)
|
os.chmod("make.sh", stat.S_IREAD|stat.S_IEXEC)
|
||||||
if is_64bits:
|
if is_64bits:
|
||||||
os.system("CAPSTONE_BUILD_CORE_ONLY=yes ./make.sh cygwin-mingw64")
|
os.system("CAPSTONE_BUILD_CORE_ONLY=yes ./make.sh cygwin-mingw64")
|
||||||
else:
|
else:
|
||||||
os.system("CAPSTONE_BUILD_CORE_ONLY=yes ./make.sh cygwin-mingw32")
|
os.system("CAPSTONE_BUILD_CORE_ONLY=yes ./make.sh cygwin-mingw32")
|
||||||
SETUP_DATA_FILES.append("src/capstone.dll")
|
|
||||||
|
so = "src/capstone.dll"
|
||||||
else: # Unix
|
else: # Unix
|
||||||
os.chmod("make.sh", stat.S_IREAD|stat.S_IEXEC)
|
os.chmod("make.sh", stat.S_IREAD|stat.S_IEXEC)
|
||||||
os.system("CAPSTONE_BUILD_CORE_ONLY=yes ./make.sh")
|
os.system("CAPSTONE_BUILD_CORE_ONLY=yes ./make.sh")
|
||||||
if SYSTEM == "darwin":
|
if SYSTEM == "darwin":
|
||||||
SETUP_DATA_FILES.append("src/libcapstone.dylib")
|
so = "src/libcapstone.dylib"
|
||||||
else: # Non-OSX
|
else: # Non-OSX
|
||||||
SETUP_DATA_FILES.append("src/libcapstone.so")
|
so = "src/libcapstone.so"
|
||||||
|
|
||||||
os.chdir("..")
|
os.chdir("..")
|
||||||
except:
|
shutil.copy(so, "capstone")
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def dummy_src():
|
def dummy_src():
|
||||||
|
@ -186,6 +192,9 @@ setup(
|
||||||
sources=dummy_src()
|
sources=dummy_src()
|
||||||
),
|
),
|
||||||
)],
|
)],
|
||||||
|
zip_safe=False,
|
||||||
data_files=[(SITE_PACKAGES, SETUP_DATA_FILES)],
|
include_package_data=True,
|
||||||
|
package_data={
|
||||||
|
"capstone": ["*.so", "*.dll", "*.dylib"],
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue