added missing dependencies to fix failing unistr/ tests
[gnulib.git] / m4 / pty.m4
1 # pty.m4 serial 7
2 dnl Copyright (C) 2010 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 #if HAVE_PTY_H
32 # include <pty.h>
33 #endif
34 #if HAVE_UTIL_H
35 # include <util.h>
36 #endif
37 #if HAVE_LIBUTIL_H
38 # include <libutil.h>
39 #endif
40 ]])
41   if test $ac_cv_have_decl_forkpty = yes; then
42     dnl The system has forkpty.
43     dnl Prefer glibc's const-safe prototype, if available.
44     AC_CACHE_CHECK([for const-safe forkpty signature],
45       [gl_cv_func_forkpty_const],
46       [AC_COMPILE_IFELSE(
47         [AC_LANG_PROGRAM([[
48 #if HAVE_PTY_H
49 # include <pty.h>
50 #endif
51 #if HAVE_UTIL_H
52 # include <util.h>
53 #endif
54 #if HAVE_LIBUTIL_H
55 # include <libutil.h>
56 #endif
57           ]], [[
58             int forkpty (int *, char *, struct termios const *,
59                          struct winsize const *);
60           ]])
61         ],
62         [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])
63       ])
64     if test $gl_cv_func_forkpty_const != yes; then
65       REPLACE_FORKPTY=1
66       AC_LIBOBJ([forkpty])
67     fi
68   else
69     dnl The system does not have forkpty.
70     HAVE_FORKPTY=0
71     AC_LIBOBJ([forkpty])
72   fi
73 ])
74
75 AC_DEFUN([gl_FUNC_OPENPTY],
76 [
77   AC_REQUIRE([gl_PTY_LIB])
78   AC_REQUIRE([gl_PTY_H])
79
80   dnl Persuade Solaris <stdlib.h> to declare posix_openpt().
81   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
82
83   dnl We assume that openpty exists (possibly in libc, possibly in libutil)
84   dnl if and only if it is declared.
85   AC_CHECK_DECLS([openpty],,, [[
86 #if HAVE_PTY_H
87 # include <pty.h>
88 #endif
89 #if HAVE_UTIL_H
90 # include <util.h>
91 #endif
92 #if HAVE_LIBUTIL_H
93 # include <libutil.h>
94 #endif
95 ]])
96   if test $ac_cv_have_decl_openpty = yes; then
97     dnl The system has openpty.
98     dnl Prefer glibc's const-safe prototype, if available.
99     AC_CACHE_CHECK([for const-safe openpty signature],
100       [gl_cv_func_openpty_const],
101       [AC_COMPILE_IFELSE(
102         [AC_LANG_PROGRAM([[
103 #if HAVE_PTY_H
104 # include <pty.h>
105 #endif
106 #if HAVE_UTIL_H
107 # include <util.h>
108 #endif
109 #if HAVE_LIBUTIL_H
110 # include <libutil.h>
111 #endif
112           ]], [[
113             int openpty (int *, int *, char *, struct termios const *,
114                        struct winsize const *);
115           ]])
116         ],
117         [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])
118       ])
119     if test $gl_cv_func_openpty_const != yes; then
120       REPLACE_OPENPTY=1
121       AC_LIBOBJ([openpty])
122       AC_DEFINE([HAVE_OPENPTY], [1],
123         [Define to 1 if the system has the 'openpty' function.])
124     fi
125   else
126     dnl The system does not have openpty.
127     HAVE_OPENPTY=0
128     AC_LIBOBJ([openpty])
129     AC_CHECK_FUNCS([_getpty posix_openpt])
130   fi
131 ])
132
133 AC_DEFUN([gl_FUNC_LOGIN_TTY],
134 [
135   AC_REQUIRE([gl_PTY_LIB])
136
137   AC_CHECK_FUNCS_ONCE([login_tty])
138   if test $ac_cv_func_login_tty = no; then
139     AC_LIBOBJ([login_tty])
140   fi
141 ])