]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/scripts/genconfig.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / scripts / genconfig.py
CommitLineData
11fdf7f2 1#!/usr/bin/env python3
7c673cae
FG
2
3import os
4import re
5import sys
6
9f95a23c
TL
7comment = re.compile(r'^\s*#')
8assign = re.compile(r'^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)')
7c673cae
FG
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
7c673cae 18defs = {}
11fdf7f2
TL
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
7c673cae 34 else:
11fdf7f2
TL
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")
7c673cae 41
11fdf7f2 42for key, value in sorted(defs.items()):
7c673cae 43 if value == 0:
11fdf7f2 44 print("#undef {0}".format(key))
7c673cae 45 else:
11fdf7f2 46 print("#define {0} {1}".format(key, value))