summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 71d5096523..86122f42c8 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -47,6 +47,7 @@ __all__ = [
'copy_mode',
'filter_file',
'find_libraries',
+ 'find_system_libraries',
'fix_darwin_install_name',
'force_remove',
'force_symlink',
@@ -583,6 +584,54 @@ class LibraryList(collections.Sequence):
return self.joined()
+def find_system_libraries(args, shared=True):
+ """Searches the usual system library locations for the libraries
+ specified in args.
+
+ Search order is as follows:
+
+ 1. /lib64
+ 2. /lib
+ 3. /usr/lib64
+ 4. /usr/lib
+ 5. /usr/local/lib64
+ 6. /usr/local/lib
+
+ :param args: Library name(s) to search for
+ :type args: str or collections.Sequence
+ :param bool shared: if True searches for shared libraries,
+
+ :returns: The libraries that have been found
+ :rtype: LibraryList
+ """
+ if isinstance(args, str):
+ args = [args]
+ elif not isinstance(args, collections.Sequence):
+ message = '{0} expects a string or sequence of strings as the '
+ message += 'first argument [got {1} instead]'
+ message = message.format(find_system_libraries.__name__, type(args))
+ raise TypeError(message)
+
+ libraries_found = []
+ search_locations = [
+ '/lib64',
+ '/lib',
+ '/usr/lib64',
+ '/usr/lib',
+ '/usr/local/lib64',
+ '/usr/local/lib',
+ ]
+
+ for library in args:
+ for root in search_locations:
+ result = find_libraries(library, root, shared, recurse=True)
+ if result:
+ libraries_found += result
+ break
+
+ return libraries_found
+
+
def find_libraries(args, root, shared=True, recurse=False):
"""Returns an iterable object containing a list of full paths to
libraries if found.