Package SCons :: Package Scanner :: Module Prog
[hide private]
[frames] | no frames]

Source Code for Module SCons.Scanner.Prog

  1  # 
  2  # Copyright (c) 2001 - 2014 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   
 24  __revision__ = "src/engine/SCons/Scanner/Prog.py  2014/07/05 09:42:21 garyo" 
 25   
 26  import SCons.Node 
 27  import SCons.Node.FS 
 28  import SCons.Scanner 
 29  import SCons.Util 
 30   
 31  # global, set by --debug=findlibs 
 32  print_find_libs = None 
 33   
34 -def ProgramScanner(**kw):
35 """Return a prototype Scanner instance for scanning executable 36 files for static-lib dependencies""" 37 kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH') 38 ps = SCons.Scanner.Base(scan, "ProgramScanner", **kw) 39 return ps
40
41 -def scan(node, env, libpath = ()):
42 """ 43 This scanner scans program files for static-library 44 dependencies. It will search the LIBPATH environment variable 45 for libraries specified in the LIBS variable, returning any 46 files it finds as dependencies. 47 """ 48 try: 49 libs = env['LIBS'] 50 except KeyError: 51 # There are no LIBS in this environment, so just return a null list: 52 return [] 53 if SCons.Util.is_String(libs): 54 libs = libs.split() 55 else: 56 libs = SCons.Util.flatten(libs) 57 58 try: 59 prefix = env['LIBPREFIXES'] 60 if not SCons.Util.is_List(prefix): 61 prefix = [ prefix ] 62 except KeyError: 63 prefix = [ '' ] 64 65 try: 66 suffix = env['LIBSUFFIXES'] 67 if not SCons.Util.is_List(suffix): 68 suffix = [ suffix ] 69 except KeyError: 70 suffix = [ '' ] 71 72 pairs = [] 73 for suf in map(env.subst, suffix): 74 for pref in map(env.subst, prefix): 75 pairs.append((pref, suf)) 76 77 result = [] 78 79 if callable(libpath): 80 libpath = libpath() 81 82 find_file = SCons.Node.FS.find_file 83 adjustixes = SCons.Util.adjustixes 84 for lib in libs: 85 if SCons.Util.is_String(lib): 86 lib = env.subst(lib) 87 for pref, suf in pairs: 88 l = adjustixes(lib, pref, suf) 89 l = find_file(l, libpath, verbose=print_find_libs) 90 if l: 91 result.append(l) 92 else: 93 result.append(lib) 94 95 return result
96 97 # Local Variables: 98 # tab-width:4 99 # indent-tabs-mode:nil 100 # End: 101 # vim: set expandtab tabstop=4 shiftwidth=4: 102