forkpty, openpty: split functions into new modules
[gnulib.git] / m4 / pty_h.m4
1 # pty_h.m4 serial 3
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 AC_DEFUN_ONCE([gl_PTY],
11 [
12   AC_REQUIRE([gl_PTY_H_DEFAULTS])
13
14   # Make sure that pty.h provides forkpty, or setup the replacement.
15   AC_CHECK_HEADERS_ONCE([pty.h])
16   if test $ac_cv_header_pty_h != yes; then
17     HAVE_PTY_H=0
18     AC_CHECK_HEADERS([util.h libutil.h])
19     if test $ac_cv_header_util_h = yes; then
20       HAVE_UTIL_H=1
21     fi
22     if test $ac_cv_header_libutil_h = yes; then
23       HAVE_LIBUTIL_H=1
24     fi
25     dnl FIXME - move this into forkpty module, when replacement is provided
26     AC_CHECK_DECLS([forkpty],,, [[
27 #if HAVE_UTIL_H
28 # include <util.h>
29 #endif
30 #if HAVE_LIBUTIL_H
31 # include <libutil.h>
32 #endif
33 ]])
34     if test $ac_cv_have_decl_forkpty = no; then
35       AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
36     fi
37   else # Have <pty.h>, assume forkpty is declared there.
38     HAVE_PTY_H=1
39   fi
40   AC_SUBST([HAVE_PTY_H])
41   dnl <pty.h> is always overridden, because of GNULIB_POSIXCHECK.
42   gl_CHECK_NEXT_HEADERS([pty.h])
43
44   dnl Check for declarations of anything we want to poison if the
45   dnl corresponding gnulib module is not in use.
46   gl_WARN_ON_USE_PREPARE([[
47 #if HAVE_PTY_H
48 # include <pty.h>
49 #endif
50 #if HAVE_UTIL_H
51 # include <util.h>
52 #endif
53 #if HAVE_LIBUTIL_H
54 # include <libutil.h>
55 #endif
56     ]], [forkpty openpty])
57 ])
58
59 AC_DEFUN([gl_PTY_MODULE_INDICATOR],
60 [
61   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
62   AC_REQUIRE([gl_PTY_H_DEFAULTS])
63   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
64 ])
65
66 AC_DEFUN([gl_PTY_H_DEFAULTS],
67 [
68   GNULIB_FORKPTY=0;     AC_SUBST([GNULIB_FORKPTY])
69   GNULIB_OPENPTY=0;     AC_SUBST([GNULIB_OPENPTY])
70   dnl Assume proper GNU behavior unless another module says otherwise.
71   HAVE_UTIL_H=0;        AC_SUBST([HAVE_UTIL_H])
72   HAVE_LIBUTIL_H=0;     AC_SUBST([HAVE_LIBUTIL_H])
73 ])