#___________________________________________________________
#
# barebones poor-man's configure.sh
# ( to be replaced by the real gnu autotools' stuff )
# Sep'2010	alexandre botao
#___________________________________________________________
#
CFH=config.h
CLD=curses.ld
TMP=/tmp/.conftemp
TCS=$TMP/x.c
TCX=$TMP/x
#___________________________________________________________
#
[ -d $TMP ] && rm -fr $TMP
mkdir $TMP
echo '/* ' "config.h for vdt @ `date`" ' */' > $CFH
#___________________________________________________________
#
echo "+ looking for curses"
if [ -f /usr/include/ncurses/curses.h ]
then
	cif=ncurses
	echo "#define USE_NCURSES" >> $CFH
	echo "-lncurses" >> $CLD
elif [ -f /usr/include/curses.h ]
then
	cif=curses
	echo "#define USE_CURSES" >> $CFH
	echo "-lcurses" >> $CLD
else
	cif=not
fi
if [ "$cif" = "not" ]
then
	echo "*** curses not found !"
	exit 1
else
	echo "... found $cif"
fi
#___________________________________________________________
#
echo "+ looking for termio"
if [ -f /usr/include/asm/termios.h ]
then
	tif=asm/termios
	echo "#define USE_ASM_TIOS" >> $CFH
elif [ -f /usr/include/sys/termios.h ]
then
	tif=sys/termios
	echo "#define USE_SYS_TIOS" >> $CFH
elif [ -f /usr/include/termios.h ]
then
	tif=termios
	echo "#define USE_TIOS" >> $CFH
else
	tif=not
fi
if [ "$tif" = "not" ]
then
	echo "*** termio not found !"
	exit 1
else
	echo "... found $tif"
fi
#___________________________________________________________
#
echo "+ looking for cc"
if type cc
then
	cc=cc
fi
echo "+ checking if cc works"
if cc | grep "not installed" > /dev/null
then
	echo "...NO"
	cc=""
else
	echo "...yes"
fi
echo "+ looking for gcc"
if type gcc
then
	cc=gcc
fi
if [ "$cc" = "" ]
then
	echo "*** no working [g]cc found !"
	exit 1
fi
#___________________________________________________________
#
echo "+ checking if libm works"
echo "main(){float x=sqrt(2.0);}" > $TCS
$cc $TCS -o $TCX -lm > /dev/null 2>&1
if [ $? -eq 0 ]
then
	echo "...yes"
else
	echo "...NO"
	exit 1
fi
#___________________________________________________________
#
echo "+ creating Makefile"
echo CC=$cc > Makefile
cat vdt.Makefile >> Makefile
echo "... done!"
#___________________________________________________________
#
echo "+ cleaning up"
[ -d $TMP ] && rm -fr $TMP
echo "... done!"
#___________________________________________________________
#
exit 0
#___________________________________________________________
#
# vi:nu ts=8
