xref: /spdk/scripts/genconfig.py (revision be2d2c76cf7208202bfb2c4f109451f6b00c4ec2)
1#!/usr/bin/env python3
2
3import os
4import re
5import sys
6
7comment = re.compile('^\s*#')
8assign = re.compile('^\s*([a-zA-Z_]+)\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 = {}
19for config in ('CONFIG', 'CONFIG.local'):
20    try:
21        with open(config) as f:
22            for line in f:
23                line = line.strip()
24                if not comment.match(line):
25                    m = assign.match(line)
26                    if m:
27                        var = m.group(1).strip()
28                        default = m.group(3).strip()
29                        val = default
30                        if var in args:
31                            val = args[var]
32                        if default.lower() == 'y' or default.lower() == 'n':
33                            if val.lower() == 'y':
34                                defs["SPDK_{0}".format(var)] = 1
35                            else:
36                                defs["SPDK_{0}".format(var)] = 0
37                        else:
38                            strval = val.replace('"', '\"')
39                            defs["SPDK_{0}".format(var)] = strval
40    except IOError:
41        continue
42
43for key, value in sorted(defs.items()):
44    if value == 0:
45        print("#undef {0}".format(key))
46    else:
47        print("#define {0} {1}".format(key, value))
48