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