5 from distutils
import log
6 from distutils.core
import setup
7 from distutils.extension
import Extension
8 from distutils.command.build
import build
9 from Cython.Distutils
import build_ext
16 IS_64BITS = sys.maxsize > 2**32
19 ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
20 LIBS_DIR = os.path.join(ROOT_DIR,
'pyx',
'lib')
21 HEADERS_DIR = os.path.join(ROOT_DIR,
'pyx',
'include')
22 SRC_DIR = os.path.join(ROOT_DIR,
'src')
23 BUILD_DIR = SRC_DIR
if os.path.exists(SRC_DIR)
else os.path.join(ROOT_DIR,
'../..')
24 PYPACKAGE_DIR = os.path.join(ROOT_DIR,
'capstone')
25 CYPACKAGE_DIR = os.path.join(ROOT_DIR,
'pyx')
27 if SYSTEM ==
'darwin':
28 VERSIONED_LIBRARY_FILE =
"libcapstone.4.dylib"
29 LIBRARY_FILE =
"libcapstone.dylib"
30 STATIC_LIBRARY_FILE =
'libcapstone.a'
31 elif SYSTEM
in (
'win32',
'cygwin'):
32 VERSIONED_LIBRARY_FILE =
"capstone.dll"
33 LIBRARY_FILE =
"capstone.dll"
34 STATIC_LIBRARY_FILE =
None
36 VERSIONED_LIBRARY_FILE =
"libcapstone.so.4"
37 LIBRARY_FILE =
"libcapstone.so"
38 STATIC_LIBRARY_FILE =
'libcapstone.a'
40 compile_args = [
'-O3',
'-fomit-frame-pointer',
'-I' + HEADERS_DIR]
41 link_args = [
'-L' + LIBS_DIR]
43 ext_module_names = [
'arm',
'arm_const',
'arm64',
'arm64_const',
'm68k',
'm68k_const',
'm680x',
'm680x_const',
'mips',
'mips_const',
'ppc',
'ppc_const',
'x86',
'x86_const',
'sparc',
'sparc_const',
'systemz',
'sysz_const',
'xcore',
'xcore_const',
'tms320c64x',
'tms320c64x_const',
'evm',
'evm_const' ]
45 ext_modules = [Extension(
"capstone.ccapstone",
46 [
"pyx/ccapstone.pyx"],
47 libraries=[
"capstone"],
48 extra_compile_args=compile_args,
49 extra_link_args=link_args)]
50 ext_modules += [Extension(
"capstone.%s" % name,
51 [
"pyx/%s.pyx" % name],
52 extra_compile_args=compile_args,
53 extra_link_args=link_args)
54 for name
in ext_module_names]
57 shutil.rmtree(LIBS_DIR, ignore_errors=
True)
58 shutil.rmtree(HEADERS_DIR, ignore_errors=
True)
61 for fname
in os.listdir(PYPACKAGE_DIR):
62 if not fname.endswith(
'.py'):
65 if fname ==
'__init__.py':
66 shutil.copy(os.path.join(PYPACKAGE_DIR, fname), os.path.join(CYPACKAGE_DIR, fname))
68 shutil.copy(os.path.join(PYPACKAGE_DIR, fname), os.path.join(CYPACKAGE_DIR, fname +
'x'))
72 Prepare the capstone directory for a binary distribution or installation.
73 Builds shared libraries and copies header files.
75 Will use a src/ dir if one exists in the current directory, otherwise assumes it's in the repo
83 shutil.copytree(os.path.join(BUILD_DIR,
'include',
'capstone'), os.path.join(HEADERS_DIR,
'capstone'))
92 if not os.path.exists(
"build"): os.mkdir(
"build")
95 os.system(
'cmake -DCMAKE_BUILD_TYPE=RELEASE -DCAPSTONE_BUILD_TESTS=0 -DCAPSTONE_BUILD_STATIC=0 -G "NMake Makefiles" ..')
98 os.system(
"CAPSTONE_BUILD_CORE_ONLY=yes bash ./make.sh")
100 shutil.copy(VERSIONED_LIBRARY_FILE, os.path.join(LIBS_DIR, LIBRARY_FILE))
101 if STATIC_LIBRARY_FILE: shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR)
107 log.info(
'Copying python sources')
109 log.info(
'Building C extensions')
111 return build.run(self)
125 provides = [
'capstone'],
126 package_dir = {
'capstone' :
'pyx'},
127 packages = [
'capstone'],
130 cmdclass = {
'build_ext': build_ext,
'build': custom_build},
131 ext_modules = ext_modules,
132 author =
'Nguyen Anh Quynh',
133 author_email =
'aquynh@gmail.com',
134 description =
'Capstone disassembly engine',
135 url =
'http://www.capstone-engine.org',
137 'License :: OSI Approved :: BSD License',
138 'Programming Language :: Python :: 2',
140 include_package_data=
True,
142 "capstone": [
"lib/*",
"include/capstone/*"],
static RzBuffer * build(RzEgg *egg)