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

Source Code for Module SCons.Scanner.Prog

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