1 # canonicalize.m4 serial 29
3 dnl Copyright (C) 2003-2007, 2009-2018 Free Software Foundation, Inc.
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.
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],
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 AC_CHECK_FUNCS_ONCE([canonicalize_file_name])
15 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
16 AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
17 if test $ac_cv_func_canonicalize_file_name = no; then
18 HAVE_CANONICALIZE_FILE_NAME=0
20 case "$gl_cv_func_realpath_works" in
22 *) REPLACE_CANONICALIZE_FILE_NAME=1 ;;
27 # Provides canonicalize_file_name and realpath.
28 AC_DEFUN([gl_CANONICALIZE_LGPL],
30 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
31 AC_REQUIRE([gl_CANONICALIZE_LGPL_SEPARATE])
32 if test $ac_cv_func_canonicalize_file_name = no; then
33 HAVE_CANONICALIZE_FILE_NAME=0
34 if test $ac_cv_func_realpath = no; then
37 case "$gl_cv_func_realpath_works" in
39 *) REPLACE_REALPATH=1 ;;
43 case "$gl_cv_func_realpath_works" in
47 REPLACE_CANONICALIZE_FILE_NAME=1
54 # Like gl_CANONICALIZE_LGPL, except prepare for separate compilation
55 # (no REPLACE_CANONICALIZE_FILE_NAME, no REPLACE_REALPATH, no AC_LIBOBJ).
56 AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE],
58 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
59 AC_CHECK_FUNCS_ONCE([canonicalize_file_name getcwd readlink])
60 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
61 AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
62 AC_CHECK_HEADERS_ONCE([sys/param.h])
65 # Check whether realpath works. Assume that if a platform has both
66 # realpath and canonicalize_file_name, but the former is broken, then
68 AC_DEFUN([gl_FUNC_REALPATH_WORKS],
70 AC_CHECK_FUNCS_ONCE([realpath])
71 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
72 AC_CACHE_CHECK([whether realpath works], [gl_cv_func_realpath_works], [
83 char *name = realpath ("conftest.a", NULL);
84 if (!(name && *name == '/'))
89 char *name = realpath ("conftest.b/../conftest.a", NULL);
95 char *name = realpath ("conftest.a/", NULL);
101 char *name1 = realpath (".", NULL);
102 char *name2 = realpath ("conftest.d//./..", NULL);
103 if (! name1 || ! name2 || strcmp (name1, name2))
111 [gl_cv_func_realpath_works=yes],
112 [gl_cv_func_realpath_works=no],
114 # Guess yes on glibc systems.
115 *-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
116 # Guess no on native Windows.
117 mingw*) gl_cv_func_realpath_works="guessing no" ;;
118 # If we don't know, assume the worst.
119 *) gl_cv_func_realpath_works="guessing no" ;;
122 rm -rf conftest.a conftest.d
124 case "$gl_cv_func_realpath_works" in
126 AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath()
127 can malloc memory, always gives an absolute path, and handles
128 trailing slash correctly.])