build: for unbundled libraries install devel link too
[samba.git] / buildtools / wafsamba / samba_install.py
index 71d6b86122f2f75d30434defcca13e935f214cc1..74730dd3b26839447a52c6089e845329850819a9 100644 (file)
@@ -7,6 +7,8 @@ import Options
 from TaskGen import feature, before, after
 from samba_utils import *
 
+O755 = 493
+
 @feature('install_bin')
 @after('apply_core')
 @before('apply_link')
@@ -41,7 +43,7 @@ def install_binary(self):
     # tell waf to install the right binary
     bld.install_as(os.path.join(install_path, orig_target),
                    os.path.join(self.path.abspath(bld.env), self.target),
-                   chmod=0755)
+                   chmod=O755)
 
 
 
@@ -80,6 +82,8 @@ def install_library(self):
 
     t.env.append_value('LINKFLAGS', install_ldflags)
 
+    dev_link     = None
+
     if self.samba_realname:
         install_name = self.samba_realname
         install_link = None
@@ -89,6 +93,9 @@ def install_library(self):
         install_name = 'lib%s.so.%s' % (self.target, self.vnum)
         install_link = 'lib%s.so.%s' % (self.target, vnum_base)
         inst_name    = 'lib%s.so' % t.target
+        if self.target == self.name:
+            # only generate the dev link for non-bundled libs
+            dev_link     = 'lib%s.so' % self.target
     else:
         install_name = 'lib%s.so' % self.target
         install_link = None
@@ -101,25 +108,25 @@ def install_library(self):
         # and the symlink if needed
         bld.symlink_as(os.path.join(install_path, install_link),
                        install_name)
+    if dev_link:
+        bld.symlink_as(os.path.join(install_path, dev_link),
+                       install_name)
 
 
 
 ##############################
 # handle the creation of links for libraries and binaries in the build tree
-# note that we use a relative symlink path to allow the whole tree
-# to me moved/copied elsewhere without breaking the links
-t = Task.simple_task_type('symlink_lib', 'rm -f ${LINK_TARGET} && ln -s ${LINK_SOURCE} ${LINK_TARGET}',
-                          shell=True, color='PINK', ext_in='.bin')
-t.quiet = True
 
 @feature('symlink_lib')
 @after('apply_link')
 def symlink_lib(self):
     '''symlink a shared lib'''
-    if Options.is_install:
+
+    if self.target.endswith('.inst'):
         return
 
-    tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
+    blddir = os.path.dirname(self.bld.srcnode.abspath(self.bld.env))
+    libpath = self.link_task.outputs[0].abspath(self.env)
 
     # calculat the link target and put it in the environment
     soext=""
@@ -131,28 +138,29 @@ def symlink_lib(self):
     if link_target == '':
         link_target = '%s/lib%s.so%s' % (LIB_PATH, self.target, soext)
 
+    link_target = os.path.join(blddir, link_target)
 
-    link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
-                                  os.path.join(self.env.BUILD_DIRECTORY, link_target))
+    if os.path.lexists(link_target):
+        if os.path.islink(link_target) and os.readlink(link_target) == libpath:
+            return
+        os.unlink(link_target)
+    os.symlink(libpath, link_target)
 
-    tsk.env.LINK_TARGET = link_target
-    tsk.env.LINK_SOURCE = link_source[3:]
-    debug('task_gen: LINK for %s is %s -> %s',
-          self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
-
-
-t = Task.simple_task_type('symlink_bin', 'rm -f ${BIN_TARGET} && ln -s ${SRC} ${BIN_TARGET}',
-                          shell=True, color='PINK', ext_in='.bin')
-t.quiet = True
 
 @feature('symlink_bin')
 @after('apply_link')
 def symlink_bin(self):
-    '''symlink a binary'''
-    if Options.is_install:
+    '''symlink a binary into the build directory'''
+
+    if self.target.endswith('.inst'):
         return
-    tsk = self.create_task('symlink_bin', self.link_task.outputs[0])
 
-    tsk.env.BIN_TARGET = self.target
-    debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
+    blddir = os.path.dirname(self.bld.srcnode.abspath(self.bld.env))
+    binpath = self.link_task.outputs[0].abspath(self.env)
+    bldpath = os.path.join(self.bld.env.BUILD_DIRECTORY, self.link_task.outputs[0].name)
 
+    if os.path.lexists(bldpath):
+        if os.path.islink(bldpath) and os.readlink(bldpath) == binpath:
+            return
+        os.unlink(bldpath)
+    os.symlink(binpath, bldpath)