aboriginal

view sources/toys/miniconfig.sh @ 1600:e50c2b9588b8

Fluff out the architectures page.
author Rob Landley <rob@landley.net>
date Mon May 06 00:29:57 2013 -0500 (2 weeks ago)
parents e948f92964b5
children
line source
1 #!/bin/bash
3 # miniconfig.sh copyright 2005 by Rob Landley <rob@landley.net>
4 # Licensed under the GNU General Public License version 2.
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.
11 # A miniconfig file is essentially the list of symbols you'd have to switch
12 # on if you started from "allnoconfig" and then went through menuconfig
13 # selecting what you wanted. It's just the list of symbols you're interested
14 # in, without including the ones set automatically by dependency checking.
16 # To use a miniconfig: make allnoconfig KCONFIG_ALLCONFIG=/path/to/mini.conf
18 # Miniconfig is more easily human-readable than a full .config file, and in
19 # some ways more version-independent than full .config files. On the other
20 # hand, when you update to a new kernel it won't get default values for newly
21 # created symbols (they'll be off if they didn't exist before and thus weren't
22 # in your "I need this and this and this" checklist), which can cause problems.
24 # See sources/more/migrate_kernel.sh for a script that expands a miniconfig
25 # to a .config under an old kernel version, copies it to a new version,
26 # runs "make oldconfig" to update it, creates a new mini.config from the
27 # result, and then shows a diff so you can see whether you want the new symbols.
29 export KCONFIG_NOTIMESTAMP=1
31 if [ $# -ne 1 ]
32 then
33 echo "Usage: miniconfig.sh configfile"
34 exit 1
35 fi
37 if [ ! -f "$1" ]
38 then
39 echo "Couldn't find "'"'"$1"'"'
40 exit 1
41 fi
43 if [ "$1" == ".config" ]
44 then
45 echo "It overwrites .config, rename it and try again."
46 exit 1
47 fi
49 make allnoconfig KCONFIG_ALLCONFIG="$1" > /dev/null
50 # Shouldn't need this, but kconfig goes "boing" at times...
51 yes "" | make oldconfig > /dev/null
52 if ! cmp .config "$1"
53 then
54 echo Sanity test failed, normalizing starting configuration...
55 diff -u "$1" .config
56 fi
57 cp .config .big.config
59 # Speed heuristic: remove all blank/comment lines
60 grep -v '^[#$]' .config | grep -v '^$' > mini.config
61 # This should never fail, but kconfig is so broken it does sometimes.
62 make allnoconfig KCONFIG_ALLCONFIG=mini.config > /dev/null
63 if ! cmp .config "$1"
64 then
65 echo Insanity test failed: reversing blank line removal heuristic.
66 cp .big.config mini.config
67 fi
68 #cp .config mini.config
70 echo "Calculating mini.config..."
72 LENGTH=`cat mini.config | wc -l`
73 OLDLENGTH=$LENGTH
75 # Loop through all lines in the file
76 I=1
77 while true
78 do
79 [ $I -gt $LENGTH ] && break
80 sed -n "$I,$(($I+${STRIDE:-1}-1))!p" mini.config > .config.test
81 # Do a config with this file
82 rm .config
83 make allnoconfig KCONFIG_ALLCONFIG=.config.test 2>/dev/null | head -n 1000000 > /dev/null
84 # Compare. Because we normalized at the start, the files should be identical.
85 if cmp -s .config .big.config
86 then
87 # Found unneeded line(s)
88 mv .config.test mini.config
89 LENGTH=$(($LENGTH-${STRIDE:-1}))
90 # Cosmetic: if stride tests off the end don't show total length less
91 # than number of entries found.
92 [ $I -gt $LENGTH ] && LENGTH=$(($I-1))
93 # Special case where we know the next line _is_ needed: stride 2 failed
94 # but we discarded the first line
95 [ -z "$STRIDE" ] && [ ${OLDSTRIDE:-1} -eq 2 ] && I=$(($I+1))
96 STRIDE=$(($STRIDE+1))
97 OLDSTRIDE=$STRIDE
98 else
99 # That hunk was needed
100 if [ ${STRIDE:-1} -le 1 ]
101 then
102 I=$(($I+1))
103 OLDSTRIDE=
104 fi
105 STRIDE=
106 fi
107 echo -n -e "\r[${STRIDE:-1}] $[$I-1]/$LENGTH lines $(cat mini.config | wc -c) bytes $[100-((($LENGTH-$I)*100)/$OLDLENGTH)]% "
108 done
109 rm .big.config
110 echo