#!/bin/bash
# This script is run by the general build script to perform some
# kernel-specific setup of the package.  It should not be run directly.
#
# In this case it generates CONTROL/builtfiles with the correct directory name
# in lib/modules depending on the kernel's version number.
#
# The arguments it expects are PACKAGE and TAGNAME

# Reciva specific drivers
# XXX You also need to change the version of reciva_knl_drivers in service_pack/CONTROL/control.in
# to ensure OE builds are the same as non OE builds
RECIVA_KNL_DRIVERS_VERSION="v389"
cvs co -r $RECIVA_KNL_DRIVERS_VERSION reciva_knl_drivers

REALTAG=`echo $2 | sed -e "s/-/./g;s/^v//;s/==/||CARTON||/g;s/_/-/g;s/=-/_/g;s/=c/:/g;s/||CARTON||/=/g"`

VERSION=`     grep VERSION      Makefile \
               | head -n1 | sed -e 's/.*= *\([0-9]*\).*/\1/'`
PATCHLEVEL=`  grep PATCHLEVEL   Makefile \
               | head -n1 | sed -e 's/.*= *\([0-9]*\).*/\1/'`
SUBLEVEL=`    grep SUBLEVEL     Makefile \
               | head -n1 | sed -e 's/.*= *\([0-9]*\).*/\1/'`
EXTRAVERSION=`grep EXTRAVERSION Makefile \
               | head -n1 | sed -e 's/.*= *\(\([0-9]\|[a-z]\|-\)*\).*/\1/'`

PACKAGEVERSION=$REALTAG

< CONTROL/builtfiles.in            \
sed "s/KERNELVERSION/$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION/" \
> CONTROL/builtfiles

< reciva_knl_drivers/builtfiles.in            \
sed "s/KERNELVERSION/$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION/" \
>> CONTROL/builtfiles

< CONTROL/control.in                  \
sed "/^Version/cVersion: $PACKAGEVERSION" \
> CONTROL/control
