-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgen-config.py
executable file
·71 lines (57 loc) · 2.08 KB
/
gen-config.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import os, re, sys
CONFIG_H = """\
#ifndef CONFIG_H_
#define CONFIG_H_
/* Detected headers */
${{includes}}
/* Functions */
${{functions}}
/* Sizes */
${{sizes}}
/* Definitions */
${{definitions}}
#endif /* CONFIG_H_ */
"""
PATH_SRC = sys.argv[1]
PATH_BIN = sys.argv[2]
FILENAME_CMK = os.path.join (PATH_SRC, 'CMakeLists.txt')
FILENAME_NEW = os.path.join (PATH_BIN, 'config.h.in')
# Parse CMakeLists.txt
with open(FILENAME_CMK, 'r') as f:
cont = f.read()
includes_t = ''
for h in re.findall (r'HPACK_CHECK_INCLUDE *\(.+? *(\w+)\)', cont, re.IGNORECASE):
includes_t += '#cmakedefine %s\n' %(h)
functions_t = ''
for f in re.findall (r'CHECK_FUNCTION_EXISTS *\(.+? *(\w+)\)', cont, re.IGNORECASE):
functions_t += '#cmakedefine %s\n' %(f)
for f in re.findall (r'CHECK_C_SOURCE_COMPILES *\(.+?(HAVE_.+?)\)\n', cont, re.S):
functions_t += '#cmakedefine %s\n' %(f)
for f in re.findall (r'CHECK_C_SOURCE_RUNS *\(.+?(HAVE_.+?)\)\n', cont, re.S):
functions_t += '#cmakedefine %s\n' %(f)
definitions_t = ''
for f in re.findall (r'DEF_SET *\((\w+)? +(.+?)\)', cont, re.IGNORECASE):
definitions_t += '#cmakedefine %s %s\n' %(f[0], f[1])
for f in re.findall (r'DEF_SET_IFNDEF *\((\w+)? +(.+?)\)', cont, re.IGNORECASE):
definitions_t += '#ifndef %s\n' %(f[0])
definitions_t += '#cmakedefine %s %s\n' %(f[0], f[1])
definitions_t += '#endif\n'
for f in re.findall (r'DEF_DEFINE *\((\w+)?\)', cont, re.IGNORECASE):
definitions_t += '#cmakedefine %s\n' %(f)
sizes_t = ''
for h in re.findall (r'CHECK_TYPE_SIZE *\(.+? *(\w+)\)', cont, re.IGNORECASE):
sizes_t += '@%s_CODE@\n' %(h)
sizes_t += '#cmakedefine HAVE_%s\n' %(h)
sizes_t += '#ifdef HAVE_%s\n' %(h)
sizes_t += '# define HAVE_%s\n' %(h.replace('SIZEOF_',''))
sizes_t += '#endif\n'
# Replacements
config_h = CONFIG_H
config_h = config_h.replace ("${{includes}}", includes_t)
config_h = config_h.replace ("${{functions}}", functions_t)
config_h = config_h.replace ("${{sizes}}", sizes_t)
config_h = config_h.replace ("${{definitions}}", definitions_t)
# Write config.h
with open(FILENAME_NEW, 'w+') as f:
f.write (config_h)