libguile/Makefile.am (snarfcppopts): Remove CFLAGS
[bpt/guile.git] / m4 / canonicalize.m4
CommitLineData
7ae4e75a 1# canonicalize.m4 serial 26
8912421c 2
5e69ceb7 3dnl Copyright (C) 2003-2007, 2009-2014 Free Software Foundation, Inc.
8912421c
LC
4
5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it,
7dnl 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.
11AC_DEFUN([gl_FUNC_CANONICALIZE_FILENAME_MODE],
12[
8912421c
LC
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
015b7087
LC
19 else
20 case "$gl_cv_func_realpath_works" in
21 *yes) ;;
22 *) REPLACE_CANONICALIZE_FILE_NAME=1 ;;
23 esac
8912421c
LC
24 fi
25])
26
27# Provides canonicalize_file_name and realpath.
28AC_DEFUN([gl_CANONICALIZE_LGPL],
29[
3d458a81 30 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
8912421c
LC
31 AC_REQUIRE([gl_CANONICALIZE_LGPL_SEPARATE])
32 if test $ac_cv_func_canonicalize_file_name = no; then
33 HAVE_CANONICALIZE_FILE_NAME=0
8912421c
LC
34 if test $ac_cv_func_realpath = no; then
35 HAVE_REALPATH=0
015b7087
LC
36 else
37 case "$gl_cv_func_realpath_works" in
38 *yes) ;;
39 *) REPLACE_REALPATH=1 ;;
40 esac
8912421c 41 fi
015b7087
LC
42 else
43 case "$gl_cv_func_realpath_works" in
44 *yes)
45 ;;
46 *)
47 REPLACE_CANONICALIZE_FILE_NAME=1
48 REPLACE_REALPATH=1
49 ;;
50 esac
8912421c
LC
51 fi
52])
53
54# Like gl_CANONICALIZE_LGPL, except prepare for separate compilation
3d458a81 55# (no REPLACE_CANONICALIZE_FILE_NAME, no REPLACE_REALPATH, no AC_LIBOBJ).
8912421c
LC
56AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE],
57[
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])
63])
64
65# Check whether realpath works. Assume that if a platform has both
66# realpath and canonicalize_file_name, but the former is broken, then
67# so is the latter.
68AC_DEFUN([gl_FUNC_REALPATH_WORKS],
69[
70 AC_CHECK_FUNCS_ONCE([realpath])
005de2e8 71 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
8912421c
LC
72 AC_CACHE_CHECK([whether realpath works], [gl_cv_func_realpath_works], [
73 touch conftest.a
3d458a81 74 mkdir conftest.d
8912421c
LC
75 AC_RUN_IFELSE([
76 AC_LANG_PROGRAM([[
3d458a81 77 ]GL_NOCRASH[
8912421c 78 #include <stdlib.h>
3d458a81 79 #include <string.h>
8912421c 80 ]], [[
0f00f2c3
LC
81 int result = 0;
82 {
83 char *name = realpath ("conftest.a", NULL);
84 if (!(name && *name == '/'))
85 result |= 1;
86 }
87 {
88 char *name = realpath ("conftest.b/../conftest.a", NULL);
89 if (name != NULL)
90 result |= 2;
91 }
92 {
93 char *name = realpath ("conftest.a/", NULL);
94 if (name != NULL)
95 result |= 4;
96 }
3d458a81
AW
97 {
98 char *name1 = realpath (".", NULL);
99 char *name2 = realpath ("conftest.d//./..", NULL);
100 if (strcmp (name1, name2) != 0)
101 result |= 8;
102 }
0f00f2c3 103 return result;
8912421c 104 ]])
005de2e8
LC
105 ],
106 [gl_cv_func_realpath_works=yes],
107 [gl_cv_func_realpath_works=no],
108 [case "$host_os" in
7ae4e75a
LC
109 # Guess yes on glibc systems.
110 *-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
111 # If we don't know, assume the worst.
112 *) gl_cv_func_realpath_works="guessing no" ;;
005de2e8
LC
113 esac
114 ])
3d458a81 115 rm -rf conftest.a conftest.d
8912421c 116 ])
005de2e8
LC
117 case "$gl_cv_func_realpath_works" in
118 *yes)
119 AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath()
120 can malloc memory, always gives an absolute path, and handles
121 trailing slash correctly.])
122 ;;
123 esac
8912421c 124])