#! /bin/sh
# make.makefile for yamsweeper
#
# $Id: configure.euc,v 1.7 1994/11/03 00:18:42 hirofumi Rel hirofumi $
#

# check built-in echo

if echo "Hello \c" | grep c > /dev/null; then
	ECHO=echo
	ECHOn="echo -n"
	ECHOt=
else
	ECHO=echo
	ECHOn=echo
	ECHOt="\c"
fi

case `basename $0` in
configure)
	MSG=e;;
configure.euc)
	MSG=j;;
esac

$ECHO
case $MSG in
e)
	$ECHO "********* YAMSWEEPER CONFIGURE SCRIPT *********"
	$ECHO
	;;
j)	cat <<'EOF'
********* YAMSWEEPER ե졼 *********

EOF
esac

case $MSG in
e)
	$ECHO "This script will build an Imakefile and a Makefile for yamsweeper."
	$ECHOn "Press RETURN to continue. > " $ECHOt;;
j)
cat <<'EOF'
ΥץȤϡImakefileMakefileޤ

꥿󥭡򲡤Ʋ
EOF
	$ECHOn "> " $ECHOt;;
esac
read ans
$ECHO

case $MSG in
e)
	$ECHO "I will ask you some questions about your system and configuration."
	$ECHO "If you do not know the answer to any question,"
	$ECHO "just press RETURN and I will choose a default for you."
	$ECHOn "Press RETURN now. > " $ECHOt;;
j)
cat <<'EOF'
줫顢ĤԤޤϤäʬʤä顢Ȥꤢ
꥿󥭡򲡤ؿʤǲ

꥿󥭡򲡤Ʋ
EOF
	$ECHOn '> ' $ECHOt
esac
read ans
$ECHO

def=/usr/local/bin
LMPlace=$def

case $MSG in
e)
$ECHO "Where do you want to place the load module of Yamsweeper ?";;
j)
cat <<'EOF'
Yamsweeper򥤥󥹥ȡ뤹ϡ
EOF
esac
$ECHOn "[$def] > " $ECHOt
read ans

case X$ans in
X)	;;
*)	LMPlace=$ans;;
esac
$ECHO

def=/usr/local/man/man1
ManPlace=$def
case $MSG in
e)
$ECHO "Where do you want to place the man page of Yamsweeper ?";;
j)
cat <<'EOF'
ޥ˥奢ڡ򥤥󥹥ȡ뤹ϡ
EOF
esac

$ECHOn "[$def] > " $ECHOt
read ans
case X$ans in
X)	;;
*)	ManPlace=$ans;;
esac
$ECHO

def=yes
HasRandom=1
case $MSG in
e)
$ECHO "Typically, BSD system has random(), while System V"
$ECHO "provides rand(). My experience says that BSD usually has"
$ECHO "poor rand() routine, and it screws up yamsweeper."
$ECHO "If you are using a BSD system, you should use random()"
$ECHO "rather than rand(). To do so, answer \"yes\" to the question."
$ECHO "If you are using a System V system, answer \"no.\""
$ECHO "If you are using Linux, answer \"yes.\""
$ECHO
$ECHOn "Does your system have random() routine ? [$def] > " $ECHOt;;
j)
cat <<'EOF'
BSDƥrandom()äƤޤSystem Vrand()ȤޤBSD
rand()ϤޤɤʤȤ褦ǤBSDȤäƤСrand()
random()ȤäɤǤ礦ξ硢μ"yes"
Ʋ⤷System VѤƤС"no"ƲLinux
Ȥʤ顢"yes"Ʋ

ʤΥƥϡrandom()롼äƤޤ
EOF
$ECHOn "[$def] > " $ECHOt
esac

read ans
$ECHO

case X$ans in
X[Yy]*)	HasRandom=1;;
X[Nn]*)	HasRandom=0;;
esac

