#!/bin/bash
# Run this script in an empty directory
# It downloads all the necessary parts and builds alsa driver with
# latest hpklinux

HPKVER="3.07.12"
ALSADRV="1.0.14"
ALSALIB="1.0.14a"

if [ ! -e hpklinux-$HPKVER.tar.bz2 ]
then
   wget http://audioscience.com/internet/download/hpklinux-$HPKVER.tar.bz2
   tar xf hpklinux-$HPKVER.tar.bz2
fi

if [ ! -e alsa-driver-$ALSADRV.tar.bz2 ]
then
wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-$ALSADRV.tar.bz2
tar xf alsa-driver-$ALSADRV.tar.bz2
fi

if [ ! -e alsa-lib-$ALSALIB.tar.bz2 ]
then
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-$ALSALIB.tar.bz2
tar xf alsa-lib-$ALSALIB.tar.bz2
fi
cd hpklinux-$HPKVER
./configure
make && sudo make install
cd ..

cd alsa-driver-$ALSADRV
./configure --with-cards=asihpi --with-debug=full
rm pci/asihpi/*.[ch]
cp ../hpklinux-$HPKVER/alsa/Makefile pci/asihpi
make && sudo make install
cd ..

cd alsa-lib-$ALSALIB
./configure
make && sudo make install
cd ..

sudo modprobe -r asihpi # cant run both drivers simultaneously!
sudo modprobe snd-asihpi
