#!/bin/sh
#
#    CDplayer 1.1 - command line Audio CDplayer
#    Copyright (C) 1993,1994 Mark Buckaway (mark@datasoft.com)
# 
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Configure script. Asks user various questions and generates the 
# Makefile. If /bin/sh is not bash, this may not work as bash
# requires -n and -e on echo to get things to work correctly.
#
echo -n "CDplayer Configure

This configure script will ask a few questions about your system
and how CDplayer should be configured. This information will
be used in compiling CDplayer.

Currently Linux and Cohernet 4.2 are supported. Others SHOULD work as well.

Press <ENTER> to continue.  "
read JUNK

UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown

case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
	i[34]86:*:*COHERENT)
		echo "Hmmm...looks like a Coherent system."
		OS="COHERENT" ;;
	i[34]86:Linux:*:*)
		echo "Hmmm...looks like a Linux system."
		OS="LINUX" ;;
	*)
		echo "Hmmm...don't know what system this is. Assuming this is not Linux."
		OS="$UNAME_SYSTEM" ;;
esac
echo
echo -n "Getting list of devices..."
find /dev -print >.$$.tmp
FOUNDIT=0
for device in mcd cdrom1 cdrom mitsumi_cd sr0
do
	if grep $device .$$.tmp >/dev/null
        then
           FOUNDIT=1
           echo -en "\nHmmm...found /dev/$device. Should I use this device? [y/n] "
           read REPLY JUNK
           case $REPLY in
              [yY]*) echo "OK. Using /dev/$device."
                     break ;;
	      [nN]*) FOUNDIT=0
		     break ;;
		  *) FOUNDIT=0
		     break ;;
           esac
        fi
done
rm -f .$$.tmp
if [ "$FOUNDIT" = "1" ]
then
	DEVICE_CDROM="/dev/$device"
else
	done=0
	while [ "$done" != "1" ]
        do
		echo "What device (e.g. /dev/sr0) should I use for the CD?"
		echo -n ": "
		read REPLY JUNK
		if [ ! -b $REPLY ]
                then
			echo -e "$REPLY does not exist or is not a CDROM device\n" 
   		else
			done=1
		fi
	done
	DEVICE_CDROM="$REPLY"
	echo "Ok. Using $REPLY for the CD."
fi
echo -n "
NEC CDROM drives are strange and the method of accessing the audio
functions is NOT the same as other CDROM drives. For an NEC CDROM
to work with CDROM, a special function is called to send commands
to the NEC CDROM drive. If you do not have an NEC CDROM, you can ignore
this.

Do you have an NEC CDROM drive? [y/n] "
read REPLY JUNK
NEC=0
case $REPLY in
	[yY]*) NEC=1 ;;
esac
echo -n "NEC CDROM code will "
if [ "$NEC" = "1" ]
then
	echo "be used."
else
	echo "NOT be used."
fi
echo "
/*
 *   CDplayer 1.1 - command line Audio CDplayer
 *   Copyright (C) 1993,1994 Mark Buckaway (mark@datasoft.com)
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* DO NOT MODIFY - AUTOMATICALLY GENERATED BY Configure */

#define DEV_CDROM \"$DEVICE_CDROM\"
#define OS \"$OS\"
" > config.h
if [ "$NEC" = "1" ]
then
	echo "#define NEC_CDROM" >> config.h

fi
case $OS in
	"COHERENT") echo "#define COHERNET" >> config.h ;;
	"LINUX") echo "#define LINUX" >> config.h ;;
	*) echo "Opps...error in script. Aborted" ;;
esac
if [ -f .install ]
then
	. ./.install
else
	INSTALLDIR="/usr/local/bin"
	MANDIR="/usr/local/man"
fi
done=0
while [ "$done" != "1" ]
do
	echo "Where should CDplayer be installed? [$INSTALLDIR]"
	echo -n ": "
	read REPLY JUNK
	if [ "$REPLY" = "" ]
	then
		break
	fi
	if [ ! -d $REPLY ]
        then
		echo -e "$REPLY does not exist or is not a directory\n"
   	else
		done=1
		INSTALLDIR=$REPLY
	fi
done
echo "CDplayer will be installed in $INSTALLDIR"
MANDIR="/usr/local/man"
done=0
while [ "$done" != "1" ]
do
	echo "Where should CDplayer manpage be installed? [$MANDIR]"
	echo -n ": "
	read REPLY JUNK
	if [ "$REPLY" = "" ]
	then
		break
	fi
	if [ ! -d $REPLY ]
        then
		echo -e "$REPLY does not exist or is not a directory\n"
   	else
		done=1
		MANDIR=$REPLY
	fi
done
echo "CDplayer's manpage will be installed in $MANDIR/man1"
echo "INSTALLDIR=$INSTALLDIR
MANDIR=$MANDIR
" > .install
echo -e "Configuration complete.\n\n"
