"Fossies" - the Fresh Open Source Software Archive

Member "scons-3.0.5/engine/SCons/Tool/applelink.py" (26 Mar 2019, 8618 Bytes) of package /linux/misc/scons-3.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "applelink.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.0.4_vs_3.0.5.

    1 """SCons.Tool.applelink
    2 
    3 Tool-specific initialization for Apple's gnu-like linker.
    4 
    5 There normally shouldn't be any need to import this module directly.
    6 It will usually be imported through the generic SCons.Tool.Tool()
    7 selection method.
    8 
    9 """
   10 
   11 #
   12 # Copyright (c) 2001 - 2019 The SCons Foundation
   13 #
   14 # Permission is hereby granted, free of charge, to any person obtaining
   15 # a copy of this software and associated documentation files (the
   16 # "Software"), to deal in the Software without restriction, including
   17 # without limitation the rights to use, copy, modify, merge, publish,
   18 # distribute, sublicense, and/or sell copies of the Software, and to
   19 # permit persons to whom the Software is furnished to do so, subject to
   20 # the following conditions:
   21 #
   22 # The above copyright notice and this permission notice shall be included
   23 # in all copies or substantial portions of the Software.
   24 #
   25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
   26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
   27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
   28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
   29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
   30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   32 #
   33 
   34 __revision__ = "src/engine/SCons/Tool/applelink.py a56bbd8c09fb219ab8a9673330ffcd55279219d0 2019-03-26 23:16:31 bdeegan"
   35 
   36 import SCons.Util
   37 
   38 # Even though the Mac is based on the GNU toolchain, it doesn't understand
   39 # the -rpath option, so we use the "link" tool instead of "gnulink".
   40 from . import link
   41 
   42 
   43 class AppleLinkInvalidCurrentVersionException(Exception):
   44     pass
   45 
   46 class AppleLinkInvalidCompatibilityVersionException(Exception):
   47     pass
   48 
   49 
   50 def _applelib_versioned_lib_suffix(env, suffix, version):
   51     """For suffix='.dylib' and version='0.1.2' it returns '.0.1.2.dylib'"""
   52     Verbose = False
   53     if Verbose:
   54         print("_applelib_versioned_lib_suffix: suffix={!r}".format(suffix))
   55         print("_applelib_versioned_lib_suffix: version={!r}".format(version))
   56     if version not in suffix:
   57         suffix = "." + version + suffix
   58     if Verbose:
   59         print("_applelib_versioned_lib_suffix: return suffix={!r}".format(suffix))
   60     return suffix
   61 
   62 
   63 def _applelib_versioned_lib_soname(env, libnode, version, prefix, suffix, name_func):
   64     """For libnode='/optional/dir/libfoo.X.Y.Z.dylib' it returns 'libfoo.X.dylib'"""
   65     Verbose = False
   66     if Verbose:
   67         print("_applelib_versioned_lib_soname: version={!r}".format(version))
   68     name = name_func(env, libnode, version, prefix, suffix)
   69     if Verbose:
   70         print("_applelib_versioned_lib_soname: name={!r}".format(name))
   71     major = version.split('.')[0]
   72     (libname,_suffix) = name.split('.')
   73     soname = '.'.join([libname, major, _suffix])
   74     if Verbose:
   75         print("_applelib_versioned_lib_soname: soname={!r}".format(soname))
   76     return soname
   77 
   78 def _applelib_versioned_shlib_soname(env, libnode, version, prefix, suffix):
   79     return _applelib_versioned_lib_soname(env, libnode, version, prefix, suffix, link._versioned_shlib_name)
   80 
   81 
   82 # User programmatically describes how SHLIBVERSION maps to values for compat/current.
   83 _applelib_max_version_values = (65535, 255, 255)
   84 def _applelib_check_valid_version(version_string):
   85     """
   86     Check that the version # is valid.
   87     X[.Y[.Z]]
   88     where X 0-65535
   89     where Y either not specified or 0-255
   90     where Z either not specified or 0-255
   91     :param version_string:
   92     :return:
   93     """
   94     parts = version_string.split('.')
   95     if len(parts) > 3:
   96         return False, "Version string has too many periods [%s]"%version_string
   97     if len(parts) <= 0:
   98         return False, "Version string unspecified [%s]"%version_string
   99 
  100     for (i, p) in enumerate(parts):
  101         try:
  102             p_i = int(p)
  103         except ValueError:
  104             return False, "Version component %s (from %s) is not a number"%(p, version_string)
  105         if p_i < 0 or p_i > _applelib_max_version_values[i]:
  106             return False, "Version component %s (from %s) is not valid value should be between 0 and %d"%(p, version_string, _applelib_max_version_values[i])
  107 
  108     return True, ""
  109 
  110 
  111 def _applelib_currentVersionFromSoVersion(source, target, env, for_signature):
  112     """
  113     A generator function to create the -Wl,-current_version flag if needed.
  114     If env['APPLELINK_NO_CURRENT_VERSION'] contains a true value no flag will be generated
  115     Otherwise if APPLELINK_CURRENT_VERSION is not specified, env['SHLIBVERSION']
  116     will be used.
  117 
  118     :param source:
  119     :param target:
  120     :param env:
  121     :param for_signature:
  122     :return: A string providing the flag to specify the current_version of the shared library
  123     """
  124     if env.get('APPLELINK_NO_CURRENT_VERSION', False):
  125         return ""
  126     elif env.get('APPLELINK_CURRENT_VERSION', False):
  127         version_string = env['APPLELINK_CURRENT_VERSION']
  128     elif env.get('SHLIBVERSION', False):
  129         version_string = env['SHLIBVERSION']
  130     else:
  131         return ""
  132 
  133     version_string = ".".join(version_string.split('.')[:3])
  134 
  135     valid, reason = _applelib_check_valid_version(version_string)
  136     if not valid:
  137         raise AppleLinkInvalidCurrentVersionException(reason)
  138 
  139     return "-Wl,-current_version,%s" % version_string
  140 
  141 
  142 def _applelib_compatVersionFromSoVersion(source, target, env, for_signature):
  143     """
  144     A generator function to create the -Wl,-compatibility_version flag if needed.
  145     If env['APPLELINK_NO_COMPATIBILITY_VERSION'] contains a true value no flag will be generated
  146     Otherwise if APPLELINK_COMPATIBILITY_VERSION is not specified
  147     the first two parts of env['SHLIBVERSION'] will be used with a .0 appended.
  148 
  149     :param source:
  150     :param target:
  151     :param env:
  152     :param for_signature:
  153     :return: A string providing the flag to specify the compatibility_version of the shared library
  154     """
  155     if env.get('APPLELINK_NO_COMPATIBILITY_VERSION', False):
  156         return ""
  157     elif env.get('APPLELINK_COMPATIBILITY_VERSION', False):
  158         version_string = env['APPLELINK_COMPATIBILITY_VERSION']
  159     elif env.get('SHLIBVERSION', False):
  160         version_string = ".".join(env['SHLIBVERSION'].split('.')[:2] + ['0'])
  161     else:
  162         return ""
  163 
  164     if version_string is None:
  165         return ""
  166 
  167     valid, reason = _applelib_check_valid_version(version_string)
  168     if not valid:
  169         raise AppleLinkInvalidCompatibilityVersionException(reason)
  170 
  171     return "-Wl,-compatibility_version,%s" % version_string
  172 
  173 
  174 def generate(env):
  175     """Add Builders and construction variables for applelink to an
  176     Environment."""
  177     link.generate(env)
  178 
  179     env['FRAMEWORKPATHPREFIX'] = '-F'
  180     env['_FRAMEWORKPATH'] = '${_concat(FRAMEWORKPATHPREFIX, FRAMEWORKPATH, "", __env__, RDirs)}'
  181 
  182     env['_FRAMEWORKS'] = '${_concat("-framework ", FRAMEWORKS, "", __env__)}'
  183     env['LINKCOM'] = env['LINKCOM'] + ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
  184     env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -dynamiclib')
  185     env['SHLINKCOM'] = env['SHLINKCOM'] + ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
  186 
  187 
  188     # see: http://docstore.mik.ua/orelly/unix3/mac/ch05_04.htm  for proper naming
  189     link._setup_versioned_lib_variables(env, tool = 'applelink')#, use_soname = use_soname)
  190     env['LINKCALLBACKS'] = link._versioned_lib_callbacks()
  191     env['LINKCALLBACKS']['VersionedShLibSuffix'] = _applelib_versioned_lib_suffix
  192     env['LINKCALLBACKS']['VersionedShLibSoname'] = _applelib_versioned_shlib_soname
  193 
  194     env['_APPLELINK_CURRENT_VERSION'] = _applelib_currentVersionFromSoVersion
  195     env['_APPLELINK_COMPATIBILITY_VERSION'] = _applelib_compatVersionFromSoVersion
  196     env['_SHLIBVERSIONFLAGS'] = '$_APPLELINK_CURRENT_VERSION $_APPLELINK_COMPATIBILITY_VERSION '
  197     env['_LDMODULEVERSIONFLAGS'] = '$_APPLELINK_CURRENT_VERSION $_APPLELINK_COMPATIBILITY_VERSION '
  198 
  199     # override the default for loadable modules, which are different
  200     # on OS X than dynamic shared libs.  echoing what XCode does for
  201     # pre/suffixes:
  202     env['LDMODULEPREFIX'] = '' 
  203     env['LDMODULESUFFIX'] = '' 
  204     env['LDMODULEFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -bundle')
  205     env['LDMODULECOM'] = '$LDMODULE -o ${TARGET} $LDMODULEFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
  206 
  207     env['__SHLIBVERSIONFLAGS'] = '${__libversionflags(__env__,"SHLIBVERSION","_SHLIBVERSIONFLAGS")}'
  208 
  209 
  210 
  211 def exists(env):
  212     return env['PLATFORM'] == 'darwin'
  213 
  214 # Local Variables:
  215 # tab-width:4
  216 # indent-tabs-mode:nil
  217 # End:
  218 # vim: set expandtab tabstop=4 shiftwidth=4: