3 __revision__ = "$Id: setup.py,v 1.30 2005/06/14 01:20:22 akuchling Exp $"
5 from distutils import core
6 from distutils.core import Extension
7 from distutils.command.build_ext import build_ext
10 if sys.version[0:1] == '1':
11 raise RuntimeError, ("The Python Cryptography Toolkit requires "
12 "Python 2.x to build.")
19 debug_build_kw.update({
20 'extra_compile_args': ['-O0', '-g',],
21 'extra_link_args': ['-g',],
22 'undef_macros': ['NDEBUG',], })
24 if sys.platform == 'win32':
25 HTONS_LIBS = ['ws2_32']
27 Extension("Crypto.Util.winrandom",
28 libraries = HTONS_LIBS + ['advapi32'],
29 include_dirs=['src/'],
30 extra_compile_args=['-O0 -g',],
31 extra_link_args=['-g',],
32 undef_macros=['NDEBUG',],
33 sources=["src/winrand.c"],
40 # Functions for finding libraries and files, copied from Python's setup.py.
42 def find_file(filename, std_dirs, paths):
43 """Searches for the directory where a given file is located,
44 and returns a possibly-empty list of additional directories, or None
45 if the file couldn't be found at all.
47 'filename' is the name of a file, such as readline.h or libcrypto.a.
48 'std_dirs' is the list of standard system directories; if the
49 file is found in one of them, no additional directives are needed.
50 'paths' is a list of additional locations to check; if the file is
51 found in one of them, the resulting list will contain the directory.
54 # Check the standard locations
56 f = os.path.join(dir, filename)
57 if os.path.exists(f): return []
59 # Check the additional directories
61 f = os.path.join(dir, filename)
68 def find_library_file(compiler, libname, std_dirs, paths):
69 filename = compiler.library_filename(libname, lib_type='shared')
70 result = find_file(filename, std_dirs, paths)
71 if result is not None: return result
73 filename = compiler.library_filename(libname, lib_type='static')
74 result = find_file(filename, std_dirs, paths)
78 def cc_remove_option (compiler, option):
80 Remove option from Unix-style compiler.
82 for optlist in (compiler.compiler, compiler.compiler_so):
84 optlist.remove(option)
87 class PCTBuildExt (build_ext):
88 def build_extensions(self):
91 Extension("Crypto.Hash.MD4",
92 include_dirs=['src/'],
93 sources=["src/MD4.c"],
95 Extension("Crypto.Hash.SHA256",
96 include_dirs=['src/'],
97 sources=["src/SHA256.c"],
100 # Block encryption algorithms
101 Extension("Crypto.Cipher.AES",
102 include_dirs=['src/'],
103 sources=["src/AES.c"],
105 Extension("Crypto.Cipher.ARC2",
106 include_dirs=['src/'],
107 sources=["src/ARC2.c"],
109 Extension("Crypto.Cipher.Blowfish",
110 include_dirs=['src/'],
111 sources=["src/Blowfish.c"],
113 Extension("Crypto.Cipher.CAST",
114 include_dirs=['src/'],
115 sources=["src/CAST.c"],
117 Extension("Crypto.Cipher.DES",
118 include_dirs=['src/'],
119 sources=["src/DES.c"],
121 Extension("Crypto.Cipher.DES3",
122 include_dirs=['src/'],
123 sources=["src/DES3.c"],
127 Extension("Crypto.Cipher.ARC4",
128 include_dirs=['src/'],
129 sources=["src/ARC4.c"],
131 Extension("Crypto.Cipher.XOR",
132 include_dirs=['src/'],
133 sources=["src/XOR.c"],
137 # Detect which modules should be compiled
138 self.detect_modules()
139 if self.compiler.compiler_type == 'unix':
140 if os.uname()[4] == 'm68k':
141 # work around ICE on m68k machines in gcc 4.0.1
142 cc_remove_option(self.compiler, "-O3")
143 build_ext.build_extensions(self)
145 def detect_modules (self):
146 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
147 inc_dirs = self.compiler.include_dirs + ['/usr/include']
149 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
150 exts.append(Extension("Crypto.PublicKey._fastmath",
151 include_dirs=['src/'],
153 sources=["src/_fastmath.c"]))
154 self.extensions += exts
157 kw = {'name':"pycrypto",
159 'description':"Cryptographic modules for Python.",
160 'author':"A.M. Kuchling",
161 'author_email':"amk@amk.ca",
162 'url':"http://www.amk.ca/python/code/crypto",
164 'cmdclass' : {'build_ext':PCTBuildExt},
165 'packages' : ["Crypto", "Crypto.Hash", "Crypto.Cipher", "Crypto.Util",
166 "Crypto.Protocol", "Crypto.PublicKey"],
167 'package_dir' : { "Crypto":"." },
168 # One module is defined here, because build_ext won't be
169 # called unless there's at least one extension module defined.
170 'ext_modules':[Extension("Crypto.Hash.MD2",
171 include_dirs=['src/'],
172 sources=["src/MD2.c"],
176 # If we're running Python 2.3, add extra information
177 if hasattr(core, 'setup_keywords'):
178 if 'classifiers' in core.setup_keywords:
179 kw['classifiers'] = [
180 'Development Status :: 4 - Beta',
181 'License :: Public Domain',
182 'Intended Audience :: Developers',
183 'Operating System :: Unix',
184 'Operating System :: Microsoft :: Windows',
185 'Operating System :: MacOS :: MacOS X',
186 'Topic :: Security :: Cryptography',
188 if 'download_url' in core.setup_keywords:
189 kw['download_url'] = ('http://www.amk.ca/files/python/crypto/'
190 '%s-%s.tar.gz' % (kw['name'], kw['version']) )