Commit | Line | Data |
---|---|---|
3d458a81 | 1 | # canonicalize.m4 serial 23 |
8912421c | 2 | |
f0007cad | 3 | dnl Copyright (C) 2003-2007, 2009-2012 Free Software Foundation, Inc. |
8912421c LC |
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 | [ | |
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 | |
19 | elif test "$gl_cv_func_realpath_works" != yes; then | |
20 | REPLACE_CANONICALIZE_FILE_NAME=1 | |
21 | fi | |
22 | ]) | |
23 | ||
24 | # Provides canonicalize_file_name and realpath. | |
25 | AC_DEFUN([gl_CANONICALIZE_LGPL], | |
26 | [ | |
3d458a81 | 27 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
8912421c LC |
28 | AC_REQUIRE([gl_CANONICALIZE_LGPL_SEPARATE]) |
29 | if test $ac_cv_func_canonicalize_file_name = no; then | |
30 | HAVE_CANONICALIZE_FILE_NAME=0 | |
8912421c LC |
31 | if test $ac_cv_func_realpath = no; then |
32 | HAVE_REALPATH=0 | |
33 | elif test "$gl_cv_func_realpath_works" != yes; then | |
34 | REPLACE_REALPATH=1 | |
35 | fi | |
36 | elif test "$gl_cv_func_realpath_works" != yes; then | |
8912421c | 37 | REPLACE_CANONICALIZE_FILE_NAME=1 |
3d458a81 | 38 | REPLACE_REALPATH=1 |
8912421c LC |
39 | fi |
40 | ]) | |
41 | ||
42 | # Like gl_CANONICALIZE_LGPL, except prepare for separate compilation | |
3d458a81 | 43 | # (no REPLACE_CANONICALIZE_FILE_NAME, no REPLACE_REALPATH, no AC_LIBOBJ). |
8912421c LC |
44 | AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE], |
45 | [ | |
46 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | |
47 | AC_CHECK_FUNCS_ONCE([canonicalize_file_name getcwd readlink]) | |
48 | AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) | |
49 | AC_REQUIRE([gl_FUNC_REALPATH_WORKS]) | |
50 | AC_CHECK_HEADERS_ONCE([sys/param.h]) | |
51 | ]) | |
52 | ||
53 | # Check whether realpath works. Assume that if a platform has both | |
54 | # realpath and canonicalize_file_name, but the former is broken, then | |
55 | # so is the latter. | |
56 | AC_DEFUN([gl_FUNC_REALPATH_WORKS], | |
57 | [ | |
58 | AC_CHECK_FUNCS_ONCE([realpath]) | |
59 | AC_CACHE_CHECK([whether realpath works], [gl_cv_func_realpath_works], [ | |
60 | touch conftest.a | |
3d458a81 | 61 | mkdir conftest.d |
8912421c LC |
62 | AC_RUN_IFELSE([ |
63 | AC_LANG_PROGRAM([[ | |
3d458a81 | 64 | ]GL_NOCRASH[ |
8912421c | 65 | #include <stdlib.h> |
3d458a81 | 66 | #include <string.h> |
8912421c | 67 | ]], [[ |
0f00f2c3 LC |
68 | int result = 0; |
69 | { | |
70 | char *name = realpath ("conftest.a", NULL); | |
71 | if (!(name && *name == '/')) | |
72 | result |= 1; | |
73 | } | |
74 | { | |
75 | char *name = realpath ("conftest.b/../conftest.a", NULL); | |
76 | if (name != NULL) | |
77 | result |= 2; | |
78 | } | |
79 | { | |
80 | char *name = realpath ("conftest.a/", NULL); | |
81 | if (name != NULL) | |
82 | result |= 4; | |
83 | } | |
3d458a81 AW |
84 | { |
85 | char *name1 = realpath (".", NULL); | |
86 | char *name2 = realpath ("conftest.d//./..", NULL); | |
87 | if (strcmp (name1, name2) != 0) | |
88 | result |= 8; | |
89 | } | |
0f00f2c3 | 90 | return result; |
8912421c LC |
91 | ]]) |
92 | ], [gl_cv_func_realpath_works=yes], [gl_cv_func_realpath_works=no], | |
93 | [gl_cv_func_realpath_works="guessing no"]) | |
3d458a81 | 94 | rm -rf conftest.a conftest.d |
8912421c LC |
95 | ]) |
96 | if test "$gl_cv_func_realpath_works" = yes; then | |
97 | AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath() | |
98 | can malloc memory, always gives an absolute path, and handles | |
99 | trailing slash correctly.]) | |
100 | fi | |
101 | ]) |