Correct m4 conditionals in curses.m4
[pkg-k5-afs_openafs.git] / src / cf / curses.m4
blobdc01469f5efe53e3fab4bfa252af40f6ab16f9e1
1 dnl _OPENAFS_CURSES_HEADERS
2 dnl abstracting out the preprocessor gunk to #include curses
3 AC_DEFUN([_OPENAFS_CURSES_HEADERS],[
4 #if defined(HAVE_NCURSES_H)
5 # include <ncurses.h>
6 #elif defined(HAVE_NCURSES_NCURSES_H)
7 # include <ncurses/ncurses.h>
8 #elif defined(HAVE_CURSES_H)
9 # include <curses.h>
10 #endif
13 dnl OPENAFS_CURSES_LIB([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
14 dnl check for a working curses library and set $LIB_curses if so
15 AC_DEFUN([OPENAFS_CURSES_LIB],
16 [AC_CACHE_VAL([openafs_cv_curses_lib],
17    [save_LIBS="$LIBS"
18     openafs_cv_curses_lib=
19     AC_CHECK_LIB([ncurses], [initscr], [openafs_cv_curses_lib=-lncurses])
20     AS_IF([test "x$openafs_cv_curses_lib" = x],
21           [AC_CHECK_LIB([Hcurses], [initscr], [openafs_cv_curses_lib=-lHcurses])])
22     AS_IF([test "x$openafs_cv_curses_lib" = x],
23           [AC_CHECK_LIB([curses], [initscr], [openafs_cv_curses_lib=-lcurses])])
24     LIBS="$save_LIBS"])
25  LIB_curses="$openafs_cv_curses_lib"
26  AC_SUBST(LIB_curses)
27  AC_MSG_NOTICE([checking for curses library... ${openafs_cv_curses_lib:-none}])
28  AS_IF([test "x$openafs_cv_curses_lib" != x], [$1], [$2])])
30 dnl _OPENAFS_CURSES_GETMAXYX_XTI([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
31 dnl test for XTI-standard getmaxyx()
32 AC_DEFUN([_OPENAFS_CURSES_GETMAXYX_XTI],
33 [dnl paranoid check because of complex macros in various curses impls
34  AC_CACHE_CHECK([getmaxyx macro], [openafs_cv_curses_getmaxyx],
35    [save_LIBS="$LIBS"
36     LIBS="$LIBS $LIB_curses"
37     AC_TRY_LINK(_OPENAFS_CURSES_HEADERS,
38                 [int mx, my; initscr(); getmaxyx(stdscr, my, mx); endwin();],
39                 [openafs_cv_curses_getmaxyx=yes],
40                 [openafs_cv_curses_getmaxyx=no])
41     LIBS="$save_LIBS"])
42  AS_IF([test x"$openafs_cv_curses_getmaxyx" = xyes],
43        [AC_DEFINE(HAVE_GETMAXYX, 1,
44                   [define if your curses has the getmaxyx() macro])
45         $1],
46        [$2])])
48 dnl _OPENAFS_CURSES_GETMAXYX_BSD43([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
49 dnl test for getmaxx() and getmaxy() as from later BSD curses
50 AC_DEFUN([_OPENAFS_CURSES_GETMAXYX_BSD43],
51 [OPENAFS_CURSES_LIB
52  save_LIBS="$LIBS"
53  LIBS="$LIBS $LIB_curses"
54  _openafs_curses_bsd43=yes
55  dnl possibly this may need to be done as above in some cases?
56  AC_CHECK_FUNCS([getmaxx getmaxy], [], [_openafs_curses_bsd43=no])
57  LIBS="$save_LIBS"
58  AS_IF([test "$_openafs_curses_bsd43" = yes], [$1], [$2])])
60 dnl _OPENAFS_CURSES_GETMAXYX_BSDVI([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
61 dnl test for getmaxx() and getmaxy() as from BSD curses as bodily ripped
62 dnl out of the original vi sources
63 AC_DEFUN([_OPENAFS_CURSES_GETMAXYX_BSDVI],
64 [OPENAFS_CURSES_LIB
65  save_LIBS="$LIBS"
66  LIBS="$LIBS $LIB_curses"
67  _openafs_curses_bsdvi=yes
68  AC_CHECK_MEMBERS([WINDOW._maxx WINDOW._maxy], [], [_openafs_curses_bsdvi=no],
69                   _OPENAFS_CURSES_HEADERS)
70  LIBS="$save_LIBS"
71  AS_IF([test "$_openafs_curses_bsdvi" = yes], [$1], [$2])])
73 dnl OPENAFS_CURSES_WINDOW_EXTENTS([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
74 dnl check for standard getmaxyx macro. failing that, try the
75 dnl older getmaxx and getmaxy functions/macros; failing those,
76 dnl try the 4.2BSD _maxx and _maxy fields
77 AC_DEFUN([OPENAFS_CURSES_WINDOW_EXTENTS],
78 [OPENAFS_CURSES_LIB
79  openafs_curses_extent=none
80  _OPENAFS_CURSES_GETMAXYX_XTI([openafs_curses_extent=xti])
81  AS_IF([test "$openafs_curses_extent" = none],
82        [_OPENAFS_CURSES_GETMAXYX_BSD43([openafs_curses_extent=bsd])])
83  AS_IF([test "$openafs_curses_extent" = none],
84        [_OPENAFS_CURSES_GETMAXYX_BSDVI([openafs_curses_extent=vi])],)
85  AS_IF([test "$openafs_curses_extent" != none], [$1], [$2])])
87 dnl The top level curses group
88 AC_DEFUN([OPENAFS_CURSES],
89 [AC_ARG_ENABLE([gtx],
90     [AS_HELP_STRING([--disable-gtx], [disable gtx curses-based terminal tools])])
91  AS_IF([test "x$enable_gtx" != "xno"],
92        [OPENAFS_CURSES_LIB([], [enable_gtx=no])])
93  AS_IF([test "x$enable_gtx" != "xno"],
94        [OPENAFS_CURSES_WINDOW_EXTENTS([], [enable_gtx=no])])])