#!/bin/sh

# pathetic attempt at a configure utility -- bjd
# for one thing it doesn't check if what you specify exists in those
# places -- don't worry, you'll find out soon enough...  :^)

#set -x

rm -f Makefile config.h *.o


CC=gcc
echo
echo
echo "Compile sysline for aout or ELF? [ELF]"
echo "1) ELF"
echo "2) aout"		# aout-phaseout
read choice
echo
case $choice in
	2)	CC="gcc -bi486-linuxaout	# aout"
		LDFLAGS="-L/usr/i486-linuxaout/lib " ;;
	*)	CC="gcc	# ELF is assumed" ;;
esac
echo "...using ${CC}"


ask_LIBPATH()
{
	#LDFLAGS="${LDFLAGS}"
	echo -n "Path lib$1.a? [$2] "
	read choice
	echo
	case $choice in
		"")	;;
		*)	LDFLAGS="${LDFLAGS} -L$choice" ;;
	esac
}


ask_INCPATH()
{
	CFLAGS=-I$2
	echo -n "Path for $1 include files? [$2] "
	read choice
	echo
	case $choice in
		"")	;;
		*)	CFLAGS=-I$choice ;;
	esac
}


echo
echo "Compile sysline for the termcap or the terminfo database? [termcap]"
echo "1) termcap"
echo "2) terminfo (ncurses)"
read choice
case $choice in
	2)	echo -e "...using terminfo (ncurses)\n"
		TERMLIB=-lncurses
		ask_LIBPATH "ncurses" "/usr/local/lib"
		ask_INCPATH "ncurses" "/usr/include/ncurses"
		;;
	*)	echo -e "...using termcap\n"
		TERMLIB=-ltermcap
		;;
esac


# make config.h
cp config.h.in config.h
echo "...creating config.h"
if [ ! "$TERMLIB" = "-ltermcap" ]
then
	cat <<- EOT >>config.h
	/* terminfo */
	#define TERMINFO
	#include <term.h>
	EOT
fi

# make Makefile
if [ "$TERMLIB" = "-ltermcap" ]
then
	cat <<- EOT >>config.h
	/* curses */
	/*#include <curses.h>*/
	EOT
else
	cat <<- EOT >>config.h
	/* ncurses */
	#include <ncurses.h>
	#include <unctrl.h>
	EOT
fi

echo -e "...creating Makefile\n"
sed "s|@CC@|${CC}|
s|@CFLAGS@|${CFLAGS}|
s|@LDFLAGS@|${LDFLAGS}|
s|@COMMENT@|${COMMENT}|
s|@TERMLIB@|${TERMLIB}|" <Makefile.in >Makefile
