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