|
2 | 2 |
|
3 | 3 |
|
4 | 4 | from setuptools import setup, find_packages, Extension |
| 5 | +import subprocess |
| 6 | +import os |
5 | 7 |
|
6 | 8 | VERSION = (0, 7, 0) |
7 | 9 | VERSION_STR = ".".join([str(x) for x in VERSION]) |
8 | 10 |
|
| 11 | +# Check to see if we have a lz4 library installed on the system and |
| 12 | +# use it if so. If not, we'll use the bundled library. If lz4 is |
| 13 | +# installed it will have a pkg-config file, so we'll use pkg-config to |
| 14 | +# check for existence of the library. |
| 15 | +pkg_config_exe = os.environ.get('PKG_CONFIG', None) or 'pkg-config' |
| 16 | +cmd = '{0} --exists liblz4'.format(pkg_config_exe).split() |
| 17 | +liblz4_found = subprocess.call(cmd) == 0 |
| 18 | + |
| 19 | +if liblz4_found: |
| 20 | + # Use system lz4, and don't set optimization and warning flags for |
| 21 | + # the compiler. Specifically we don't define LZ4_VERSION since the |
| 22 | + # system lz4 library could be updated (that's the point of a |
| 23 | + # shared library). |
| 24 | + lz4mod = Extension('lz4', |
| 25 | + [ |
| 26 | + 'src/python-lz4.c' |
| 27 | + ], |
| 28 | + extra_compile_args=[ |
| 29 | + "-std=c99", |
| 30 | + "-DVERSION=\"%s\"" % VERSION_STR, |
| 31 | + ], |
| 32 | + libraries=['lz4'], |
| 33 | + ) |
| 34 | +else: |
| 35 | + # Use the bundled lz4 libs, and set the compiler flags as they |
| 36 | + # historically have been set. We do set LZ4_VERSION here, since it |
| 37 | + # won't change after compilation. |
| 38 | + lz4mod = Extension('lz4', |
| 39 | + [ |
| 40 | + 'src/lz4.c', |
| 41 | + 'src/lz4hc.c', |
| 42 | + 'src/python-lz4.c' |
| 43 | + ], |
| 44 | + extra_compile_args=[ |
| 45 | + "-std=c99", |
| 46 | + "-O3", |
| 47 | + "-Wall", |
| 48 | + "-W", |
| 49 | + "-Wundef", |
| 50 | + "-DVERSION=\"%s\"" % VERSION_STR, |
| 51 | + "-DLZ4_VERSION=\"r130\"", |
| 52 | + ] |
| 53 | + ) |
| 54 | + |
| 55 | + |
9 | 56 | setup( |
10 | 57 | name='lz4', |
11 | 58 | version=VERSION_STR, |
|
16 | 63 | url='https://github.com/steeve/python-lz4', |
17 | 64 | packages=find_packages('src'), |
18 | 65 | package_dir={'': 'src'}, |
19 | | - ext_modules=[ |
20 | | - Extension('lz4', [ |
21 | | - 'src/lz4.c', |
22 | | - 'src/lz4hc.c', |
23 | | - 'src/python-lz4.c' |
24 | | - ], extra_compile_args=[ |
25 | | - "-std=c99", |
26 | | - "-O3", |
27 | | - "-Wall", |
28 | | - "-W", |
29 | | - "-Wundef", |
30 | | - "-DVERSION=\"%s\"" % VERSION_STR, |
31 | | - "-DLZ4_VERSION=\"r130\"", |
32 | | - ]) |
33 | | - ], |
| 66 | + ext_modules=[lz4mod,], |
34 | 67 | setup_requires=["nose>=1.0"], |
35 | 68 | test_suite = "nose.collector", |
36 | 69 | classifiers=[ |
|
0 commit comments