]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - Crypto/setup.py
allmydata.Crypto: fix all internal imports
[tahoe-lafs/tahoe-lafs.git] / Crypto / setup.py
1 #! /usr/bin/env python
2
3 __revision__ = "$Id: setup.py,v 1.30 2005/06/14 01:20:22 akuchling Exp $"
4
5 from distutils import core
6 from distutils.core import Extension
7 from distutils.command.build_ext import build_ext
8 import os, sys
9
10 if sys.version[0:1] == '1':
11     raise RuntimeError, ("The Python Cryptography Toolkit requires "
12                          "Python 2.x to build.")
13
14 debug_build_kw = {}
15
16 DEBUG_BUILD=False
17 # DEBUG_BUILD=True
18 if DEBUG_BUILD:
19     debug_build_kw.update({
20         'extra_compile_args': ['-O0', '-g',],
21         'extra_link_args': ['-g',],
22         'undef_macros': ['NDEBUG',], })
23
24 if sys.platform == 'win32':
25     HTONS_LIBS = ['ws2_32']
26     plat_ext = [
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"],
34                           **debug_build_kw)
35                ]
36 else:
37     HTONS_LIBS = []
38     plat_ext = []
39
40 # Functions for finding libraries and files, copied from Python's setup.py.
41
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.
46
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.
52     """
53
54     # Check the standard locations
55     for dir in std_dirs:
56         f = os.path.join(dir, filename)
57         if os.path.exists(f): return []
58
59     # Check the additional directories
60     for dir in paths:
61         f = os.path.join(dir, filename)
62         if os.path.exists(f):
63             return [dir]
64
65     # Not found anywhere
66     return None
67
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
72
73     filename = compiler.library_filename(libname, lib_type='static')
74     result = find_file(filename, std_dirs, paths)
75     return result
76
77
78 def cc_remove_option (compiler, option):
79     """
80     Remove option from Unix-style compiler.
81     """
82     for optlist in (compiler.compiler, compiler.compiler_so):
83         if option in optlist:
84             optlist.remove(option)
85
86
87 class PCTBuildExt (build_ext):
88     def build_extensions(self):
89         self.extensions += [
90             # Hash functions
91             Extension("Crypto.Hash.MD4",
92                       include_dirs=['src/'],
93                       sources=["src/MD4.c"],
94                       **debug_build_kw),
95             Extension("Crypto.Hash.SHA256",
96                       include_dirs=['src/'],
97                       sources=["src/SHA256.c"],
98                       **debug_build_kw),
99
100             # Block encryption algorithms
101             Extension("Crypto.Cipher.AES",
102                       include_dirs=['src/'],
103                       sources=["src/AES.c"],
104                       **debug_build_kw),
105             Extension("Crypto.Cipher.ARC2",
106                       include_dirs=['src/'],
107                       sources=["src/ARC2.c"],
108                       **debug_build_kw),
109             Extension("Crypto.Cipher.Blowfish",
110                       include_dirs=['src/'],
111                       sources=["src/Blowfish.c"],
112                       **debug_build_kw),
113             Extension("Crypto.Cipher.CAST",
114                       include_dirs=['src/'],
115                       sources=["src/CAST.c"],
116                       **debug_build_kw),
117             Extension("Crypto.Cipher.DES",
118                       include_dirs=['src/'],
119                       sources=["src/DES.c"],
120                       **debug_build_kw),
121             Extension("Crypto.Cipher.DES3",
122                       include_dirs=['src/'],
123                       sources=["src/DES3.c"],
124                       **debug_build_kw),
125
126             # Stream ciphers
127             Extension("Crypto.Cipher.ARC4",
128                       include_dirs=['src/'],
129                       sources=["src/ARC4.c"],
130                       **debug_build_kw),
131             Extension("Crypto.Cipher.XOR",
132                       include_dirs=['src/'],
133                       sources=["src/XOR.c"],
134                       **debug_build_kw),
135             ]
136
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)
144
145     def detect_modules (self):
146         lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
147         inc_dirs = self.compiler.include_dirs + ['/usr/include']
148         exts = []
149         if (self.compiler.find_library_file(lib_dirs, 'gmp')):
150             exts.append(Extension("Crypto.PublicKey._fastmath",
151                                   include_dirs=['src/'],
152                                   libraries=['gmp'],
153                                   sources=["src/_fastmath.c"]))
154         self.extensions += exts
155
156
157 kw = {'name':"pycrypto",
158       'version':"2.0.1",
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",
163
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"],
173                                **debug_build_kw)]
174      }
175
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',
187           ]
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']) )
191
192 core.setup(**kw)
193