pty: improve replacement header
[gnulib.git] / m4 / pty_h.m4
1 # pty_h.m4 serial 2
2 dnl Copyright (C) 2009, 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
8 # ------
9 # Make sure that pty.h provides forkpty, or sets up a replacement header.
10 # Also define automake variable PTY_LIB to the library needed (if any).
11 AC_DEFUN_ONCE([gl_PTY],
12 [
13   AC_REQUIRE([gl_PTY_H_DEFAULTS])
14
15   PTY_LIB=''
16   # First make sure that pty.h provides forkpty, or setup the replacement.
17   AC_CHECK_HEADERS_ONCE([pty.h])
18   if test $ac_cv_header_pty_h != yes; then
19     HAVE_PTY_H=0
20     AC_CHECK_HEADERS([util.h libutil.h])
21     if test $ac_cv_header_util_h = yes; then
22       HAVE_UTIL_H=1
23     fi
24     if test $ac_cv_header_libutil_h = yes; then
25       HAVE_LIBUTIL_H=1
26     fi
27     AC_CHECK_DECLS([forkpty],,, [[
28 #if HAVE_UTIL_H
29 # include <util.h>
30 #endif
31 #if HAVE_LIBUTIL_H
32 # include <libutil.h>
33 #endif
34 ]])
35     if test $ac_cv_have_decl_forkpty = no; then
36       AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
37     fi
38   else # Have <pty.h>, assume forkpty is declared there.
39     HAVE_PTY_H=1
40   fi
41   AC_SUBST([HAVE_PTY_H])
42   dnl <pty.h> is always overridden, because of GNULIB_POSIXCHECK.
43   gl_CHECK_NEXT_HEADERS([pty.h])
44
45   # Second check for the library required for forkpty.
46   save_LIBS="$LIBS"
47   AC_SEARCH_LIBS([forkpty], [util],
48     [if test "$ac_cv_search_forkpty" != "none required"; then
49        PTY_LIB="$ac_cv_search_forkpty"
50      fi])
51   LIBS="$save_LIBS"
52   AC_SUBST([PTY_LIB])
53
54   dnl Check for declarations of anything we want to poison if the
55   dnl corresponding gnulib module is not in use.
56   gl_WARN_ON_USE_PREPARE([[
57 #if HAVE_PTY_H
58 # include <pty.h>
59 #endif
60 #if HAVE_UTIL_H
61 # include <util.h>
62 #endif
63 #if HAVE_LIBUTIL_H
64 # include <libutil.h>
65 #endif
66     ]], [forkpty openpty])
67 ])
68
69 AC_DEFUN([gl_PTY_MODULE_INDICATOR],
70 [
71   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
72   AC_REQUIRE([gl_PTY_H_DEFAULTS])
73   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
74 ])
75
76 AC_DEFUN([gl_PTY_H_DEFAULTS],
77 [
78   dnl Assume proper GNU behavior unless another module says otherwise.
79   HAVE_UTIL_H=0;        AC_SUBST([HAVE_UTIL_H])
80   HAVE_LIBUTIL_H=0;     AC_SUBST([HAVE_LIBUTIL_H])
81 ])