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