r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[samba.git] / source / python / setup.py
index 6d03ca633a7f969082147907f87794cb54f64795..21717de659bbeec2c8287e05c92f726ae5ebad7a 100755 (executable)
@@ -3,12 +3,12 @@
 # Unix SMB/CIFS implementation.
 # Module packaging setup for Samba python extensions
 #
-# Copyright (C) Tim Potter, 2002
+# Copyright (C) Tim Potter, 2002-2003
 # Copyright (C) Martin Pool, 2002
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
 # This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
 # GNU General Public License for more details.
 #   
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 
 from distutils.core import setup
@@ -37,19 +36,47 @@ samba_cflags = os.environ.get("PYTHON_CFLAGS", "")
 
 samba_srcdir = os.environ.get("SRCDIR", "")
 
+compiler = os.environ.get("CC", "")
+
 # These variables are filled in by configure
 
 samba_libs = os.environ.get("LIBS", "")
 
-# Convert libs and objs from space separated strings to lists of strings
-# for distutils to digest.  Split "-l" prefix off library list.
-
 obj_list = string.split(samba_objs)
 
-lib_list = []
+# Unfortunately the samba_libs variable contains both shared libraries
+# and linker flags.  The python distutils doesn't like this so we have
+# to split $samba_libs into a flags component and a library component.
+
+libraries = []
+library_dirs = []
+
+next_is_path = 0
+next_is_flag = 0
 
 for lib in string.split(samba_libs):
-    lib_list.append(string.replace(lib, "-l", ""))
+    if next_is_path != 0:
+        library_dirs.append(lib);
+        next_is_path = 0;
+    elif next_is_flag != 0:
+        next_is_flag = 0;
+    elif lib == "-Wl,-rpath":
+        next_is_path = 1;
+    elif lib[0:2] == ("-l"):
+        libraries.append(lib[2:])
+    elif lib[0:8] == ("-pthread"):
+        pass # Skip linker flags
+    elif lib[0:4] == ("-pie"):
+        pass # Skip linker flags
+    elif lib[0:2] == "-L":
+        library_dirs.append(lib[2:])
+    elif lib[0:2] in ("-W","-s"):
+        pass # Skip linker flags
+    elif lib[0:2] == "-z":
+        next_is_flag = 1 # Skip linker flags
+    else:
+        print "Unknown entry '%s' in $LIBS variable passed to setup.py" % lib
+        sys.exit(1)
 
 flags_list = string.split(samba_cflags)
 
@@ -83,6 +110,7 @@ setup(
                          samba_srcdir + "python/py_common.c",
                          samba_srcdir + "python/py_conv.c",
                          samba_srcdir + "python/py_ntsec.c",
+                         samba_srcdir + "python/py_spoolss_common.c",
                          samba_srcdir + "python/py_spoolss_forms.c",
                          samba_srcdir + "python/py_spoolss_forms_conv.c",
                          samba_srcdir + "python/py_spoolss_drivers.c",
@@ -95,8 +123,8 @@ setup(
                          samba_srcdir + "python/py_spoolss_jobs.c",
                          samba_srcdir + "python/py_spoolss_jobs_conv.c",
                          ],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
@@ -106,8 +134,8 @@ setup(
               sources = [samba_srcdir + "python/py_lsa.c",
                          samba_srcdir + "python/py_common.c",
                          samba_srcdir + "python/py_ntsec.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
@@ -115,10 +143,11 @@ setup(
 
     Extension(name = "samr",
               sources = [samba_srcdir + "python/py_samr.c",
+                         samba_srcdir + "python/py_conv.c",
                          samba_srcdir + "python/py_samr_conv.c",
                          samba_srcdir + "python/py_common.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
@@ -129,8 +158,8 @@ setup(
                          samba_srcdir + "python/py_winbind_conv.c",
                          samba_srcdir + "python/py_conv.c",
                          samba_srcdir + "python/py_common.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
@@ -139,8 +168,20 @@ setup(
     Extension(name = "winreg",
               sources = [samba_srcdir + "python/py_winreg.c",
                          samba_srcdir + "python/py_common.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
+              extra_compile_args = flags_list,
+              extra_objects = obj_list),
+
+    # SRVSVC pipe module
+
+    Extension(name = "srvsvc",
+              sources = [samba_srcdir + "python/py_srvsvc.c",
+                         samba_srcdir + "python/py_conv.c",
+                         samba_srcdir + "python/py_srvsvc_conv.c",
+                         samba_srcdir + "python/py_common.c"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
@@ -148,8 +189,8 @@ setup(
 
     Extension(name = "tdb",
               sources = [samba_srcdir + "python/py_tdb.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
@@ -157,27 +198,18 @@ setup(
 
     Extension(name = "smb",
               sources = [samba_srcdir + "python/py_smb.c",
-                         samba_srcdir + "python/py_common.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
-              extra_compile_args = flags_list,
-              extra_objects = obj_list),
-
-    # Moving to merge all individual extensions in to one big
-    # extension.  This is to avoid the fact that each extension is 3MB
-    # in size due to the lack of proper depedency management in Samba.
-
-    Extension(name = "samba",
-              sources = [samba_srcdir + "python/py_samba.c",
-                         samba_srcdir + "python/py_common.c"],
-              libraries = lib_list,
-              library_dirs = ["/usr/kerberos/lib"],
+                         samba_srcdir + "python/py_common.c",
+                         samba_srcdir + "python/py_ntsec.c"],
+              libraries = libraries,
+              library_dirs = ["/usr/kerberos/lib"] + library_dirs,
               extra_compile_args = flags_list,
               extra_objects = obj_list),
 
     # tdbpack/unpack extensions.  Does not actually link to any Samba
     # code, although it implements a compatible data format.
+    
     Extension(name = "tdbpack",
-              sources = [os.path.join(samba_srcdir, "python", "py_tdbpack.c")]),
+              sources = [os.path.join(samba_srcdir, "python", "py_tdbpack.c")],
+              extra_compile_args = ["-I."])
     ],
 )