#!/bin/sh
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/
	( cd $1 && eval $0 2>&1 ) | tee -a $OUT
	exit
fi

test ! -d bin && mkdir bin
for OPT in `all-opts-lynx`
do
	#for SCREEN in curses ncurses slang
	for SCREEN in ncurses
	do
		FLAVOR=$SCREEN
		case $SCREEN in
		ncurses|curses)
			V=cfg-normal
			;;
		slang)
			V=cfg-slang
			;;
		*)
			V=cfg-normal
			;;
		esac
		TARGET=`echo lynx-$FLAVOR-$OPT | sed -e 's/=.*//'`
		if test -f bin/$TARGET ; then
			echo SKIP bin/$TARGET
			test -f makefile && make distclean
			continue
		fi
		echo MAKE bin/$TARGET
		# continue
		test -f makefile && make distclean
		rm *.out
		$V --with-screen=$SCREEN --$OPT && \
		test -f lynx_cfg.h && \
		make-out all && mv lynx bin/$TARGET && \
		save-lynx || touch bin/$TARGET
	done
done
