xref: /netbsd-src/external/gpl3/gdb/dist/gnulib/import/m4/glob.m4 (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
1# glob.m4 serial 26
2dnl Copyright (C) 2005-2007, 2009-2022 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl 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
11AC_DEFUN([gl_GLOB],
12[
13  AC_REQUIRE([gl_GLOB_H])
14
15  AC_CHECK_FUNCS_ONCE([glob glob_pattern_p])
16  if test $ac_cv_func_glob = no; then
17    HAVE_GLOB=0
18  else
19
20    AC_CACHE_CHECK([for GNU glob interface version 1 or 2],
21      [gl_cv_gnu_glob_interface_version_1_2],
22[     AC_COMPILE_IFELSE([AC_LANG_SOURCE(
23[[#include <gnu-versions.h>
24char a[_GNU_GLOB_INTERFACE_VERSION == 1 || _GNU_GLOB_INTERFACE_VERSION == 2 ? 1 : -1];]])],
25        [gl_cv_gnu_glob_interface_version_1_2=yes],
26        [gl_cv_gnu_glob_interface_version_1_2=no])])
27    if test "$gl_cv_gnu_glob_interface_version_1_2" = "no"; then
28      REPLACE_GLOB=1
29    fi
30
31    if test $REPLACE_GLOB = 0; then
32      AC_CACHE_CHECK([whether glob lists broken symlinks],
33                     [gl_cv_glob_lists_symlinks],
34        [if test $cross_compiling != yes; then
35           if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then
36             gl_cv_glob_lists_symlinks=maybe
37           else
38             # If we can't make a symlink, then we cannot test this issue.  Be
39             # pessimistic about this.
40             gl_cv_glob_lists_symlinks=no
41           fi
42           if test $gl_cv_glob_lists_symlinks = maybe; then
43             AC_RUN_IFELSE(
44               [AC_LANG_PROGRAM(
45                  [[#include <stddef.h>
46                    #include <glob.h>]],
47                  [[glob_t found;
48                    if (glob ("conf*-globtest", 0, NULL, &found) == GLOB_NOMATCH)
49                      return 1;
50                    globfree (&found);
51                  ]])],
52               [gl_cv_glob_lists_symlinks=yes],
53               [gl_cv_glob_lists_symlinks=no],
54               [dnl We don't get here.
55                :
56               ])
57           fi
58           rm -f conf$$-globtest
59         else
60           gl_cv_glob_lists_symlinks="$gl_cross_guess_normal"
61         fi
62        ])
63      case "$gl_cv_glob_lists_symlinks" in
64        *yes) ;;
65        *) REPLACE_GLOB=1 ;;
66      esac
67    fi
68
69    if test $REPLACE_GLOB = 0; then
70      AC_CACHE_CHECK([whether glob NOTDIR*/ omits symlink to nondir],
71                     [gl_cv_glob_omit_nondir_symlinks],
72        [if test $cross_compiling != yes; then
73           if ln -s conf$$-file conf$$-globtest 2>/dev/null && touch conf$$-file
74           then
75             gl_cv_glob_omit_nondir_symlinks=maybe
76           else
77             # If we can't make a symlink, then we cannot test this issue.  Be
78             # pessimistic about this.
79             gl_cv_glob_omit_nondir_symlinks=no
80           fi
81           if test $gl_cv_glob_omit_nondir_symlinks = maybe; then
82             AC_RUN_IFELSE(
83               [AC_LANG_PROGRAM(
84                  [[#include <stddef.h>
85                    #include <glob.h>]],
86                  [[glob_t found;
87                    if (glob ("conf*-globtest/", 0, NULL, &found) != GLOB_NOMATCH)
88                      return 1;
89                    globfree (&found);
90                  ]])],
91               [gl_cv_glob_omit_nondir_symlinks=yes],
92               [gl_cv_glob_omit_nondir_symlinks=no],
93               [dnl We don't get here.
94                :
95               ])
96           fi
97           rm -f conf$$-file conf$$-globtest
98         else
99           gl_cv_glob_omit_nondir_symlinks="$gl_cross_guess_normal"
100         fi
101        ])
102      case "$gl_cv_glob_omit_nondir_symlinks" in
103        *yes) ;;
104        *) REPLACE_GLOB=1 ;;
105      esac
106    fi
107
108  fi
109
110  if test $ac_cv_func_glob_pattern_p = no; then
111    HAVE_GLOB_PATTERN_P=0
112  else
113    if test $REPLACE_GLOB = 1; then
114      REPLACE_GLOB_PATTERN_P=1
115    fi
116  fi
117
118  if test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1; then
119    gl_REPLACE_GLOB_H
120  fi
121])
122
123# Prerequisites of lib/glob.c and lib/globfree.c.
124AC_DEFUN([gl_PREREQ_GLOB],
125[
126  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE])
127  AC_CHECK_HEADERS_ONCE([unistd.h])
128  AC_CHECK_FUNCS_ONCE([getlogin_r getpwnam_r])
129])
130