-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
162 lines (134 loc) · 4.35 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# =============================================================================
# >> IMPORTS
# =============================================================================
# Python
import os
import sys
import shutil
import time
from distutils.core import Extension
from distutils.core import setup
# =============================================================================
# >> PROJECT SOURCES
# =============================================================================
SOURCES = [
# binutils
'src/binutils_wrap.cpp',
'src/binutils_tools.cpp',
'src/binutils_hooks.cpp',
'src/binutils_scanner.cpp',
'src/binutils_callback.cpp',
# DynamicHooks
'src/thirdparty/DynamicHooks/DynamicHooks.cpp',
'src/thirdparty/DynamicHooks/utilities.cpp',
'src/thirdparty/DynamicHooks/asm.cpp',
]
# =============================================================================
# >> EXTRA INCLUDES
# =============================================================================
INCLUDE_DIRS = [
'src/thirdparty/boost',
'src/thirdparty/dyncall/include',
'src/thirdparty/AsmJit/include',
'src/thirdparty/DynamicHooks',
]
# =============================================================================
# >> LIBRARY SEARCH DIRECTORIES
# =============================================================================
LIBRARY_DIRS = [
'src/thirdparty/boost/lib',
'src/thirdparty/dyncall/lib',
'src/thirdparty/AsmJit/lib',
]
# =============================================================================
# >> LIBRARY NAMES
# =============================================================================
# Windows
if os.name == 'nt':
LIBRARIES = [
'libboost_python-mgw47-mt-1_54',
'libdyncall_s',
'libdyncallback_s',
'libdynload_s',
'libAsmJit',
]
# Linux
else:
LIBRARIES = [
'boost_python',
'dyncall_s',
'dyncallback_s',
'dynload_s',
'AsmJit',
]
# =============================================================================
# >> COMPILER FLAGS
# =============================================================================
COMPILER_FLAGS = [
# This disables annoying visibility warnings
'-Wno-attributes',
# Disable parentheses suggestions
'-Wno-parentheses',
# Disable "deprecated conversion from string..." warning
'-Wno-write-strings',
# Disable sign compare warnings
'-Wno-sign-compare',
]
# =============================================================================
# >> LINKER FLAGS
# =============================================================================
if os.name == 'nt':
LINKER_FLAGS = [
'-static-libgcc',
'-static-libstdc++',
]
else:
LINKER_FLAGS = [
]
# =============================================================================
# >> MACROS
# =============================================================================
MACROS = [
('BOOST_PYTHON_STATIC_LIB', ''),
('PYTHON_VERSION', sys.version_info[0]),
]
# =============================================================================
# >> MAIN
# =============================================================================
def main():
# Compile the binary
print('Compiling the binary...')
setup(
name='_binutils',
ext_modules=[
Extension(
'_binutils',
sources=SOURCES,
library_dirs=LIBRARY_DIRS,
libraries=LIBRARIES,
include_dirs=INCLUDE_DIRS,
extra_compile_args=COMPILER_FLAGS,
extra_link_args=LINKER_FLAGS,
define_macros=MACROS
),
]
)
# Remove possible garbage of last build
print('Removing possible garbage of last build...')
shutil.rmtree('binutils', True)
# Copy the binutils package to the current directory
print('Copying ../src/binutils/ to ../binutils/ ...')
shutil.copytree('src/binutils', 'binutils')
# Move the new compiled binary
name = '_binutils.' + ('pyd' if os.name == 'nt' else 'so')
print('Moving %s to ../binutils/ ...'% name)
shutil.move(
name,
'binutils/' + name
)
# Remove the build directory
print('Removing ../build/ ...')
shutil.rmtree('build', True)
now = time.time()
main()
print('Time elapsed: %.02f seconds.'% (time.time() - now))