3 """Converts a .exports file to a format consumable by linkers.
5 An .exports file is a file with one exported symbol per line.
6 This script converts a .exports file into a format that linkers
8 - It prepends a `_` to each line for use with -exported_symbols_list for Darwin
9 - It writes a .def file for use with /DEF: for Windows
10 - It writes a linker script for use with --version-script elsewhere
18 parser
= argparse
.ArgumentParser(
20 formatter_class
=argparse
.RawDescriptionHelpFormatter
)
21 parser
.add_argument("--format", required
=True, choices
=("linux", "mac", "win"))
22 parser
.add_argument("source")
23 parser
.add_argument("output")
24 args
= parser
.parse_args()
26 symbols
= open(args
.source
).readlines()
28 if args
.format
== "linux":
34 + [" %s;\n" % s
.rstrip() for s
in symbols
]
35 + [" local:\n", " *;\n", "};\n"]
37 elif args
.format
== "mac":
38 output_lines
= ["_" + s
for s
in symbols
]
40 assert args
.format
== "win"
41 output_lines
= ["EXPORTS\n"] + [" " + s
for s
in symbols
]
43 open(args
.output
, "w").writelines(output_lines
)
46 if __name__
== "__main__":