Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / gnulib-m4 / terminfo.m4
1 # terminfo.m4 serial 3 (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_TERMINFO],
11 [
12   AC_REQUIRE([gl_TERMINFO_BODY])
13   if test $gl_cv_terminfo_tparam = no && test $gl_cv_terminfo_tparm = no; then
14     AC_LIBOBJ([tparm])
15   fi
16   case "$gl_cv_terminfo" in
17     no*)
18       case "$gl_cv_termcap" in
19         no*)
20           AC_LIBOBJ([tputs])
21           ;;
22       esac
23       ;;
24   esac
25 ])
26
27 AC_DEFUN([gl_TERMINFO_BODY],
28 [
29   dnl Some systems have setupterm(), tigetnum(), tigetstr(), tigetflag(),
30   dnl tputs(), tgoto() in the same library as tgetent(), tgetnum(), tgetstr(),
31   dnl tgetflag(), e.g. Linux (in libncurses) or Solaris (in libtermcap =
32   dnl libncurses).
33   dnl Some systems have them in a different library, e.g. OSF/1 (in libcurses,
34   dnl not in libtermcap) or HP-UX (in libxcurses, not in libtermcap).
35   dnl Some systems, like NetBSD or BeOS, don't have these functions at all;
36   dnl they have only a libtermcap.
37   dnl Some systems, like BeOS, use GNU termcap, which has tparam() instead of
38   dnl tparm().
39   dnl Some systems, like mingw, have nothing at all.
40
41   dnl Some people want to avoid these libraries, in special situations such
42   dnl as when cross-compiling.
43   AC_REQUIRE([gl_CURSES])
44
45   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
46   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
47   AC_REQUIRE([AC_LIB_RPATH])
48
49   if test "$gl_curses_allowed" != no; then
50
51     dnl Search for libncurses and define LIBNCURSES, LTLIBNCURSES and INCNCURSES
52     dnl accordingly.
53     AC_LIB_LINKFLAGS_BODY([ncurses])
54
55     dnl Search for libtermcap and define LIBTERMCAP, LTLIBTERMCAP and INCTERMCAP
56     dnl accordingly.
57     AC_LIB_LINKFLAGS_BODY([termcap])
58
59     dnl Search for libxcurses and define LIBXCURSES, LTLIBXCURSES and INCXCURSES
60     dnl accordingly.
61     AC_LIB_LINKFLAGS_BODY([xcurses])
62
63     dnl Search for libcurses and define LIBCURSES, LTLIBCURSES and INCCURSES
64     dnl accordingly.
65     AC_LIB_LINKFLAGS_BODY([curses])
66
67   else
68
69     LIBNCURSES=
70     LTLIBNCURSES=
71     INCNCURSES=
72
73     LIBTERMCAP=
74     LTLIBTERMCAP=
75     INCTERMCAP=
76
77     LIBXCURSES=
78     LTLIBXCURSES=
79     INCXCURSES=
80
81     LIBCURSES=
82     LTLIBCURSES=
83     INCCURSES=
84
85   fi
86
87   dnl When searching for the terminfo functions, prefer libtermcap over
88   dnl libxcurses and libcurses, because it is smaller.
89   AC_CACHE_CHECK([where terminfo library functions come from], [gl_cv_terminfo], [
90     gl_cv_terminfo="not found, consider installing GNU ncurses"
91     AC_TRY_LINK([extern
92       #ifdef __cplusplus
93       "C"
94       #endif
95       int setupterm (const char *, int, int *);
96       extern
97       #ifdef __cplusplus
98       "C"
99       #endif
100       int tigetnum (const char *);
101       extern
102       #ifdef __cplusplus
103       "C"
104       #endif
105       int tigetflag (const char *);
106       extern
107       #ifdef __cplusplus
108       "C"
109       #endif
110       const char * tigetstr (const char *);
111       ], [return setupterm ("xterm", 0, (int *)0)
112                  + tigetnum ("colors")
113                  + tigetflag ("hc") + * tigetstr("oc");],
114       [gl_cv_terminfo=libc])
115     if test "$gl_cv_terminfo" != libc; then
116       gl_save_LIBS="$LIBS"
117       LIBS="$LIBS $LIBNCURSES"
118       AC_TRY_LINK([extern
119         #ifdef __cplusplus
120         "C"
121         #endif
122         int setupterm (const char *, int, int *);
123         extern
124         #ifdef __cplusplus
125         "C"
126         #endif
127         int tigetnum (const char *);
128         extern
129         #ifdef __cplusplus
130         "C"
131         #endif
132         int tigetflag (const char *);
133         extern
134         #ifdef __cplusplus
135         "C"
136         #endif
137         const char * tigetstr (const char *);
138         ], [return setupterm ("xterm", 0, (int *)0)
139                    + tigetnum ("colors")
140                    + tigetflag ("hc") + * tigetstr("oc");],
141         [gl_cv_terminfo=libncurses])
142       LIBS="$gl_save_LIBS"
143       if test "$gl_cv_terminfo" != libncurses; then
144         gl_save_LIBS="$LIBS"
145         LIBS="$LIBS $LIBTERMCAP"
146         AC_TRY_LINK([extern
147           #ifdef __cplusplus
148           "C"
149           #endif
150           int setupterm (const char *, int, int *);
151           extern
152           #ifdef __cplusplus
153           "C"
154           #endif
155           int tigetnum (const char *);
156           extern
157           #ifdef __cplusplus
158           "C"
159           #endif
160           int tigetflag (const char *);
161           extern
162           #ifdef __cplusplus
163           "C"
164           #endif
165           const char * tigetstr (const char *);
166           ], [return setupterm ("xterm", 0, (int *)0)
167                      + tigetnum ("colors")
168                      + tigetflag ("hc") + * tigetstr("oc");],
169           [gl_cv_terminfo=libtermcap])
170         LIBS="$gl_save_LIBS"
171         if test "$gl_cv_terminfo" != libtermcap; then
172           gl_save_LIBS="$LIBS"
173           LIBS="$LIBS $LIBXCURSES"
174           AC_TRY_LINK([extern
175             #ifdef __cplusplus
176             "C"
177             #endif
178             int setupterm (const char *, int, int *);
179             extern
180             #ifdef __cplusplus
181             "C"
182             #endif
183             int tigetnum (const char *);
184             extern
185             #ifdef __cplusplus
186             "C"
187             #endif
188             int tigetflag (const char *);
189             extern
190             #ifdef __cplusplus
191             "C"
192             #endif
193             const char * tigetstr (const char *);
194             ], [return setupterm ("xterm", 0, (int *)0)
195                        + tigetnum ("colors")
196                        + tigetflag ("hc") + * tigetstr("oc");],
197             [gl_cv_terminfo=libxcurses])
198           LIBS="$gl_save_LIBS"
199           if test "$gl_cv_terminfo" != libxcurses; then
200             gl_save_LIBS="$LIBS"
201             LIBS="$LIBS $LIBCURSES"
202             AC_TRY_LINK([extern
203               #ifdef __cplusplus
204               "C"
205               #endif
206               int setupterm (const char *, int, int *);
207               extern
208               #ifdef __cplusplus
209               "C"
210               #endif
211               int tigetnum (const char *);
212               extern
213               #ifdef __cplusplus
214               "C"
215               #endif
216               int tigetflag (const char *);
217               extern
218               #ifdef __cplusplus
219               "C"
220               #endif
221               const char * tigetstr (const char *);
222               ], [return setupterm ("xterm", 0, (int *)0)
223                          + tigetnum ("colors")
224                          + tigetflag ("hc") + * tigetstr("oc");],
225               [gl_cv_terminfo=libcurses])
226             LIBS="$gl_save_LIBS"
227           fi
228         fi
229       fi
230     fi
231   ])
232   case "$gl_cv_terminfo" in
233     libc)
234       LIBTERMINFO=
235       LTLIBTERMINFO=
236       INCTERMINFO=
237       ;;
238     libncurses)
239       LIBTERMINFO="$LIBNCURSES"
240       LTLIBTERMINFO="$LTLIBNCURSES"
241       INCTERMINFO="$INCNCURSES"
242       ;;
243     libtermcap)
244       LIBTERMINFO="$LIBTERMCAP"
245       LTLIBTERMINFO="$LTLIBTERMCAP"
246       INCTERMINFO="$INCTERMCAP"
247       ;;
248     libxcurses)
249       LIBTERMINFO="$LIBXCURSES"
250       LTLIBTERMINFO="$LTLIBXCURSES"
251       INCTERMINFO="$INCXCURSES"
252       ;;
253     libcurses)
254       LIBTERMINFO="$LIBCURSES"
255       LTLIBTERMINFO="$LTLIBCURSES"
256       INCTERMINFO="$INCCURSES"
257       ;;
258   esac
259   case "$gl_cv_terminfo" in
260     libc | libncurses | libtermcap | libxcurses | libcurses)
261       AC_DEFINE([HAVE_TERMINFO], 1,
262         [Define if setupterm(), tigetnum(), tigetstr(), tigetflag()
263          are among the termcap library functions.])
264       ;;
265     *)
266       dnl Use the termcap functions as a fallback.
267       AC_CACHE_CHECK([where termcap library functions come from], [gl_cv_termcap], [
268         gl_cv_termcap="not found, consider installing GNU ncurses"
269         AC_TRY_LINK([extern
270           #ifdef __cplusplus
271           "C"
272           #endif
273           int tgetent (char *, const char *);
274           ], [return tgetent ((char *) 0, "xterm");],
275           [gl_cv_termcap=libc])
276         if test "$gl_cv_termcap" != libc; then
277           gl_save_LIBS="$LIBS"
278           LIBS="$LIBS $LIBNCURSES"
279           AC_TRY_LINK([extern
280             #ifdef __cplusplus
281             "C"
282             #endif
283             int tgetent (char *, const char *);
284             ], [return tgetent ((char *) 0, "xterm");],
285             [gl_cv_termcap=libncurses])
286           LIBS="$gl_save_LIBS"
287           if test "$gl_cv_termcap" != libncurses; then
288             gl_save_LIBS="$LIBS"
289             LIBS="$LIBS $LIBTERMCAP"
290             AC_TRY_LINK([extern
291               #ifdef __cplusplus
292               "C"
293               #endif
294               int tgetent (char *, const char *);
295               ], [return tgetent ((char *) 0, "xterm");],
296               [gl_cv_termcap=libtermcap])
297             LIBS="$gl_save_LIBS"
298           fi
299         fi
300       ])
301       case "$gl_cv_termcap" in
302         libc)
303           LIBTERMINFO=
304           LTLIBTERMINFO=
305           INCTERMINFO=
306           ;;
307         libncurses)
308           LIBTERMINFO="$LIBNCURSES"
309           LTLIBTERMINFO="$LTLIBNCURSES"
310           INCTERMINFO="$INCNCURSES"
311           ;;
312         libtermcap)
313           LIBTERMINFO="$LIBTERMCAP"
314           LTLIBTERMINFO="$LTLIBTERMCAP"
315           INCTERMINFO="$INCTERMCAP"
316           ;;
317       esac
318       case "$gl_cv_termcap" in
319         libc | libncurses | libtermcap)
320           AC_DEFINE([HAVE_TERMCAP], 1,
321             [Define if tgetent(), tgetnum(), tgetstr(), tgetflag()
322              are among the termcap library functions.])
323           ;;
324       esac
325       ;;
326   esac
327   AC_SUBST([LIBTERMINFO])
328   AC_SUBST([LTLIBTERMINFO])
329   AC_SUBST([INCTERMINFO])
330
331   dnl Test against the old GNU termcap, which provides a tparam() function
332   dnl instead of the classical tparm() function.
333   AC_CACHE_CHECK([for tparam], [gl_cv_terminfo_tparam], [
334     gl_save_LIBS="$LIBS"
335     LIBS="$LIBS $LIBTERMINFO"
336     gl_save_CPPFLAGS="$CPPFLAGS"
337     CPPFLAGS="$CPPFLAGS $INCTERMINFO"
338     AC_TRY_LINK([extern
339       #ifdef __cplusplus
340       "C"
341       #endif
342       char * tparam (const char *, void *, int, ...);
343       char buf;
344       ], [return tparam ("\033\133%dm", &buf, 1, 8);],
345       [gl_cv_terminfo_tparam=yes], [gl_cv_terminfo_tparam=no])
346     CPPFLAGS="$gl_save_CPPFLAGS"
347     LIBS="$gl_save_LIBS"
348   ])
349   if test $gl_cv_terminfo_tparam = yes; then
350     AC_DEFINE([HAVE_TPARAM], 1,
351       [Define if tparam() is among the termcap library functions.])
352   else
353     dnl Test whether a tparm() function is provided. It is missing e.g.
354     dnl in NetBSD 3.0 libtermcap.
355     AC_CACHE_CHECK([for tparm], [gl_cv_terminfo_tparm], [
356       gl_save_LIBS="$LIBS"
357       LIBS="$LIBS $LIBTERMINFO"
358       gl_save_CPPFLAGS="$CPPFLAGS"
359       CPPFLAGS="$CPPFLAGS $INCTERMINFO"
360       AC_TRY_LINK([extern
361         #ifdef __cplusplus
362         "C"
363         #endif
364         char * tparm (const char *, ...);
365         ], [return tparm ("\033\133%dm", 8);],
366         [gl_cv_terminfo_tparm=yes], [gl_cv_terminfo_tparm=no])
367       CPPFLAGS="$gl_save_CPPFLAGS"
368       LIBS="$gl_save_LIBS"
369     ])
370   fi
371 ])