2016-06-07 18:31:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-11-30 17:05:20 +00:00
|
|
|
import os
|
2016-06-07 18:31:12 +00:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
comment = re.compile('^\s*#')
|
|
|
|
assign = re.compile('^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)')
|
|
|
|
|
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
|
|
|
|
|
2016-11-30 17:07:14 +00:00
|
|
|
# special case for DPDK_DIR, which is short for CONFIG_DPDK_DIR
|
|
|
|
if 'DPDK_DIR' in args and 'CONFIG_DPDK_DIR' not in args:
|
|
|
|
args['CONFIG_DPDK_DIR'] = args['DPDK_DIR']
|
|
|
|
|
2017-03-30 19:06:49 +00:00
|
|
|
defs = {}
|
|
|
|
for config in ('CONFIG', 'CONFIG.local'):
|
|
|
|
try:
|
|
|
|
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
|
|
|
|
if var in args:
|
|
|
|
val = args[var]
|
|
|
|
if default.lower() == 'y' or default.lower() == 'n':
|
|
|
|
if val.lower() == 'y':
|
2017-04-26 00:22:35 +00:00
|
|
|
defs["SPDK_{0}".format(var)] = 1
|
2017-03-30 19:06:49 +00:00
|
|
|
else:
|
2017-04-26 00:22:35 +00:00
|
|
|
defs["SPDK_{0}".format(var)] = 0
|
2017-03-30 19:06:49 +00:00
|
|
|
else:
|
|
|
|
strval = val.replace('"', '\"')
|
2017-04-26 00:22:35 +00:00
|
|
|
defs["SPDK_{0}".format(var)] = strval
|
2017-03-30 19:06:49 +00:00
|
|
|
except IOError:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for key, value in defs.items():
|
|
|
|
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))
|