On 10/18/2010 10:07 AM, Peter Rosin wrote:
So, your patch needs more work, either in autoconf.texi (documenting
that LN_S needs to be set in the environment rather than on the
configure command line) or we need to think or some other way to
fixup the _AS_LN_S_PREPARE result after command-line parsing, or
restructure the code otherwise.

The below one-liner makes the tests pass.  I don't know if we should
perhaps use test "${LN_S+set}" = set instead, and I don't know if it's
ok to clobber as_ln_s from "the outside" like this.  I also suppose
there's an area of the configure script that will run with unexpected
outcome of any AS_LN_S([foo], [bar]) macros (between the _AS_LN_S_PREPARE
expansion and AC_PROG_LN_S, at least as long as _AS_LN_S_PREPARE is
expanded first but that seems pretty hard to change).

Something like the attached...  still requires writing ChangeLogs.

Paolo
>From f03240084e8dfb4474f2325b694394a7b7f42280 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Thu, 21 Oct 2010 12:01:41 +0200
Subject: [PATCH] allow overriding of as_ln_s with LN_S.

---
 doc/autoconf.texi         |    3 +++
 lib/autoconf/functions.m4 |   25 ++++++++++---------------
 lib/autoconf/programs.m4  |    2 +-
 lib/m4sugar/m4sh.m4       |    2 +-
 tests/base.at             |   25 +++++++++++++++++++++++++
 tests/m4sh.at             |   26 ++++++++++++++++++++++++++
 6 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 0640320..6749ea0 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -4119,6 +4119,9 @@ Particular Programs
 @code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set
 @code{LN_S} to @samp{ln}, and otherwise set it to @samp{cp -p}.
 
+The result of this test can be overridden by setting the @code{LN_S}
+variable.
+
 If you make a link in a directory other than the current directory, its
 meaning depends on whether @samp{ln} or @samp{ln -s} is used.  To safely
 create links using @samp{$(LN_S)}, either find out which form is used
diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index f2048bf..bb8dcf0 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -856,21 +856,16 @@ AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
        [ac_cv_func_lstat_dereferences_slashed_symlink],
 [rm -f conftest.sym conftest.file
 echo >conftest.file
-if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
-  AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
-    [struct stat sbuf;
-     /* Linux will dereference the symlink and fail, as required by POSIX.
-       That is better in the sense that it means we will not
-       have to compile and use the lstat wrapper.  */
-     return lstat ("conftest.sym/", &sbuf) == 0;])],
-               [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
-               [ac_cv_func_lstat_dereferences_slashed_symlink=no],
-               [ac_cv_func_lstat_dereferences_slashed_symlink=no])
-else
-  # If the `ln -s' command failed, then we probably don't even
-  # have an lstat function.
-  ac_cv_func_lstat_dereferences_slashed_symlink=no
-fi
+AS_LN_S([conftest.file], [conftest.sym])
+AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+  [struct stat sbuf;
+   /* Linux will dereference the symlink and fail, as required by POSIX.
+      That is better in the sense that it means we will not
+      have to compile and use the lstat wrapper.  */
+   return lstat ("conftest.sym/", &sbuf) == 0;])],
+             [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
+             [ac_cv_func_lstat_dereferences_slashed_symlink=no],
+             [ac_cv_func_lstat_dereferences_slashed_symlink=no])
 rm -f conftest.sym conftest.file
 ])
 
diff --git a/lib/autoconf/programs.m4 b/lib/autoconf/programs.m4
index c90d9b2..dd8de61 100644
--- a/lib/autoconf/programs.m4
+++ b/lib/autoconf/programs.m4
@@ -799,7 +799,7 @@ AN_MAKEVAR([LN], [AC_PROG_LN_S])
 AN_PROGRAM([ln], [AC_PROG_LN_S])
 AC_DEFUN([AC_PROG_LN_S],
 [AC_MSG_CHECKING([whether ln -s works])
-AC_SUBST([LN_S], [$as_ln_s])dnl
+AC_SUBST([LN_S], [${LN_S-$as_ln_s}])dnl
 if test "$LN_S" = "ln -s"; then
   AC_MSG_RESULT([yes])
 else
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 13ad849..a5ec8ea 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -1217,7 +1217,7 @@ rmdir conf$$.dir 2>/dev/null
 # simulated with `ln' or `cp'?
 m4_defun_init([AS_LN_S],
 [AS_REQUIRE([_AS_LN_S_PREPARE])],
-[$as_ln_s $1 $2])
+[${LN_S-$as_ln_s} $1 $2])
 
 
 # _AS_MKDIR_P
diff --git a/tests/base.at b/tests/base.at
index cf12099..3e754d7 100644
--- a/tests/base.at
+++ b/tests/base.at
@@ -707,3 +707,28 @@ libdir=${exec_prefix}/lib
 ]])
 
 AT_CLEANUP
+
+
+## ------------- ##
+## AC_PROG_LN_S  ##
+## ------------- ##
+
+AT_SETUP([AC_PROG_LN_S])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_PROG_LN_S
+rm -f foo link
+echo foo > file
+$LN_S file link || AC_MSG_ERROR([$LN_S failed])
+grep foo link || AC_MSG_ERROR([link not created correctly])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK_CONFIGURE([LN_S='cp -p'])
+rm -f foo
+AT_CHECK([grep foo link], [], [ignore])
+AT_CHECK_CONFIGURE([LN_S=false], [1], [ignore], [ignore])
+
+AT_CLEANUP
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 08680c3..5be8d75 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -518,6 +518,32 @@ AT_CHECK([$CONFIG_SHELL ./script])
 AT_CLEANUP
 
 
+## --------- ##
+## AS_LN_S.  ##
+## --------- ##
+
+# Create symbolic links.
+AT_SETUP([AS@&t...@_ln_s])
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+rm -f foo link
+echo foo > file
+AS_LN_S([file], [link]) || AS_EXIT([1])
+grep foo link || AS_EXIT([1])
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([$CONFIG_SHELL ./script], [], [foo
+])
+AT_CHECK([env LN_S='cp -p' $CONFIG_SHELL ./script], [], [foo
+])
+rm -f foo
+AT_CHECK([grep foo link], [], [ignore])
+AT_CHECK([env LN_S='false' $CONFIG_SHELL ./script], [1])
+
+AT_CLEANUP
 
 
 ## -------------------- ##
-- 
1.7.2.3

Reply via email to