[lkml]   [2006]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: What about make mergeconfig ?
>>>>> "Benjamin" == Benjamin Herrenschmidt <> 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?

Samuel Tardieu -- --

#! /usr/bin/python
# (c) 2006 Samuel Tardieu <>
# 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[] = None
x = _set.match(l)
if x: d[] =
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))
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():
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:], {}))

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2006-10-26 12:59    [W:0.058 / U:39.752 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site