1#!/bin/bash
2
3# miniconfig.sh copyright 2005 by Rob Landley <rob@landley.net>
4# Licensed under the GNU General Public License version 2.
5
6# Run this in the linux kernel build directory with a starting file, and
7# it creates a file called mini.config with all the redundant lines of that
8# .config removed. The starting file must match what the kernel outputs.
9# If it doesn't, then run "make oldconfig" on it to get one that does.
10
11export KCONFIG_NOTIMESTAMP=1
12
13if [ $# -ne 1 ] || [ ! -f "$1" ]
14then
15 echo "Usage: miniconfig.sh configfile"
16 exit 1
17fi
18
19if [ "$1" == ".config" ]
20then
21 echo "It overwrites .config, rename it and try again."
22 exit 1
23fi
24
25make allnoconfig KCONFIG_ALLCONFIG="$1" > /dev/null
26if ! cmp .config "$1"
27then
28 echo Sanity test failed, normalizing starting configuration...
29 diff -u "$1" .config
30fi
31cp .config .big.config
32cp .config mini.config
33
34echo "Calculating mini.config..."
35
36LENGTH=`cat $1 | wc -l`
37
38# Loop through all lines in the file
39I=1
40while true
41do
42 if [ $I -gt $LENGTH ]
43 then
44 break
45 fi
46 sed -n "${I}!p" mini.config > .config.test
47 # Do a config with this file
48 make allnoconfig KCONFIG_ALLCONFIG=.config.test > /dev/null
49
50 # Compare. Because we normalized at the start, the files should be identical.
51 if cmp -s .config .big.config
52 then
53 mv .config.test mini.config
54 LENGTH=$[$LENGTH-1]
55 else
56 I=$[$I + 1]
57 fi
58 echo -n -e "\r$[$I-1]/$LENGTH lines $(cat mini.config | wc -c) bytes "
59done
60rm .big.config
61echo