-
Notifications
You must be signed in to change notification settings - Fork 0
/
amalgamate.py
executable file
·49 lines (39 loc) · 1.38 KB
/
amalgamate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# This script combines all sources into a single '.c' file, so that in can be
# compiled as a part of a project.
import os.path
pjoin = os.path.join
def process_file(fname, dest):
with open(fname, 'r') as f:
if '.h' in fname:
# Skip top comment and include guards
lines = f.readlines()[6:-1]
else:
# Just skip the comment
lines = f.readlines()[3:]
for line in lines:
# Should not happen (no '\n')
if not line:
continue
# Skip project includes
if line[0] == '#' and '"' in line:
continue
# Skip @file doxygen commands
if '@file' in line:
continue
dest.write(line)
def main():
src_dir = os.path.dirname(__file__)
dest_file = pjoin(src_dir, 'build', 'petrovich.c')
with open(dest_file, 'w') as dest:
dest.write('''/// @file petrovich.c
///
/// @copyright Copyright (c) Mail.Ru Group, 2016. All rights reserved. MIT License.
// Note: this file is automatically combined from petrovich-c library sources
#define PETROVICH_NDEBUG
#include "petrovich.h"''')
for name in ['buffer.h', 'utf8.h', 'utf8.c', 'petrovich.c']:
full_name = pjoin(src_dir, 'lib', name)
process_file(full_name, dest)
if __name__ == '__main__':
main()