Remove unnecessary options
[platform/upstream/libxkbcommon.git] / scripts / map-to-def
1 #!/usr/bin/env python
2
3 """A script to generate MSVC Module-Definition files from version-script
4 files (which are maintained manually)."""
5
6 import re
7 import sys
8 import pathlib
9
10
11 def symbols_from_map(path):
12     return re.findall(r"^\s+(r?xkb_.*);", path.read_text("utf-8"), re.MULTILINE)
13
14
15 if 2 > len(sys.argv) > 3:
16     raise SystemExit("Usage: {} file.map [file.def]".format(sys.argv[0]))
17
18
19 map_file = pathlib.Path(sys.argv[1])
20 map_symbols = set(symbols_from_map(map_file))
21
22 if len(sys.argv) == 3:
23     def_file = open(sys.argv[2], "w", encoding="utf-8")
24 else:
25     def_file = sys.stdout
26
27 def_file.write("LIBRARY {}\n".format(map_file.stem))
28 def_file.write("EXPORTS\n")
29 for symbol in sorted(map_symbols):
30     def_file.write("\t{}\n".format(symbol))