spawn_h.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # spawn_h.m4 serial 23
  2. dnl Copyright (C) 2008-2023 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. dnl Written by Bruno Haible.
  7. AC_DEFUN_ONCE([gl_SPAWN_H],
  8. [
  9. dnl Ensure to expand the default settings once only, before all statements
  10. dnl that occur in other macros.
  11. AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
  12. dnl <spawn.h> is always overridden, because of GNULIB_POSIXCHECK.
  13. gl_CHECK_NEXT_HEADERS([spawn.h])
  14. if test $ac_cv_header_spawn_h = yes; then
  15. HAVE_SPAWN_H=1
  16. AC_CHECK_TYPES([posix_spawnattr_t], [], [HAVE_POSIX_SPAWNATTR_T=0], [[
  17. #include <spawn.h>
  18. ]])
  19. AC_CHECK_TYPES([posix_spawn_file_actions_t], [],
  20. [HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0], [[
  21. #include <spawn.h>
  22. ]])
  23. else
  24. HAVE_SPAWN_H=0
  25. HAVE_POSIX_SPAWNATTR_T=0
  26. HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0
  27. fi
  28. AC_SUBST([HAVE_SPAWN_H])
  29. dnl Ensure the type pid_t gets defined.
  30. AC_REQUIRE([AC_TYPE_PID_T])
  31. dnl Ensure the type mode_t gets defined.
  32. AC_REQUIRE([AC_TYPE_MODE_T])
  33. AC_REQUIRE([gl_HAVE_POSIX_SPAWN])
  34. AC_REQUIRE([AC_C_RESTRICT])
  35. dnl Check for declarations of anything we want to poison if the
  36. dnl corresponding gnulib module is not in use.
  37. gl_WARN_ON_USE_PREPARE([[#include <spawn.h>
  38. ]], [posix_spawn posix_spawnp posix_spawnattr_init posix_spawnattr_destroy
  39. posix_spawnattr_getsigdefault posix_spawnattr_setsigdefault
  40. posix_spawnattr_getsigmask posix_spawnattr_setsigmask
  41. posix_spawnattr_getflags posix_spawnattr_setflags
  42. posix_spawnattr_getpgroup posix_spawnattr_setpgroup
  43. posix_spawnattr_getschedpolicy posix_spawnattr_setschedpolicy
  44. posix_spawnattr_getschedparam posix_spawnattr_setschedparam
  45. posix_spawn_file_actions_init posix_spawn_file_actions_destroy
  46. posix_spawn_file_actions_addopen posix_spawn_file_actions_addclose
  47. posix_spawn_file_actions_adddup2 posix_spawn_file_actions_addchdir
  48. posix_spawn_file_actions_addfchdir])
  49. ])
  50. dnl Checks whether the system has the functions posix_spawn.
  51. dnl Sets ac_cv_func_posix_spawn and HAVE_POSIX_SPAWN.
  52. AC_DEFUN([gl_HAVE_POSIX_SPAWN],
  53. [
  54. dnl Ensure to expand the default settings once only, before all statements
  55. dnl that occur in other macros.
  56. AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
  57. POSIX_SPAWN_LIB=
  58. AC_SUBST([POSIX_SPAWN_LIB])
  59. gl_saved_libs=$LIBS
  60. AC_SEARCH_LIBS([posix_spawn], [rt],
  61. [test "$ac_cv_search_posix_spawn" = "none required" ||
  62. POSIX_SPAWN_LIB=$ac_cv_search_posix_spawn])
  63. gl_CHECK_FUNCS_ANDROID([posix_spawn], [[#include <spawn.h>]])
  64. LIBS=$gl_saved_libs
  65. dnl For backward compatibility.
  66. LIB_POSIX_SPAWN="$POSIX_SPAWN_LIB"
  67. AC_SUBST([LIB_POSIX_SPAWN])
  68. if test $ac_cv_func_posix_spawn != yes; then
  69. HAVE_POSIX_SPAWN=0
  70. fi
  71. ])
  72. # gl_SPAWN_MODULE_INDICATOR([modulename])
  73. # sets the shell variable that indicates the presence of the given module
  74. # to a C preprocessor expression that will evaluate to 1.
  75. # This macro invocation must not occur in macros that are AC_REQUIREd.
  76. AC_DEFUN([gl_SPAWN_MODULE_INDICATOR],
  77. [
  78. dnl Ensure to expand the default settings once only.
  79. gl_SPAWN_H_REQUIRE_DEFAULTS
  80. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  81. dnl Define it also as a C macro, for the benefit of the unit tests.
  82. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  83. ])
  84. # Initializes the default values for AC_SUBSTed shell variables.
  85. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  86. # outside of macros or in macros that are not AC_REQUIREd.
  87. AC_DEFUN([gl_SPAWN_H_REQUIRE_DEFAULTS],
  88. [
  89. m4_defun(GL_MODULE_INDICATOR_PREFIX[_SPAWN_H_MODULE_INDICATOR_DEFAULTS], [
  90. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN])
  91. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNP])
  92. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT])
  93. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
  94. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE])
  95. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2])
  96. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR])
  97. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN])
  98. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY])
  99. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_INIT])
  100. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETFLAGS])
  101. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETFLAGS])
  102. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETPGROUP])
  103. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETPGROUP])
  104. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM])
  105. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM])
  106. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY])
  107. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY])
  108. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT])
  109. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT])
  110. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_GETSIGMASK])
  111. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_SETSIGMASK])
  112. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_SPAWNATTR_DESTROY])
  113. ])
  114. m4_require(GL_MODULE_INDICATOR_PREFIX[_SPAWN_H_MODULE_INDICATOR_DEFAULTS])
  115. AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
  116. ])
  117. AC_DEFUN([gl_SPAWN_H_DEFAULTS],
  118. [
  119. dnl Assume proper GNU behavior unless another module says otherwise.
  120. HAVE_POSIX_SPAWN=1; AC_SUBST([HAVE_POSIX_SPAWN])
  121. HAVE_POSIX_SPAWNATTR_T=1; AC_SUBST([HAVE_POSIX_SPAWNATTR_T])
  122. HAVE_POSIX_SPAWN_FILE_ACTIONS_T=1;
  123. AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_T])
  124. HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1;
  125. AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
  126. HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=1;
  127. AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR])
  128. REPLACE_POSIX_SPAWN=0; AC_SUBST([REPLACE_POSIX_SPAWN])
  129. REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0;
  130. AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
  131. REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0;
  132. AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE])
  133. REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0;
  134. AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2])
  135. REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=0;
  136. AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR])
  137. REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0;
  138. AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN])
  139. ])