#!/bin/bash

kversion=2.4.19-rmk6-pxa1-hh25
source=.
version=`cat $source/../version`
package=$source/../../alsa-driver-$version.tar.bz2

if [ -z "$TARGET_KERNEL" ]; then
  export TARGET_KERNEL="$kversion"
fi

make -C .. pack

if [ ! -r $package ]; then
  echo "Error: wrong package: $package"
  exit 1
fi

cp -fv $package /usr/src/redhat/SOURCES

if [ ! -r $source/buildrpm ]; then
  echo "Error: invalid directory: $source"
  exit 1
fi

if [ ! -d /usr/src/redhat ]; then
  echo "Error: /usr/src/redhat directory not found"
  exit 1
fi

if [ ! -r $source/alsa-driver.spec ]; then
  cd $source/..
  ./configure
  cd utils
fi

cp -fv $source/alsa-driver.spec /usr/src/redhat/SPECS
cd /usr/src/redhat/SPECS
rpm -ba alsa-driver.spec
cd /usr/src/redhat
