canonicalize.m4 3.2 KB

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