link.m4 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # link.m4 serial 11
  2. dnl Copyright (C) 2009-2023 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. AC_DEFUN([gl_FUNC_LINK],
  7. [
  8. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  10. AC_CHECK_FUNCS_ONCE([link])
  11. if test $ac_cv_func_link = no; then
  12. HAVE_LINK=0
  13. else
  14. AC_CACHE_CHECK([whether link obeys POSIX],
  15. [gl_cv_func_link_works],
  16. [touch conftest.a
  17. # Assume that if we have lstat, we can also check symlinks.
  18. if test $ac_cv_func_lstat = yes; then
  19. ln -s conftest.a conftest.lnk
  20. fi
  21. AC_RUN_IFELSE(
  22. [AC_LANG_PROGRAM(
  23. [[#include <unistd.h>
  24. #include <stdio.h>
  25. ]],
  26. [[int result = 0;
  27. if (!link ("conftest.a", "conftest.b/"))
  28. result |= 1;
  29. #if HAVE_LSTAT
  30. if (!link ("conftest.lnk/", "conftest.b"))
  31. result |= 2;
  32. if (rename ("conftest.a", "conftest.b"))
  33. result |= 4;
  34. if (!link ("conftest.b", "conftest.lnk"))
  35. result |= 8;
  36. #endif
  37. return result;
  38. ]])],
  39. [gl_cv_func_link_works=yes], [gl_cv_func_link_works=no],
  40. [case "$host_os" in
  41. # Guess yes on Linux systems.
  42. linux-* | linux) gl_cv_func_link_works="guessing yes" ;;
  43. # Guess yes on glibc systems.
  44. *-gnu* | gnu*) gl_cv_func_link_works="guessing yes" ;;
  45. # If we don't know, obey --enable-cross-guesses.
  46. *) gl_cv_func_link_works="$gl_cross_guess_normal" ;;
  47. esac
  48. ])
  49. rm -f conftest.a conftest.b conftest.lnk])
  50. case "$gl_cv_func_link_works" in
  51. *yes) ;;
  52. *)
  53. REPLACE_LINK=1
  54. ;;
  55. esac
  56. fi
  57. ])