numam-spdk/scripts/genconfig.py
Artur Paszkiewicz 339fb7cd15 genconfig.py: allow numbers in config option names
To make it possible to add CONFIG_RAID5.

Change-Id: I1712bde5bae552811343fb1865f1224d3adb1c7e
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/854
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
2020-02-20 14:40:19 +00:00

47 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import re
import sys
comment = re.compile(r'^\s*#')
assign = re.compile(r'^\s*([a-zA-Z0-9_]+)\s*(\?)?=\s*([^#]*)')
args = os.environ.copy()
for arg in sys.argv:
m = assign.match(arg)
if m:
var = m.group(1).strip()
val = m.group(3).strip()
args[var] = val
defs = {}
try:
with open("mk/config.mk") as f:
for line in f:
line = line.strip()
if not comment.match(line):
m = assign.match(line)
if m:
var = m.group(1).strip()
default = m.group(3).strip()
val = default
if var in args:
val = args[var]
if default.lower() == 'y' or default.lower() == 'n':
if val.lower() == 'y':
defs["SPDK_{0}".format(var)] = 1
else:
defs["SPDK_{0}".format(var)] = 0
else:
strval = val.replace('"', '\"')
defs["SPDK_{0}".format(var)] = strval
except IOError:
print("mk/config.mk not found")
for key, value in sorted(defs.items()):
if value == 0:
print("#undef {0}".format(key))
else:
print("#define {0} {1}".format(key, value))