]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/serf/build/gen_def.py
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / serf / build / gen_def.py
1 #!/usr/bin/env python
2 #
3 # gen_def.py :  Generate the .DEF file for Windows builds
4 #
5 # ====================================================================
6 #   Copyright 2002-2010 Justin Erenkrantz and Greg Stein
7 #
8 #   Licensed under the Apache License, Version 2.0 (the "License");
9 #   you may not use this file except in compliance with the License.
10 #   You may obtain a copy of the License at
11 #
12 #        http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #   Unless required by applicable law or agreed to in writing, software
15 #   distributed under the License is distributed on an "AS IS" BASIS,
16 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 #   See the License for the specific language governing permissions and
18 #   limitations under the License.
19 # ====================================================================
20 #
21 #
22 # Typically, this script is used like:
23 #
24 #    C:\PATH> python build/gen_def.py serf.h serf_bucket_types.h serf_bucket_util.h > build/serf.def
25 #
26
27 import re
28 import sys
29
30 # This regex parses function declarations that look like:
31 #
32 #    return_type serf_func1(...
33 #    return_type *serf_func2(...
34 #
35 # Where return_type is a combination of words and "*" each separated by a
36 # SINGLE space. If the function returns a pointer type (like serf_func2),
37 # then a space may exist between the "*" and the function name. Thus,
38 # a more complicated example might be:
39 #    const type * const * serf_func3(...
40 #
41 _funcs = re.compile(r'^(?:(?:\w+|\*) )+\*?(serf_[a-z][a-zA-Z_0-9]*)\(',
42                     re.MULTILINE)
43
44 # This regex parses the bucket type definitions which look like:
45 #
46 #    extern const serf_bucket_type_t serf_bucket_type_FOO;
47 #
48 _types = re.compile(r'^extern const serf_bucket_type_t (serf_[a-z_]*);',
49                     re.MULTILINE)
50
51
52 def extract_exports(fname):
53   content = open(fname).read()
54   exports = [ ]
55   for name in _funcs.findall(content):
56     exports.append(name)
57   for name in _types.findall(content):
58     exports.append(name)
59   return exports
60
61 # Blacklist the serf v2 API for now
62 blacklist = ['serf_connection_switch_protocol',
63              'serf_http_protocol_create',
64              'serf_http_request_create',
65              'serf_https_protocol_create']
66
67 if __name__ == '__main__':
68   # run the extraction over each file mentioned
69   import sys
70   print("EXPORTS")
71
72   for fname in sys.argv[1:]:
73     funclist = extract_exports(fname)
74     funclist = set(funclist) - set(blacklist)
75     for func in funclist:
76       print(func)