[3] | 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 | if sys.platform == 'win32': |
---|
| 15 | HTONS_LIBS = ['ws2_32'] |
---|
| 16 | plat_ext = [ |
---|
| 17 | Extension("Crypto.Util.winrandom", |
---|
| 18 | libraries = HTONS_LIBS + ['advapi32'], |
---|
| 19 | include_dirs=['src/'], |
---|
| 20 | sources=["src/winrand.c"]) |
---|
| 21 | ] |
---|
| 22 | else: |
---|
| 23 | HTONS_LIBS = [] |
---|
| 24 | plat_ext = [] |
---|
| 25 | |
---|
| 26 | # Functions for finding libraries and files, copied from Python's setup.py. |
---|
| 27 | |
---|
| 28 | def find_file(filename, std_dirs, paths): |
---|
| 29 | """Searches for the directory where a given file is located, |
---|
| 30 | and returns a possibly-empty list of additional directories, or None |
---|
| 31 | if the file couldn't be found at all. |
---|
| 32 | |
---|
| 33 | 'filename' is the name of a file, such as readline.h or libcrypto.a. |
---|
| 34 | 'std_dirs' is the list of standard system directories; if the |
---|
| 35 | file is found in one of them, no additional directives are needed. |
---|
| 36 | 'paths' is a list of additional locations to check; if the file is |
---|
| 37 | found in one of them, the resulting list will contain the directory. |
---|
| 38 | """ |
---|
| 39 | |
---|
| 40 | # Check the standard locations |
---|
| 41 | for dir in std_dirs: |
---|
| 42 | f = os.path.join(dir, filename) |
---|
| 43 | if os.path.exists(f): return [] |
---|
| 44 | |
---|
| 45 | # Check the additional directories |
---|
| 46 | for dir in paths: |
---|
| 47 | f = os.path.join(dir, filename) |
---|
| 48 | if os.path.exists(f): |
---|
| 49 | return [dir] |
---|
| 50 | |
---|
| 51 | # Not found anywhere |
---|
| 52 | return None |
---|
| 53 | |
---|
| 54 | def find_library_file(compiler, libname, std_dirs, paths): |
---|
| 55 | filename = compiler.library_filename(libname, lib_type='shared') |
---|
| 56 | result = find_file(filename, std_dirs, paths) |
---|
| 57 | if result is not None: return result |
---|
| 58 | |
---|
| 59 | filename = compiler.library_filename(libname, lib_type='static') |
---|
| 60 | result = find_file(filename, std_dirs, paths) |
---|
| 61 | return result |
---|
| 62 | |
---|
| 63 | class PCTBuildExt (build_ext): |
---|
| 64 | def build_extensions(self): |
---|
| 65 | self.extensions += [ |
---|
| 66 | # Hash functions |
---|
| 67 | Extension("Crypto.Hash.MD4", |
---|
| 68 | include_dirs=['src/'], |
---|
| 69 | sources=["src/MD4.c"]), |
---|
| 70 | Extension("Crypto.Hash.RIPEMD", |
---|
| 71 | include_dirs=['src/'], |
---|
| 72 | sources=["src/RIPEMD.c"], |
---|
| 73 | libraries=HTONS_LIBS), |
---|
| 74 | Extension("Crypto.Hash.SHA256", |
---|
| 75 | include_dirs=['src/'], |
---|
| 76 | sources=["src/SHA256.c"]), |
---|
| 77 | |
---|
| 78 | # Block encryption algorithms |
---|
| 79 | Extension("Crypto.Cipher.AES", |
---|
| 80 | include_dirs=['src/'], |
---|
| 81 | sources=["src/AES.c"]), |
---|
| 82 | Extension("Crypto.Cipher.ARC2", |
---|
| 83 | include_dirs=['src/'], |
---|
| 84 | sources=["src/ARC2.c"]), |
---|
| 85 | Extension("Crypto.Cipher.Blowfish", |
---|
| 86 | include_dirs=['src/'], |
---|
| 87 | sources=["src/Blowfish.c"]), |
---|
| 88 | Extension("Crypto.Cipher.CAST", |
---|
| 89 | include_dirs=['src/'], |
---|
| 90 | sources=["src/CAST.c"]), |
---|
| 91 | Extension("Crypto.Cipher.DES", |
---|
| 92 | include_dirs=['src/'], |
---|
| 93 | sources=["src/DES.c"]), |
---|
| 94 | Extension("Crypto.Cipher.DES3", |
---|
| 95 | include_dirs=['src/'], |
---|
| 96 | sources=["src/DES3.c"]), |
---|
| 97 | Extension("Crypto.Cipher.IDEA", |
---|
| 98 | include_dirs=['src/'], |
---|
| 99 | sources=["src/IDEA.c"], |
---|
| 100 | libraries=HTONS_LIBS), |
---|
| 101 | Extension("Crypto.Cipher.RC5", |
---|
| 102 | include_dirs=['src/'], |
---|
| 103 | sources=["src/RC5.c"]), |
---|
| 104 | |
---|
| 105 | # Stream ciphers |
---|
| 106 | Extension("Crypto.Cipher.ARC4", |
---|
| 107 | include_dirs=['src/'], |
---|
| 108 | sources=["src/ARC4.c"]), |
---|
| 109 | Extension("Crypto.Cipher.XOR", |
---|
| 110 | include_dirs=['src/'], |
---|
| 111 | sources=["src/XOR.c"]), |
---|
| 112 | ] |
---|
| 113 | |
---|
| 114 | # Detect which modules should be compiled |
---|
| 115 | self.detect_modules() |
---|
| 116 | build_ext.build_extensions(self) |
---|
| 117 | |
---|
| 118 | def detect_modules (self): |
---|
| 119 | lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib'] |
---|
| 120 | inc_dirs = self.compiler.include_dirs + ['/usr/include'] |
---|
| 121 | exts = [] |
---|
| 122 | if (self.compiler.find_library_file(lib_dirs, 'gmp')): |
---|
| 123 | exts.append(Extension("Crypto.PublicKey._fastmath", |
---|
| 124 | include_dirs=['src/'], |
---|
| 125 | libraries=['gmp'], |
---|
| 126 | sources=["src/_fastmath.c"])) |
---|
| 127 | self.extensions += exts |
---|
| 128 | |
---|
| 129 | kw = {'name':"pycrypto", |
---|
| 130 | 'version':"2.0.1", |
---|
| 131 | 'description':"Cryptographic modules for Python.", |
---|
| 132 | 'author':"A.M. Kuchling", |
---|
| 133 | 'author_email':"amk@amk.ca", |
---|
| 134 | 'url':"http://www.amk.ca/python/code/crypto", |
---|
| 135 | |
---|
| 136 | 'cmdclass' : {'build_ext':PCTBuildExt}, |
---|
| 137 | 'packages' : ["Crypto", "Crypto.Hash", "Crypto.Cipher", "Crypto.Util", |
---|
| 138 | "Crypto.Protocol", "Crypto.PublicKey"], |
---|
| 139 | 'package_dir' : { "Crypto":"." }, |
---|
| 140 | # One module is defined here, because build_ext won't be |
---|
| 141 | # called unless there's at least one extension module defined. |
---|
| 142 | 'ext_modules':[Extension("Crypto.Hash.MD2", |
---|
| 143 | include_dirs=['src/'], |
---|
| 144 | sources=["src/MD2.c"])], |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | # If we're running Python 2.3, add extra information |
---|
| 148 | if hasattr(core, 'setup_keywords'): |
---|
| 149 | if 'classifiers' in core.setup_keywords: |
---|
| 150 | kw['classifiers'] = [ |
---|
| 151 | 'Development Status :: 4 - Beta', |
---|
| 152 | 'License :: Public Domain', |
---|
| 153 | 'Intended Audience :: Developers', |
---|
| 154 | 'Operating System :: Unix', |
---|
| 155 | 'Operating System :: Microsoft :: Windows', |
---|
| 156 | 'Operating System :: MacOS :: MacOS X', |
---|
| 157 | 'Topic :: Security :: Cryptography', |
---|
| 158 | ] |
---|
| 159 | if 'download_url' in core.setup_keywords: |
---|
| 160 | kw['download_url'] = ('http://www.amk.ca/files/python/crypto/' |
---|
| 161 | '%s-%s.tar.gz' % (kw['name'], kw['version']) ) |
---|
| 162 | |
---|
| 163 | core.setup(**kw) |
---|
| 164 | |
---|