def=no
LogUser=0
case $MSG in
e)
$ECHO "You should read \"INSTALL\" carefully to log users."
$ECHOn "Do you want to log users? [$def] > " $ECHOt;;
j)
cat <<'EOF'
桼ΥΤˤϡ"INSTALL"褯ɤǲ

桼ΥΤޤ
EOF
$ECHOn "[$def] > " $ECHOt
esac

read ans
case X$ans in
X[Yy]*)	LogUser=1;;
X[Nn]*)	LogUser=0;;
esac

$ECHO
def=yes
HighScore=1
case $MSG in
e)
$ECHOn "Do you want High-Scoring ? [$def] > " $ECHOt;;
j)
cat <<'EOF'
ϥǽͭˤޤ
EOF
$ECHOn "[$def] > " $ECHOt
esac

read ans
case X$ans in
X[Yy]*)	HighScore=1;;
X[Nn]*)	HighScore=0;;
esac
$ECHO

def=/usr/local/.log/game/yams.hi
HighScoreFile=$def

case $HighScore in
1)
	case $MSG in
	e)
	$ECHO "It is recommended that you make an user who owns the high-score file."
	$ECHOn "Hit return. > " $ECHOt;;
	j)
cat <<'EOF'
ϥեΥʡȤʤ桼򿷤˺뤳Ȥ侩


꥿󥭡򲡤Ʋ
EOF
	$ECHOn "> " $ECHOt
	esac

	read ans
	$ECHO

	case $MSG in
	e)
	$ECHO
	$ECHO "You can customise the location of the high score file."
	$ECHO "Just hit return if the default is acceptable.";;
	j)
cat <<'EOF'
ϥեξǤޤǥեȤǤ褱СΤޤ
꥿󥭡򲡤Ʋ

EOF
	esac

	$ECHOn "[$def] > " $ECHOt
	read ans
	case X$ans in
	X) ;;
	*) HighScoreFile=$ans;;
	esac
	case $MSG in
	e)
	$ECHO "High score file will be placed as $HighScoreFile.";;
	j)
cat <<'EOF'

ϥեϡ
EOF
	$ECHO $HighScoreFile
cat <<'EOF'
Ȥꤵޤ
EOF
	esac
esac
$ECHO


UNAME=`uname`
case X$UNAME in
X[Ll]inux*)
	NoFdSet=0;;
*)
	case $MSG in
	e)
	$ECHO
	$ECHO "According to the research, for example, Sun UNIX 4.2 Release 3.5EXPORT"
	$ECHO "does not have FD_* macros in any include files."
	$ECHO "In case your system doesn't have FD_* macros, yamsweeper provides"
	$ECHO "a sample implementation of FD_*, but there may be incompatibilities."
	$ECHO "If you want to use yamsweeper's sample FD_*, answer \"yes\" to the question."
	$ECHO "Otherwise, just type return."
	$ECHO
	$ECHO "I'm checking if your system has FD_SET in /usr/include/sys/*."
	$ECHO "Just a moment..."
	$ECHO;;
	j)
cat <<'EOF'
Ĵˤȡ㤨 Sun UNIX 4.2 Release 3.5EXPORTϡ󥯥롼ɥե
FD_* ޥʤȤʬäƤޤ⤷ʤΥ
बFD_*ޥʤơyamsweeperFD_*ΥץѰ
ƤޤϤ٤ƤΥƥǻѲǽȤϸ¤ޤ󡣤
yamsweeperѰդץFD_*ޥѤʤ顢μ
"yes"ƲǤʤС꥿󥭡򲡤Ʋ

