#!/bin/sh
# $Id: build-opt-vile,v 1.3 2013/05/24 22:48:31 tom Exp $
# builds the major configuration options
if [ $# != 0 ]
then
	if [ ! -d $1 ] ; then
		echo "not a directory $1"
		exit 1
	fi
	OUT=build-opt-`partition`-`pd`.log
	cat >>$OUT <<EOF
** `date`
** run: $*
EOF
	export srcdir
	case $1 in
	/*|../*|..)
		if test ! -f $1/configure ; then
			echo '? no configure script in '$1
			exit 1
		elif test -f ./configure ; then
			echo '? redundant directory param'
		else
			rm -f configure
			ln -s $1/configure .
		fi
		srcdir="--srcdir=$1"
		( eval $0 2>&1 ) | tee -a $OUT
		;;
	*)
		srcdir=
		( cd $1 && eval $0 2>&1 ) | tee -a $OUT
		;;
	esac
	exit
fi

test ! -d bin && mkdir bin
for feature in filters nofilters noleaks perl revile small ""
do
	suffix=""
	SUFFIX=""
	case $feature in
	filters)suffix="-filters"
		SUFFIX="--with-builtin-filters=c,m4,ada --with-loadable-filters=make,vile"
		;;
	nofilters)suffix="-nofilters"
		SUFFIX="--disable-filters"
		;;
	noleaks)suffix="-noleaks"
		SUFFIX="--with-no-leaks --with-trace"
		;;
	perl)	suffix="-perl"
		SUFFIX="--with-perl"
		;;
	revile)	suffix="-revile"
		SUFFIX="--disable-shell"
		;;
	small)	suffix="-small"
		SUFFIX="--disable-extensions"
		;;
	*)	suffix=""
		SUFFIX=""
		;;
	esac
	for screen in tcap ncurses ncursesw ansi X11 Xm Xaw Xaw3d neXtaw XawPlus
	do
		case $screen in
		*X*)	source=xvile
			SCREEN="--with-$screen"
			config=cfg-x11
			;;
		*)	source=vile
			SCREEN="--with-screen=$screen"
			config=cfg-normal
			;;
		esac
		target="${source}-${screen}${suffix}"
		if test -s bin/$target ; then
			echo SKIP bin/$target 
			continue
		fi
		echo MAKE bin/$target 
		test -f makefile && make distclean
		rm *.out
		$config $srcdir --with-screen=$screen $SCREEN $SUFFIX && \
		make-out $source && mv $source bin/$target && \
		save-vile || touch bin/$target 
		echo "RESULT: `ls -l bin/$target`"
	done
done
