1AC_DEFUN([AX_CHECK_CURSES], [
2AC_CHECK_HEADER([curses.h], [
3    AC_CHECK_LIB([curses], [clear], [curses="y"], [curses="n"])
4], [curses="n"])
5AC_CHECK_HEADER([ncurses.h], [
6    AC_CHECK_LIB([ncurses], [clear], [ncurses="y"], [ncurses="n"])
7], [ncurses="n"])
8AS_IF([test "$curses" = "n" && test "$ncurses" = "n"], [
9    AC_MSG_ERROR([Unable to find a suitable curses library])
10])
11# Prefer ncurses over curses if both are present
12AS_IF([test "$ncurses" = "y"], [
13    CURSES_LIBS="-lncurses"
14    AC_DEFINE([INCLUDE_CURSES_H], [<ncurses.h>], [Define curses header to use])
15], [
16    CURSES_LIBS="-lcurses"
17    AC_DEFINE([INCLUDE_CURSES_H], [<curses.h>], [Define curses header to use])
18])
19AC_SUBST(CURSES_LIBS)
20])
21