#!/bin/bash # miniconfig.sh copyright 2005 by Rob Landley # Licensed under the GNU General Public License version 2. # Run this in the linux kernel build directory with a starting file, and # it creates a file called mini.config with all the redundant lines of that # .config removed. The starting file must match what the kernel outputs. # If it doesn't, then run "make oldconfig" on it to get one that does. # A miniconfig file is essentially the list of symbols you'd have to switch # on if you started from "allnoconfig" and then went through menuconfig # selecting what you wanted. It's just the list of symbols you're interested # in, without including the ones set automatically by dependency checking. # To use a miniconfig: make allnoconfig KCONFIG_ALLCONFIG=/path/to/mini.conf # Miniconfig is more easily human-readable than a full .config file, and in # some ways more version-independent than full .config files. On the other # hand, when you update to a new kernel it won't get default values for newly # created symbols (they'll be off if they didn't exist before and thus weren't # in your "I need this and this and this" checklist), which can cause problems. # See sources/more/migrate_kernel.sh for a script that expands a miniconfig # to a .config under an old kernel version, copies it to a new version, # runs "make oldconfig" to update it, creates a new mini.config from the # result, and then shows a diff so you can see whether you want the new symbols. export KCONFIG_NOTIMESTAMP=1 if test $Argc -ne 1 { echo "Usage: miniconfig.sh configfile" exit 1 } if test ! -f $1 { echo "Couldn't find "'"'"$1"'"' exit 1 } if test $1 == ".config" { echo "It overwrites .config, rename it and try again." exit 1 } make allnoconfig KCONFIG_ALLCONFIG="$1" > /dev/null # Shouldn't need this, but kconfig goes "boing" at times... yes "" | make oldconfig > /dev/null if ! cmp .config $1 { echo Sanity test failed, normalizing starting configuration... diff -u $1 .config } cp .config .big.config # Speed heuristic: remove all blank/comment lines grep -v '^[#$]' .config | grep -v '^$' > mini.config # This should never fail, but kconfig is so broken it does sometimes. make allnoconfig KCONFIG_ALLCONFIG=mini.config > /dev/null if ! cmp .config $1 { echo Insanity test failed: reversing blank line removal heuristic. cp .big.config mini.config } #cp .config mini.config echo "Calculating mini.config..." global LENGTH := $[cat mini.config | wc -l] global OLDLENGTH := $LENGTH # Loop through all lines in the file global I := '1' while true { test $I -gt $LENGTH && break sed -n "$I,$($I+${STRIDE:-1}-1)!p" mini.config > .config.test # Do a config with this file rm .config make allnoconfig KCONFIG_ALLCONFIG=.config.test !2 >/dev/null | head -n 1000000 > /dev/null # Compare. Because we normalized at the start, the files should be identical. if cmp -s .config .big.config { # Found unneeded line(s) mv .config.test mini.config global LENGTH := $($LENGTH-${STRIDE:-1}) # Cosmetic: if stride tests off the end don't show total length less # than number of entries found. test $I -gt $LENGTH && global LENGTH := $($I-1) # Special case where we know the next line _is_ needed: stride 2 failed # but we discarded the first line test -z $STRIDE && test $(OLDSTRIDE:-1) -eq 2 && global I := $($I+1) global STRIDE := $($STRIDE+1) global OLDSTRIDE := $STRIDE } else { # That hunk was needed if test $(STRIDE:-1) -le 1 { global I := $($I+1) global OLDSTRIDE := '' } global STRIDE := '' } echo -n -e "\r[$(STRIDE:-1)] $($I-)/$LENGTH lines $[cat mini.config | wc -c] bytes $(100-((($LENGTH-$I)*100)/$OLDLENGTH)% " } rm .big.config echo (CommandList children: [ (C {(export)} {(Lit_VarLike "KCONFIG_NOTIMESTAMP=") (1)}) (If arms: [ (if_arm cond: [(C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(-ne)} {(1)} {(Lit_Other "]")})] action: [(C {(echo)} {(DQ ("Usage: miniconfig.sh configfile"))}) (C {(exit)} {(1)})] spids: [-1 88] ) ] spids: [-1 103] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(KW_Bang "!")} {(-f)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "]")}) ] action: [ (C {(echo)} {(DQ ("Couldn't find ")) (SQ <"\"">) (DQ ($ VSub_Number "$1")) (SQ <"\"">)}) (C {(exit)} {(1)}) ] spids: [-1 120] ) ] spids: [-1 143] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (.config))} {(Lit_Other "]")} ) ] action: [ (C {(echo)} {(DQ ("It overwrites .config, rename it and try again."))}) (C {(exit)} {(1)}) ] spids: [-1 163] ) ] spids: [-1 177] ) (SimpleCommand words: [{(make)} {(allnoconfig)} {(Lit_VarLike "KCONFIG_ALLCONFIG=") (DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[189])] ) (Pipeline children: [ (C {(yes)} {(DQ )}) (SimpleCommand words: [{(make)} {(oldconfig)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[207])] ) ] negated: False ) (If arms: [ (if_arm cond: [ (Pipeline children: [(C {(cmp)} {(.config)} {(DQ ($ VSub_Number "$1"))})] negated: True ) ] action: [ (C {(echo)} {(Sanity)} {(test)} {(failed) (Lit_Comma ",")} {(normalizing)} {(starting)} {(configuration...)} ) (C {(diff)} {(-u)} {(DQ ($ VSub_Number "$1"))} {(.config)}) ] spids: [-1 224] ) ] spids: [-1 253] ) (C {(cp)} {(.config)} {(.big.config)}) (Pipeline children: [ (C {(grep)} {(-v)} {(SQ <"^[#$]">)} {(.config)}) (SimpleCommand words: [{(grep)} {(-v)} {(SQ <"^$">)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(mini.config)} spids:[285])] ) ] negated: False ) (SimpleCommand words: [{(make)} {(allnoconfig)} {(Lit_VarLike "KCONFIG_ALLCONFIG=") (mini.config)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[299])] ) (If arms: [ (if_arm cond: [ (Pipeline children: [(C {(cmp)} {(.config)} {(DQ ($ VSub_Number "$1"))})] negated: True ) ] action: [ (C {(echo)} {(Insanity)} {(test)} {(failed) (Lit_Other ":")} {(reversing)} {(blank)} {(line)} {(removal)} {(heuristic.)} ) (C {(cp)} {(.big.config)} {(mini.config)}) ] spids: [-1 315] ) ] spids: [-1 344] ) (C {(echo)} {(DQ ("Calculating mini.config..."))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LENGTH) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(cat)} {(mini.config)}) (C {(wc)} {(-l)})] negated: False ) ] ) left_token: spids: [358 368] ) } spids: [357] ) ] spids: [357] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OLDLENGTH) op: Equal rhs: {($ VSub_Name "$LENGTH")} spids: [370] ) ] spids: [370] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:I) op:Equal rhs:{(1)} spids:[377])] spids: [377] ) (While cond: [(C {(true)})] body: (DoGroup children: [ (AndOr children: [ (C {(Lit_Other "[")} {($ VSub_Name "$I")} {(-gt)} {($ VSub_Name "$LENGTH")} {(Lit_Other "]")} ) (ControlFlow token:) ] op_id: Op_DAmp ) (SimpleCommand words: [ {(sed)} {(-n)} { (DQ ($ VSub_Name "$I") (",") (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$I")}) right: (ArithWord w: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(1)}) spids: [412 416] ) } ) ) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [409 420] ) ("!p") ) } {(mini.config)} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(.config.test)} spids:[426])] ) (C {(rm)} {(.config)}) (Pipeline children: [ (SimpleCommand words: [{(make)} {(allnoconfig)} {(Lit_VarLike "KCONFIG_ALLCONFIG=") (.config.test)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[447])] ) (SimpleCommand words: [{(head)} {(-n)} {(1000000)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[458])] ) ] negated: False ) (If arms: [ (if_arm cond: [(C {(cmp)} {(-s)} {(.config)} {(.big.config)})] action: [ (C {(mv)} {(.config.test)} {(mini.config)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LENGTH) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{($ VSub_Name "$LENGTH")}) right: (ArithWord w: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {(1)} ) spids: [496 500] ) } ) ) spids: [493 502] ) } spids: [492] ) ] spids: [492] ) (AndOr children: [ (C {(Lit_Other "[")} {($ VSub_Name "$I")} {(-gt)} {($ VSub_Name "$LENGTH")} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LENGTH) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{($ VSub_Name "$I")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [526 531] ) } spids: [525] ) ] spids: [525] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$STRIDE"))} {(Lit_Other "]")}) (AndOr children: [ (C {(Lit_Other "[")} { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(1)}) spids: [556 560] ) } {(-eq)} {(2)} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:I) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$I")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [571 576] ) } spids: [570] ) ] spids: [570] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:STRIDE) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$STRIDE")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [580 585] ) } spids: [579] ) ] spids: [579] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OLDSTRIDE) op: Equal rhs: {($ VSub_Name "$STRIDE")} spids: [588] ) ] spids: [588] ) ] spids: [-1 478] ) ] else_action: [ (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(1)}) spids: [603 607] ) } {(-le)} {(1)} {(Lit_Other "]")} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:I) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$I")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [620 625] ) } spids: [619] ) ] spids: [619] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OLDSTRIDE) op: Equal rhs: {(SQ )} spids: [628] ) ] spids: [628] ) ] spids: [-1 616] ) ] spids: [-1 631] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:STRIDE) op:Equal rhs:{(SQ )} spids:[634])] spids: [634] ) ] spids: [592 637] ) (C {(echo)} {(-n)} {(-e)} { (DQ (EscapedLiteralPart token:) ("[") (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(1)}) spids: [649 653] ) ("] ") (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{($ VSub_Name "$I")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [655 659] ) (/) ($ VSub_Name "$LENGTH") (" lines ") (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(cat)} {(mini.config)}) (C {(wc)} {(-c)})] negated: False ) ] ) left_token: spids: [663 673] ) (" bytes ") (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{(Lit_Digits 100)}) right: (ArithBinary op_id: Arith_Slash left: (ArithBinary op_id: Arith_Star left: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{($ VSub_Name "$LENGTH")}) right: (ArithWord w:{($ VSub_Name "$I")}) ) right: (ArithWord w:{(Lit_Digits 100)}) ) right: (ArithWord w:{($ VSub_Name "$OLDLENGTH")}) ) ) spids: [675 691] ) ("% ") ) } ) ] spids: [384 695] ) ) (C {(rm)} {(.big.config)}) (C {(echo)}) ] )