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