canonicalize.m4 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # canonicalize.m4 serial 26
  2. dnl Copyright (C) 2003-2007, 2009-2014 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. }
  81. {
  82. char *name = realpath ("conftest.b/../conftest.a", NULL);
  83. if (name != NULL)
  84. result |= 2;
  85. }
  86. {
  87. char *name = realpath ("conftest.a/", NULL);
  88. if (name != NULL)
  89. result |= 4;
  90. }
  91. {
  92. char *name1 = realpath (".", NULL);
  93. char *name2 = realpath ("conftest.d//./..", NULL);
  94. if (strcmp (name1, name2) != 0)
  95. result |= 8;
  96. }
  97. return result;
  98. ]])
  99. ],
  100. [gl_cv_func_realpath_works=yes],
  101. [gl_cv_func_realpath_works=no],
  102. [case "$host_os" in
  103. # Guess yes on glibc systems.
  104. *-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
  105. # If we don't know, assume the worst.
  106. *) gl_cv_func_realpath_works="guessing no" ;;
  107. esac
  108. ])
  109. rm -rf conftest.a conftest.d
  110. ])
  111. case "$gl_cv_func_realpath_works" in
  112. *yes)
  113. AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath()
  114. can malloc memory, always gives an absolute path, and handles
  115. trailing slash correctly.])
  116. ;;
  117. esac
  118. ])