Look for apr-config in more locations. Should help MacPorts users.
[jelmer/subvertpy.git] / setup.py
1 #!/usr/bin/env python
2 # Setup file for bzr-svn
3 # Copyright (C) 2005-2008 Jelmer Vernooij <jelmer@samba.org>
4
5 from distutils.core import setup
6 from distutils.extension import Extension
7 import os
8
9 class CommandException(Exception):
10     """Encapsulate exit status of apr-config execution"""
11     def __init__(self, msg, cmd, arg, status, val):
12         self.message = msg % (cmd, val)
13         super(CommandException, self).__init__(self.message)
14         self.cmd = cmd
15         self.arg = arg
16         self.status = status
17     def not_found(self):
18         return os.WIFEXITED(self.status) and os.WEXITSTATUS(self.status) == 127
19
20 def run_cmd(cmd, arg):
21     """Run specified command with given arguments, handling status"""
22     f = os.popen("'%s' %s" % (cmd, arg))
23     dir = f.read().rstrip("\n")
24     status = f.close()
25     if status is None:
26         return dir
27     if os.WIFEXITED(status):
28         code = os.WEXITSTATUS(status)
29         if code == 0:
30             return dir
31         raise CommandException("%s exited with status %d",
32                                cmd, arg, status, code)
33     if os.WIFSIGNALED(status):
34         signal = os.WTERMSIG(status)
35         raise CommandException("%s killed by signal %d",
36                                cmd, arg, status, signal)
37     raise CommandException("%s terminated abnormally (%d)",
38                            cmd, arg, status, status)
39
40 def apr_config(arg):
41     apr_config_cmd = os.getenv("APR_CONFIG")
42     if apr_config_cmd is None:
43         cmds = ["apr-config", "apr-1-config", "/usr/local/apr/bin/apr-config",
44                 "/usr/local/bin/apr-config"]
45         for cmd in cmds:
46             try:
47                 res = run_cmd(cmd, arg)
48                 apr_config_cmd = cmd
49                 break
50             except CommandException, e:
51                 if not e.not_found():
52                     raise
53         else:
54             raise Exception("apr-config not found."
55                             " Please set APR_CONFIG environment variable")
56     else:
57         res = run_cmd(apr_config_cmd, arg)
58     return res
59
60 def apr_build_data():
61     """Determine the APR header file location."""
62     includedir = apr_config("--includedir")
63     if not os.path.isdir(includedir):
64         raise Exception("APR development headers not found")
65     ldflags = filter(lambda x: x != "", apr_config("--link-ld").split(" "))
66     return (includedir, ldflags)
67
68 def svn_build_data():
69     """Determine the Subversion header file location."""
70     basedirs = ["/usr/local", "/usr"]
71     for basedir in basedirs:
72         includedir = os.path.join(basedir, "include/subversion-1")
73         if os.path.isdir(includedir):
74             return (includedir, os.path.join(basedir, "lib"))
75     raise Exception("Subversion development files not found")
76
77 (apr_includedir, apr_ldflags) = apr_build_data()
78 (svn_includedir, svn_libdir) = svn_build_data()
79
80 def SvnExtension(*args, **kwargs):
81     kwargs["include_dirs"] = [apr_includedir, svn_includedir]
82     kwargs["library_dirs"] = [svn_libdir]
83     kwargs["extra_link_args"] = apr_ldflags
84     return Extension(*args, **kwargs)
85
86
87 setup(name='bzr-svn',
88       description='Support for Subversion branches in Bazaar',
89       keywords='plugin bzr svn',
90       version='0.4.11',
91       url='http://bazaar-vcs.org/BzrForeignBranches/Subversion',
92       download_url='http://bazaar-vcs.org/BzrSvn',
93       license='GPL',
94       author='Jelmer Vernooij',
95       author_email='jelmer@samba.org',
96       long_description="""
97       This plugin adds support for branching off and 
98       committing to Subversion repositories from 
99       Bazaar.
100       """,
101       package_dir={'bzrlib.plugins.svn':'.', 
102                    'bzrlib.plugins.svn.tests':'tests'},
103       packages=['bzrlib.plugins.svn', 
104                 'bzrlib.plugins.svn.mapping3', 
105                 'bzrlib.plugins.svn.tests'],
106       ext_modules=[
107           SvnExtension("client", ["client.c", "editor.c", "util.c", "ra.c", "wc.c"], libraries=["svn_client-1", "svn_subr-1"]), 
108           SvnExtension("ra", ["ra.c", "util.c", "editor.c"], libraries=["svn_ra-1", "svn_delta-1", "svn_subr-1"]),
109           SvnExtension("repos", ["repos.c", "util.c"], libraries=["svn_repos-1", "svn_subr-1"]),
110           SvnExtension("wc", ["wc.c", "util.c", "editor.c"], libraries=["svn_wc-1", "svn_subr-1"]),
111           ]
112       )