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