-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·179 lines (153 loc) · 5.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python
from distutils.core import setup, Extension
from distutils.command.install import install
from distutils.command.build import build
DEBUG = 1
perl = 'perl'
import os
import sys
import subprocess
MULTI_PERL = os.path.isfile("MULTI_PERL")
BOOT_FROM_PERL = os.path.isfile("BOOT_FROM_PERL")
p = os.popen(perl + ' ./opts.pl')
perl_ccopts = p.readline()
perl_ldopts = p.readline()
p.close()
ext_name = "perl"
include_dirs = []
macros = []
cc_extra = []
for x in perl_ccopts.split():
if x[:2] == '-I':
include_dirs.append(x[2:])
else:
cc_extra.append(x)
lib_dirs = []
libs = []
ld_extra = []
o_extra = []
sym_extra = []
extra_ext = []
# Hack name to get it to compile as C++ file on Windows
svrv_object_c_name = "svrv_object.c"
if sys.platform[:3] == "win":
import shutil
svrv_object_c_name = "svrv_object.cpp"
if os.path.exists(svrv_object_c_name):
os.chmod(svrv_object_c_name, 0o777)
os.unlink(svrv_object_c_name)
shutil.copy("svrv_object.c", svrv_object_c_name)
sources = ['perlmodule.c',
'lang_lock.c',
'lang_map.c',
svrv_object_c_name,
'pyo.c',
'try_perlapi.c',
]
if BOOT_FROM_PERL:
cc_extra.append("-DBOOT_FROM_PERL")
else:
for x in perl_ldopts.split():
if x[:2] == '-L':
lib_dirs.append(x[2:])
elif x[:2] == '-l' and sys.platform != 'win32':
libs.append(x[2:])
elif x[:1] != '-' and (x[-3:] == '.so' or
x[-2:] == '.o' or
x[-2:] == '.a'
):
o_extra.append(x)
else:
ld_extra.append(x)
if not os.path.isfile("perlxsi.c"):
os.system(perl + " -MExtUtils::Embed -e xsinit")
sources.append('perlxsi.c');
# Try to figure out if we use dlopen on this platform
p = os.popen(perl + ' -V:dlsrc')
dlsrc = p.readline()
p.close()
if dlsrc == "dlsrc='dl_dlopen.xs';\n":
ext_name = "perl2"
cc_extra.append("-DDL_HACK")
extra_ext.append(Extension(name = "perl",
sources = ["dlhack.c"],
libraries= ["dl"],
))
if MULTI_PERL:
cc_extra.append("-DMULTI_PERL")
sources.append('thrd_ctx.c')
if not os.path.isfile("try_perlapi.c") or \
os.path.getmtime("try_perlapi.c") < os.path.getmtime("try_perlapi.pl"):
os.system(perl + " try_perlapi.pl")
if sys.platform == 'win32':
libs.append('perl56')
for x in ['15','16','20']:
if os.access(os.path.join(sys.prefix, 'libs', 'python'+x+'.lib'), os.F_OK):
libs.append('python'+x)
sym_extra.append('get_thread_ctx')
sym_extra.append('sv2pyo')
sym_extra.append('pyo2sv')
sym_extra.append('newPerlPyObject_noinc')
sym_extra.append('newPerlPyObject_inc')
sym_extra.append('PerlPyObject_pyo')
sym_extra.append('PerlPyObject_pyo_or_null')
sym_extra.append('vtbl_free_pyo')
if DEBUG:
print(("Macros:", macros))
print(("Include: ", include_dirs))
print(("Extra CC: ", cc_extra))
print(("Obj: ", o_extra))
print(("Libs:", libs))
print(("Lib dirs:", lib_dirs))
print(("Extra LD: ", ld_extra))
ext_modules = []
ext_modules.append(Extension(name = ext_name,
sources = sources,
define_macros = macros,
include_dirs = include_dirs,
extra_compile_args = cc_extra,
extra_objects = o_extra,
libraries = libs,
library_dirs = lib_dirs,
extra_link_args = ld_extra,
export_symbols = sym_extra,
))
ext_modules.extend(extra_ext)
class build_perl(build):
def run(self):
os.chdir('Python-Object')
build.spawn(self, ['perl','Makefile.PL', 'INSTALLDIRS=vendor'], 'Python-Object')
build.spawn(self, ['make'])
os.chdir('..')
build.run(self)
class test(build):
def run(self):
cwd=os.getcwd()
ldpath = '%s/Python-Object/blib/arch/auto/Python/Object' % cwd
perllib = '%s/Python-Object/blib/lib' % cwd
pypath = '%s/%s' % (cwd, self.build_lib)
os.system('LD_LIBRARY_PATH="%s" PERL5LIB="%s" PYTHONPATH="%s" python test.py' % (ldpath, perllib, pypath))
build.run(self)
class my_install(install):
def run(self):
cur_dir = os.getcwd()
if self.root is None:
self.root = ''
os.chdir('Python-Object')
install.spawn(self, ["make", "DESTDIR=%s" % self.root, "install"])
os.chdir('..')
if "-DMULTI_PERL" in cc_extra:
cc_extra.pop(cc_extra.index("-DMULTI_PERL"))
sources.pop(sources.index('thrd_ctx.c'))
# Run actual install
install.run(self)
setup (name = "pyperl",
version = "1.0.1",
description = "Embed a Perl interpreter",
url = "http://www.ActiveState.com",
author = "ActiveState",
author_email= "gisle@ActiveState.com",
py_modules = ['dbi', 'dbi2', 'perlpickle', 'perlmod'],
ext_modules = ext_modules,
cmdclass = { 'install': my_install, 'build': build_perl, 'test': test }
)