summaryrefslogtreecommitdiffstats
path: root/m4/spawn_h.m4
blob: 1b28d8036b2abbb3a108a5b84cebfe304a3f11db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# spawn_h.m4 serial 21
dnl Copyright (C) 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl Written by Bruno Haible.

AC_DEFUN_ONCE([gl_SPAWN_H],
[
  dnl Ensure to expand the default settings once only, before all statements
  dnl that occur in other macros.
  AC_REQUIRE([gl_SPAWN_H_DEFAULTS])

  dnl <spawn.h> is always overridden, because of GNULIB_POSIXCHECK.
  gl_CHECK_NEXT_HEADERS([spawn.h])

  if test $ac_cv_header_spawn_h = yes; then
    HAVE_SPAWN_H=1
    AC_CHECK_TYPES([posix_spawnattr_t], [], [HAVE_POSIX_SPAWNATTR_T=0], [[
#include <spawn.h>
      ]])
    AC_CHECK_TYPES([posix_spawn_file_actions_t], [],
      [HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0], [[
#include <spawn.h>
      ]])
  else
    HAVE_SPAWN_H=0
    HAVE_POSIX_SPAWNATTR_T=0
    HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0
  fi
  AC_SUBST([HAVE_SPAWN_H])

  dnl Ensure the type pid_t gets defined.
  AC_REQUIRE([AC_TYPE_PID_T])

  dnl Ensure the type mode_t gets defined.
  AC_REQUIRE([AC_TYPE_MODE_T])

  AC_REQUIRE([gl_HAVE_POSIX_SPAWN])

  AC_REQUIRE([AC_C_RESTRICT])

  dnl Check for declarations of anything we want to poison if the
  dnl corresponding gnulib module is not in use.
  gl_WARN_ON_USE_PREPARE([[#include <spawn.h>
    ]], [posix_spawn posix_spawnp posix_spawnattr_init posix_spawnattr_destroy
    posix_spawnattr_getsigdefault posix_spawnattr_setsigdefault
    posix_spawnattr_getsigmask posix_spawnattr_setsigmask
    posix_spawnattr_getflags posix_spawnattr_setflags
    posix_spawnattr_getpgroup posix_spawnattr_setpgroup
    posix_spawnattr_getschedpolicy posix_spawnattr_setschedpolicy
    posix_spawnattr_getschedparam posix_spawnattr_setschedparam
    posix_spawn_file_actions_init posix_spawn_file_actions_destroy
    posix_spawn_file_actions_addopen posix_spawn_file_actions_addclose
    posix_spawn_file_actions_adddup2 posix_spawn_file_actions_addchdir
    posix_spawn_file_actions_addfchdir])
])

dnl Checks whether the system has the functions posix_spawn.
dnl Sets ac_cv_func_posix_spawn and HAVE_POSIX_SPAWN.
AC_DEFUN([gl_HAVE_POSIX_SPAWN],
[
  dnl Ensure to expand the default settings once only, before all statements
  dnl that occur in other macros.
  AC_REQUIRE([gl_SPAWN_H_DEFAULTS])

  LIB_POSIX_SPAWN=
  AC_SUBST([LIB_POSIX_SPAWN])
  gl_saved_libs=$LIBS
    AC_SEARCH_LIBS([posix_spawn], [rt],
                   [test "$ac_cv_search_posix_spawn" = "none required" ||
                    LIB_POSIX_SPAWN=$ac_cv_search_posix_spawn])
    AC_CHECK_FUNCS([posix_spawn])
  LIBS=$gl_saved_libs

  if test $ac_cv_func_posix_spawn != yes; then
    HAVE_POSIX_SPAWN=0
  fi
])

# gl_SPAWN_MODULE_INDICATOR([modulename])
# sets the shell variable that indicates the presence of the given module
# to a C preprocessor expression that will evaluate to 1.
# This macro invocation must not occur in macros that are AC_REQUIREd.
AC_DEFUN([gl_SPAWN_MODULE_INDICATOR],
[
  dnl Ensure to expand the default settings once only.
  gl_SPAWN_H_REQUIRE_DEFAULTS
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  dnl Define it also as a C macro, for the benefit of the unit tests.
  gl_MODULE_INDICATOR_FOR_TESTS([$1])
])

# Initializes the default values for AC_SUBSTed shell variables.
# This macro must not be AC_REQUIREd.  It must only be invoked, and only
# outside of macros or in macros that are not AC_REQUIREd.
AC_DEFUN([gl_SPAWN_H_REQUIRE_DEFAULTS],
[
  m4_defun(GL_MODULE_INDICATOR_PREFIX[_SPAWN_H_MODULE_INDICATOR_DEFAULTS], [
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNP])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_INIT])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETFLAGS])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETFLAGS])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETPGROUP])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETPGROUP])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSIGMASK])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSIGMASK])
    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_DESTROY])
  ])
  m4_require(GL_MODULE_INDICATOR_PREFIX[_SPAWN_H_MODULE_INDICATOR_DEFAULTS])
  AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
])

AC_DEFUN([gl_SPAWN_H_DEFAULTS],
[
  dnl Assume proper GNU behavior unless another module says otherwise.
  HAVE_POSIX_SPAWN=1;        AC_SUBST([HAVE_POSIX_SPAWN])
  HAVE_POSIX_SPAWNATTR_T=1;  AC_SUBST([HAVE_POSIX_SPAWNATTR_T])
  HAVE_POSIX_SPAWN_FILE_ACTIONS_T=1;
                             AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_T])
  HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1;
                             AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
  HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=1;
                             AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR])
  REPLACE_POSIX_SPAWN=0;     AC_SUBST([REPLACE_POSIX_SPAWN])
  REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0;
                             AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
  REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0;
                             AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE])
  REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0;
                             AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2])
  REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=0;
                             AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR])
  REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0;
                             AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN])
])