havelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.
[gnulib.git] / m4 / pty.m4
blob9a25742386006481d0a7a7bf0515e44bdc268067
1 # pty.m4 serial 14
2 dnl Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 # gl_PTY_LIB
8 # ----------
9 # Define automake variable PTY_LIB to the library needed (if any).
10 AC_DEFUN([gl_PTY_LIB],
12   # Check for the library required for forkpty.
13   PTY_LIB=
14   save_LIBS="$LIBS"
15   AC_SEARCH_LIBS([forkpty], [util],
16     [if test "$ac_cv_search_forkpty" != "none required"; then
17        PTY_LIB="$ac_cv_search_forkpty"
18      fi])
19   LIBS="$save_LIBS"
20   AC_SUBST([PTY_LIB])
23 AC_DEFUN([gl_FUNC_FORKPTY],
25   AC_REQUIRE([gl_PTY_LIB])
26   AC_REQUIRE([gl_PTY_H])
28   dnl We assume that forkpty exists (possibly in libc, possibly in libutil)
29   dnl if and only if it is declared.
30   AC_CHECK_DECLS([forkpty],,, [[
31 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
32 #include <sys/types.h>
33 #if HAVE_PTY_H
34 # include <pty.h>
35 #endif
36 #if HAVE_UTIL_H
37 # include <util.h>
38 #endif
39 #if HAVE_LIBUTIL_H
40 # include <libutil.h>
41 #endif
42 #if HAVE_TERMIOS_H
43 # include <termios.h>
44 #endif
45 ]])
46   if test $ac_cv_have_decl_forkpty = yes; then
47     dnl The system has forkpty.
48     dnl Prefer glibc's const-safe prototype, if available.
49     AC_CACHE_CHECK([for const-safe forkpty signature],
50       [gl_cv_func_forkpty_const],
51       [AC_COMPILE_IFELSE(
52         [AC_LANG_PROGRAM([[
53 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
54 #include <sys/types.h>
55 #if HAVE_PTY_H
56 # include <pty.h>
57 #endif
58 #if HAVE_UTIL_H
59 # include <util.h>
60 #endif
61 #if HAVE_LIBUTIL_H
62 # include <libutil.h>
63 #endif
64 #if HAVE_TERMIOS_H
65 # include <termios.h>
66 #endif
67           ]], [[
68             int forkpty (int *, char *, struct termios const *,
69                          struct winsize const *);
70           ]])
71         ],
72         [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])
73       ])
74     if test $gl_cv_func_forkpty_const != yes; then
75       REPLACE_FORKPTY=1
76     fi
77   else
78     dnl The system does not have forkpty.
79     HAVE_FORKPTY=0
80   fi
81   AC_DEFINE_UNQUOTED([HAVE_FORKPTY], [$HAVE_FORKPTY],
82     [Define to 1 if the system has the 'forkpty' function.])
85 AC_DEFUN([gl_FUNC_OPENPTY],
87   AC_REQUIRE([gl_PTY_LIB])
88   AC_REQUIRE([gl_PTY_H])
90   dnl Persuade Solaris <stdlib.h> to declare posix_openpt().
91   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
93   dnl We assume that openpty exists (possibly in libc, possibly in libutil)
94   dnl if and only if it is declared.
95   AC_CHECK_DECLS([openpty],,, [[
96 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
97 #include <sys/types.h>
98 #if HAVE_PTY_H
99 # include <pty.h>
100 #endif
101 #if HAVE_UTIL_H
102 # include <util.h>
103 #endif
104 #if HAVE_LIBUTIL_H
105 # include <libutil.h>
106 #endif
107 #if HAVE_TERMIOS_H
108 # include <termios.h>
109 #endif
111   if test $ac_cv_have_decl_openpty = yes; then
112     AC_DEFINE([HAVE_OPENPTY], [1],
113       [Define to 1 if the system has the 'openpty' function.])
114     dnl The system has openpty.
115     dnl Prefer glibc's const-safe prototype, if available.
116     AC_CACHE_CHECK([for const-safe openpty signature],
117       [gl_cv_func_openpty_const],
118       [AC_COMPILE_IFELSE(
119         [AC_LANG_PROGRAM([[
120 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
121 #include <sys/types.h>
122 #if HAVE_PTY_H
123 # include <pty.h>
124 #endif
125 #if HAVE_UTIL_H
126 # include <util.h>
127 #endif
128 #if HAVE_LIBUTIL_H
129 # include <libutil.h>
130 #endif
131 #if HAVE_TERMIOS_H
132 # include <termios.h>
133 #endif
134           ]], [[
135             int openpty (int *, int *, char *, struct termios const *,
136                        struct winsize const *);
137           ]])
138         ],
139         [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])
140       ])
141     if test $gl_cv_func_openpty_const != yes; then
142       REPLACE_OPENPTY=1
143     fi
144   else
145     dnl The system does not have openpty.
146     HAVE_OPENPTY=0
147     dnl Prerequisites of lib/openpty.c in this case.
148     AC_CHECK_FUNCS([_getpty posix_openpt])
149   fi
152 AC_DEFUN([gl_FUNC_LOGIN_TTY],
154   AC_REQUIRE([gl_PTY_LIB])
156   gl_saved_libs="$LIBS"
157   LIBS="$LIBS $PTY_LIB"
158   AC_CHECK_FUNCS([login_tty])
159   LIBS="$gl_saved_LIBS"