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
24from distutils.core import setup
25from distutils.extension import Extension
26
27import 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
34samba_objs = os.environ.get("PYTHON_OBJS", "")
35
36samba_cflags = os.environ.get("PYTHON_CFLAGS", "")
37
38samba_srcdir = os.environ.get("SRCDIR", "")
39
40compiler = os.environ.get("CC", "")
41
42# These variables are filled in by configure
43
44samba_libs = os.environ.get("LIBS", "")
45
46obj_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
52libraries = []
53library_dirs = []
54
55next_is_path = 0
56next_is_flag = 0
57
58for 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] == ("-l"):
67        libraries.append(lib[2:])
68    elif lib[0:8] == ("-pthread"):
69        pass # Skip linker flags
70    elif lib[0:4] == ("-pie"):
71        pass # Skip linker flags
72    elif lib[0:2] == "-L":
73        library_dirs.append(lib[2:])
74    elif lib[0:2] in ("-W","-s"):
75        pass # Skip linker flags
76    elif lib[0:2] == "-z":
77        next_is_flag = 1 # Skip linker flags
78    else:
79        print "Unknown entry '%s' in $LIBS variable passed to setup.py" % lib
80        sys.exit(1)
81
82flags_list = string.split(samba_cflags)
83
84# Invoke distutils.setup
85
86setup(
87
88    # Overview information
89
90    name = "Samba Python Extensions",
91    version = "0.1",
92    author = "Tim Potter",
93    author_email = "tpot@samba.org",
94    license = "GPL",
95
96    # Get the "samba" directory of Python source.  At the moment this
97    # just contains the __init__ file that makes it work as a
98    # subpackage.  This is needed even though everything else is an
99    # extension module.
100    package_dir = {"samba": os.path.join(samba_srcdir, "python", "samba")},
101    packages = ["samba"],
102
103    # Module list
104    ext_package = "samba",
105    ext_modules = [
106
107    # SPOOLSS pipe module
108
109    Extension(name = "spoolss",
110              sources = [samba_srcdir + "python/py_spoolss.c",
111                         samba_srcdir + "python/py_common.c",
112                         samba_srcdir + "python/py_conv.c",
113                         samba_srcdir + "python/py_ntsec.c",
114                         samba_srcdir + "python/py_spoolss_common.c",
115                         samba_srcdir + "python/py_spoolss_forms.c",
116                         samba_srcdir + "python/py_spoolss_forms_conv.c",
117                         samba_srcdir + "python/py_spoolss_drivers.c",
118                         samba_srcdir + "python/py_spoolss_drivers_conv.c",
119                         samba_srcdir + "python/py_spoolss_printers.c",
120                         samba_srcdir + "python/py_spoolss_printers_conv.c",
121                         samba_srcdir + "python/py_spoolss_printerdata.c",
122                         samba_srcdir + "python/py_spoolss_ports.c",
123                         samba_srcdir + "python/py_spoolss_ports_conv.c",
124                         samba_srcdir + "python/py_spoolss_jobs.c",
125                         samba_srcdir + "python/py_spoolss_jobs_conv.c",
126                         ],
127              libraries = libraries,
128              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
129              extra_compile_args = flags_list,
130              extra_objects = obj_list),
131
132    # LSA pipe module
133
134    Extension(name = "lsa",
135              sources = [samba_srcdir + "python/py_lsa.c",
136                         samba_srcdir + "python/py_common.c",
137                         samba_srcdir + "python/py_ntsec.c"],
138              libraries = libraries,
139              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
140              extra_compile_args = flags_list,
141              extra_objects = obj_list),
142
143    # SAMR pipe module
144
145    Extension(name = "samr",
146              sources = [samba_srcdir + "python/py_samr.c",
147                         samba_srcdir + "python/py_conv.c",
148                         samba_srcdir + "python/py_samr_conv.c",
149                         samba_srcdir + "python/py_common.c"],
150              libraries = libraries,
151              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
152              extra_compile_args = flags_list,
153              extra_objects = obj_list),
154
155    # winbind client module
156
157    Extension(name = "winbind",
158              sources = [samba_srcdir + "python/py_winbind.c",
159                         samba_srcdir + "python/py_winbind_conv.c",
160                         samba_srcdir + "python/py_conv.c",
161                         samba_srcdir + "python/py_common.c"],
162              libraries = libraries,
163              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
164              extra_compile_args = flags_list,
165              extra_objects = obj_list),
166
167    # WINREG pipe module
168
169    Extension(name = "winreg",
170              sources = [samba_srcdir + "python/py_winreg.c",
171                         samba_srcdir + "python/py_common.c"],
172              libraries = libraries,
173              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
174              extra_compile_args = flags_list,
175              extra_objects = obj_list),
176
177    # SRVSVC pipe module
178
179    Extension(name = "srvsvc",
180              sources = [samba_srcdir + "python/py_srvsvc.c",
181                         samba_srcdir + "python/py_conv.c",
182                         samba_srcdir + "python/py_srvsvc_conv.c",
183                         samba_srcdir + "python/py_common.c"],
184              libraries = libraries,
185              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
186              extra_compile_args = flags_list,
187              extra_objects = obj_list),
188
189    # tdb module
190
191    Extension(name = "tdb",
192              sources = [samba_srcdir + "python/py_tdb.c"],
193              libraries = libraries,
194              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
195              extra_compile_args = flags_list,
196              extra_objects = obj_list),
197
198    # libsmb module
199
200    Extension(name = "smb",
201              sources = [samba_srcdir + "python/py_smb.c",
202                         samba_srcdir + "python/py_common.c",
203                         samba_srcdir + "python/py_ntsec.c"],
204              libraries = libraries,
205              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
206              extra_compile_args = flags_list,
207              extra_objects = obj_list),
208
209    # tdbpack/unpack extensions.  Does not actually link to any Samba
210    # code, although it implements a compatible data format.
211
212    Extension(name = "tdbpack",
213              sources = [os.path.join(samba_srcdir, "python", "py_tdbpack.c")],
214              extra_compile_args = ["-I."])
215    ],
216)
217