forkpty, openpty: prefer glibc's const-safe prototype
[gnulib.git] / m4 / pty.m4
1 # pty.m4 serial 2
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_FORKPTY],
24 [
25   AC_REQUIRE([gl_PTY_LIB])
26   AC_REQUIRE([gl_PTY])
27
28   AC_CHECK_DECLS([forkpty],,, [[
29 #if HAVE_PTY_H
30 # include <pty.h>
31 #endif
32 #if HAVE_UTIL_H
33 # include <util.h>
34 #endif
35 #if HAVE_LIBUTIL_H
36 # include <libutil.h>
37 #endif
38 ]])
39   if test $ac_cv_have_decl_forkpty = no; then
40     AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
41   fi
42
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       [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])])
62   if test $gl_cv_func_forkpty_const != yes; then
63     REPLACE_FORKPTY=1
64     AC_LIBOBJ([forkpty])
65   fi
66 ])
67
68 AC_DEFUN([gl_OPENPTY],
69 [
70   AC_REQUIRE([gl_PTY_LIB])
71   AC_REQUIRE([gl_PTY])
72
73   AC_CHECK_DECLS([openpty],,, [[
74 #if HAVE_PTY_H
75 # include <pty.h>
76 #endif
77 #if HAVE_UTIL_H
78 # include <util.h>
79 #endif
80 #if HAVE_LIBUTIL_H
81 # include <libutil.h>
82 #endif
83 ]])
84   if test $ac_cv_have_decl_openpty = no; then
85     AC_MSG_WARN([[Cannot find openpty, build will likely fail]])
86   fi
87
88   dnl Prefer glibc's const-safe prototype, if available.
89   AC_CACHE_CHECK([for const-safe openpty signature],
90     [gl_cv_func_openpty_const],
91     [AC_COMPILE_IFELSE(
92       [AC_LANG_PROGRAM([[
93 #if HAVE_PTY_H
94 # include <pty.h>
95 #endif
96 #if HAVE_UTIL_H
97 # include <util.h>
98 #endif
99 #if HAVE_LIBUTIL_H
100 # include <libutil.h>
101 #endif
102       ]], [[
103         int openpty (int *, int *, char *, struct termios const *,
104                      struct winsize const *);
105       ]])],
106       [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])])
107   if test $gl_cv_func_openpty_const != yes; then
108     REPLACE_OPENPTY=1
109     AC_LIBOBJ([openpty])
110   fi
111 ])