#!/bin/sh

export LINGUAS;LINGUAS=""
export NLSDIR;NLSDIR="/usr/lib/locale"

OPTIONS=""

echo
echo "WindowMaker configuration"
echo "========================="

echo "Read the INSTALL and README files before executing this script."
echo "Type <Return> if you've read them"
read foo

######################## Button Style
echo -n "Do you want a style of titlebar buttons different from the original? <y/n> [n] "
read foo

if [ "$foo" = "Y" -o "$foo" = "y" ]; then
	OPTIONS="$OPTIONS --enable-newstyle"
fi

####################### Superfluous stuff
echo "Do you want silly and superfluous stuff (more animations and others)?"
echo -n "Only for people with fast machines <y/n> [n] "
read foo

if [ "$foo" = "Y" -o "$foo" = "y" ]; then
	OPTIONS="$OPTIONS --enable-superfluous"
fi

######################## NLS
echo -n "Do you want National Language Support? <y/n> [n] "
read NLS

if [ "$NLS" = "y" -o "$NLS" = "Y" ]; then
	NLS="Y"
	echo "The supported locales are:"
	ling=` (cd src/po; /bin/ls *.po) `
	ALL_LINGUAS=""
	for l in $ling; do
		lname=` (cd src/po; grep Language-Team $l|cut -f 2 -d:)`
		lcode=`basename $l .po`
		ALL_LINGUAS="$ALL_LINGUAS $lcode"
		echo "$lcode $lname"
	done
	echo "Type in the locales you want  [$ALL_LINGUAS]"
	read foo
	if test "x$foo" = "x"; then
		LINGUAS=$ALL_LINGUAS
	else
		LINGUAS="$foo"
	fi

	MB=""
	for i in $LINGUAS; do
		if [ "$MB" = "" -a "$i" = "ja" -o "$i" = "kr" ]; then
			echo "A language you selected needs multi-byte character support"
			echo -n "Do you want to enable it? <y/n> [n] "
			read MB
			if [ "$MB" = "y" -o "$MB" = "Y" ]; then
				OPTIONS="$OPTIONS --enable-kanji"
			fi
		fi
	done

	echo "Where do you want to put the message files? [$NLSDIR]"
	read foo
	if test "x$foo" != "x"; then
		NLSDIR=$foo
	fi
fi

#####################  Configure

echo "Configuring..."

if [ `uname -s` = "SCO_SV" ]; then
	echo "CFLAGS=\"$CFLAGS -belf -DANSICPP\" ./configure --enable-shape $OPTIONS"
	CFLAGS="$CFLAGS -belf -DANSICPP" ./configure --enable-shape $OPTIONS
else
	echo "CFLAGS=\"$CFLAGS $GCCFLAGS\" ./configure --enable-shape $OPTIONS"
	CFLAGS="$CFLAGS $GCCFLAGS" ./configure --enable-shape $OPTIONS
fi


#################### Compile

echo "Compiling..."

make

if [ -x wmaker ]; then 
	echo "You can now su to root, run make install"
	echo "and copy the Library directory to ~/gnustep/Library"
	if test "$NLS" = "Y"; then
		echo "Also don't forget to set the LANG environment variable to the locale you want"
	fi 
fi

