From 19ee7ead6be107f50bc51ba47386694546e71ebf Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Wed, 20 Mar 2019 15:01:29 -0700 Subject: Fix shared library installs on OSX. Shared libraries on OSX need to have their IDs set to their full paths in order to get the proper paths into executables. Ideally, SCons would take care of this, but doesn't. It's necessary to use the OSX install_name_tool on an installed library to fix that. This adds code to do that, verifying that install_name_tool actually exists, and falling back to installing without it (the former behavior) otherwise. However, the CheckProg function didn't exist in some old versions of SCons, so if it's missing (on OSX), the code just assumes that the tool is present and hopes for the best. The version of SCons provided by MacPorts is known to have CheckProg. TESTED: Ran installs on OSX 10.9, 10.13, and 10.5 (PPC), as well as Ubuntu 14.04. Verified that the tool is used and has the intended effect when present on OSX. Verified that the install works without using it on OSX without it, as well as Linux without it, including when a dummy version is present on Linux. Did *not* test with an old SCons. --- SConstruct | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'SConstruct') diff --git a/SConstruct b/SConstruct index 595a3aab..a7022341 100644 --- a/SConstruct +++ b/SConstruct @@ -1008,6 +1008,18 @@ else: if option not in config.env['CFLAGS']: config.CheckCompilerOption(option) +# OSX needs to set the ID for installed shared libraries. See if this is OSX +# and whether we have the tool. + +if sys.platform.startswith('darwin'): + try: + tool = config.CheckProg('install_name_tool') + except AttributeError: + tool = 'install_name_tool' # Just assume it's there if old SCons +else: + tool = None +env['osx_lib_tool'] = tool + # Set up configuration for target Python PYTHON_LIBDIR_CALL = 'sysconfig.get_python_lib()' @@ -1233,7 +1245,11 @@ else: SHLIBVERSION=version) def LibraryInstall(env, libdir, sources, version): - return env.InstallVersionedLib(libdir, sources, SHLIBVERSION=version) + inst = env.InstallVersionedLib(libdir, sources, SHLIBVERSION=version) + if env['osx_lib_tool']: + toolcmd = '%s -id $TARGET $TARGET' % env['osx_lib_tool'] + env.AddPostAction(inst, toolcmd) + return inst compiled_gpslib = Library(env=env, target="gps", -- cgit v1.2.1