줫顢ʤΥƥब/usr/include/sys/*FD_SETޥäƤ
뤫ɤåޤ
Ф餯Ԥ....

EOF
	;;
	esac
LASTPWD=`pwd`
cd /usr/include/sys
if grep FD_SET * >/dev/null 2>&1; then
	def=no
	case $MSG in
	e)
	$ECHO "Your system has FD_SET macro.";;
	j)
	cat <<'EOF'
ʤΥƥϡFD_SETޥäƤޤ
EOF
	esac
	NoFdSet=0
else
	def=yes
	case $MSG in
	e)	$ECHO "Your system does not have FD_SET macro.";;
	j)	cat <<'EOF'
ʤΥƥϡFD_SETޥäƤޤ
EOF
	esac
	NoFdSet=1
fi
cd $LASTPWD
$ECHO
case $MSG in
e)	$ECHOn "Do you want to use the sample FD_* macros? [$def] > " $ECHOt;;
j)	cat <<'EOF'
ץFD_*ޥȤޤ
EOF
	$ECHOn "[$def] > " $ECHOt
esac
read ans
$ECHO
case X$ans in
X[Yy]*)	NoFdSet=1;;
X[Nn]*)	NoFdSet=0;;
esac;;
esac

TemplateFile=imake.src

case $MSG in
e)	$ECHO "Summary of your choice:";;
j)	cat <<'EOF'
ޤǤΥޥǤ
EOF
esac

$ECHO "yamsweeper   : $LMPlace"
$ECHO "man page     : $ManPlace"
$ECHO "has random() : $HasRandom"
$ECHO "log users    : $LogUser"
$ECHO "high scoring : $HighScore"
$ECHO "hi-score file: $HighScoreFile"
$ECHO "NoFdSet      : $NoFdSet"
$ECHO

case $MSG in
e)
$ECHO "This is the last chance to quit."
$ECHOn "Hit Return to continue. > " $ECHOt;;
j)
cat <<'EOF'
줬ǽλǤǸΥ󥹤Ǥ

꥿󥭡򲡤мؿʤߤޤ
EOF
$ECHOn "> " $ECHOt
esac

read ans

HighScoreFileDir=`dirname $HighScoreFile`

if sed -e "s/xxHasRandom/$HasRandom/" -e "s/xxNoFdSet/$NoFdSet/" \
	-e "s/xxLogUser/$LogUser/" \
	-e "s:xxHighScoreFileDir:$HighScoreFileDir:" \
	-e "s:xxHighScoreFile:$HighScoreFile:"  -e "s/xxHighScore/$HighScore/" \
	-e "s:xxLMPlace:$LMPlace:" -e "s:xxManPlace:$ManPlace:" \
	$TemplateFile > Imakefile; then
	:
else
	case $MSG in
	e)
		$ECHO "Imakefile can't be made."
		$ECHO "Check to see all the neccessary files, or"
		$ECHO "Contact the auther."
		;;
	j)	cat <<'EOF'

ImakefileκǤޤ󡣤줾Υեå뤫
Ϣ򤷤Ʋ

EOF
	esac
	exit 1
fi

$ECHO
if xmkmf; then
	:
else
	case $MSG in
	e)
	$ECHO "Error found. Cannot make Makefile with xmkmf."
	$ECHO "Consult the system manager, or contact the auther.";;
	j)	cat <<'EOF'

顼ȯޤxmkmfȤäơMakefileκǤޤ󡣥
ƥԤ̤뤫ԤϢ򤷤Ʋ

EOF
	esac
	exit 1
fi


case $MSG in
e)
	$ECHO
	$ECHO "The Imakefile and Makefile have been built."
	$ECHO "You should check them before making anything."
	$ECHO "When you are satisfied with the makefile, just type \"make\""
	$ECHO "and \"yamsweeper\" will be built."
	$ECHO "See \"INSTALL\" or \"INSTALL.euc\" for more information."
	$ECHO
	;;
j)	cat <<'EOF'

ImakefileȡMakefileޤºݤmakeԤˡ
եåƲ

MakefileγǧǤ顢makeyamsweeperϺޤʤ
󥹥ȡξܺ٤ˤĤƤϡ"INSTALL"ޤ"INSTALL.euc"

EOF
esac

