setup.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/python -u
  2. #
  3. # Python Bindings for LZMA
  4. #
  5. # Copyright (c) 2004-2006 by Joachim Bauch, mail@joachim-bauch.de
  6. # 7-Zip Copyright (C) 1999-2005 Igor Pavlov
  7. # LZMA SDK Copyright (C) 1999-2005 Igor Pavlov
  8. #
  9. # This library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2.1 of the License, or (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. # Lesser General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Lesser General Public
  20. # License along with this library; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. #
  23. # $Id: setup.py 120 2006-09-29 21:14:23Z jojo $
  24. #
  25. import sys, os
  26. from warnings import warn
  27. # are we building an egg package?
  28. BUILD_EGG = 'bdist_egg' in sys.argv
  29. kw = {}
  30. if BUILD_EGG:
  31. from setuptools import setup, Extension
  32. kw['test_suite'] = 'tests'
  33. kw['zip_safe'] = False
  34. else:
  35. from distutils.core import setup, Extension
  36. PYTHON_VERSION=sys.version[:3]
  37. PYTHON_PREFIX=sys.prefix
  38. class UnsupportedPlatformWarning(Warning):
  39. pass
  40. # set this to any true value to enable multithreaded compression
  41. ENABLE_MULTITHREADING = True
  42. # set this to any true value to add the compatibility decoder
  43. # from version 0.0.3 to be able to decompress strings without
  44. # the end of stream mark and you don't know their lengths
  45. ENABLE_COMPATIBILITY = True
  46. # compile including debug symbols on Windows?
  47. COMPILE_DEBUG = False
  48. if os.name == 'posix':
  49. # This is the directory, your Python is installed in. It must contain the header and include files.
  50. PYTHON_INCLUDE_DIR="%s/include/python%s" % (PYTHON_PREFIX, PYTHON_VERSION)
  51. PYTHON_LIB_DIR="%s/lib/python%s" % (PYTHON_PREFIX, PYTHON_VERSION)
  52. libraries=[]
  53. else:
  54. PYTHON_INCLUDE_DIR="%s\\include" % (PYTHON_PREFIX)
  55. PYTHON_LIB_DIR="%s\\libs" % (PYTHON_PREFIX)
  56. libraries=['user32', 'oleaut32']
  57. include_dirs = [
  58. PYTHON_INCLUDE_DIR,
  59. ".",
  60. ]
  61. library_dirs = [
  62. PYTHON_LIB_DIR,
  63. ".",
  64. ]
  65. mt_platforms = (
  66. 'win32',
  67. )
  68. if ENABLE_MULTITHREADING and not sys.platform in mt_platforms:
  69. warn("""\
  70. Multithreading is not supported on the platform "%s",
  71. please contact mail@joachim-bauch.de for more informations.""" % (sys.platform), UnsupportedPlatformWarning)
  72. ENABLE_MULTITHREADING = 0
  73. descr = "Python bindings for the LZMA library by Igor Pavlov."
  74. long_descr = """PyLZMA provides a platform independent way to read and write data
  75. that has been compressed or can be decompressed by the LZMA library by Igor Pavlov."""
  76. try: version = open('version.txt', 'rb').read().strip()
  77. except: version = 'unknown'
  78. modules = ['py7zlib']
  79. c_files = ['pylzma.c', 'pylzma_decompressobj.c', 'pylzma_compressfile.cpp',
  80. 'pylzma_decompress.c', 'pylzma_compress.cpp', 'pylzma_guids.cpp']
  81. compile_args = []
  82. link_args = []
  83. macros = []
  84. if 'win' in sys.platform:
  85. macros.append(('WIN32', 1))
  86. if COMPILE_DEBUG:
  87. compile_args.append('/Zi')
  88. compile_args.append('/MTd')
  89. link_args.append('/DEBUG')
  90. else:
  91. compile_args.append('/MT')
  92. if not 'win' in sys.platform:
  93. # disable gcc warning about virtual functions with non-virtual destructors
  94. compile_args.append(('-Wno-non-virtual-dtor'))
  95. if ENABLE_MULTITHREADING:
  96. macros.append(('COMPRESS_MF_MT', 1))
  97. lzma_files = ('7zip/LzmaStateDecode.c', '7zip/7zip/Compress/LZMA/LZMAEncoder.cpp',
  98. '7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp', '7zip/Common/CRC.cpp',
  99. '7zip/7zip/Compress/LZ/LZInWindow.cpp', '7zip/7zip/Common/StreamUtils.cpp',
  100. '7zip/7zip/Common/OutBuffer.cpp', '7zip/Common/Alloc.cpp', '7zip/Common/NewHandler.cpp', )
  101. if ENABLE_MULTITHREADING:
  102. lzma_files += ('7zip/7zip/Compress/LZ/MT/MT.cpp', '7zip/OS/Synchronization.cpp', )
  103. if ENABLE_COMPATIBILITY:
  104. c_files += ('pylzma_decompress_compat.c', 'pylzma_decompressobj_compat.c', )
  105. lzma_files += ('7zip/LzmaCompatDecode.c', )
  106. macros.append(('WITH_COMPAT', 1))
  107. join = os.path.join
  108. normalize = os.path.normpath
  109. c_files += map(lambda x: normalize(join('.', x)), lzma_files)
  110. extens=[Extension('pylzma', c_files, include_dirs=include_dirs, libraries=libraries,
  111. library_dirs=library_dirs, define_macros=macros, extra_compile_args=compile_args,
  112. extra_link_args=link_args)]
  113. if sys.platform == 'win32':
  114. operating_system = 'Microsoft :: Windows'
  115. else:
  116. operating_system = 'POSIX :: Linux'
  117. setup(
  118. name = "pylzma",
  119. version = version,
  120. description = descr,
  121. author = "Joachim Bauch",
  122. author_email = "mail@joachim-bauch.de",
  123. url = "http://www.joachim-bauch.de",
  124. license = 'LGPL',
  125. keywords = "lzma compression",
  126. long_description = long_descr,
  127. platforms = sys.platform,
  128. classifiers = [
  129. 'Development Status :: 5 - Production/Stable',
  130. 'Programming Language :: Python',
  131. 'Topic :: Software Development :: Libraries :: Python Modules',
  132. 'Intended Audience :: Developers',
  133. 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
  134. 'Operating System :: %s' % operating_system,
  135. ],
  136. py_modules = modules,
  137. ext_modules = extens,
  138. **kw
  139. )
  140. sys.exit(0)