-
Notifications
You must be signed in to change notification settings - Fork 57
/
setup.py
149 lines (122 loc) · 5.9 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
#!/usr/bin/env python
"""
Distutils/setuptools installer for M2Crypto.
Copyright (c) 1999-2004, Ng Pheng Siong. All rights reserved.
Portions created by Open Source Applications Foundation (OSAF) are
Copyright (C) 2004-2007 OSAF. All Rights Reserved.
Copyright 2008-2009 Heikki Toivonen. All rights reserved.
Copyright 2014 Martin Paljak
"""
import os, sys, platform
from setuptools import setup
from setuptools.command import build_ext
from distutils.core import Extension
from distutils.spawn import find_executable
class _M2CryptoBuildExt(build_ext.build_ext):
'''Specialization of build_ext to enable swig_opts to inherit any
include_dirs settings made at the command line or in a setup.cfg file'''
user_options = build_ext.build_ext.user_options + \
[('openssl=', 'o', 'Prefix for OpenSSL installation location')]
def initialize_options(self):
'''Overload to enable custom OpenSSL settings to be picked up'''
build_ext.build_ext.initialize_options(self)
# openssl is the attribute corresponding to openssl directory prefix
# command line option
if os.name == 'nt':
self.libraries = ['ssleay32', 'libeay32']
self.openssl = 'c:\\pkg'
else:
self.libraries = ['ssl', 'crypto']
self.openssl = '/usr'
def add_multiarch_paths(self):
# Debian/Ubuntu multiarch support.
# https://wiki.ubuntu.com/MultiarchSpec
if not find_executable('dpkg-architecture'):
return
tmpfile = os.path.join(self.build_temp, 'multiarch')
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
ret = os.system(
'dpkg-architecture -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
tmpfile)
try:
if ret >> 8 == 0:
with open(tmpfile) as fp:
multiarch_path_component = fp.readline().strip()
self.library_dirs.append(os.path.join('/usr/lib/' + multiarch_path_component))
self.include_dirs.append(os.path.join('/usr/include/' + multiarch_path_component))
finally:
os.unlink(tmpfile)
def finalize_options(self):
'''Overloaded build_ext implementation to append custom openssl
include file and library linking options'''
build_ext.build_ext.finalize_options(self)
self.add_multiarch_paths()
opensslIncludeDir = os.path.join(self.openssl, 'include')
opensslLibraryDir = os.path.join(self.openssl, 'lib')
self.swig_opts = ['-I%s' % i for i in self.include_dirs + \
[opensslIncludeDir, os.path.join(opensslIncludeDir, "openssl")]]
self.swig_opts.append('-includeall')
self.swig_opts.append('-modern')
# Fedora does hat tricks.
if platform.linux_distribution()[0] in ['Fedora', 'CentOS']:
if platform.architecture()[0] == '64bit':
self.swig_opts.append('-D__x86_64__')
elif platform.architecture()[0] == '32bit':
self.swig_opts.append('-D__i386__')
self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir),
os.path.join(os.getcwd(), 'SWIG')]
if sys.platform == 'cygwin':
# Cygwin SHOULD work (there's code in distutils), but
# if one first starts a Windows command prompt, then bash,
# the distutils code does not seem to work. If you start
# Cygwin directly, then it would work even without this change.
# Someday distutils will be fixed and this won't be needed.
self.library_dirs += [os.path.join(self.openssl, 'bin')]
self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)]
if sys.platform == 'darwin':
my_extra_compile_args = ["-Wno-deprecated-declarations"]
else:
my_extra_compile_args = []
m2crypto = Extension(name = 'M2Crypto.__m2crypto',
sources = ['SWIG/_m2crypto.i'],
extra_compile_args = ['-DTHREADING'] + my_extra_compile_args,
#extra_link_args = ['-Wl,-search_paths_first'], # Uncomment to build Universal Mac binaries
)
setup(name = 'M2Crypto',
version = '0.22.3',
description = 'M2Crypto: A Python crypto and SSL toolkit',
long_description = '''\
M2Crypto is the most complete Python wrapper for OpenSSL featuring RSA, DSA,
DH, EC, HMACs, message digests, symmetric ciphers (including AES); SSL
functionality to implement clients and servers; HTTPS extensions to Python's
httplib, urllib, and xmlrpclib; unforgeable HMAC'ing AuthCookies for web
session management; FTP/TLS client and server; S/MIME; ZServerSSL: A HTTPS
server for Zope and ZSmime: An S/MIME messenger for Zope. M2Crypto can also be
used to provide SSL for Twisted. Smartcards supported through the Engine
interface.''',
license = 'BSD-style license',
platforms = ['any'],
author = 'Ng Pheng Siong',
author_email = 'ngps at sandbox rulemaker net',
maintainer = 'Martin Paljak',
maintainer_email = '[email protected]',
url = 'https://github.com/martinpaljak/M2Crypto',
packages = ['M2Crypto', 'M2Crypto.SSL'],
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Security :: Cryptography',
'Topic :: Software Development :: Libraries :: Python Modules',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: Implementation :: CPython'
],
ext_modules = [m2crypto],
test_suite='tests.alltests.suite',
cmdclass = {'build_ext': _M2CryptoBuildExt}
)