bootstrap: Avoid failure when gnulib-tool removed gettext.m4.
[gnulib.git] / m4 / pty.m4
blobf666b12589aa7fafa056c02a0f7e7228c1a6c601
1 # pty.m4
2 # serial 20
3 dnl Copyright (C) 2010-2024 Free Software Foundation, 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.
8 # gl_PTY_LIB
9 # ----------
10 # Define automake variable PTY_LIB to the library needed (if any).
11 AC_DEFUN([gl_PTY_LIB],
13   AC_REQUIRE([AC_CANONICAL_HOST])
14   # Check for the library required for forkpty.
15   PTY_LIB=
16   case "$host_os" in
17     haiku*) PTY_LIB='-lbsd' ;;
18     *)
19       saved_LIBS="$LIBS"
20       AC_SEARCH_LIBS([forkpty], [util],
21         [if test "$ac_cv_search_forkpty" != "none required"; then
22            PTY_LIB="$ac_cv_search_forkpty"
23          fi
24         ])
25       LIBS="$saved_LIBS"
26       ;;
27   esac
28   AC_SUBST([PTY_LIB])
31 AC_DEFUN([gl_FUNC_FORKPTY],
33   AC_REQUIRE([gl_PTY_LIB])
34   AC_REQUIRE([gl_PTY_H])
36   dnl We assume that forkpty exists (possibly in libc, possibly in libutil or
37   dnl libbsd) if and only if it is declared.
38   AC_CHECK_DECLS([forkpty],,, [[
39 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
40 #include <sys/types.h>
41 #if HAVE_PTY_H
42 # include <pty.h>
43 #endif
44 #if HAVE_UTIL_H
45 # include <util.h>
46 #endif
47 #if HAVE_LIBUTIL_H
48 # include <libutil.h>
49 #endif
50 #if HAVE_TERMIOS_H
51 # include <termios.h>
52 #endif
53 ]])
54   if test $ac_cv_have_decl_forkpty = yes; then
55     dnl The system has forkpty.
56     dnl Prefer glibc's const-safe prototype, if available.
57     AC_CACHE_CHECK([for const-safe forkpty signature],
58       [gl_cv_func_forkpty_const],
59       [AC_COMPILE_IFELSE(
60         [AC_LANG_PROGRAM([[
61 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
62 #include <sys/types.h>
63 #if HAVE_PTY_H
64 # include <pty.h>
65 #endif
66 #if HAVE_UTIL_H
67 # include <util.h>
68 #endif
69 #if HAVE_LIBUTIL_H
70 # include <libutil.h>
71 #endif
72 #if HAVE_TERMIOS_H
73 # include <termios.h>
74 #endif
75           ]], [[
76             int forkpty (int *, char *, struct termios const *,
77                          struct winsize const *);
78           ]])
79         ],
80         [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])
81       ])
82     if test $gl_cv_func_forkpty_const != yes; then
83       REPLACE_FORKPTY=1
84     fi
85   else
86     dnl The system does not have forkpty.
87     HAVE_FORKPTY=0
88   fi
89   AC_DEFINE_UNQUOTED([HAVE_FORKPTY], [$HAVE_FORKPTY],
90     [Define to 1 if the system has the 'forkpty' function.])
93 AC_DEFUN([gl_FUNC_OPENPTY],
95   AC_REQUIRE([gl_PTY_LIB])
96   AC_REQUIRE([gl_PTY_H])
98   dnl Persuade Solaris <stdlib.h> to declare posix_openpt().
99   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
101   dnl We assume that openpty exists (possibly in libc, possibly in libutil or
102   dnl libbsd) if and only if it is declared.
103   AC_CHECK_DECLS([openpty],,, [[
104 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
105 #include <sys/types.h>
106 #if HAVE_PTY_H
107 # include <pty.h>
108 #endif
109 #if HAVE_UTIL_H
110 # include <util.h>
111 #endif
112 #if HAVE_LIBUTIL_H
113 # include <libutil.h>
114 #endif
115 #if HAVE_TERMIOS_H
116 # include <termios.h>
117 #endif
119   if test $ac_cv_have_decl_openpty = yes; then
120     AC_DEFINE([HAVE_OPENPTY], [1],
121       [Define to 1 if the system has the 'openpty' function.])
122     dnl The system has openpty.
123     dnl Prefer glibc's const-safe prototype, if available.
124     AC_CACHE_CHECK([for const-safe openpty signature],
125       [gl_cv_func_openpty_const],
126       [AC_COMPILE_IFELSE(
127         [AC_LANG_PROGRAM([[
128 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
129 #include <sys/types.h>
130 #if HAVE_PTY_H
131 # include <pty.h>
132 #endif
133 #if HAVE_UTIL_H
134 # include <util.h>
135 #endif
136 #if HAVE_LIBUTIL_H
137 # include <libutil.h>
138 #endif
139 #if HAVE_TERMIOS_H
140 # include <termios.h>
141 #endif
142           ]], [[
143             int openpty (int *, int *, char *, struct termios const *,
144                        struct winsize const *);
145           ]])
146         ],
147         [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])
148       ])
149     if test $gl_cv_func_openpty_const != yes; then
150       REPLACE_OPENPTY=1
151     fi
152   else
153     dnl The system does not have openpty.
154     HAVE_OPENPTY=0
155     dnl Prerequisites of lib/openpty.c in this case.
156     AC_CHECK_FUNCS([_getpty])
157     gl_CHECK_FUNCS_ANDROID([posix_openpt], [[#include <stdlib.h>]])
158   fi