build: install build python modules correctly
[nivanova/samba-autobuild/.git] / buildtools / wafsamba / samba_python.py
index 0845a7e61c562e1e6bde31df4457f50c2546573b..bb8939caf9982da1beac1585366748dc30682b14 100644 (file)
@@ -1,7 +1,6 @@
 # waf build tool for building IDL files with pidl
 
-from TaskGen import taskgen, before
-import Build, os, string, Utils
+import Build
 from samba_utils import *
 from samba_autoconf import *
 
@@ -15,9 +14,31 @@ def SAMBA_PYTHON(bld, name,
                  includes='',
                  init_function_sentinal=None,
                  local_include=True,
+                 vars=None,
                  enabled=True):
     '''build a python extension for Samba'''
 
+    # when we support static python modules we'll need to gather
+    # the list from all the SAMBA_PYTHON() targets
+    if init_function_sentinal is not None:
+        cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinal
+
+    source = bld.EXPAND_VARIABLES(source, vars=vars)
+
+    if realname is None:
+        # a SAMBA_PYTHON target without a realname is just a
+        # subsystem with needs_python=True
+        return bld.SAMBA_SUBSYSTEM(name,
+                                   source=source,
+                                   deps=deps,
+                                   public_deps=public_deps,
+                                   cflags=cflags,
+                                   includes=includes,
+                                   init_function_sentinal=init_function_sentinal,
+                                   local_include=local_include,
+                                   needs_python=True,
+                                   enabled=enabled)
+
     if not enabled:
         SET_TARGET_TYPE(bld, name, 'DISABLED')
         return
@@ -27,18 +48,27 @@ def SAMBA_PYTHON(bld, name,
 
     deps += ' ' + public_deps
 
-    # when we support static python modules we'll need to gather
-    # the list from all the SAMBA_PYTHON() targets
-    if init_function_sentinal is not None:
-        cflags += '-DSTATIC_LIBPYTHON_MODULES="%s"' % init_function_sentinal
+    if realname is None:
+        realname = '%s.so' % name
+    link_name = 'python/%s' % realname
 
     t = bld(
-        features       = 'cc cshlib pyext',
+        features       = 'cc cshlib pyext symlink_lib',
         source         = source,
         target         = name,
-        ccflags        = CURRENT_CFLAGS(bld, name, cflags),
+        samba_cflags   = CURRENT_CFLAGS(bld, name, cflags),
         samba_includes = includes,
         local_include  = local_include,
-        samba_deps     = TO_LIST(deps)
+        samba_deps     = TO_LIST(deps),
+        link_name      = link_name,
+        name          = name,
+        install_path   = None
         )
+
+    destdir='${PYTHONDIR}'
+    dname=os.path.dirname(realname)
+    if dname:
+        destdir += '/' + dname
+    bld.INSTALL_FILES(destdir, name + '.so', destname=os.path.basename(realname))
+
 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON