#!/bin/bash

# find source package
function find_source {
   local name=$1
   local ext=$2
   SRCPKG=$(find ../../source -type f -name "${name}.${ext}")
   if [ -e "$SRCPKG" ] ; then
      echo "found source pkg at ${SRCPKG}"
   else
      echo "couldn't find source tgz for $name" 1>&2
      exit 1
   fi
}

PKG=linux
VERSION=2.6.13
CWD=$(pwd)
INSTALL_DIR=${CWD}/install
mkdir -p ${INSTALL_DIR}/usr/share/uml_linux/
mkdir -p ${INSTALL_DIR}/usr/bin/

find_source ${PKG}-${VERSION} tar.bz2

#unpack
bzip2 -dc $SRCPKG | tar xv

#kernel
cd ${PKG}-${VERSION}
chown -R root.root .

#compile
# INSTALL_MOD_PATH is a prefix to /usr/lib/modules-version used when
# copying modules to /lib.
make mrproper
cp ../config-2.6.13 .config
make oldconfig ARCH=um
make linux ARCH=um
make modules ARCH=um
make INSTALL_MOD_PATH=${INSTALL_DIR}/usr/share/uml_linux modules_install

# copy kernel image and map and config to boot
#strip linux
cp linux ${INSTALL_DIR}/usr/bin/uml_linux
cp System.map ${INSTALL_DIR}/usr/share/uml_linux/System.map-${VERSION}
cp .config ${INSTALL_DIR}/usr/share/uml_linux/config-${VERSION}

# clean the src directory, reconfig it, and copy into package
#make mrproper
#cp ../config-${VERSION} ./config
#make oldconfig ARCH=um
#mkdir -p ${INSTALL}/usr/share/uml_linux/src/linux-${VERSION}
#rsync -ra ./ ${INSTALL}/usr/share/uml_linux/src/linux-${VERSION}
#cd ..

# fix /lib/modules/<version>/source link to point to slackware source directory
# instead of the temporary one we just compiled in
#ln -sf /usr/src/linux-2.6.10 ${INSTALL_DIR}/lib/modules/2.6.10/build

# Build the package:
cd ${INSTALL_DIR}
if ! [ -d "../../../new" ] ; then
   echo "couldn't find new directory in the proper place"
else
   makepkg -l y -c n ../../../new/uml_linux-${VERSION}.tgz
   installpkg ../../../new/uml_linux-${VERSION}.tgz
fi

# clean up
cd $CWD
rm -rf ${INSTALL_DIR}
rm -rf ${PKG}-${VERSION}

hopeless_linux: UserModeLinux/CompileScript (last modified 2007-07-01 16:01:00)