Debian Codegraph @

m4/canonicalize.m4

raw
1 # canonicalize.m4 serial 38
2
3 dnl Copyright (C) 2003-2007, 2009-2023 Free Software Foundation, Inc.
4
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
8
9 # Provides canonicalize_file_name and canonicalize_filename_mode, but does
10 # not provide or fix realpath.
11 AC_DEFUN([gl_FUNC_CANONICALIZE_FILENAME_MODE],
12 [
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
15 AC_CHECK_FUNCS_ONCE([canonicalize_file_name])
16 gl_CHECK_FUNCS_ANDROID([faccessat], [[#include <unistd.h>]])
17 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
18 AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
19 if test $ac_cv_func_canonicalize_file_name = no; then
20 HAVE_CANONICALIZE_FILE_NAME=0
21 else
22 case "$gl_cv_func_realpath_works" in
23 *yes) ;;
24 *) REPLACE_CANONICALIZE_FILE_NAME=1 ;;
25 esac
26 fi
27 ])
28
29 # Provides canonicalize_file_name and realpath.
30 AC_DEFUN([gl_CANONICALIZE_LGPL],
31 [
32 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
33 AC_REQUIRE([gl_CANONICALIZE_LGPL_SEPARATE])
34 if test $ac_cv_func_canonicalize_file_name = no; then
35 HAVE_CANONICALIZE_FILE_NAME=0
36 if test $ac_cv_func_realpath = no; then
37 HAVE_REALPATH=0
38 else
39 case "$gl_cv_func_realpath_works" in
40 *yes) ;;
41 *) REPLACE_REALPATH=1 ;;
42 esac
43 fi
44 else
45 case "$gl_cv_func_realpath_works" in
46 *yes)
47 ;;
48 *)
49 REPLACE_CANONICALIZE_FILE_NAME=1
50 REPLACE_REALPATH=1
51 ;;
52 esac
53 fi
54 ])
55
56 # Like gl_CANONICALIZE_LGPL, except prepare for separate compilation
57 # (no REPLACE_CANONICALIZE_FILE_NAME, no REPLACE_REALPATH, no AC_LIBOBJ).
58 AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE],
59 [
60 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
61 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
62 AC_CHECK_FUNCS_ONCE([canonicalize_file_name])
63 gl_CHECK_FUNCS_ANDROID([faccessat], [[#include <unistd.h>]])
64
65 dnl On native Windows, we use _getcwd(), regardless whether getcwd() is
66 dnl available through the linker option '-loldnames'.
67 AC_REQUIRE([AC_CANONICAL_HOST])
68 case "$host_os" in
69 mingw*) ;;
70 *) AC_CHECK_FUNCS([getcwd]) ;;
71 esac
72
73 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
74 AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
75 AC_CHECK_HEADERS_ONCE([sys/param.h])
76 ])
77
78 # Check whether realpath works. Assume that if a platform has both
79 # realpath and canonicalize_file_name, but the former is broken, then
80 # so is the latter.
81 AC_DEFUN([gl_FUNC_REALPATH_WORKS],
82 [
83 AC_CHECK_FUNCS_ONCE([realpath lstat])
84 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
85 AC_CACHE_CHECK([whether realpath works], [gl_cv_func_realpath_works], [
86 rm -rf conftest.a conftest.d
87 touch conftest.a
88 # Assume that if we have lstat, we can also check symlinks.
89 if test $ac_cv_func_lstat = yes; then
90 ln -s conftest.a conftest.l
91 fi
92 mkdir conftest.d
93 AC_RUN_IFELSE([
94 AC_LANG_PROGRAM([[
95 ]GL_NOCRASH[
96 #include <errno.h>
97 #include <stdlib.h>
98 #include <string.h>
99 ]], [[
100 int result = 0;
101 /* This test fails on Solaris 10. */
102 {
103 char *name = realpath ("conftest.a", NULL);
104 if (!(name && *name == '/'))
105 result |= 1;
106 free (name);
107 }
108 /* This test fails on older versions of Cygwin. */
109 {
110 char *name = realpath ("conftest.b/../conftest.a", NULL);
111 if (name != NULL)
112 result |= 2;
113 free (name);
114 }
115 /* This test fails on Cygwin 2.9. */
116 #if HAVE_LSTAT
117 {
118 char *name = realpath ("conftest.l/../conftest.a", NULL);
119 if (name != NULL || errno != ENOTDIR)
120 result |= 4;
121 free (name);
122 }
123 #endif
124 /* This test fails on Mac OS X 10.13, OpenBSD 6.0. */
125 {
126 char *name = realpath ("conftest.a/", NULL);
127 if (name != NULL)
128 result |= 8;
129 free (name);
130 }
131 /* This test fails on AIX 7, Solaris 10. */
132 {
133 char *name1 = realpath (".", NULL);
134 char *name2 = realpath ("conftest.d//./..", NULL);
135 if (! name1 || ! name2 || strcmp (name1, name2))
136 result |= 16;
137 free (name1);
138 free (name2);
139 }
140 #ifdef __linux__
141 /* On Linux, // is the same as /. See also double-slash-root.m4.
142 realpath() should respect this.
143 This test fails on musl libc 1.2.2. */
144 {
145 char *name = realpath ("//", NULL);
146 if (! name || strcmp (name, "/"))
147 result |= 32;
148 free (name);
149 }
150 #endif
151 return result;
152 ]])
153 ],
154 [gl_cv_func_realpath_works=yes],
155 [case $? in
156 32) gl_cv_func_realpath_works=nearly ;;
157 *) gl_cv_func_realpath_works=no ;;
158 esac
159 ],
160 [case "$host_os" in
161 # Guess yes on glibc systems.
162 *-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
163 # Guess 'nearly' on musl systems.
164 *-musl*) gl_cv_func_realpath_works="guessing nearly" ;;
165 # Guess no on Cygwin.
166 cygwin*) gl_cv_func_realpath_works="guessing no" ;;
167 # Guess no on native Windows.
168 mingw*) gl_cv_func_realpath_works="guessing no" ;;
169 # If we don't know, obey --enable-cross-guesses.
170 *) gl_cv_func_realpath_works="$gl_cross_guess_normal" ;;
171 esac
172 ])
173 rm -rf conftest.a conftest.l conftest.d
174 ])
175 case "$gl_cv_func_realpath_works" in
176 *yes)
177 AC_DEFINE([FUNC_REALPATH_WORKS], [1],
178 [Define to 1 if realpath() can malloc memory, always gives an absolute path, and handles leading slashes and a trailing slash correctly.])
179 ;;
180 *nearly)
181 AC_DEFINE([FUNC_REALPATH_NEARLY_WORKS], [1],
182 [Define to 1 if realpath() can malloc memory, always gives an absolute path, and handles a trailing slash correctly.])
183 ;;
184 esac
185 ])