#!/usr/bin/env python

# This is a slightly modified version of ChromiumOS' splitconfig
# https://chromium.googlesource.com/chromiumos/third_party/kernel/+/stabilize-5899.B-chromeos-3.14/chromeos/scripts/splitconfig

"""See this page for more details:
http://dev.chromium.org/chromium-os/how-tos-and-troubleshooting/kernel-configuration
"""
import os
import re
import sys

allconfigs = {}

# Parse config files
for config in sys.argv[1:]:

    allconfigs[config] = set()

    for line in open(config):
        m = re.match("#*\s*CONFIG_(\w+)[\s=](.*)$", line)
        if not m:
            continue
        option, value = m.groups()
        allconfigs[config].add((option, value))

# Split out common config options
common = allconfigs.values()[0].copy()
for config in allconfigs.keys():
    common &= allconfigs[config]
for config in allconfigs.keys():
    allconfigs[config] -= common

allconfigs["common"] = common

# Generate new splitconfigs
for config in allconfigs.keys():
    f = open("split-" + config, "w")
    for option, value in sorted(list(allconfigs[config])):
        if value == "is not set":
            print >>f, "# CONFIG_%s %s" % (option, value)
        else:
            print >>f, "CONFIG_%s=%s" % (option, value)
    f.close()

Add script to split kernel config files
scripts: Add script to split kernel config files

This script is slightly modified from the ChromiumOS splitconfig

It takes a number of kernel config files and prints the common
on specific kernel config options to seperate files.

Signed-off-by: Rolf Neugebauer <6fdd1d8677ab4fbcb4df3eff6e190c3298f7f742@docker.com>
