build: remove redundant config include
[dpdk.git] / buildtools / map_to_def.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2019 Intel Corporation
4
5 from __future__ import print_function
6 import sys
7 from os.path import dirname, basename, join, exists
8
9
10 def is_function_line(ln):
11     return ln.startswith('\t') and ln.endswith(';\n') and ":" not in ln
12
13
14 def main(args):
15     if not args[1].endswith('version.map') or \
16             not args[2].endswith('exports.def'):
17         return 1
18
19 # special case, allow override if an def file already exists alongside map file
20     override_file = join(dirname(args[1]), basename(args[2]))
21     if exists(override_file):
22         with open(override_file) as f_in:
23             functions = f_in.readlines()
24
25 # generate def file from map file.
26 # This works taking indented lines only which end with a ";" and which don't
27 # have a colon in them, i.e. the lines defining functions only.
28     else:
29         with open(args[1]) as f_in:
30             functions = [ln[:-2] + '\n' for ln in sorted(f_in.readlines())
31                          if is_function_line(ln)]
32             functions = ["EXPORTS\n"] + functions
33
34     with open(args[2], 'w') as f_out:
35         f_out.writelines(functions)
36     return 0
37
38
39 if __name__ == "__main__":
40     sys.exit(main(sys.argv))