1#!/usr/bin/env python3
2
3import io, os, re, sys
4
5if len (sys.argv) < 3:
6	sys.exit("usage: gen-def.py harfbuzz.def hb.h [hb-blob.h hb-buffer.h ...]")
7
8output_file = sys.argv[1]
9header_paths = sys.argv[2:]
10
11headers_content = []
12for h in header_paths:
13	if h.endswith (".h"):
14		with io.open (h, encoding='utf-8') as f: headers_content.append (f.read ())
15
16symbols = sorted (re.findall (r"^hb_\w+(?= \()", "\n".join (headers_content), re.M))
17if not os.environ.get('HB_EXPERIMENTAL_API', ''):
18	# Move these to harfbuzz-sections.txt when got stable
19	experimental_symbols = \
20"""hb_font_draw_glyph
21hb_draw_funcs_t
22hb_draw_close_path_func_t
23hb_draw_cubic_to_func_t
24hb_draw_line_to_func_t
25hb_draw_move_to_func_t
26hb_draw_quadratic_to_func_t
27hb_draw_funcs_create
28hb_draw_funcs_destroy
29hb_draw_funcs_is_immutable
30hb_draw_funcs_make_immutable
31hb_draw_funcs_reference
32hb_draw_funcs_set_close_path_func
33hb_draw_funcs_set_cubic_to_func
34hb_draw_funcs_set_line_to_func
35hb_draw_funcs_set_move_to_func
36hb_draw_funcs_set_quadratic_to_func""".splitlines ()
37	symbols = [x for x in symbols if x not in experimental_symbols]
38symbols = "\n".join (symbols)
39
40result = symbols if os.environ.get('PLAIN_LIST', '') else """EXPORTS
41%s
42LIBRARY lib%s-0.dll""" % (symbols, output_file.replace ('src/', '').replace ('.def', ''))
43
44with open (output_file, "w") as f: f.write (result)
45