Use spaces for indentation, not tabs.
[gnulib.git] / m4 / glob.m4
1 # glob.m4 serial 10
2 dnl Copyright (C) 2005-2007 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 # The glob module assumes you want GNU glob, with glob_pattern_p etc,
8 # rather than vanilla POSIX glob.  This means your code should
9 # always include <glob.h> for the glob prototypes.
10
11 AC_DEFUN([gl_GLOB_SUBSTITUTE],
12 [
13   gl_PREREQ_GLOB
14
15   GLOB_H=glob.h
16   AC_LIBOBJ([glob])
17   AC_SUBST([GLOB_H])
18 ])
19
20 AC_DEFUN([gl_GLOB],
21 [ GLOB_H=
22   AC_CHECK_HEADERS([glob.h], [], [GLOB_H=glob.h])
23
24   if test -z "$GLOB_H"; then
25     AC_CACHE_CHECK([for GNU glob interface version 1],
26       [gl_cv_gnu_glob_interface_version_1],
27 [     AC_COMPILE_IFELSE(
28 [[#include <gnu-versions.h>
29 char a[_GNU_GLOB_INTERFACE_VERSION == 1 ? 1 : -1];]],
30         [gl_cv_gnu_glob_interface_version_1=yes],
31         [gl_cv_gnu_glob_interface_version_1=no])])
32
33     if test "$gl_cv_gnu_glob_interface_version_1" = "no"; then
34       GLOB_H=glob.h
35     fi
36   fi
37
38   if test -z "$GLOB_H"; then
39     AC_CACHE_CHECK([whether glob lists broken symlinks],
40                    [gl_cv_glob_lists_symlinks],
41 [     if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then
42         gl_cv_glob_lists_symlinks=maybe
43       else
44         # If we can't make a symlink, then we cannot test this issue.  Be
45         # pessimistic about this.
46         gl_cv_glob_lists_symlinks=no
47       fi
48
49       if test $gl_cv_glob_lists_symlinks = maybe; then
50         AC_RUN_IFELSE(
51 AC_LANG_PROGRAM(
52 [[#include <stddef.h>
53 #include <glob.h>]],
54 [[glob_t found;
55 if (glob ("conf*-globtest", 0, NULL, &found) == GLOB_NOMATCH) return 1;]]),
56           [gl_cv_glob_lists_symlinks=yes],
57           [gl_cv_glob_lists_symlinks=no], [gl_cv_glob_lists_symlinks=no])
58       fi])
59
60     if test $gl_cv_glob_lists_symlinks = no; then
61       GLOB_H=glob.h
62     fi
63   fi
64
65   rm -f conf$$-globtest
66
67   if test -n "$GLOB_H"; then
68     gl_GLOB_SUBSTITUTE
69   fi
70 ])
71
72 # Prerequisites of lib/glob.*.
73 AC_DEFUN([gl_PREREQ_GLOB],
74 [
75   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE])dnl
76   AC_REQUIRE([AC_C_RESTRICT])dnl
77   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])dnl
78   AC_CHECK_HEADERS_ONCE([sys/cdefs.h unistd.h])dnl
79   if test $ac_cv_header_sys_cdefs_h = yes; then
80     HAVE_SYS_CDEFS_H=1
81   else
82     HAVE_SYS_CDEFS_H=0
83   fi
84   AC_SUBST([HAVE_SYS_CDEFS_H])
85   AC_CHECK_FUNCS_ONCE([fstatat getlogin_r getpwnam_r])dnl
86 ])