#!/bin/bash # # Usage: configinit.sh config-spec-file [ build output dir ] # # Create a .config file from the spec file. Run from the kernel source tree. # Exits with 0 if all went well, with 1 if all went well but the config # did not match, and some other number for other failures. # # The first argument is the .config specification file, which contains # desired settings, for example, "CONFIG_NO_HZ=y". For best results, # this should be a full pathname. # # The second argument is a optional path to a build output directory, # for example, "O=/tmp/foo". If this argument is omitted, the .config # file will be generated directly in the current directory. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, you can access it online at # http://www.gnu.org/licenses/gpl-2.0.html. # # Copyright (C) IBM Corporation, 2013 # # Authors: Paul E. McKenney global T := "/tmp/configinit.sh.$Pid" trap 'rm -rf $T' 0 mkdir $T # Capture config spec file. global c := $1 global buildloc := $2 global builddir := '' if test -n $buildloc { if echo $buildloc | grep -q '^O=' { global builddir := $[echo $buildloc | sed -e 's/^O=//] if test ! -d $builddir { mkdir $builddir } } else { echo Bad build directory: '"'$builddir'"' exit 2 } } sed -e 's/^\(CONFIG[0-9A-Z_]*\)=.*$/grep -v "^# \1" |/' < $c > $T/u.sh sed -e 's/^\(CONFIG[0-9A-Z_]*=\).*$/grep -v \1 |/' < $c >> $T/u.sh grep '^grep' < $T/u.sh > $T/upd.sh echo "cat - $c" >> $T/upd.sh make mrproper make $buildloc distclean > $builddir/Make.distclean !2 > !1 make $buildloc $TORTURE_DEFCONFIG > $builddir/Make.defconfig.out !2 > !1 mv $builddir/.config $builddir/.config.sav sh $T/upd.sh < $builddir/.config.sav > $builddir/.config cp $builddir/.config $builddir/.config.new yes '' | make $buildloc oldconfig > $builddir/Make.oldconfig.out !2 > $builddir/Make.oldconfig.err # verify new config matches specification. configcheck.sh $builddir/.config $c exit 0 (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:T) op: Equal rhs: {(/tmp/configinit.sh.) ($ VSub_Dollar "$$")} spids: [100] ) ] spids: [100] ) (C {(trap)} {(SQ <"rm -rf $T">)} {(0)}) (C {(mkdir)} {($ VSub_Name "$T")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:c) op:Equal rhs:{($ VSub_Number "$1")} spids:[121])] spids: [121] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:buildloc) op: Equal rhs: {($ VSub_Number "$2")} spids: [124] ) ] spids: [124] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:builddir) op:Equal rhs:{(SQ )} spids:[127])] spids: [127] ) (If arms: [ (if_arm cond: [(C {(test)} {(-n)} {($ VSub_Name "$buildloc")})] action: [ (If arms: [ (if_arm cond: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$buildloc")}) (C {(grep)} {(-q)} {(SQ <"^O=">)}) ] negated: False ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:builddir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$buildloc")}) (C {(sed)} {(-e)} {(SQ <"s/^O=//">)}) ] negated: False ) ] ) left_token: spids: [161 175] ) } spids: [160] ) ] spids: [160] ) (If arms: [ (if_arm cond: [(C {(test)} {(KW_Bang "!")} {(-d)} {($ VSub_Name "$builddir")})] action: [(C {(mkdir)} {($ VSub_Name "$builddir")})] spids: [-1 189] ) ] spids: [-1 197] ) ] spids: [-1 157] ) ] else_action: [ (C {(echo)} {(Bad)} {(build)} {(directory) (Lit_Other ":")} {(EscapedLiteralPart token:) ($ VSub_Name "$builddir") (EscapedLiteralPart token:) } ) (C {(exit)} {(2)}) ] spids: [200 222] ) ] spids: [-1 137] ) ] spids: [-1 224] ) (SimpleCommand words: [{(sed)} {(-e)} {(SQ <"s/^\\(CONFIG[0-9A-Z_]*\\)=.*$/grep -v \"^# \\1\" |/">)}] redirects: [ (Redir op_id:Redir_Less fd:-1 arg_word:{($ VSub_Name "$c")} spids:[235]) (Redir op_id:Redir_Great fd:-1 arg_word:{($ VSub_Name "$T") (/u.sh)} spids:[239]) ] ) (SimpleCommand words: [{(sed)} {(-e)} {(SQ <"s/^\\(CONFIG[0-9A-Z_]*=\\).*$/grep -v \\1 |/">)}] redirects: [ (Redir op_id:Redir_Less fd:-1 arg_word:{($ VSub_Name "$c")} spids:[252]) (Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Name "$T") (/u.sh)} spids:[256]) ] ) (SimpleCommand words: [{(grep)} {(SQ <"^grep">)}] redirects: [ (Redir op_id:Redir_Less fd:-1 arg_word:{($ VSub_Name "$T") (/u.sh)} spids:[267]) (Redir op_id:Redir_Great fd:-1 arg_word:{($ VSub_Name "$T") (/upd.sh)} spids:[272]) ] ) (SimpleCommand words: [{(echo)} {(DQ ("cat - ") ($ VSub_Name "$c"))}] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Name "$T") (/upd.sh)} spids:[284]) ] ) (C {(make)} {(mrproper)}) (SimpleCommand words: [{(make)} {($ VSub_Name "$buildloc")} {(distclean)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$builddir") (/Make.distclean)} spids: [299] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[304]) ] ) (SimpleCommand words: [{(make)} {($ VSub_Name "$buildloc")} {($ VSub_Name "$TORTURE_DEFCONFIG")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$builddir") (/Make.defconfig.out)} spids: [313] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[318]) ] ) (C {(mv)} {($ VSub_Name "$builddir") (/.config)} {($ VSub_Name "$builddir") (/.config.sav)}) (SimpleCommand words: [{(sh)} {($ VSub_Name "$T") (/upd.sh)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {($ VSub_Name "$builddir") (/.config.sav)} spids: [334] ) (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$builddir") (/.config)} spids: [339] ) ] ) (C {(cp)} {($ VSub_Name "$builddir") (/.config)} {($ VSub_Name "$builddir") (/.config.new)}) (Pipeline children: [ (C {(yes)} {(SQ )}) (SimpleCommand words: [{(make)} {($ VSub_Name "$buildloc")} {(oldconfig)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$builddir") (/Make.oldconfig.out)} spids: [365] ) (Redir op_id: Redir_Great fd: 2 arg_word: {($ VSub_Name "$builddir") (/Make.oldconfig.err)} spids: [370] ) ] ) ] negated: False ) (C {(configcheck.sh)} {($ VSub_Name "$builddir") (/.config)} {($ VSub_Name "$c")}) (C {(exit)} {(0)}) ] )