2018-09-11 13:26:14 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-06-07 18:31:12 +00:00
|
|
|
|
2016-11-30 17:05:20 +00:00
|
|
|
import os
|
2016-06-07 18:31:12 +00:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2019-02-08 17:50:49 +00:00
|
|
|
comment = re.compile(r'^\s*#')
|
2020-02-03 13:24:32 +00:00
|
|
|
assign = re.compile(r'^\s*([a-zA-Z0-9_]+)\s*(\?)?=\s*([^#]*)')
|
2016-06-07 18:31:12 +00:00
|
|
|
|
2016-11-30 17:05:20 +00:00
|
|
|
args = os.environ.copy()
|
2016-11-30 17:04:14 +00:00
|
|
|
for arg in sys.argv:
|
|
|
|
m = assign.match(arg)
|
|
|
|
if m:
|
|
|
|
var = m.group(1).strip()
|
|
|
|
val = m.group(3).strip()
|
|
|
|
args[var] = val
|
|
|
|
|
2017-03-30 19:06:49 +00:00
|
|
|
defs = {}
|
2018-10-18 20:04:36 +00:00
|
|
|
try:
|
2018-10-08 17:03:38 +00:00
|
|
|
with open("mk/config.mk") as f:
|
2018-10-18 20:04:36 +00:00
|
|
|
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
|
2017-03-30 19:06:49 +00:00
|
|
|
else:
|
2018-10-18 20:04:36 +00:00
|
|
|
defs["SPDK_{0}".format(var)] = 0
|
|
|
|
else:
|
|
|
|
strval = val.replace('"', '\"')
|
|
|
|
defs["SPDK_{0}".format(var)] = strval
|
|
|
|
except IOError:
|
2018-10-08 17:03:38 +00:00
|
|
|
print("mk/config.mk not found")
|
2017-03-30 19:06:49 +00:00
|
|
|
|
2018-02-07 20:58:11 +00:00
|
|
|
for key, value in sorted(defs.items()):
|
2017-03-30 19:06:49 +00:00
|
|
|
if value == 0:
|
2017-06-02 06:13:30 +00:00
|
|
|
print("#undef {0}".format(key))
|
2017-03-30 19:06:49 +00:00
|
|
|
else:
|
2017-06-02 06:13:30 +00:00
|
|
|
print("#define {0} {1}".format(key, value))
|