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