Update serial number.
[gnulib.git] / m4 / glob.m4
1 # glob.m4 serial 2
2 dnl Copyright (C) 2005 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 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_DEFINE([GLOB_PREFIX], [[rpl_]],
18     [Define to rpl_ if the glob replacement functions and variables
19      should be used.])
20   AC_SUBST([GLOB_H])
21 ])
22
23 AC_DEFUN([gl_GLOB],
24 [ GLOB_H=
25   AC_CHECK_HEADERS([glob.h], [], [GLOB_H=glob.h])
26
27   if test -z "$GLOB_H"; then
28     AC_CACHE_CHECK([for GNU glob interface version 1],
29       [gl_cv_gnu_glob_interface_version_1],
30 [     AC_COMPILE_IFELSE(
31 [[#include <gnu-versions.h>
32 char a[_GNU_GLOB_INTERFACE_VERSION == 1 ? 1 : -1];]],
33         [gl_cv_gnu_glob_interface_version_1=yes],
34         [gl_cv_gnu_glob_interface_version_1=no])])
35
36     if test "$gl_cv_gnu_glob_interface_version_1" = "no"; then
37       GLOB_H=glob.h
38     fi
39   fi
40
41   if test -z "$GLOB_H"; then
42     AC_CACHE_CHECK([whether glob lists broken symlinks],
43                    [gl_cv_glob_lists_symlinks],
44 [     if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then
45         gl_cv_glob_lists_symlinks=maybe
46       else
47         # If we can't make a symlink, then we cannot test this issue.  Be
48         # pessimistic about this.
49         gl_cv_glob_lists_symlinks=no
50       fi
51
52       if test $gl_cv_glob_lists_symlinks = maybe; then
53         AC_RUN_IFELSE(
54 AC_LANG_PROGRAM(
55 [[#include <stddef.h>
56 #include <glob.h>]],
57 [[glob_t found;
58 if (glob ("conf*-globtest", 0, NULL, &found) == GLOB_NOMATCH) return 1;]]),
59           [gl_cv_glob_lists_symlinks=yes],
60           [gl_cv_glob_lists_symlinks=no], [gl_cv_glob_lists_symlinks=no])
61       fi])
62
63     if test $gl_cv_glob_lists_symlinks = no; then
64       GLOB_H=glob.h
65     fi
66   fi
67
68   rm -f conf$$-globtest
69
70   if test -n "$GLOB_H"; then
71     gl_GLOB_SUBSTITUTE
72   fi
73 ])
74
75 # Prerequisites of lib/glob.*.
76 AC_DEFUN([gl_PREREQ_GLOB],
77 [ AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE])dnl
78   AC_REQUIRE([AC_HEADER_DIRENT])dnl
79   AC_CHECK_HEADERS_ONCE([sys/cdefs.h unistd.h])dnl
80   AC_CHECK_FUNCS_ONCE([getlogin_r getpwnam_r])dnl
81   AC_CHECK_HEADERS([sys/cdefs.h], [SYS_CDEFS_H=yes], [SYS_CDEFS_H=no])
82
83   dnl Note the reversal of the common HAVE_SYS_CDEFS_H idiom below.  In this
84   dnl way, #ifndef _SYS_CDEFS_H may be used to include <sys/cdefs.h> both when
85   dnl it has been checked for via the GNULIB configure test and found and when
86   dnl it has not been checked for, which we can presume means that the <glob.h>
87   dnl GNULIB shares with GLIBC is being included as a system header and not as
88   dnl part of GNULIB, in which case <sys/cdefs.h> may be assumed.
89   if test $SYS_CDEFS_H = no; then
90     AC_DEFINE(_SYS_CDEFS_H, 1,
91       [Define to `1' if <sys/cdefs.h> is *not* available on this system.])
92   fi
93   :])