#!/bin/sh
#
# WindowMaker configuration and compilation script.
#

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

OPTIONS=""
PREFIX="/usr/local"

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 the titlebar buttons to have the new style appearance? <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 po; /bin/ls *.po) `
	ALL_LINGUAS=""
	for l in $ling; do
		lname=`(cd po; grep Language-Team $l|cut -f 2 -d: |cut -f 2 -d\ )`
		lname=`echo $lname`
		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
	echo "Selected locales are: $LINGUAS"

	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
##################### Installation path

done=0
while [ $done = 0 ]; do
    echo "Where do you want to put WindowMaker stuff? [$PREFIX]"
    echo "(This will install WindowMaker in $PREFIX/bin, $PREFIX/lib etc.)"
    echo -n "? "
    read foo

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

OPTIONS="$OPTIONS --prefix=$PREFIX"


######################  Build libPropList

if [ ! -d libPropList ]; then
	gunzip -c libPropList.tar.gz | tar xf -
fi

if [ ! -f libPropList/libPropList.a ]; then
	echo "-----------------------"
	echo "Building libPropList..."
	echo "-----------------------"
	cd libPropList
	./configure
	make
	cd ..
fi

if [ ! -f libPropList/libPropList.a ]; then
	echo "Build of libPropList was not successfull."
	exit
fi


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


#################### Compile
echo "------------------------"
echo "Compiling WindowMaker..."
echo "------------------------"
(cd src; make clean)
make

if [ -x src/wmaker ]; then 
	echo "You can now login as root and run make install"
	echo "Run wmaker.inst to install personal configuration files for you"
	if test "$NLS" = "Y"; then
		echo "Don't forget to set the LANG environment variable to your locale"
	fi 
	echo "Hit <Return>"
	read foo
	more NEWS
fi

