public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@rfc1149.net>
To: linux-kernel@vger.kernel.org
Subject: Re: What about make mergeconfig ?
Date: 26 Oct 2006 12:50:51 +0200	[thread overview]
Message-ID: <87r6wvjqpg.fsf@willow.rfc1149.net> (raw)
In-Reply-To: 1161755164.22582.60.camel@localhost.localdomain

>>>>> "Benjamin" == Benjamin Herrenschmidt <benh@kernel.crashing.org> writes:

Benjamin> That would merge all entries in the specified file with the
Benjamin> current .config.

You don't need it to be a Makefile target, it can be an external
script. Would this one (untested!) do what you want?

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/

#! /usr/bin/python
#
# (c) 2006 Samuel Tardieu <sam@rfc1149.net>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# Usage: mergeconfig config1 config2 ... > newconfig
#
# To get the formatting back, it is advised to run "make oldconfig" on the
# result.
#
# Be careful in not using the same file as input and output

import sre, sys

_not_set = sre.compile('# (CONFIG_\S+) is not set')
_set = sre.compile('(CONFIG_[^=]+)=(.*)')

def read_config(fn):
    """Read a kernel configuration file and return a dictionary with
    all the options present in the file. If an option is commented out,
    set its value as None."""
    d = {}
    for l in file(fn):
        l = l.rstrip('\r\n')
        x = _not_set.match(l)
        if x: d[x.group(1)] = None
        x = _set.match(l)
        if x: d[x.group(1)] = x.group(2)
    return d

def merge_option(o, v1, v2):
    """Merge option value v1 and v2."""
    if 'y' in [v1, v2]: return 'y'
    if 'm' in [v1, v2]: return 'm'
    if v1 != v2:
        sys.stderr.write('Option %s has two incompatible values: %s and %s' %
                         (o, v1, v2))
        sys.exit(1)
    return v1

def merge_config_into(a, b):
    """Merge configuration dictionary a into configuration dictionary b.
    In addition, this function returns b after the merge."""
    for k, v in a.items():
        try:
            b[v] = merge_option(k, v, b[v])
        except KeyError:
            b[k] = v
    return b

def output_config(d):
    for k, v in d.items():
        if v is None: print '# %s is not set' % k
        else: print '%s=%s' % (k, v)

if __name__ == '__main__':
    output_config (reduce(lambda x, y: merge_config_into(x, read_config(y)),
                          sys.argv[1:], {}))


      parent reply	other threads:[~2006-10-26 10:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-25  5:46 What about make mergeconfig ? Benjamin Herrenschmidt
2006-10-25  6:59 ` David Woodhouse
2006-10-25 10:01 ` Jesper Juhl
2006-10-25 13:52   ` Benjamin Herrenschmidt
2006-10-25 10:18 ` Dick Streefland
2006-10-25 11:39   ` Jan Engelhardt
2006-10-25 12:07     ` Dick Streefland
2006-10-26  8:00       ` Jan Engelhardt
2006-10-26  9:03         ` Geert Uytterhoeven
2006-10-26 11:25           ` Jan Engelhardt
2006-10-26 12:00             ` Geert Uytterhoeven
2006-10-27  9:58               ` Jan Engelhardt
2006-10-27 11:14                 ` Geert Uytterhoeven
2006-10-25 17:41 ` Christoph Lameter
2006-10-26 10:50 ` Samuel Tardieu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r6wvjqpg.fsf@willow.rfc1149.net \
    --to=sam@rfc1149.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox