maint: update copyright
[gnulib.git] / m4 / pty.m4
1 # pty.m4 serial 13
2 dnl Copyright (C) 2010-2014 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.
6
7 # gl_PTY_LIB
8 # ----------
9 # Define automake variable PTY_LIB to the library needed (if any).
10 AC_DEFUN([gl_PTY_LIB],
11 [
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])
21 ])
22
23 AC_DEFUN([gl_FUNC_FORKPTY],
24 [
25   AC_REQUIRE([gl_PTY_LIB])
26   AC_REQUIRE([gl_PTY_H])
27
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 ]])
43   if test $ac_cv_have_decl_forkpty = yes; then
44     dnl The system has forkpty.
45     dnl Prefer glibc's const-safe prototype, if available.
46     AC_CACHE_CHECK([for const-safe forkpty signature],
47       [gl_cv_func_forkpty_const],
48       [AC_COMPILE_IFELSE(
49         [AC_LANG_PROGRAM([[
50 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
51 #include <sys/types.h>
52 #if HAVE_PTY_H
53 # include <pty.h>
54 #endif
55 #if HAVE_UTIL_H
56 # include <util.h>
57 #endif
58 #if HAVE_LIBUTIL_H
59 # include <libutil.h>
60 #endif
61           ]], [[
62             int forkpty (int *, char *, struct termios const *,
63                          struct winsize const *);
64           ]])
65         ],
66         [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])
67       ])
68     if test $gl_cv_func_forkpty_const != yes; then
69       REPLACE_FORKPTY=1
70     fi
71   else
72     dnl The system does not have forkpty.
73     HAVE_FORKPTY=0
74   fi
75   AC_DEFINE_UNQUOTED([HAVE_FORKPTY], [$HAVE_FORKPTY],
76     [Define to 1 if the system has the 'forkpty' function.])
77 ])
78
79 AC_DEFUN([gl_FUNC_OPENPTY],
80 [
81   AC_REQUIRE([gl_PTY_LIB])
82   AC_REQUIRE([gl_PTY_H])
83
84   dnl Persuade Solaris <stdlib.h> to declare posix_openpt().
85   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
86
87   dnl We assume that openpty exists (possibly in libc, possibly in libutil)
88   dnl if and only if it is declared.
89   AC_CHECK_DECLS([openpty],,, [[
90 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
91 #include <sys/types.h>
92 #if HAVE_PTY_H
93 # include <pty.h>
94 #endif
95 #if HAVE_UTIL_H
96 # include <util.h>
97 #endif
98 #if HAVE_LIBUTIL_H
99 # include <libutil.h>
100 #endif
101 ]])
102   if test $ac_cv_have_decl_openpty = yes; then
103     AC_DEFINE([HAVE_OPENPTY], [1],
104       [Define to 1 if the system has the 'openpty' function.])
105     dnl The system has openpty.
106     dnl Prefer glibc's const-safe prototype, if available.
107     AC_CACHE_CHECK([for const-safe openpty signature],
108       [gl_cv_func_openpty_const],
109       [AC_COMPILE_IFELSE(
110         [AC_LANG_PROGRAM([[
111 /* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0.  */
112 #include <sys/types.h>
113 #if HAVE_PTY_H
114 # include <pty.h>
115 #endif
116 #if HAVE_UTIL_H
117 # include <util.h>
118 #endif
119 #if HAVE_LIBUTIL_H
120 # include <libutil.h>
121 #endif
122           ]], [[
123             int openpty (int *, int *, char *, struct termios const *,
124                        struct winsize const *);
125           ]])
126         ],
127         [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])
128       ])
129     if test $gl_cv_func_openpty_const != yes; then
130       REPLACE_OPENPTY=1
131     fi
132   else
133     dnl The system does not have openpty.
134     HAVE_OPENPTY=0
135     dnl Prerequisites of lib/openpty.c in this case.
136     AC_CHECK_FUNCS([_getpty posix_openpt])
137   fi
138 ])
139
140 AC_DEFUN([gl_FUNC_LOGIN_TTY],
141 [
142   AC_REQUIRE([gl_PTY_LIB])
143
144   gl_saved_libs="$LIBS"
145   LIBS="$LIBS $PTY_LIB"
146   AC_CHECK_FUNCS([login_tty])
147   LIBS="$gl_saved_LIBS"
148 ])