xref: /spdk/scripts/genconfig.py (revision 0ed85362c8132a2d1927757fbcade66b6660d26a)
1#!/usr/bin/env python3
2
3import os
4import re
5import sys
6
7comment = re.compile(r'^\s*#')
8assign = re.compile(r'^\s*([a-zA-Z0-9_]+)\s*(\?)?=\s*([^#]*)')
9
10args = os.environ.copy()
11for arg in sys.argv:
12    m = assign.match(arg)
13    if m:
14        var = m.group(1).strip()
15        val = m.group(3).strip()
16        args[var] = val
17
18defs = {}
19try:
20    with open("mk/config.mk") as f:
21        for line in f:
22            line = line.strip()
23            if not comment.match(line):
24                m = assign.match(line)
25                if m:
26                    var = m.group(1).strip()
27                    default = m.group(3).strip()
28                    val = default
29                    if var in args:
30                        val = args[var]
31                    if default.lower() == 'y' or default.lower() == 'n':
32                        if val.lower() == 'y':
33                            defs["SPDK_{0}".format(var)] = 1
34                        else:
35                            defs["SPDK_{0}".format(var)] = 0
36                    else:
37                        strval = val.replace('"', '\"')
38                        defs["SPDK_{0}".format(var)] = strval
39except IOError:
40    print("mk/config.mk not found")
41
42for key, value in sorted(defs.items()):
43    if value == 0:
44        print("#undef {0}".format(key))
45    else:
46        print("#define {0} {1}".format(key, value))
47