#! /bin/sh
# create_kernel_allnoconfig:
# make a config.kernel file and export its name in DEFAULT_CONFIG
# (or worst case, write it to /base_dir/pkgs_dir/pkg_name/config.default)
# or write DEFAULT_CONFIG=<value> to run_id/run_profile.txt
# so that following steps/phases can use it;
# use ARCH=$BUILDARCH if BUILDARCH is set;

. run_profile.txt
. $base_dir/plans/commands/common.fns

[ -f $base_dir/etc/global.cfg ] && source $base_dir/etc/global.cfg
if [ "$SRC_DIR" == "" ]; then
	SRC_DIR="/usr/local/src"
fi

kernel_info
src_dir="$SRC_DIR/linux-$kernel_id"
cfg_dest="$all_pkgs_dir/$pkg_name"

SUT=`hostname -s`
log_dir=$run_dir/logs/$SUT
[ -d $log_dir ] || mkdir -p $log_dir

sut_type=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc/ -e s/arm.*/arm/ \
     -e s/s390.*/s390/ -e s/sa110/arm/ -e s/ppc64/powerpc/ -e s/parisc64/parisc/`

if [ -e "$all_suts_dir/$SUT/profile.txt" ]; then
    sut_type=`grep ^sut_type= $all_suts_dir/$SUT/profile.txt | cut -d '=' -f 2`
fi

karch=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc/ -e s/arm.*/arm/ \
     -e s/s390.*/s390/ -e s/sa110/arm/ -e s/ppc64/powerpc/ -e s/parisc64/parisc/`

pwd=`/bin/pwd`

if [ ! -d $src_dir ]; then
    echo "ERROR:  missing src_dir: $src_dir"
    exit -11
fi
cd $src_dir

if [ "$BUILDARCH" = "" ]; then
	bldarch=
else
	bldarch="ARCH=$BUILDARCH"
fi

echo "make $bldarch allnoconfig"
make $bldarch allnoconfig >$log_dir/kernel.allnoconfig.$karch.log 2>&1
[ ! -e $src_dir/.config ] && echo "ERROR: no .config created" && exit 1

DEFAULT_CONFIG="$cfg_dest/config.allno"
cp -a .config $DEFAULT_CONFIG
##TEST:cp -a .config $cfg_dest/config.default
##export DEFAULT_CONFIG
# add DEFAULT_CONFIG to run_profile file for next step(s)
profile="$RUNS_DIR/$id/run_profile.txt"
echo "DEFAULT_CONFIG:$DEFAULT_CONFIG"
echo "DEFAULT_CONFIG=\"$DEFAULT_CONFIG\"" >>$profile

cd $pwd
