7 from collections import OrderedDict
9 # cat fontconfig/fontconfig.h | grep '^Fc[^ ]* *(' | sed -e 's/ *(.*$//'
12 with open(fname, 'r', encoding='utf-8') as f:
13 for l in f.readlines():
15 m = re.match(r'^(Fc[^ ]*)[\s\w]*\(.*', l)
17 if m and m.group(1) not in ['FcCacheDir', 'FcCacheSubdir']:
20 if __name__=='__main__':
21 parser = argparse.ArgumentParser()
22 parser.add_argument('srcdir')
23 parser.add_argument('head')
24 parser.add_argument('tail')
25 parser.add_argument('headers', nargs='+')
27 args = parser.parse_args()
31 for fname in os.listdir(args.srcdir):
32 define_name, ext = os.path.splitext(fname)
36 define_name = '__%s__' % os.path.basename(define_name)
38 for definition in extract(os.path.join(args.srcdir, fname)):
39 definitions[definition] = define_name
41 declarations = OrderedDict()
43 for fname in args.headers:
44 for declaration in extract(fname):
46 define_name = definitions[declaration]
48 print ('error: could not locate %s in src/*.c' % declaration)
51 declarations[declaration] = define_name
53 with open(args.head, 'w') as head:
54 with open(args.tail, 'w') as tail:
55 tail.write('#if HAVE_GNUC_ATTRIBUTE\n')
57 for name, define_name in declarations.items():
58 alias = 'IA__%s' % name
59 hattr = 'FC_ATTRIBUTE_VISIBILITY_HIDDEN'
60 head.write('extern __typeof (%s) %s %s;\n' % (name, alias, hattr))
61 head.write('#define %s %s\n' % (name, alias))
62 if define_name != last:
64 tail.write('#endif /* %s */\n' % last)
65 tail.write('#ifdef %s\n' % define_name)
67 tail.write('# undef %s\n' % name)
68 cattr = '__attribute((alias("%s"))) FC_ATTRIBUTE_VISIBILITY_EXPORT' % alias
69 tail.write('extern __typeof (%s) %s %s;\n' % (name, name, cattr))
70 tail.write('#endif /* %s */\n' % last)
71 tail.write('#endif /* HAVE_GNUC_ATTRIBUTE */\n')