parse-datetime: Make the build rule work with parallel 'make'.
[gnulib.git] / m4 / popen.m4
blob8d0793ab7caa35a135a6604abd74005a1da2941d
1 # popen.m4 serial 6
2 dnl Copyright (C) 2009-2020 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.
7 AC_DEFUN([gl_FUNC_POPEN],
9   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11   AC_CHECK_FUNCS_ONCE([popen])
12   if test $ac_cv_func_popen = no; then
13     HAVE_POPEN=0
14   else
15     AC_CACHE_CHECK([whether popen works with closed stdin],
16       [gl_cv_func_popen_works],
17       [
18         AC_RUN_IFELSE(
19           [AC_LANG_PROGRAM(
20              [[#include <stdio.h>]],
21              [[int result = 0;
22                FILE *child;
23                fclose (stdin);
24                fclose (stdout);
25                child = popen ("echo a", "r");
26                if (fgetc (child) != 'a')
27                  result |= 1;
28                if (pclose (child) != 0)
29                  result |= 2;
30                return result;
31              ]])],
32           [gl_cv_func_popen_works=yes],
33           [gl_cv_func_popen_works=no],
34           [case "$host_os" in
35                       # For now, only cygwin 1.5 or older is known to be broken.
36              cygwin*) gl_cv_func_popen_works="guessing no" ;;
37                       # Guess yes on native Windows.
38              mingw*)  gl_cv_func_popen_works="guessing yes" ;;
39              *)       gl_cv_func_popen_works="guessing yes" ;;
40            esac
41           ])
42       ])
43     case "$gl_cv_func_popen_works" in
44       *yes) ;;
45       *) REPLACE_POPEN=1 ;;
46     esac
47   fi
50 # Prerequisites of lib/popen.c.
51 AC_DEFUN([gl_PREREQ_POPEN],
53   :