#!/bin/sh
#
# set up alsa-kernel directory from an external linux kernel tree
#
# the linux kernel tree has to contain the latest alsa-kernel files
# (this script doesn't check the consistency)
#
# with the option -c, the tree is copied instead of symlinks
# so that it can be easily archived
#

copy_tree=""

if [ x"$1" = x"-c" ]; then
    copy_tree=1
    shift
fi

if [ -z "$1" ]; then
    echo "usage: setup-alsa-kernel [-c] kernel-tree-dir"
    exit 1
fi

if [ ! -d acore ]; then
    echo "Run this script in alsa-driver directory"
    exit 1
fi

kern="$1"
alsa=$(pwd)
if [ -z "$copy_tree" ]; then
    rm -f $alsa/linux
    ln -s $kern linux
fi

rm -rf alsa-kernel
mkdir alsa-kernel
cd $kern/sound
for i in *; do
    if [ -n "$copy_tree" ]; then
	if [ "$i" = "oss" ]; then
	    mkdir $alsa/alsa-kernel/oss
	    cp oss/Makefile $alsa/alsa-kernel/oss
	else
	    cp -al $i $alsa/alsa-kernel/
	fi
    else
	ln -s ../linux/sound/$i $alsa/alsa-kernel/$i
    fi
done

cd $alsa
if [ -n "$copy_tree" ]; then
    cp -al $kern/include/sound alsa-kernel/include
    cp -al $kern/Documentation/sound/alsa alsa-kernel/Documentation
    cp -al $kern/Documentation/DocBook/alsa-driver-api.tmpl alsa-kernel/Documentation/DocBook
    cp -al $kern/Documentation/DocBook/writing-an-alsa-driver.tmpl alsa-kernel/Documentation/DocBook
    cp -al $kern/Documentation/DocBook/stylesheet.xsl alsa-kernel/Documentation/DocBook
else
    ln -s ../linux/include/sound alsa-kernel/include
    mkdir alsa-kernel/Documentation
    (cd alsa-kernel/Documentation;
	for i in ../../linux/Documentation/sound/alsa/*; do
	    ln -s $i
	done
	)
    ln -s ../../linux/Documentation/DocBook alsa-kernel/Documentation/
    rm -f scripts
    ln -s linux/scripts scripts
fi
rm -f sound
ln -s alsa-kernel sound
exit 0
