PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/OldUniversityStuff/ZIKS/pycrypto-2.0.1/setup.py

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