#!/bin/bash

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

kernel_info

SUT=`hostname -s`
out_dir=$run_dir/logs/$SUT
[ -d $out_dir ] || mkdir -p $out_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

# Look for a .config for this specific package by machine name
# unless DEFAULT_CONFIG is specified.
if [ -n "$DEFAULT_CONFIG" ]; then
    default_config="$DEFAULT_CONFIG"
elif [ -e "$all_pkgs_dir/$pkg_name/config.default-$SUT" ]; then
    default_config="$all_pkgs_dir/$pkg_name/config.default-$SUT"

# Look for a .config for this specific package by machine type
elif [ -e "$all_pkgs_dir/$pkg_name/config.default-$sut_type" ]; then
    default_config="$all_pkgs_dir/$pkg_name/config.default-$sut_type"

# Look for a .config for this specific package in general
elif [ -e "$all_pkgs_dir/$pkg_name/config.default" ]; then
    default_config="$all_pkgs_dir/$pkg_name/config.default"

# Look for a .config for this machine name
elif [ -e "$all_suts_dir/$SUT/config.default" ]; then
    default_config="$all_suts_dir/$SUT/config.default"

# Look for a .config for this machine type
elif [ -e "$all_suts_dir/config.default-$sut_type" ]; then
    default_config="$all_suts_dir/config.default-$sut_type"
else
    default_config="$all_pkgs_dir/linux/config.default"
fi

[ $kernel_id ] && kernel_id="-i $kernel_id"
[ $kernel_label ] && kernel_label="-k $kernel_label"
[ $default_config ] && default_config="-c $default_config"
[ "$kernel_args" ] && kernel_args="-a $kernel_args"
[ $out_dir ] && out_dir="-l $out_dir"

build_kernel $kernel_id $kernel_label $default_config $out_dir "$kernel_args"

