1#! /usr/bin/env python
2# vi:ts=4:et
3
4from __future__ import print_function
5
6import os, sys
7import distutils
8from distutils.cmd import Command
9from distutils.core import setup
10from distutils.extension import Extension
11from distutils.util import split_quoted
12
13include_dirs = []
14define_macros = []
15library_dirs = []
16libraries = []
17runtime_library_dirs = []
18extra_objects = []
19extra_compile_args = []
20extra_link_args = []
21
22class TestCommand(Command):
23    user_options = []
24
25    def initialize_options(self):
26        pass
27
28    def finalize_options(self):
29        pass
30
31    def run(self):
32        import sys, subprocess
33        raise SystemExit(
34            subprocess.call([sys.executable,
35                             '-m',
36                             'nose']))
37
38
39if sys.platform == "win32":
40    # Windows users have to configure the LZO_DIR path parameter to match
41    # their LZO source installation.  The path set here is just an example
42    # and thus unlikely to match your installation.
43
44    LZO_DIR = os.environ.get('LZO_DIR', r"c:\src\lzo-1.08")
45    if not os.path.exists(LZO_DIR):
46        raise Exception("please set LZO_DIR to where the lzo source lives")
47    include_dirs.append(os.path.join(LZO_DIR, r"include\lzo"))
48    include_dirs.append(os.path.join(LZO_DIR, "include"))
49    lib1_file = os.path.join(LZO_DIR, "lzo.lib")
50    lib2_file = os.path.join(LZO_DIR, "lzo2.lib")
51    if os.path.exists(lib2_file):
52        lib_file = lib2_file
53    else:
54        lib_file = lib1_file
55    extra_objects.append(lib_file)
56else:
57    libraries = ["lzo2"]
58    include_dirs.append(os.environ.get("PREFIX", "/usr")+"/include")
59    ##library_dirs.append("/usr/local/lib")
60    ##runtime_library_dirs.append("/usr/local/lib")
61
62    # Add extra compile flag for MacOS X
63    if sys.platform[:-1] == "darwin":
64        extra_link_args.append("-flat_namespace")
65
66
67###############################################################################
68
69def get_kw(**kw): return kw
70
71ext = Extension(
72    name="lzo",
73    sources=["lzomodule.c"],
74    include_dirs=include_dirs,
75    define_macros=define_macros,
76    library_dirs=library_dirs,
77    libraries=libraries,
78    runtime_library_dirs=runtime_library_dirs,
79    extra_objects=extra_objects,
80    extra_compile_args=extra_compile_args,
81    extra_link_args=extra_link_args,
82)
83
84setup_args = get_kw(
85    name="python-lzo",
86    version="1.14",
87    description="Python bindings for the LZO data compression library",
88    author="Markus F.X.J. Oberhumer",
89    author_email="markus@oberhumer.com",
90    maintainer="Joshua D. Boyd",
91    maintainer_email="jdboyd@jdboyd.net",
92    url="https://github.com/jd-boyd/python-lzo",
93    license="GNU General Public License (GPL)",
94    tests_require=['nose'],
95    cmdclass={
96        'test': TestCommand
97    },
98    ext_modules=[ext],
99    long_description="""
100This module provides Python bindings for the LZO data compression library.
101
102LZO is a portable lossless data compression library written in ANSI C.
103It offers pretty fast compression and *very* fast decompression.
104Decompression requires no memory.
105
106In addition there are slower compression levels achieving a quite
107competitive compression ratio while still decompressing at
108this very high speed.""",
109)
110
111if distutils.__version__ >= "1.0.2":
112    setup_args["platforms"] = "All"
113
114setup(**setup_args)
115