r10819: merging a couple of fixes from trunk
[samba.git] / source / python / setup.py
1 # -*- mode: python -*-
2 #
3 # Unix SMB/CIFS implementation.
4 # Module packaging setup for Samba python extensions
5 #
6 # Copyright (C) Tim Potter, 2002-2003
7 # Copyright (C) Martin Pool, 2002
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #   
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #   
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #
23
24 from distutils.core import setup
25 from distutils.extension import Extension
26
27 import sys, string, os
28
29 # The Makefile passes in environment variable $PYTHON_OBJ as being the
30 # list of Samba objects.  This kind of goes against the distutils.cmd
31 # method of adding setup commands and will also confuse people who are
32 # familiar with the python Distutils module.
33
34 samba_objs = os.environ.get("PYTHON_OBJS", "")
35
36 samba_cflags = os.environ.get("PYTHON_CFLAGS", "")
37
38 samba_srcdir = os.environ.get("SRCDIR", "")
39
40 compiler = os.environ.get("CC", "")
41
42 # These variables are filled in by configure
43
44 samba_libs = os.environ.get("LIBS", "")
45
46 obj_list = string.split(samba_objs)
47
48 # Unfortunately the samba_libs variable contains both shared libraries
49 # and linker flags.  The python distutils doesn't like this so we have
50 # to split $samba_libs into a flags component and a library component.
51
52 libraries = []
53 library_dirs = []
54
55 next_is_path = 0
56 next_is_flag = 0
57
58 for lib in string.split(samba_libs):
59     if next_is_path != 0:
60         library_dirs.append(lib);
61         next_is_path = 0;
62     elif next_is_flag != 0:
63         next_is_flag = 0;
64     elif lib == "-Wl,-rpath":
65         next_is_path = 1;
66     elif lib[0:2] in ("-l","-pthread"):
67         libraries.append(lib[2:])
68     elif lib[0:2] == "-L":
69         library_dirs.append(lib[2:])
70     elif lib[0:2] in ("-W","-s"):
71         pass # Skip linker flags
72     elif lib[0:2] == "-z":
73         next_is_flag = 1 # Skip linker flags
74     else:
75         print "Unknown entry '%s' in $LIBS variable passed to setup.py" % lib
76         sys.exit(1)
77
78 flags_list = string.split(samba_cflags)
79
80 # Invoke distutils.setup
81
82 setup(
83
84     # Overview information
85     
86     name = "Samba Python Extensions",
87     version = "0.1",
88     author = "Tim Potter",
89     author_email = "tpot@samba.org",
90     license = "GPL",
91
92     # Get the "samba" directory of Python source.  At the moment this
93     # just contains the __init__ file that makes it work as a
94     # subpackage.  This is needed even though everything else is an
95     # extension module.
96     package_dir = {"samba": os.path.join(samba_srcdir, "python", "samba")},
97     packages = ["samba"],
98     
99     # Module list
100     ext_package = "samba", 
101     ext_modules = [
102
103     # SPOOLSS pipe module
104
105     Extension(name = "spoolss",
106               sources = [samba_srcdir + "python/py_spoolss.c",
107                          samba_srcdir + "python/py_common.c",
108                          samba_srcdir + "python/py_conv.c",
109                          samba_srcdir + "python/py_ntsec.c",
110                          samba_srcdir + "python/py_spoolss_common.c",
111                          samba_srcdir + "python/py_spoolss_forms.c",
112                          samba_srcdir + "python/py_spoolss_forms_conv.c",
113                          samba_srcdir + "python/py_spoolss_drivers.c",
114                          samba_srcdir + "python/py_spoolss_drivers_conv.c",
115                          samba_srcdir + "python/py_spoolss_printers.c",
116                          samba_srcdir + "python/py_spoolss_printers_conv.c",
117                          samba_srcdir + "python/py_spoolss_printerdata.c",
118                          samba_srcdir + "python/py_spoolss_ports.c",
119                          samba_srcdir + "python/py_spoolss_ports_conv.c",
120                          samba_srcdir + "python/py_spoolss_jobs.c",
121                          samba_srcdir + "python/py_spoolss_jobs_conv.c",
122                          ],
123               libraries = libraries,
124               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
125               extra_compile_args = flags_list,
126               extra_objects = obj_list),
127
128     # LSA pipe module
129
130     Extension(name = "lsa",
131               sources = [samba_srcdir + "python/py_lsa.c",
132                          samba_srcdir + "python/py_common.c",
133                          samba_srcdir + "python/py_ntsec.c"],
134               libraries = libraries,
135               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
136               extra_compile_args = flags_list,
137               extra_objects = obj_list),
138
139     # SAMR pipe module
140
141     Extension(name = "samr",
142               sources = [samba_srcdir + "python/py_samr.c",
143                          samba_srcdir + "python/py_conv.c",
144                          samba_srcdir + "python/py_samr_conv.c",
145                          samba_srcdir + "python/py_common.c"],
146               libraries = libraries,
147               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
148               extra_compile_args = flags_list,
149               extra_objects = obj_list),
150
151     # winbind client module
152
153     Extension(name = "winbind",
154               sources = [samba_srcdir + "python/py_winbind.c",
155                          samba_srcdir + "python/py_winbind_conv.c",
156                          samba_srcdir + "python/py_conv.c",
157                          samba_srcdir + "python/py_common.c"],
158               libraries = libraries,
159               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
160               extra_compile_args = flags_list,
161               extra_objects = obj_list),
162
163     # WINREG pipe module
164
165     Extension(name = "winreg",
166               sources = [samba_srcdir + "python/py_winreg.c",
167                          samba_srcdir + "python/py_common.c"],
168               libraries = libraries,
169               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
170               extra_compile_args = flags_list,
171               extra_objects = obj_list),
172
173     # SRVSVC pipe module
174
175     Extension(name = "srvsvc",
176               sources = [samba_srcdir + "python/py_srvsvc.c",
177                          samba_srcdir + "python/py_conv.c",
178                          samba_srcdir + "python/py_srvsvc_conv.c",
179                          samba_srcdir + "python/py_common.c"],
180               libraries = libraries,
181               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
182               extra_compile_args = flags_list,
183               extra_objects = obj_list),
184
185     # tdb module
186
187     Extension(name = "tdb",
188               sources = [samba_srcdir + "python/py_tdb.c"],
189               libraries = libraries,
190               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
191               extra_compile_args = flags_list,
192               extra_objects = obj_list),
193
194     # libsmb module
195
196     Extension(name = "smb",
197               sources = [samba_srcdir + "python/py_smb.c",
198                          samba_srcdir + "python/py_common.c",
199                          samba_srcdir + "python/py_ntsec.c"],
200               libraries = libraries,
201               library_dirs = ["/usr/kerberos/lib"] + library_dirs,
202               extra_compile_args = flags_list,
203               extra_objects = obj_list),
204
205     # tdbpack/unpack extensions.  Does not actually link to any Samba
206     # code, although it implements a compatible data format.
207     
208     Extension(name = "tdbpack",
209               sources = [os.path.join(samba_srcdir, "python", "py_tdbpack.c")],
210               extra_compile_args = ["-I."])
211     ],
212 )