#! /usr/bin/env python # vim: set fileencoding=utf-8 : # Copyright (C) 2010 by Uwe Kleine-König import getopt import re import os import subprocess import sys # This prevents including a timestamp in the .config which makes comparing a # bit easier. os.environ['KCONFIG_NOTIMESTAMP'] = 'Yes, please' re_interesting = re.compile(r'^(# )?CONFIG_') opts, args = getopt.getopt(sys.argv[1:], '', ['arch=', 'src=']) src = '' arch = 'arm' for o, a in opts: if o == '--arch': arch = a elif o == '--src': src = a configdir = os.path.join(src, 'arch', arch, 'configs') def all_defconfigs(): lc = len(configdir) for root, dirs, files in os.walk(configdir): root = root[lc + 1:] for f in filter(lambda s: s.endswith('_defconfig'), files): yield os.path.join(root, f) if not args: args = all_defconfigs() for target in args: defconfig_src = os.path.join(configdir, target) subprocess.check_call(['make', '-s', 'ARCH=%s' % arch, target]) origconfig = list(open('.config')) config = list(origconfig) config_size = os.stat('.config').st_size i = 0 while i < len(config): mo = re_interesting.match(config[i]) if mo: defconfig = open(defconfig_src, 'w') defconfig.writelines(config[:i]) defconfig.writelines(config[i + 1:]) defconfig.close() subprocess.check_call(['make', '-s', 'ARCH=%s' % arch, target]) if os.stat('.config').st_size == config_size and list(open('.config')) == origconfig: print '-%s' % config[i][:-1] del config[i] else: print ' %s' % config[i][:-1] i += 1 else: del config[i] defconfig = open(defconfig_src, 'w') defconfig.writelines(config) defconfig.close()