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