#!/bin/bash
## src2pkg script for: 	kernel-huge
## Auto-generated by src2pkg-1.9.6
## src2pkg Copyright 2005-2008 Gilbert Ashley <amigo@ibilio.org>

# KNAME for standard kernels is 'huge, 'huge-smp', 'generic', or 'generic-smp'
# KNAME gets appended to the name of the package (like 'kernel-$KNAME')
# in order to avoid that installpkg or upgradepkg overwrite your existing kernel(s),
# you should give this kernel build a unique KNAME
KNAME='tiny'

# if you want to build a kernel for architecture other than i386, change this
# the most likely alternatives are: ia64, ppc or x86_64
# this needs to be set so that the script can find the finished bzImage file 
#under $SRC_DIR/arch/$KARCH/boot/bzImage
KARCH='i386'

# edit to change this to the correct kernel version
SOURCE_NAME='linux-2.6.23.tar.bz2'
# uncomment and edit this to reset the default VERSION (needed if using kernel version patches)
# ALT_VERSION=2.6.23.6

BUILD='1'

# you shouldn't need to change anything below here
ALT_NAME="kernel-$KNAME"

# Get the functions and configs
. /usr/libexec/src2pkg/FUNCTIONS ;

# do_all_processes can substitute these 16 steps:

pre_process
find_source
make_dirs
unpack_source
fix_source_perms

#configure_source
#compile_source
#fake_install

if [[ -r $CWD/config-$KNAME-$VERSION ]] ; then
 cp $CWD/config-$KNAME-$VERSION $SRC_DIR/.config
elif [[ -r $CWD/config-$KNAME ]] ; then
 cp $CWD/config-$KNAME $SRC_DIR/.config
elif [[ -r $CWD/config ]] ; then
 cp $CWD/config $SRC_DIR/.config
elif [[ -r $CWD/config* ]] ; then
 cp $CWD/config* $SRC_DIR/.config
else
 echo ""
 echo "Checking for a kernel configuration file:"
 echo "To use a custom configuration, place a copy of your"
 echo "kernel configuration file in the current directory"
 echo "and name it 'config-$KNAME-$VERSION' or 'config'."
 
 echo "Otherwise, this script will check for the file 'usr/src/linux/.config'"
 echo "and use that configuration. If that file is not found, this script"
 echo "will attempt to use the configuration options from the running kernel."
 echo ""
 echo "Continue? [y/n]"
 read -n 1 ANSWER
 if [[ "$ANSWER" = "y" ]] ; then
  echo ""
 else
  echo ""
  echo "Exiting..."
  exit 0
 fi
 
 if [[ -e /proc/config.gz ]] ; then
  echo "Found /proc/config.gz"
  zcat /proc/config > $SRC_DIR/.config
 elif [[ -e /proc/config ]] ; then
  echo "Found /proc/config"
  cat /proc/config > $SRC_DIR/.config
 elif [[ -e /usr/src/linux/.config ]] ; then
  echo "Found /usr/src/linux/.config"
  cat /usr/src/linux/.config > $SRC_DIR/.config
 else
  echo $RED"No kernel configuration file found!"$NORMAL
  exit 0
 fi
fi

cd $SRC_DIR && make oldconfig

KVERS=$(echo $VERSION |cut -f 1-2 -d'.')

if [[ $KVERS = 2.6 ]] ; then
 cd $SRC_DIR && make
 STATUS=$?
else
 cd $SRC_DIR && make bzimage
 STATUS=$?
fi 

if [[ $STATUS = 0 ]] ; then
 mkdir -p $PKG_DIR/boot
  cp $SRC_DIR/arch/$KARCH/boot/bzImage $PKG_DIR/boot/vmlinuz-$KNAME-$VERSION
  cp $SRC_DIR/System.map $PKG_DIR/boot/System.map-$KNAME-$VERSION
  cp $SRC_DIR/.config $PKG_DIR/boot/config-$KNAME-$VERSION
else
 echo "Kernel failed to compile cleanly! Exiting..."
 exit 0
fi

if [[ -e $CWD/slack-desc ]] ; then
cat > $CWD/slack-desc <<EOF
$NAME: vmlinuz-$KNAME-$VERSION (a custom-configured kernel)
$NAME:
$NAME: This is a custom-configured kernel. See the file
$NAME: /boot/config-$KNAME-$VERSION for the
$NAME: configuration details of this build.
$NAME:
$NAME:
$NAME:
$NAME:
$NAME:
$NAME: Packaged by src2pkg

EOF
fi

fix_pkg_perms
strip_bins
create_docs
compress_man_pages
make_description
make_doinst
make_package
post_process

# src2pkg - Copyright 2005-2008  Gilbert Ashley <amigo@ibiblio.org>
## See the documentation for more help and examples. Below are some of
# the most common Extras and Options for easy cut-and-paste use.
# EXTRA_CONFIGS='' PRE_FIX='' DOCLIST=''
# MAKE_COMMAND='' INSTALL_LINE='' 
# SHELL_INSTALL='YES' CORRECT_PERMS='NO'
# When editing src2pkg scripts to add custom code, use these variables
# to refer to the current directory, the sources or the package tree:
# $CWD (current directory), $SRC_DIR (sources), $PKG_DIR (package tree)
