pty: Make forkpty check work.
[gnulib.git] / m4 / pty.m4
1 # pty.m4 serial 1
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([gl_PTY],
12 [
13   PTY_H=''
14   PTY_LIB=''
15   # First make sure that pty.h provides forkpty, or setup the replacement.
16   AC_CHECK_HEADERS_ONCE([pty.h])
17   if test $ac_cv_header_pty_h != yes; then
18     AC_CHECK_DECL([forkpty],,, [[#include <util.h>]])
19     if test $ac_cv_have_decl_forkpty = no; then
20       unset ac_cv_have_decl_forkpty
21       AC_CHECK_DECL([forkpty],,, [[#include <libutil.h>]])
22       if test $ac_cv_have_decl_forkpty = no; then
23         AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
24       else
25         PTY_H='pty.h'
26         PTY_HEADER='libutil.h'
27       fi
28     else
29       PTY_H='pty.h'
30       PTY_HEADER='util.h'
31     fi
32   fi
33   # Second check for the library required for forkpty.
34   save_LIBS="$LIBS"
35   AC_SEARCH_LIBS([forkpty], [util],
36     [if test "$ac_cv_search_forkpty" != "none required"; then
37        PTY_LIB="$ac_cv_search_forkpty"
38      fi])
39   LIBS="$save_LIBS"
40   AC_SUBST([PTY_H])
41   AC_SUBST([PTY_LIB])
42   AC_SUBST([PTY_HEADER])
43 ])