numam-spdk/scripts/genconfig.py

33 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import re
import sys
comment = re.compile('^\s*#')
assign = re.compile('^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)')
with open('CONFIG') 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
for arg in sys.argv:
m = assign.match(arg)
if m:
argvar = m.group(1).strip()
argval = m.group(3).strip()
if argvar == var:
val = argval
if default.lower() == 'y' or default.lower() == 'n':
if val.lower() == 'y':
print "#define SPDK_{} 1".format(var)
else:
print "#undef SPDK_{}".format(var)
else:
strval = val.replace('"', '\"')
print "#define SPDK_{} \"{}\"".format(var, strval)