Avoid "guessing no" guesses when cross-compiling to glibc systems.
[gnulib.git] / m4 / remove.m4
1 # remove.m4 serial 4
2 dnl Copyright (C) 2009-2012 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 AC_DEFUN([gl_FUNC_REMOVE],
8 [
9   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
10   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_RMDIR])
12   AC_REQUIRE([gl_FUNC_UNLINK])
13   if { case "$gl_cv_func_rmdir_works" in
14          *yes) false;;
15          *) true;;
16        esac
17      } \
18      || { case "$gl_cv_func_unlink_works" in
19             *yes) false;;
20             *) true;;
21           esac
22         }; then
23     dnl If either underlying syscall is broken, then remove likely has
24     dnl the same bug; blindly use our replacement.
25     REPLACE_REMOVE=1
26   else
27     dnl C89 requires remove(), but only POSIX requires it to handle
28     dnl directories.  On mingw, directories fails with EPERM.
29     AC_CACHE_CHECK([whether remove handles directories],
30       [gl_cv_func_remove_dir_works],
31       [mkdir conftest.dir
32        AC_RUN_IFELSE(
33          [AC_LANG_PROGRAM(
34            [[#include <stdio.h>
35 ]], [[return remove ("conftest.dir");]])],
36          [gl_cv_func_remove_dir_works=yes], [gl_cv_func_remove_dir_works=no],
37          [case $host_os in
38             mingw*) gl_cv_func_remove_dir_works="guessing no";;
39             *) gl_cv_func_remove_dir_works="guessing yes";;
40           esac])
41        rm -rf conftest.dir])
42     case $gl_cv_func_remove_dir_works in
43       *no*) REPLACE_REMOVE=1;;
44     esac
45   fi
46 ])