summaryrefslogtreecommitdiff
path: root/gettext-tools/gnulib-m4/terminfo.m4
blob: 070e86ed85f98b90c12e1fef63baf383dcb841b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# terminfo.m4 serial 3 (gettext-0.18)
dnl Copyright (C) 2000-2002, 2006, 2008, 2015 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl From Bruno Haible.

AC_DEFUN([gl_TERMINFO],
[
  AC_REQUIRE([gl_TERMINFO_BODY])
  if test $gl_cv_terminfo_tparam = no && test $gl_cv_terminfo_tparm = no; then
    AC_LIBOBJ([tparm])
  fi
  case "$gl_cv_terminfo" in
    no*)
      case "$gl_cv_termcap" in
        no*)
          AC_LIBOBJ([tputs])
          ;;
      esac
      ;;
  esac
])

AC_DEFUN([gl_TERMINFO_BODY],
[
  dnl Some systems have setupterm(), tigetnum(), tigetstr(), tigetflag(),
  dnl tputs(), tgoto() in the same library as tgetent(), tgetnum(), tgetstr(),
  dnl tgetflag(), e.g. Linux (in libncurses) or Solaris (in libtermcap =
  dnl libncurses).
  dnl Some systems have them in a different library, e.g. OSF/1 (in libcurses,
  dnl not in libtermcap) or HP-UX (in libxcurses, not in libtermcap).
  dnl Some systems, like NetBSD or BeOS, don't have these functions at all;
  dnl they have only a libtermcap.
  dnl Some systems, like BeOS, use GNU termcap, which has tparam() instead of
  dnl tparm().
  dnl Some systems, like mingw, have nothing at all.

  dnl Some people want to avoid these libraries, in special situations such
  dnl as when cross-compiling.
  AC_REQUIRE([gl_CURSES])

  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
  AC_REQUIRE([AC_LIB_RPATH])

  if test "$gl_curses_allowed" != no; then

    dnl Search for libncurses and define LIBNCURSES, LTLIBNCURSES and INCNCURSES
    dnl accordingly.
    AC_LIB_LINKFLAGS_BODY([ncurses])

    dnl Search for libtermcap and define LIBTERMCAP, LTLIBTERMCAP and INCTERMCAP
    dnl accordingly.
    AC_LIB_LINKFLAGS_BODY([termcap])

    dnl Search for libxcurses and define LIBXCURSES, LTLIBXCURSES and INCXCURSES
    dnl accordingly.
    AC_LIB_LINKFLAGS_BODY([xcurses])

    dnl Search for libcurses and define LIBCURSES, LTLIBCURSES and INCCURSES
    dnl accordingly.
    AC_LIB_LINKFLAGS_BODY([curses])

  else

    LIBNCURSES=
    LTLIBNCURSES=
    INCNCURSES=

    LIBTERMCAP=
    LTLIBTERMCAP=
    INCTERMCAP=

    LIBXCURSES=
    LTLIBXCURSES=
    INCXCURSES=

    LIBCURSES=
    LTLIBCURSES=
    INCCURSES=

  fi

  dnl When searching for the terminfo functions, prefer libtermcap over
  dnl libxcurses and libcurses, because it is smaller.
  AC_CACHE_CHECK([where terminfo library functions come from], [gl_cv_terminfo], [
    gl_cv_terminfo="not found, consider installing GNU ncurses"
    AC_TRY_LINK([extern
      #ifdef __cplusplus
      "C"
      #endif
      int setupterm (const char *, int, int *);
      extern
      #ifdef __cplusplus
      "C"
      #endif
      int tigetnum (const char *);
      extern
      #ifdef __cplusplus
      "C"
      #endif
      int tigetflag (const char *);
      extern
      #ifdef __cplusplus
      "C"
      #endif
      const char * tigetstr (const char *);
      ], [return setupterm ("xterm", 0, (int *)0)
                 + tigetnum ("colors")
                 + tigetflag ("hc") + * tigetstr("oc");],
      [gl_cv_terminfo=libc])
    if test "$gl_cv_terminfo" != libc; then
      gl_save_LIBS="$LIBS"
      LIBS="$LIBS $LIBNCURSES"
      AC_TRY_LINK([extern
        #ifdef __cplusplus
        "C"
        #endif
        int setupterm (const char *, int, int *);
        extern
        #ifdef __cplusplus
        "C"
        #endif
        int tigetnum (const char *);
        extern
        #ifdef __cplusplus
        "C"
        #endif
        int tigetflag (const char *);
        extern
        #ifdef __cplusplus
        "C"
        #endif
        const char * tigetstr (const char *);
        ], [return setupterm ("xterm", 0, (int *)0)
                   + tigetnum ("colors")
                   + tigetflag ("hc") + * tigetstr("oc");],
        [gl_cv_terminfo=libncurses])
      LIBS="$gl_save_LIBS"
      if test "$gl_cv_terminfo" != libncurses; then
        gl_save_LIBS="$LIBS"
        LIBS="$LIBS $LIBTERMCAP"
        AC_TRY_LINK([extern
          #ifdef __cplusplus
          "C"
          #endif
          int setupterm (const char *, int, int *);
          extern
          #ifdef __cplusplus
          "C"
          #endif
          int tigetnum (const char *);
          extern
          #ifdef __cplusplus
          "C"
          #endif
          int tigetflag (const char *);
          extern
          #ifdef __cplusplus
          "C"
          #endif
          const char * tigetstr (const char *);
          ], [return setupterm ("xterm", 0, (int *)0)
                     + tigetnum ("colors")
                     + tigetflag ("hc") + * tigetstr("oc");],
          [gl_cv_terminfo=libtermcap])
        LIBS="$gl_save_LIBS"
        if test "$gl_cv_terminfo" != libtermcap; then
          gl_save_LIBS="$LIBS"
          LIBS="$LIBS $LIBXCURSES"
          AC_TRY_LINK([extern
            #ifdef __cplusplus
            "C"
            #endif
            int setupterm (const char *, int, int *);
            extern
            #ifdef __cplusplus
            "C"
            #endif
            int tigetnum (const char *);
            extern
            #ifdef __cplusplus
            "C"
            #endif
            int tigetflag (const char *);
            extern
            #ifdef __cplusplus
            "C"
            #endif
            const char * tigetstr (const char *);
            ], [return setupterm ("xterm", 0, (int *)0)
                       + tigetnum ("colors")
                       + tigetflag ("hc") + * tigetstr("oc");],
            [gl_cv_terminfo=libxcurses])
          LIBS="$gl_save_LIBS"
          if test "$gl_cv_terminfo" != libxcurses; then
            gl_save_LIBS="$LIBS"
            LIBS="$LIBS $LIBCURSES"
            AC_TRY_LINK([extern
              #ifdef __cplusplus
              "C"
              #endif
              int setupterm (const char *, int, int *);
              extern
              #ifdef __cplusplus
              "C"
              #endif
              int tigetnum (const char *);
              extern
              #ifdef __cplusplus
              "C"
              #endif
              int tigetflag (const char *);
              extern
              #ifdef __cplusplus
              "C"
              #endif
              const char * tigetstr (const char *);
              ], [return setupterm ("xterm", 0, (int *)0)
                         + tigetnum ("colors")
                         + tigetflag ("hc") + * tigetstr("oc");],
              [gl_cv_terminfo=libcurses])
            LIBS="$gl_save_LIBS"
          fi
        fi
      fi
    fi
  ])
  case "$gl_cv_terminfo" in
    libc)
      LIBTERMINFO=
      LTLIBTERMINFO=
      INCTERMINFO=
      ;;
    libncurses)
      LIBTERMINFO="$LIBNCURSES"
      LTLIBTERMINFO="$LTLIBNCURSES"
      INCTERMINFO="$INCNCURSES"
      ;;
    libtermcap)
      LIBTERMINFO="$LIBTERMCAP"
      LTLIBTERMINFO="$LTLIBTERMCAP"
      INCTERMINFO="$INCTERMCAP"
      ;;
    libxcurses)
      LIBTERMINFO="$LIBXCURSES"
      LTLIBTERMINFO="$LTLIBXCURSES"
      INCTERMINFO="$INCXCURSES"
      ;;
    libcurses)
      LIBTERMINFO="$LIBCURSES"
      LTLIBTERMINFO="$LTLIBCURSES"
      INCTERMINFO="$INCCURSES"
      ;;
  esac
  case "$gl_cv_terminfo" in
    libc | libncurses | libtermcap | libxcurses | libcurses)
      AC_DEFINE([HAVE_TERMINFO], 1,
        [Define if setupterm(), tigetnum(), tigetstr(), tigetflag()
         are among the termcap library functions.])
      ;;
    *)
      dnl Use the termcap functions as a fallback.
      AC_CACHE_CHECK([where termcap library functions come from], [gl_cv_termcap], [
        gl_cv_termcap="not found, consider installing GNU ncurses"
        AC_TRY_LINK([extern
          #ifdef __cplusplus
          "C"
          #endif
          int tgetent (char *, const char *);
          ], [return tgetent ((char *) 0, "xterm");],
          [gl_cv_termcap=libc])
        if test "$gl_cv_termcap" != libc; then
          gl_save_LIBS="$LIBS"
          LIBS="$LIBS $LIBNCURSES"
          AC_TRY_LINK([extern
            #ifdef __cplusplus
            "C"
            #endif
            int tgetent (char *, const char *);
            ], [return tgetent ((char *) 0, "xterm");],
            [gl_cv_termcap=libncurses])
          LIBS="$gl_save_LIBS"
          if test "$gl_cv_termcap" != libncurses; then
            gl_save_LIBS="$LIBS"
            LIBS="$LIBS $LIBTERMCAP"
            AC_TRY_LINK([extern
              #ifdef __cplusplus
              "C"
              #endif
              int tgetent (char *, const char *);
              ], [return tgetent ((char *) 0, "xterm");],
              [gl_cv_termcap=libtermcap])
            LIBS="$gl_save_LIBS"
          fi
        fi
      ])
      case "$gl_cv_termcap" in
        libc)
          LIBTERMINFO=
          LTLIBTERMINFO=
          INCTERMINFO=
          ;;
        libncurses)
          LIBTERMINFO="$LIBNCURSES"
          LTLIBTERMINFO="$LTLIBNCURSES"
          INCTERMINFO="$INCNCURSES"
          ;;
        libtermcap)
          LIBTERMINFO="$LIBTERMCAP"
          LTLIBTERMINFO="$LTLIBTERMCAP"
          INCTERMINFO="$INCTERMCAP"
          ;;
      esac
      case "$gl_cv_termcap" in
        libc | libncurses | libtermcap)
          AC_DEFINE([HAVE_TERMCAP], 1,
            [Define if tgetent(), tgetnum(), tgetstr(), tgetflag()
             are among the termcap library functions.])
          ;;
      esac
      ;;
  esac
  AC_SUBST([LIBTERMINFO])
  AC_SUBST([LTLIBTERMINFO])
  AC_SUBST([INCTERMINFO])

  dnl Test against the old GNU termcap, which provides a tparam() function
  dnl instead of the classical tparm() function.
  AC_CACHE_CHECK([for tparam], [gl_cv_terminfo_tparam], [
    gl_save_LIBS="$LIBS"
    LIBS="$LIBS $LIBTERMINFO"
    gl_save_CPPFLAGS="$CPPFLAGS"
    CPPFLAGS="$CPPFLAGS $INCTERMINFO"
    AC_TRY_LINK([extern
      #ifdef __cplusplus
      "C"
      #endif
      char * tparam (const char *, void *, int, ...);
      char buf;
      ], [return tparam ("\033\133%dm", &buf, 1, 8);],
      [gl_cv_terminfo_tparam=yes], [gl_cv_terminfo_tparam=no])
    CPPFLAGS="$gl_save_CPPFLAGS"
    LIBS="$gl_save_LIBS"
  ])
  if test $gl_cv_terminfo_tparam = yes; then
    AC_DEFINE([HAVE_TPARAM], 1,
      [Define if tparam() is among the termcap library functions.])
  else
    dnl Test whether a tparm() function is provided. It is missing e.g.
    dnl in NetBSD 3.0 libtermcap.
    AC_CACHE_CHECK([for tparm], [gl_cv_terminfo_tparm], [
      gl_save_LIBS="$LIBS"
      LIBS="$LIBS $LIBTERMINFO"
      gl_save_CPPFLAGS="$CPPFLAGS"
      CPPFLAGS="$CPPFLAGS $INCTERMINFO"
      AC_TRY_LINK([extern
        #ifdef __cplusplus
        "C"
        #endif
        char * tparm (const char *, ...);
        ], [return tparm ("\033\133%dm", 8);],
        [gl_cv_terminfo_tparm=yes], [gl_cv_terminfo_tparm=no])
      CPPFLAGS="$gl_save_CPPFLAGS"
      LIBS="$gl_save_LIBS"
    ])
  fi
])