#!/bin/sh
#
# WMSound configuration and compilation script
#

OPTIONS=""
WMDIR="/usr/local/share/WindowMaker"
PREFIX="/usr/local"
DEVICE="/dev/dsp"

echo
echo "======================"
echo " WMSound Installation "
echo "======================"
echo
echo "NOTE: If the installation procudre fails, read the INSTALL file and do"
echo "the installation manually."
echo "Type <Return> when ready."
read foo
echo

if test "$USER" != "root"; then
	echo "=================================================="
	echo "Warning: you must run this script as the root user"
	echo "Type <Return> to continue or <Control>-<C> to stop"
	echo "=================================================="
	read foo
	echo "================================================="
	echo "Be sure to specify an installation where you have"
	echo "write permissions."
	echo "================================================="
fi

################# Installation Path
done=0
while [ $done = 0 ]; do
	echo 
	echo "==============================================="
	echo "Where do you want to install WMSound? [$PREFIX]"
	echo "(The Default path will install WMSound in"
	echo "$PREFIX/bin, $PREFIX/lib etc.)"
	echo -n "? "
	read foo

		if test "x$foo" != "x"; then
			if [ "$foo" = "y" -o "$foo" = "n" ]; then
				echo
				echo "Hmmm. I don't think you really want to install WMSound into \"$foo\""
				echo 
			else
				done=1
				PREFIX=$foo
			fi
		else
		 done=1
		fi
done

############### WindowMaker Path
done=0
while [ $done = 0 ]; do
	echo 
	echo "Please select your default audio device [$DEVICE]"
	echo -n ":  "
	read foo

	if test "x$foo" != "x"; then
		if [ "$foo" != "/dev/dsp" -a "$foo" != "/dev/audio" ]; then
			echo
			echo "You need to pick either '/dev/dsp', or '/dev/audio'"
			echo
		else
			done=1
			DEVICE=$foo
		fi
	else
		done=1
	fi
done




OPTIONS="$OPTIONS --prefix=$PREFIX --with-wmdir=$WMDIR --with-device=$DEVICE"


########## Configure
echo "------------------------"
echo " Configuring WMSound... "
echo "------------------------"
	echo "CFLAGS=\"$CFLAGS $GCCFLAGS\" ./configure $OPTIONS"
	CFLAGS="$CFLAGS $GCCFLAGS" ./configure $OPTIONS
echo "----------------------"
echo " Compiling WMSound... "
echo "----------------------"
make install

echo "Installation Finished!"
echo
echo "Now just start WMSound, dock it, and set it to autolaunch"
