-if test "$with_tty" != "no" ; then
- AS_MESSAGE(checking for TTY-related features)
- AC_DEFINE([HAVE_TTY], [1], [Description here!])
- AC_DEFINE([HAVE_UNIXOID_EVENT_LOOP], [1], [Description here!])
- SXE_ADD_SXEUITTY_OBJS([console-tty.o device-tty.o event-tty.o frame-tty.o objects-tty.o redisplay-tty.o cm.o])
-
- dnl Autodetect ncurses.
- AC_CHECK_LIB(ncurses, tgetent, , with_ncurses=no)
- AC_CHECK_LIB(ncurses, tgetstr, , with_ncurses=no)
- AC_CHECK_LIB(ncurses, tparm, , with_ncurses=no)
- if test "$with_ncurses" != "no"; then
- AC_DEFINE([HAVE_NCURSES], [1], [Description here!])
- with_ncurses=yes
- AC_CHECK_HEADER(ncurses/ncurses.h, curses_h_file=ncurses/ncurses.h)
- if test -z "$curses_h_file"; then
- AC_CHECK_HEADER(ncurses/curses.h, curses_h_file=ncurses/curses.h)
- fi
- if test -n "$curses_h_file"; then
- AC_CHECK_HEADER(ncurses/termcap.h, termcap_h_file=ncurses/termcap.h)
- AC_CHECK_HEADER(ncurses/term.h, term_h_file=ncurses/term.h)
- else
- AC_CHECK_HEADER(ncurses.h, curses_h_file=ncurses.h)
- AC_CHECK_HEADER(termcap.h, termcap_h_file=termcap.h)
- AC_CHECK_HEADER(term.h, term_h_file=term.h)
- fi
- SXE_ADD_SXEUITTY_OBJS(terminfo.o)
- SXE_PREPEND(-lncurses, LIBS)
-
- if test -z "$curses_h_file" ; then
- dnl Try again, and check for the bogus ncurses/ include bug.
- dnl (i.e. ncurses/curses.h bogusly includes <unctrl.h> instead of
- dnl <ncurses/unctrl.h>)
- save_c_switch_site="$c_switch_site"
- c_switch_site="$c_switch_site -I/usr/include/ncurses"
+AS_IF([test "$with_tty" != "no"],[
+ AS_MESSAGE(checking for TTY-related features)
+ dnl Check if needed calls are available at all...
+
+ with_tty_libs=""
+ detect_tty_libs=""
+ for lib in ncurses curses tinfo terminfo termlib termcap
+ do
+ eval "with=\$with_${lib}"
+ if test "$with" = no
+ then
+ AC_MSG_WARN(["Ignoring available ${lib} due to --with-${lib}=no"])
+ elif test "$with" = "yes"
+ then
+ with_tty_libs="$with_tty_libs $lib"
+ else
+ detect_tty_libs="$detect_tty_libs $lib"
+ fi
+ done
+
+ # All terminal info functions needed
+ tty_funcs="tgetent tgetstr tgetflag tgetnum tparm tgoto tputs"
+ tty_libs=""
+ # Filter by existing libs, printf is sure to be available with libc, so failure
+ # would come from lib not find
+ for lib in $with_tty_libs $detect_tty_libs
+ do
+ SXE_CHECK_LINK_LIB($lib)
+ if eval "test \"\$sxe_cv_c_lib_${lib}\" != yes"
+ then
+ if eval "test \"\$with_${lib}\" = yes"
+ then
+ AC_MSG_WARN(["Ignoring --with-${lib}=yes due to library not linkable"])
+ eval "with_${lib}=no"
+ fi
+ continue
+ fi
+
+ AC_CHECK_LIB([$lib], [$tty_funcs])
+
+ # Lets verify we have all functions
+ for func in $tty_func
+ do
+ if eval "test \"\$ac_cv_lib_${lib}_${func}\" = no"
+ then
+ AS_MESSAGE(["Skipping ${lib}, does not support to all TTY functions"])
+ lib=""
+ break
+ fi
+ done
+
+ tty_libs="$tty_libs $lib"
+ done
+
+ if test -n "$tty_libs"
+ then
+ AS_MESSAGE(["Considering libraries: $tty_libs"])
+
+ # Check which preferred lib can be used
+ for func in $tty_funcs
+ do
+ # Make sure no flags are harmed during the search
+ sxe_save_LIBS=$LIBS
+ AC_SEARCH_LIBS($func, $tty_libs)
+ LIBS=$sxe_save_LIBS
+ done
+
+ # Minimize the set of libraries
+ tty_feature=""
+ tty_fun=""
+ for func in $tty_funcs
+ do
+ eval lib=\$ac_cv_search_${func}
+ if test "$lib" != no -a "$lib" != "none required"
+ then
+ for feature in $tty_feature
+ do
+ if test "$feature" = "$lib"
+ then
+ lib=""
+ func=""
+ break;
+ fi
+ done
+ tty_feature="$tty_feature $lib"
+ tty_fun="$tty_fun $func"
+ fi
+ done
+ fi
+
+ if test -n "$tty_feature"
+ then
+ # Check all the expected functions still compile with all the added
+ # libraries
+ sxe_save_LIBS=$LIBS
+ LIBS="$LIBS $tty_feature"
+ AC_CHECK_FUNCS($tty_funcs)
+ for func in $tty_fun
+ do
+ if eval "test \"\$ac_cv_func_${func}\" = no"
+ then
+ tty_feature=""
+ break
+ fi
+ done
+ LIBS=$sxe_save_LIBS
+ fi
+
+ if test -n "$tty_feature"
+ then
+ SXE_PREPEND($tty_feature, LIBS)
+ for lib in $tty_feature
+ do
+ l=`echo $lib | sed -e 's/^-l//g'`
+ eval "with_${l}=yes"
+ done
+ with_builtin_tty=no
+ have_tty=yes
+ else
+ AC_MSG_WARN([Could not link all needed tty functions.]
+ [Please consider installing ncurses.])
+ if test "$with_builtin_tty" = yes
+ then
+ AC_MSG_WARN([Using builtin tty support.])
+ have_tty=yes
+ else
+ AC_MSG_WARN([Use --with-builtin-tty=yes if you cannot use ncurses.])
+ have_tty=no
+ fi
+ fi
+
+ if test "$with_builtin_tty" = yes
+ then
+ # Add our own wrappers using termcap
+ SXE_ADD_SXEUITTY_OBJS(termcap.o)
+ SXE_ADD_SXEUITTY_OBJS(tparam.o)
+ have_tty=yes
+ elif test "$have_tty" = yes
+ then
+ # Terminfo interface, since tgetent etc are available
+ SXE_ADD_SXEUITTY_OBJS(terminfo.o)
+ fi
+
+ # Check headers, first generally
+ AC_CHECK_HEADER(termcap.h, termcap_h_file=termcap.h)
+ AC_CHECK_HEADER(term.h, term_h_file=term.h)
+
+ if test "$have_ncurses" = yes; then
+ # Verify how ncurses overrides them