You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.5 KiB

6 years ago
  1. #
  2. # Copyright (c) 2001 - 2017 The SCons Foundation
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  16. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #
  23. __revision__ = "src/engine/SCons/Scanner/Prog.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  24. import SCons.Node
  25. import SCons.Node.FS
  26. import SCons.Scanner
  27. import SCons.Util
  28. # global, set by --debug=findlibs
  29. print_find_libs = None
  30. def ProgramScanner(**kw):
  31. """Return a prototype Scanner instance for scanning executable
  32. files for static-lib dependencies"""
  33. kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH')
  34. ps = SCons.Scanner.Base(scan, "ProgramScanner", **kw)
  35. return ps
  36. def _subst_libs(env, libs):
  37. """
  38. Substitute environment variables and split into list.
  39. """
  40. if SCons.Util.is_String(libs):
  41. libs = env.subst(libs)
  42. if SCons.Util.is_String(libs):
  43. libs = libs.split()
  44. elif SCons.Util.is_Sequence(libs):
  45. _libs = []
  46. for l in libs:
  47. _libs += _subst_libs(env, l)
  48. libs = _libs
  49. else:
  50. # libs is an object (Node, for example)
  51. libs = [libs]
  52. return libs
  53. def scan(node, env, libpath = ()):
  54. """
  55. This scanner scans program files for static-library
  56. dependencies. It will search the LIBPATH environment variable
  57. for libraries specified in the LIBS variable, returning any
  58. files it finds as dependencies.
  59. """
  60. try:
  61. libs = env['LIBS']
  62. except KeyError:
  63. # There are no LIBS in this environment, so just return a null list:
  64. return []
  65. libs = _subst_libs(env, libs)
  66. try:
  67. prefix = env['LIBPREFIXES']
  68. if not SCons.Util.is_List(prefix):
  69. prefix = [ prefix ]
  70. except KeyError:
  71. prefix = [ '' ]
  72. try:
  73. suffix = env['LIBSUFFIXES']
  74. if not SCons.Util.is_List(suffix):
  75. suffix = [ suffix ]
  76. except KeyError:
  77. suffix = [ '' ]
  78. pairs = []
  79. for suf in map(env.subst, suffix):
  80. for pref in map(env.subst, prefix):
  81. pairs.append((pref, suf))
  82. result = []
  83. if callable(libpath):
  84. libpath = libpath()
  85. find_file = SCons.Node.FS.find_file
  86. adjustixes = SCons.Util.adjustixes
  87. for lib in libs:
  88. if SCons.Util.is_String(lib):
  89. for pref, suf in pairs:
  90. l = adjustixes(lib, pref, suf)
  91. l = find_file(l, libpath, verbose=print_find_libs)
  92. if l:
  93. result.append(l)
  94. else:
  95. result.append(lib)
  96. return result
  97. # Local Variables:
  98. # tab-width:4
  99. # indent-tabs-mode:nil
  100. # End:
  101. # vim: set expandtab tabstop=4 shiftwidth=4: