| 1 |
# link.m4 |
| 2 |
# serial 12 |
| 3 |
dnl Copyright (C) 2009-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_LINK], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 13 |
AC_CHECK_FUNCS_ONCE([link]) |
| 14 |
if test $ac_cv_func_link = no; then |
| 15 |
HAVE_LINK=0 |
| 16 |
else |
| 17 |
AC_CACHE_CHECK([whether link obeys POSIX], |
| 18 |
[gl_cv_func_link_works], |
| 19 |
[touch conftest.a |
| 20 |
# Assume that if we have lstat, we can also check symlinks. |
| 21 |
if test $ac_cv_func_lstat = yes; then |
| 22 |
ln -s conftest.a conftest.lnk |
| 23 |
fi |
| 24 |
AC_RUN_IFELSE( |
| 25 |
[AC_LANG_PROGRAM( |
| 26 |
[[#include <unistd.h> |
| 27 |
#include <stdio.h> |
| 28 |
]], |
| 29 |
[[int result = 0; |
| 30 |
if (!link ("conftest.a", "conftest.b/")) |
| 31 |
result |= 1; |
| 32 |
#if HAVE_LSTAT |
| 33 |
if (!link ("conftest.lnk/", "conftest.b")) |
| 34 |
result |= 2; |
| 35 |
if (rename ("conftest.a", "conftest.b")) |
| 36 |
result |= 4; |
| 37 |
if (!link ("conftest.b", "conftest.lnk")) |
| 38 |
result |= 8; |
| 39 |
#endif |
| 40 |
return result; |
| 41 |
]])], |
| 42 |
[gl_cv_func_link_works=yes], [gl_cv_func_link_works=no], |
| 43 |
[case "$host_os" in |
| 44 |
# Guess yes on Linux systems. |
| 45 |
linux-* | linux) gl_cv_func_link_works="guessing yes" ;; |
| 46 |
# Guess yes on systems that emulate the Linux system calls. |
| 47 |
midipix*) gl_cv_func_link_works="guessing yes" ;; |
| 48 |
# Guess yes on glibc systems. |
| 49 |
*-gnu* | gnu*) gl_cv_func_link_works="guessing yes" ;; |
| 50 |
# If we don't know, obey --enable-cross-guesses. |
| 51 |
*) gl_cv_func_link_works="$gl_cross_guess_normal" ;; |
| 52 |
esac |
| 53 |
]) |
| 54 |
rm -f conftest.a conftest.b conftest.lnk]) |
| 55 |
case "$gl_cv_func_link_works" in |
| 56 |
*yes) ;; |
| 57 |
*) |
| 58 |
REPLACE_LINK=1 |
| 59 |
;; |
| 60 |
esac |
| 61 |
fi |
| 62 |
]) |