ctf-writer: externalize libbabeltrace2-ctf-writer
[babeltrace.git] / extras / gen-babeltrace-h.py
CommitLineData
a3dc8f46
PP
1import re
2
3
4class _Section:
5 def __init__(self, title, filenames):
6 self.title = title
7 self.filenames = filenames
8
9
10def _get_sections(file):
11 sections = []
12 cur_title = None
13 cur_filenames = []
14
15 for line in file:
16 m = re.match(r'^# (.+API.*)$', line)
17
18 if m:
19 if cur_filenames:
20 sections.append(_Section(cur_title, cur_filenames))
21 cur_title = None
22 cur_filenames = []
23
24 cur_title = m.group(1)
25 continue
26
3fadfbc0 27 m = re.match(r'^\s+(babeltrace2/.+\.h).*$', line)
a3dc8f46
PP
28
29 if m:
3fadfbc0 30 if m.group(1) != 'babeltrace2/babeltrace.h':
a3dc8f46
PP
31 cur_filenames.append(m.group(1))
32
33 continue
34
35 if re.match(r'^noinst_HEADERS.*', line):
36 break
37
38 if cur_filenames:
39 sections.append(_Section(cur_title, cur_filenames))
40
41 return sections
42
43
44def _c_includes_from_sections(sections):
45 src = ''
46
47 for section in sections:
67d2ce02
MJ
48 if 'ctf' in section.title.lower():
49 continue
50
a3dc8f46
PP
51 src += '/* {} */\n'.format(section.title)
52
53 for filename in sorted(section.filenames):
54 src += '#include <{}>\n'.format(filename)
55
56 src += '\n'
57
58 return src[:-1]
59
60
61def _main():
62 with open('include/Makefile.am') as f:
63 sections = _get_sections(f)
64
65 print('''#ifndef BABELTRACE_BABELTRACE_H
66#define BABELTRACE_BABELTRACE_H
67
68/*
69 * Babeltrace API
70 *
d94d92ac 71 * Copyright 2010-2018 EfficiOS Inc. <http://www.efficios.com/>
a3dc8f46
PP
72 *
73 * Permission is hereby granted, free of charge, to any person obtaining a copy
74 * of this software and associated documentation files (the "Software"), to deal
75 * in the Software without restriction, including without limitation the rights
76 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77 * copies of the Software, and to permit persons to whom the Software is
78 * furnished to do so, subject to the following conditions:
79 *
80 * The above copyright notice and this permission notice shall be included in
81 * all copies or substantial portions of the Software.
82 *
83 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89 * SOFTWARE.
90 */
91''')
92 print(_c_includes_from_sections(sections))
93 print('#endif /* BABELTRACE_BABELTRACE_H */')
94
95if __name__ == '__main__':
96 _main()
This page took 0.037539 seconds and 4 git commands to generate.