canonicalize.m4 3.7 KB

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