Commits

Rob Managan committed 66de1b4

Add the versioned sh lib and install methods to Environment

Comments (0)

Files changed (2)

src/engine/SCons/Environment.py

             install._UNIQUE_INSTALLED_FILES = SCons.Util.uniquer_hashables(install._INSTALLED_FILES)
         return install._UNIQUE_INSTALLED_FILES
 
+    def VersionedSharedLibrary(self, libname, version, lib_objs=[],parse_flags=[]):
+        platform = self.subst('$PLATFORM')
+        shlib_pre_action = None
+        shlib_suffix = self.subst('$SHLIBSUFFIX')
+        shlib_post_action = None
+        shlink_flags = SCons.Util.CLVar(self.subst('$SHLINKFLAGS'))
+
+        if platform == 'posix':
+            ilib_suffix = shlib_suffix + '.' + version
+            (major, age, revision) = version.split(".")
+            soname = "lib" + libname + shlib_suffix + "." + major
+            shlink_flags += [ '-Wl,-Bsymbolic', '-Wl,-soname=%s' % soname ]
+        elif platform == 'cygwin':
+            ilib_suffix = shlib_suffix
+            shlink_flags += [ '-Wl,-Bsymbolic',
+                              '-Wl,--out-implib,${TARGET.base}.a' ]
+        elif platform == 'darwin':
+            ilib_suffix = '.' + version + shlib_suffix
+            shlink_flags += [ '-current_version', '%s' % version,
+                              '-compatibility_version', '%s' % version,
+                              '-undefined', 'dynamic_lookup' ]
+
+        ilib = self.SharedLibrary(libname,lib_objs,
+                                SHLIBSUFFIX=ilib_suffix,
+                                SHLINKFLAGS=shlink_flags,
+                                parse_flags=parse_flags)
+
+        if platform == 'darwin':
+            if version.count(".") != 2:
+                # We need a library name in libfoo.x.y.z.dylib form to proceed
+                raise ValueError
+            lib = 'lib' + libname + '.' + version + '.dylib'
+            lib_no_ver = 'lib' + libname + '.dylib'
+            # Link libfoo.x.y.z.dylib to libfoo.dylib
+            self.AddPostAction(ilib, 'rm -f %s; ln -s %s %s' % (
+                lib_no_ver, lib, lib_no_ver))
+            self.Clean(lib, lib_no_ver)
+        elif platform == 'posix':
+            if version.count(".") != 2:
+                # We need a library name in libfoo.so.x.y.z form to proceed
+                raise ValueError
+            lib = "lib" + libname + ".so." + version
+            suffix_re = '%s\\.[0-9\\.]*$' % re.escape(shlib_suffix)
+            # For libfoo.so.x.y.z, links libfoo.so libfoo.so.x.y libfoo.so.x
+            major_name = shlib_suffix + "." + lib.split(".")[2]
+            minor_name = major_name + "." + lib.split(".")[3]
+            for linksuffix in [shlib_suffix, major_name, minor_name]:
+                linkname = re.sub(suffix_re, linksuffix, lib)
+                self.AddPostAction(ilib, 'rm -f %s; ln -s %s %s' % (
+                    linkname, lib, linkname))
+                self.Clean(lib, linkname)
+
+        return ilib
+
+    def VersionedSharedLibraryInstall(self, destination, libs):
+       platform = self.subst('$PLATFORM')
+       shlib_suffix = self.subst('$SHLIBSUFFIX')
+       ilibs = self.Install(destination, libs)
+       if platform == 'posix':
+           suffix_re = '%s\\.[0-9\\.]*$' % re.escape(shlib_suffix)
+           for lib in map(str, libs):
+               if lib.count(".") != 4:
+                   # We need a library name in libfoo.so.x.y.z form to proceed
+                   raise ValueError
+               # For libfoo.so.x.y.z, links libfoo.so libfoo.so.x.y libfoo.so.x
+               major_name = shlib_suffix + "." + lib.split(".")[2]
+               minor_name = major_name + "." + lib.split(".")[3]
+               for linksuffix in [shlib_suffix, major_name, minor_name]:
+                   linkname = re.sub(suffix_re, linksuffix, lib)
+                   self.AddPostAction(ilibs, 'cd %s; rm -f %s; ln -s %s %s' % (destination, linkname, lib, linkname))
+               self.Clean(lib, linkname)
+       return ilibs
+
+
 class OverrideEnvironment(Base):
     """A proxy that overrides variables in a wrapped construction
     environment by returning values from an overrides dictionary in

src/engine/SCons/Script/__init__.py

     'TypeLibrary',
     'Zip',
     'Package',
+    'VersionedSharedLibrary',
 ]
 
 for name in GlobalDefaultEnvironmentFunctions + GlobalDefaultBuilders: