# Recipe for version 2.6.20.4 by Lucas C. Villa Real, on Wed Apr 4 01:14:50 BRT 2007
# Recipe for Linux 2.6.20.4 by Lucas Correia Villa Real
# Recipe for Linux 2.6.15 by Lucas Correia Villa Real
# Recipe for Linux 2.6.13.4 by Lucas Correia Villa Real
# Recipe for Linux 2.6.12.2 by Lucas Correia Villa Real
# Recipe for Linux 2.6.11.9 by Lucas Correia Villa Real
# Recipe for Linux 2.6.11 by Lucas Correia Villa Real
compile_version=1.8.2
url="http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.4.tar.bz2"
file_size=43373415
file_md5=ad6df0431ce9eb91dd558538e71239de
recipe_type=makefile
build_target="all"
install_target="modules_install"

unmanaged_files=(
   $goboModules/${version}-Gobo
   $goboBoot
   $goboLibraries/modules
)

#sandbox_options=(
#   "--no-sandbox"
#)

pre_build() {
   if [ ! -f .config ]
   then
      if [ ! -f $goboStatus/config.gz ]
      then
         cp "$archsubdir"/dot-config .config
      else
         if Ask "Do you want to keep the current kernel configuration?"
         then
            cp $goboStatus/config.gz .
            gzip -d config.gz && mv config .config
            yes "" | make oldconfig
         else
            Log_Normal "Using the kernel configuration shipped with the recipe"
            cp "$archsubdir"/dot-config .config
         fi
      fi
   fi

   suffix="-Gobo"

   source GoboPath
   GrepReplace "\$(INSTALL_MOD_PATH)/lib/modules/\$(KERNELRELEASE)" \
               "$goboModules/\$(KERNELRELEASE)" \
               Makefile >& /dev/null
   GrepReplace "CONFIG_LOCALVERSION=\"\"" \
               "CONFIG_LOCALVERSION=\"$suffix\"" \
               .config >& /dev/null

   # Sanity check to make sure patches are not trying to mess
   # with the version id.
   local v=`grep "^VERSION =" Makefile | awk '{print $3}'`
   local p=`grep "^PATCHLEVEL" Makefile | awk '{print $3}'`
   local s=`grep "^SUBLEVEL" Makefile | awk '{print $3}'`
   local e=`grep "^EXTRAVERSION" Makefile | awk '{print $3}'`
   local reported="$v.$p.$s$e"
   if [ "$reported" != "$version" ]
   then Die "Reported version ($reported) does not match version ($version). Please fix recipe."
   fi

   make menuconfig
}

private__calculate_full_version() {
   if grep -q "^CONFIG_LOCALVERSION=" .config
   then suffix=`grep "^CONFIG_LOCALVERSION=" .config | cut -d= -f2 | tr -d '"' | sed 's/-[0-9]*-//'`
   fi
   local newsuffix="$suffix"
   local count=`ls $goboBoot/kernel-$version-* 2> /dev/null | sort -n | wc -l | awk '{print $1}'`
   if [ "$count" -gt "0" ]
   then
      let count=$count+1
      newsuffix="-$count$suffix"
   fi
   echo "$version$newsuffix"
}

private__link_at_system_kernel_boot() {
   local fullversion="$1"
   mkdir -p $target/Resources/Unmanaged/$goboLibraries/modules
   dest=$target/Resources/Unmanaged/$goboBoot
   ln -sf kernel-$fullversion $dest/kernel
   ln -sf System.map-$fullversion $dest/System.map
   ln -nfs $goboModules/$fullversion $target/Resources/Unmanaged/$goboModules/Current
   ln -nfs $fullversion $target/Resources/Unmanaged/$goboLibraries/modules
}

private__check_dependant_modules() {
   local check_prefix="$1"
   if [ -d $check_prefix ]
   then
      for i in $check_prefix/*
      do
         depapp=`basename $i`
         if ! Boolean "batch"                                            
         then Ask "$depapp depends on the Linux kernel. Would you like to compile it?" || continue
         fi
         Compile $batch $lazy $noweb $depapp
      done
   fi
}
