Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import re |
| 5 | import sys |
| 6 | |
| 7 | allconfigs = {} |
| 8 | |
| 9 | # Parse config files |
| 10 | for 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 |
| 31 | common = allconfigs.values()[0].copy() |
| 32 | for config in allconfigs.keys(): |
| 33 | common &= allconfigs[config] |
| 34 | for config in allconfigs.keys(): |
| 35 | allconfigs[config] -= common |
| 36 | allconfigs["config.common"] = common |
| 37 | |
| 38 | # Generate new splitconfigs |
| 39 | for 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() |