566a2eb8ab71c4db11b9c56d7cbd44d2de42d86b
[packages/capstone.git] / debian / patches / fix_python_bindings
1 Description: Fix build system for Python bindings.
2  The build system in capstone for the Python bindings works by installing
3  the library with the headers, and then building the bindings.  Change that
4  to allow building them in the same run we create the library, and search
5  for the versioned library instead of the .so one, removing the dependency
6  on libcapstone-dev.
7 Author: David Martínez Moreno <ender@debian.org>
8 Forwarded: no
9 Last-Update: 2014-05-05
10
11 --- a/bindings/python/setup_cython.py
12 +++ b/bindings/python/setup_cython.py
13 @@ -6,19 +6,21 @@
14  VERSION = '2.1'
15  
16  compile_args = ['-O3', '-fomit-frame-pointer']
17 +include_dirs = ['../../include']
18 +library_dirs = ['../../']
19  
20 -ext_modules = [ Extension("capstone.capstone", ["pyx/capstone.pyx"], extra_compile_args=compile_args),
21 -    Extension("capstone.ccapstone", ["pyx/ccapstone.pyx"], libraries=["capstone"], extra_compile_args=compile_args),
22 -    Extension("capstone.arm", ["pyx/arm.pyx"], extra_compile_args=compile_args),
23 -    Extension("capstone.arm_const", ["pyx/arm_const.pyx"], extra_compile_args=compile_args),
24 -    Extension("capstone.arm64", ["pyx/arm64.pyx"], extra_compile_args=compile_args),
25 -    Extension("capstone.arm64_const", ["pyx/arm64_const.pyx"], extra_compile_args=compile_args),
26 -    Extension("capstone.mips", ["pyx/mips.pyx"], extra_compile_args=compile_args),
27 -    Extension("capstone.mips_const", ["pyx/mips_const.pyx"], extra_compile_args=compile_args),
28 -    Extension("capstone.ppc", ["pyx/ppc.pyx"], extra_compile_args=compile_args),
29 -    Extension("capstone.ppc_const", ["pyx/ppc_const.pyx"], extra_compile_args=compile_args),
30 -    Extension("capstone.x86", ["pyx/x86.pyx"], extra_compile_args=compile_args),
31 -    Extension("capstone.x86_const", ["pyx/x86_const.pyx"], extra_compile_args=compile_args)
32 +ext_modules = [ Extension("capstone.capstone", ["pyx/capstone.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
33 +    Extension("capstone.ccapstone", ["pyx/ccapstone.pyx"], libraries=["capstone"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
34 +    Extension("capstone.arm", ["pyx/arm.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
35 +    Extension("capstone.arm_const", ["pyx/arm_const.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
36 +    Extension("capstone.arm64", ["pyx/arm64.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
37 +    Extension("capstone.arm64_const", ["pyx/arm64_const.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
38 +    Extension("capstone.mips", ["pyx/mips.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
39 +    Extension("capstone.mips_const", ["pyx/mips_const.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
40 +    Extension("capstone.ppc", ["pyx/ppc.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
41 +    Extension("capstone.ppc_const", ["pyx/ppc_const.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
42 +    Extension("capstone.x86", ["pyx/x86.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs),
43 +    Extension("capstone.x86_const", ["pyx/x86_const.pyx"], extra_compile_args=compile_args, include_dirs=include_dirs, library_dirs=library_dirs)
44  ]
45  
46  # clean package directory first
47 --- a/bindings/python/pyx/ccapstone.pxd
48 +++ b/bindings/python/pyx/ccapstone.pxd
49 @@ -3,7 +3,7 @@
50  from libcpp cimport bool
51  from libc.stdint cimport uint8_t, uint64_t, uint16_t
52  
53 -cdef extern from "<capstone/capstone.h>":
54 +cdef extern from "<capstone.h>":
55  
56      ctypedef size_t csh
57  
58 --- a/bindings/python/Makefile
59 +++ b/bindings/python/Makefile
60 @@ -27,7 +27,7 @@
61         # clean up first
62         rm -rf build
63         # then install
64 -       python setup_cython.py install
65 +       python setup_cython.py install $(OPTS)
66  
67  clean:
68         rm -rf capstone/*.pyc
69 --- a/bindings/python/capstone/capstone.py
70 +++ b/bindings/python/capstone/capstone.py
71 @@ -124,7 +124,7 @@
72      __file__ = inspect.getfile(inspect.currentframe())
73  
74  _lib_path = split(__file__)[0]
75 -_all_libs = ['libcapstone.dll', 'libcapstone.so', 'libcapstone.dylib']
76 +_all_libs = ['libcapstone.dll', 'libcapstone.so.2', 'libcapstone.dylib']
77  _found = False
78  
79  for _lib in _all_libs: