waf: use -Wl,--version-script if available
authorAndrew Tridgell <tridge@samba.org>
Wed, 8 Dec 2010 03:52:43 +0000 (14:52 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 8 Dec 2010 04:26:06 +0000 (05:26 +0100)
This enables symbol version on our libraries, if the system supports
it

If the library is a public library, then set the symbol version based
on the major number. If it is a private library then set it based on
the full version number (which will include the git hash if
available).

This ensures that applications using our libraries don't use symbols
from other libraries that they may be linked to. It also ensures we
only use the right version of any private libraries.

Note that the linker ends up generating both a version and unversioned
symbol for all symbols. This means existing users of our public
libraries will continue to work, with symbols resolved to the
unversioned symbol. When applications are re-linked they will bind to
the specific symbol version.

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Pair-Programmed-With: Jelmer Vernooij <jelmer@samba.org>

buildtools/wafsamba/samba_deps.py
buildtools/wafsamba/wafsamba.py

index 91737d587357c5dd595e048880259e4e3625e64a..0ea966033cf170366b1bbab4e17b1a28665c302c 100644 (file)
@@ -952,7 +952,8 @@ def show_object_duplicates(bld, tgt_list):
 ######################################################################
 # this provides a way to save our dependency calculations between runs
 savedeps_version = 3
-savedeps_inputs  = ['samba_deps', 'samba_includes', 'local_include', 'local_include_first', 'samba_cflags', 'source', 'grouping_library']
+savedeps_inputs  = ['samba_deps', 'samba_includes', 'local_include', 'local_include_first', 'samba_cflags',
+                    'source', 'grouping_library', 'ldflags']
 savedeps_outputs = ['uselib', 'uselib_local', 'add_objects', 'includes', 'ccflags', 'ldflags', 'samba_deps_extended']
 savedeps_outenv  = ['INC_PATHS']
 savedeps_envvars = ['NONSHARED_BINARIES', 'GLOBAL_DEPENDENCIES', 'EXTRA_CFLAGS', 'EXTRA_LDFLAGS' ]
index 10b7dfe0f4863e4f704fbecdab68df8e77e99985..fc75def98dc66e3465f72fc85dce01a08635535e 100644 (file)
@@ -103,6 +103,7 @@ def SAMBA_LIBRARY(bld, libname, source,
                   vnum=None,
                   soname=None,
                   cflags='',
+                  ldflags='',
                   external_library=False,
                   realname=None,
                   autoproto=None,
@@ -188,11 +189,24 @@ def SAMBA_LIBRARY(bld, libname, source,
     else:
         bundled_name = PRIVATE_NAME(bld, libname, bundled_extension, private_library)
 
+    ldflags = TO_LIST(ldflags)
+
     if private_library:
         if vnum:
             Logs.error("vnum is invalid for private libraries")
             sys.exit(1)
-        vnum = Utils.g_module.VERSION[0]
+        vnum = Utils.g_module.VERSION.split(".")[0]
+        version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
+    else:
+        version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION.split(".")[0])
+
+    if bld.env.HAVE_LD_VERSION_SCRIPT:
+        vscript = "%s.vscript" % libname
+        bld.SAMBA_GENERATOR(vscript,
+                            rule="echo %s \{ global: \*\; \}\; > ${TGT}" % version.replace("-","_").upper(),
+                            group='vscripts',
+                            target=vscript)
+        ldflags.append("-Wl,--version-script=%s/%s" % (bld.path.abspath(bld.env), vscript))
 
     features = 'cc cshlib symlink_lib install_lib'
     if target_type == 'PYTHON':
@@ -213,6 +227,7 @@ def SAMBA_LIBRARY(bld, libname, source,
         source          = [],
         target          = bundled_name,
         depends_on      = depends_on,
+        ldflags                = ldflags,
         samba_deps      = deps,
         samba_includes  = includes,
         local_include   = local_include,
@@ -525,6 +540,7 @@ def SETUP_BUILD_GROUPS(bld):
     bld.env['USING_BUILD_GROUPS'] = True
     bld.add_group('setup')
     bld.add_group('build_compiler_source')
+    bld.add_group('vscripts')
     bld.add_group('base_libraries')
     bld.add_group('generators')
     bld.add_group('compiler_prototypes')