]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | #!/usr/bin/env python3 |
7c673cae FG |
2 | |
3 | import os | |
4 | import re | |
5 | import sys | |
6 | ||
9f95a23c TL |
7 | comment = re.compile(r'^\s*#') |
8 | assign = re.compile(r'^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)') | |
7c673cae FG |
9 | |
10 | args = os.environ.copy() | |
11 | for 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 | 18 | defs = {} |
11fdf7f2 TL |
19 | try: |
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 | |
39 | except IOError: | |
40 | print("mk/config.mk not found") | |
7c673cae | 41 | |
11fdf7f2 | 42 | for 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)) |