1# termcap.m4 serial 6 (gettext-0.17) 2dnl Copyright (C) 2000-2002, 2006 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl From Bruno Haible. 8 9AC_DEFUN([gl_TERMCAP], 10[ 11 AC_REQUIRE([gl_TERMCAP_BODY]) 12 if test $gl_cv_termcap_tparam = no && test $gl_cv_termcap_tparm = no; then 13 AC_LIBOBJ([tparm]) 14 fi 15 case "$gl_cv_termcap" in 16 no*) 17 AC_LIBOBJ([tputs]) 18 ;; 19 esac 20]) 21 22AC_DEFUN([gl_TERMCAP_BODY], 23[ 24 dnl Some systems have tgetent(), tgetnum(), tgetstr(), tgetflag(), tparm(), 25 dnl tputs(), tgoto() in libc, some have it in libtermcap, some have it in 26 dnl libncurses. 27 dnl When both libtermcap and libncurses exist, we prefer the latter, 28 dnl because libtermcap is unsecure by design and obsolete since 1994. 29 dnl libcurses is useless: all platforms which have libcurses also have 30 dnl libtermcap, and libcurses is unusable on some old Unices. 31 dnl Some systems have the terminfo functions setupterm(), tigetnum(), 32 dnl tigetstr(), tigetflag() in the same library. 33 dnl Some systems, like BeOS, use GNU termcap, which has tparam() instead of 34 dnl tparm(). 35 dnl Some systems, like mingw, have nothing at all. 36 37 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 38 AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 39 AC_REQUIRE([AC_LIB_RPATH]) 40 41 dnl Search for libncurses and define LIBNCURSES, LTLIBNCURSES and INCNCURSES 42 dnl accordingly. 43 AC_LIB_LINKFLAGS_BODY([ncurses]) 44 45 dnl Search for libtermcap and define LIBTERMCAP, LTLIBTERMCAP and INCTERMCAP 46 dnl accordingly. 47 AC_LIB_LINKFLAGS_BODY([termcap]) 48 49 AC_CACHE_CHECK([where termcap library functions come from], [gl_cv_termcap], [ 50 gl_cv_termcap="not found, consider installing GNU ncurses" 51 AC_TRY_LINK([extern 52 #ifdef __cplusplus 53 "C" 54 #endif 55 int tgetent (char *, const char *); 56 ], [return tgetent ((char *) 0, "xterm");], [gl_cv_termcap=libc]) 57 if test "$gl_cv_termcap" != libc; then 58 gl_save_LIBS="$LIBS" 59 LIBS="$LIBS $LIBNCURSES" 60 AC_TRY_LINK([extern 61 #ifdef __cplusplus 62 "C" 63 #endif 64 int tgetent (char *, const char *); 65 ], [return tgetent ((char *) 0, "xterm");], [gl_cv_termcap=libncurses]) 66 LIBS="$gl_save_LIBS" 67 if test "$gl_cv_termcap" != libncurses; then 68 gl_save_LIBS="$LIBS" 69 LIBS="$LIBS $LIBTERMCAP" 70 AC_TRY_LINK([extern 71 #ifdef __cplusplus 72 "C" 73 #endif 74 int tgetent (char *, const char *); 75 ], [return tgetent ((char *) 0, "xterm");], [gl_cv_termcap=libtermcap]) 76 LIBS="$gl_save_LIBS" 77 fi 78 fi 79 ]) 80 case "$gl_cv_termcap" in 81 libc) 82 LIBTERMCAP= 83 LTLIBTERMCAP= 84 INCTERMCAP= 85 ;; 86 libncurses) 87 LIBTERMCAP="$LIBNCURSES" 88 LTLIBTERMCAP="$LTLIBNCURSES" 89 INCTERMCAP="$INCNCURSES" 90 ;; 91 libtermcap) 92 ;; 93 esac 94 case "$gl_cv_termcap" in 95 libc | libncurses | libtermcap) 96 AC_DEFINE([HAVE_TERMCAP], 1, 97 [Define if tgetent(), tgetnum(), tgetstr(), tgetflag() 98 are among the termcap library functions.]) 99 ;; 100 esac 101 AC_SUBST([LIBTERMCAP]) 102 AC_SUBST([LTLIBTERMCAP]) 103 AC_SUBST([INCTERMCAP]) 104 105 dnl Test whether the terminfo functions are available from the same library. 106 AC_CACHE_CHECK([for terminfo functions], [gl_cv_func_terminfo], [ 107 gl_save_LIBS="$LIBS" 108 LIBS="$LIBS $LIBTERMCAP" 109 gl_save_CPPFLAGS="$CPPFLAGS" 110 CPPFLAGS="$CPPFLAGS $INCTERMCAP" 111 AC_TRY_LINK([extern 112 #ifdef __cplusplus 113 "C" 114 #endif 115 int setupterm (const char *, int, int *); 116 extern 117 #ifdef __cplusplus 118 "C" 119 #endif 120 int tigetnum (const char *); 121 extern 122 #ifdef __cplusplus 123 "C" 124 #endif 125 int tigetflag (const char *); 126 extern 127 #ifdef __cplusplus 128 "C" 129 #endif 130 const char * tigetstr (const char *); 131 ], [return setupterm ("xterm", 0, (int *)0) 132 + tigetnum ("colors") + tigetflag ("hc") + * tigetstr("oc");], 133 [gl_cv_func_terminfo=yes], [gl_cv_func_terminfo=no]) 134 CPPFLAGS="$gl_save_CPPFLAGS" 135 LIBS="$gl_save_LIBS" 136 ]) 137 if test $gl_cv_func_terminfo = yes; then 138 AC_DEFINE([HAVE_TERMINFO], 1, 139 [Define if setupterm(), tigetnum(), tigetstr(), tigetflag() 140 are among the termcap library functions.]) 141 fi 142 143 dnl Test against the old GNU termcap, which provides a tparam() function 144 dnl instead of the classical tparm() function. 145 AC_CACHE_CHECK([for tparam], [gl_cv_termcap_tparam], [ 146 gl_save_LIBS="$LIBS" 147 LIBS="$LIBS $LIBTERMCAP" 148 gl_save_CPPFLAGS="$CPPFLAGS" 149 CPPFLAGS="$CPPFLAGS $INCTERMCAP" 150 AC_TRY_LINK([extern 151 #ifdef __cplusplus 152 "C" 153 #endif 154 char * tparam (const char *, void *, int, ...); 155 char buf; 156 ], [return tparam ("\033\133%dm", &buf, 1, 8);], 157 [gl_cv_termcap_tparam=yes], [gl_cv_termcap_tparam=no]) 158 CPPFLAGS="$gl_save_CPPFLAGS" 159 LIBS="$gl_save_LIBS" 160 ]) 161 if test $gl_cv_termcap_tparam = yes; then 162 AC_DEFINE([HAVE_TPARAM], 1, 163 [Define if tparam() is among the termcap library functions.]) 164 else 165 dnl Test whether a tparm() function is provided. It is missing e.g. 166 dnl in NetBSD 3.0 libtermcap. 167 AC_CACHE_CHECK([for tparm], [gl_cv_termcap_tparm], [ 168 gl_save_LIBS="$LIBS" 169 LIBS="$LIBS $LIBTERMCAP" 170 gl_save_CPPFLAGS="$CPPFLAGS" 171 CPPFLAGS="$CPPFLAGS $INCTERMCAP" 172 AC_TRY_LINK([extern 173 #ifdef __cplusplus 174 "C" 175 #endif 176 char * tparm (const char *, ...); 177 ], [return tparm ("\033\133%dm", 8);], 178 [gl_cv_termcap_tparm=yes], [gl_cv_termcap_tparm=no]) 179 CPPFLAGS="$gl_save_CPPFLAGS" 180 LIBS="$gl_save_LIBS" 181 ]) 182 fi 183]) 184