~ubuntu-branches/ubuntu/trusty/libprelude/trusty

« back to all changes in this revision

Viewing changes to bindings/low-level/python/setup.py.in

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-04-29 11:31:50 UTC
  • mfrom: (1.1.12 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090429113150-qw9oxc1e50ldljck
Tags: 0.9.22-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Build-Depend on libltdl7-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys, os
 
2
from os.path import abspath, exists
 
3
import shutil
 
4
 
 
5
from distutils.sysconfig import get_python_lib
 
6
from distutils.core import setup, Extension
 
7
 
 
8
FILES_TO_BE_COPIED = ("_prelude.c", "prelude.py")
 
9
 
 
10
 
 
11
def split_args(s):
 
12
    import re
 
13
    return re.split("\s+", s.strip())
 
14
 
 
15
 
 
16
def get_root():
 
17
    try:
 
18
        return sys.argv[sys.argv.index("--root") + 1]
 
19
    except ValueError:
 
20
        return ""
 
21
 
 
22
 
 
23
def is_system_wide_install():
 
24
    return os.access(get_python_lib(), os.W_OK)
 
25
 
 
26
 
 
27
def builddir_is_srcdir():
 
28
    return abspath("@top_srcdir@") == abspath("@top_builddir@")
 
29
 
 
30
 
 
31
def pre_install():
 
32
    if not is_system_wide_install():
 
33
        sys.argv.extend(["--prefix", "@prefix@"])
 
34
 
 
35
 
 
36
def pre_build():
 
37
    if not builddir_is_srcdir():
 
38
        for file in FILES_TO_BE_COPIED:
 
39
            src = "@top_srcdir@/bindings/low-level/python/" + file
 
40
            dst = "@top_builddir@/bindings/low-level/python/" + file
 
41
            if not exists(dst):
 
42
                shutil.copy(src, dst)
 
43
 
 
44
 
 
45
def pre_clean():
 
46
    if not builddir_is_srcdir():
 
47
        for file in FILES_TO_BE_COPIED:
 
48
            exists(file) and os.remove(file)
 
49
 
 
50
 
 
51
def uninstall():
 
52
    if is_system_wide_install():
 
53
        prefix = None
 
54
    else:
 
55
        prefix = "@prefix@"
 
56
    
 
57
    for f in "prelude.py", "prelude.pyc", "_prelude.so":
 
58
        file = get_root() + "/" + get_python_lib(prefix=prefix) + "/" + f
 
59
        exists(file) and os.remove(file)
 
60
 
 
61
        file = get_root() + "/" + get_python_lib(plat_specific=True, prefix=prefix) + "/" + f
 
62
        exists(file) and os.remove(file)
 
63
 
 
64
    sys.exit(0)
 
65
 
 
66
 
 
67
 
 
68
commands = {
 
69
    "install": pre_install,
 
70
    "build": pre_build,
 
71
    "clean": pre_clean,
 
72
    "uninstall": uninstall,
 
73
    }
 
74
 
 
75
if len(sys.argv) > 1 and commands.has_key(sys.argv[1]):
 
76
    commands[sys.argv[1]]()
 
77
 
 
78
setup(name="prelude",
 
79
      version="@VERSION@",
 
80
      description="Low-level Python bindings for the Prelude Library",
 
81
      author="PreludeIDS Technologies",
 
82
      url="http://www.prelude-ids.com",
 
83
      package_dir={'prelude': '@top_srcdir@/bindings/low-level/python'},
 
84
      py_modules=["prelude"],
 
85
      ext_modules=[Extension("_prelude",
 
86
                             ["_prelude.c"],
 
87
                             extra_compile_args=split_args("-I@top_builddir@ -I@top_srcdir@/src/include -I@top_builddir@/src/include -I@top_builddir@/src/libprelude-error -I@top_srcdir@/bindings"),
 
88
                             library_dirs=[ "@top_builddir@/src/.libs/" ],
 
89
                             extra_link_args=split_args("-lprelude @LIBPRELUDE_LIBS@ @LIBADD_DL@ @LTLIBTHREAD@"))])