1#!/usr/bin/env python
2#===----------------------------------------------------------------------===##
3#
4#                     The LLVM Compiler Infrastructure
5#
6# This file is dual licensed under the MIT and the University of Illinois Open
7# Source Licenses. See LICENSE.TXT for details.
8#
9#===----------------------------------------------------------------------===##
10"""
11sym_extract - Extract and output a list of symbols from a shared library.
12"""
13from argparse import ArgumentParser
14from libcxx.sym_check import extract, util
15
16
17def main():
18    parser = ArgumentParser(
19        description='Extract a list of symbols from a shared library.')
20    parser.add_argument('library', metavar='shared-lib', type=str,
21                        help='The library to extract symbols from')
22    parser.add_argument('-o', '--output', dest='output',
23                        help='The output file. stdout is used if not given',
24                        type=str, action='store', default=None)
25    parser.add_argument('--names-only', dest='names_only',
26                        help='Output only the name of the symbol',
27                        action='store_true', default=False)
28    parser.add_argument('--only-stdlib-symbols', dest='only_stdlib',
29                        help="Filter all symbols not related to the stdlib",
30                        action='store_true', default=False)
31    args = parser.parse_args()
32    if args.output is not None:
33        print('Extracting symbols from %s to %s.'
34              % (args.library, args.output))
35    syms = extract.extract_symbols(args.library)
36    if args.only_stdlib:
37        syms, other_syms = util.filter_stdlib_symbols(syms)
38    util.write_syms(syms, out=args.output, names_only=args.names_only)
39
40
41if __name__ == '__main__':
42    main()
43