blob: 262fa2015c1d3bae69ab4f8a7da030e5b31ac31f [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001#!/usr/bin/env python
2
3import os
4import re
5import sys
6
7allconfigs = {}
8
9# Parse config files
10for config in os.listdir("."):
11 # Only config.*
12 if not config.startswith("config."):
13 continue
14 # Ignore emacs backups
15 if config.endswith("~"):
16 continue
17 # Nothing that is disabled, or remnant
18 if re.search("\.(default|disabled|stub)$", config):
19 continue
20
21 allconfigs[config] = set()
22
23 for line in open(config):
24 m = re.match("#*\s*CONFIG_(\w+)[\s=](.*)$", line)
25 if not m:
26 continue
27 option, value = m.groups()
28 allconfigs[config].add((option, value))
29
30# Split out common config options
31common = allconfigs.values()[0].copy()
32for config in allconfigs.keys():
33 common &= allconfigs[config]
34for config in allconfigs.keys():
35 allconfigs[config] -= common
36allconfigs["config.common"] = common
37
38# Generate new splitconfigs
39for config in allconfigs.keys():
40 f = open(config, "w")
41 command = os.path.basename(sys.argv[0])
42 print >>f, "#\n# Config options generated by %s\n#" % command
43 for option, value in sorted(list(allconfigs[config])):
44 if value == "is not set":
45 print >>f, "# CONFIG_%s %s" % (option, value)
46 else:
47 print >>f, "CONFIG_%s=%s" % (option, value)
48
49 f.close()