46
49
if os.name == 'nt' or sys.platform == 'win32':
48
51
Libraries = ['Ws2_32']
49
def makeTellMeIf(original, what):
50
class tellMeIf(original):
51
def __init__(*a, **kw):
52
Libraries.extend(what)
53
return original.__init__(*a, **kw)
56
from distutils import cygwinccompiler
57
cygwinccompiler.Mingw32CCompiler = makeTellMeIf(cygwinccompiler.Mingw32CCompiler, ['eay32', 'ssl32'])
58
from distutils import msvccompiler
59
msvccompiler.MSVCCompiler = makeTellMeIf(msvccompiler.MSVCCompiler, ['libeay32', 'ssleay32'])
62
shutil.copy("C:\\OpenSSL\\ssleay32.dll", os.path.split(os.path.abspath(__file__))[0])
63
shutil.copy("C:\\OpenSSL\\libeay32.dll", os.path.split(os.path.abspath(__file__))[0])
64
package_data = {'': ['ssleay32.dll', 'libeay32.dll']}
55
class BuildExtension(build_ext):
57
A custom command that semiautomatically finds dependencies required by
61
user_options = (build_ext.user_options +
62
[("with-openssl=", None,
63
"directory where OpenSSL is installed")])
69
def finalize_options(self):
71
Update build options with details about OpenSSL.
73
build_ext.finalize_options(self)
74
if self.with_openssl is None:
76
self.find_openssl_dlls()
77
self.add_openssl_compile_info()
80
def find_openssl(self):
82
Find OpenSSL's install directory.
85
dirs = os.environ.get("PATH").split(os.pathsep)
87
if os.path.exists(os.path.join(d, "openssl.exe")):
88
ssldir, bin = os.path.split(d)
90
ssldir, bin = os.path.split(ssldir)
91
potentials.append(ssldir)
92
childdirs = os.listdir(ssldir)
93
if "lib" in childdirs and "include" in childdirs:
94
self.with_openssl = ssldir
97
raise DistutilsFileError(
98
"Only found improper OpenSSL directories: %r" % (
101
raise DistutilsFileError("Could not find 'openssl.exe'")
104
def find_openssl_dlls(self):
106
Find OpenSSL's shared libraries.
108
self.openssl_dlls = []
109
self.find_openssl_dll("libssl32.dll", False)
110
if self.openssl_dlls:
111
self.openssl_mingw = True
113
self.find_openssl_dll("ssleay32.dll", True)
114
self.find_openssl_dll("libeay32.dll", True)
115
# add zlib to the mix if it looks like OpenSSL
116
# was linked with a private copy of it
117
self.find_openssl_dll("zlib1.dll", False)
120
def find_openssl_dll(self, name, required):
122
Find OpenSSL's shared library and its path after installation.
124
dllpath = os.path.join(self.with_openssl, "bin", name)
125
if not os.path.exists(dllpath):
127
raise DistutilsFileError("could not find '%s'" % name)
130
newpath = os.path.join(self.build_lib, "OpenSSL", name)
131
self.openssl_dlls.append((dllpath, newpath))
134
def add_openssl_compile_info(self):
136
Set up various compile and link parameters.
138
if self.compiler == "mingw32":
139
if self.openssl_mingw:
140
# Library path and library names are sane when OpenSSL is
143
libs = ["eay32", "ssl32"]
147
# Unlike when using the binary installer, which creates
148
# an atypical shared library name 'ssleay32', so we have
149
# to use this workaround.
150
if self.link_objects is None:
151
self.link_objects = []
152
for dllpath, _ in self.openssl_dlls:
153
dllname = os.path.basename(dllpath)
154
libname = os.path.splitext(dllname)[0] + ".a"
155
libpath = os.path.join(self.with_openssl,
156
"lib", "MinGW", libname)
157
self.link_objects.append(libpath)
160
libs = ["libeay32", "ssleay32"]
161
self.include_dirs.append(os.path.join(self.with_openssl, "include"))
162
self.library_dirs.append(os.path.join(self.with_openssl, libdir))
163
self.libraries.extend(libs)
168
Build extension modules and copy shared libraries.
171
for dllpath, newpath in self.openssl_dlls:
172
self.copy_file(dllpath, newpath)
175
def get_outputs(self):
177
Return a list of file paths built by this comand.
179
output = [pathpair[1] for pathpair in self.openssl_dlls]
180
output.extend(build_ext.get_outputs(self))
66
186
Libraries = ['ssl', 'crypto']
187
BuildExtension = build_ext
70
191
def mkExtension(name):