Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / cf / curses.m4
blob261305ce187ddf5497835c2c71f474d8a6a32b06
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],
20                  [AC_CHECK_LIB([ncurses], [LINES], [openafs_cv_curses_lib=-lncurses],
21                                [AC_CHECK_LIB([tinfo], [LINES],
22                                              [openafs_cv_curses_lib="-lncurses -ltinfo"])])])
23     AS_IF([test "x$openafs_cv_curses_lib" = x],
24           [AC_CHECK_LIB([Hcurses], [initscr], [openafs_cv_curses_lib=-lHcurses])])
25     AS_IF([test "x$openafs_cv_curses_lib" = x],
26           [AC_CHECK_LIB([curses], [initscr], [openafs_cv_curses_lib=-lcurses])])
27     LIBS="$save_LIBS"])
28  LIB_curses="$openafs_cv_curses_lib"
29  AC_SUBST(LIB_curses)
30  AC_MSG_NOTICE([checking for curses library... ${openafs_cv_curses_lib:-none}])
31  AS_IF([test "x$openafs_cv_curses_lib" != x], [$1], [$2])])
33 dnl _OPENAFS_CURSES_GETMAXYX_XTI([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
34 dnl test for XTI-standard getmaxyx()
35 AC_DEFUN([_OPENAFS_CURSES_GETMAXYX_XTI],
36 [dnl paranoid check because of complex macros in various curses impls
37  AC_CACHE_CHECK([getmaxyx macro], [openafs_cv_curses_getmaxyx],
38    [save_LIBS="$LIBS"
39     LIBS="$LIBS $LIB_curses"
40     AC_TRY_LINK(_OPENAFS_CURSES_HEADERS,
41                 [int mx, my; initscr(); getmaxyx(stdscr, my, mx); endwin();],
42                 [openafs_cv_curses_getmaxyx=yes],
43                 [openafs_cv_curses_getmaxyx=no])
44     LIBS="$save_LIBS"])
45  AS_IF([test x"$openafs_cv_curses_getmaxyx" = xyes],
46        [AC_DEFINE(HAVE_GETMAXYX, 1,
47                   [define if your curses has the getmaxyx() macro])
48         $1],
49        [$2])])
51 dnl _OPENAFS_CURSES_GETMAXYX_BSD43([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
52 dnl test for getmaxx() and getmaxy() as from later BSD curses
53 AC_DEFUN([_OPENAFS_CURSES_GETMAXYX_BSD43],
54 [OPENAFS_CURSES_LIB
55  save_LIBS="$LIBS"
56  LIBS="$LIBS $LIB_curses"
57  _openafs_curses_bsd43=yes
58  dnl possibly this may need to be done as above in some cases?
59  AC_CHECK_FUNCS([getmaxx getmaxy], [], [_openafs_curses_bsd43=no])
60  LIBS="$save_LIBS"
61  AS_IF([test "$_openafs_curses_bsd43" = yes], [$1], [$2])])
63 dnl _OPENAFS_CURSES_GETMAXYX_BSDVI([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
64 dnl test for getmaxx() and getmaxy() as from BSD curses as bodily ripped
65 dnl out of the original vi sources
66 AC_DEFUN([_OPENAFS_CURSES_GETMAXYX_BSDVI],
67 [OPENAFS_CURSES_LIB
68  save_LIBS="$LIBS"
69  LIBS="$LIBS $LIB_curses"
70  _openafs_curses_bsdvi=yes
71  AC_CHECK_MEMBERS([WINDOW._maxx WINDOW._maxy], [], [_openafs_curses_bsdvi=no],
72                   _OPENAFS_CURSES_HEADERS)
73  LIBS="$save_LIBS"
74  AS_IF([test "$_openafs_curses_bsdvi" = yes], [$1], [$2])])
76 dnl OPENAFS_CURSES_WINDOW_EXTENTS([ACTION-IF-SUCCESS], [ACTION_IF_FAILURE])
77 dnl check for standard getmaxyx macro. failing that, try the
78 dnl older getmaxx and getmaxy functions/macros; failing those,
79 dnl try the 4.2BSD _maxx and _maxy fields
80 AC_DEFUN([OPENAFS_CURSES_WINDOW_EXTENTS],
81 [OPENAFS_CURSES_LIB
82  openafs_curses_extent=none
83  _OPENAFS_CURSES_GETMAXYX_XTI([openafs_curses_extent=xti])
84  AS_IF([test "$openafs_curses_extent" = none],
85        [_OPENAFS_CURSES_GETMAXYX_BSD43([openafs_curses_extent=bsd])])
86  AS_IF([test "$openafs_curses_extent" = none],
87        [_OPENAFS_CURSES_GETMAXYX_BSDVI([openafs_curses_extent=vi])],)
88  AS_IF([test "$openafs_curses_extent" != none], [$1], [$2])])
90 dnl The top level curses group
91 AC_DEFUN([OPENAFS_CURSES],
92 [AC_ARG_ENABLE([gtx],
93     [AS_HELP_STRING([--disable-gtx], [disable gtx curses-based terminal tools])])
94  AS_IF([test "x$enable_gtx" != "xno"],
95        [OPENAFS_CURSES_LIB([], [enable_gtx=no])])
96  AS_IF([test "x$enable_gtx" != "xno"],
97        [OPENAFS_CURSES_WINDOW_EXTENTS([], [enable_gtx=no])])])