From 1f90ddd30bd3a27a085246dcfe39871eeb17cb63 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 29 Jun 2015 10:05:31 -0700 Subject: [PATCH] linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X It started like this when building coreutils' latest on OS X, invoking ./configure with a nonempty --cache=.cache: lib/linkat.c:46:42: error: operator '||' has no right operand lib/linkat.c: In function 'rpl_linkat': lib/linkat.c:330:27: error: #if with no expression Here's linkat.c's line 46: #if !HAVE_LINKAT || LINKAT_SYMLINK_NOTSUP Here's some context: $ grep linkat_nofoll .cache gl_cv_func_linkat_nofollow=${gl_cv_func_linkat_nofollow=no} $ grep LINKAT_SYM lib/config.h #define LINKAT_SYMLINK_NOTSUP The problem is that m4/linkat.m4's gl_FUNC_LINKAT uses AC_CACHE_CHECK to set LINKAT_SYMLINK_NOTSUP, but that violates a tenet of AC_CACHE_CHECK: it must have no side effect other than setting its cache variable. What happens is that when the cache is set, we'd skip the code in that AC_CACHE_CHECK call, and leave LINKAT_SYMLINK_NOTSUP defined to whatever value it happened to have in configure's environment. In my case, it was not defined, so this later code: AC_DEFINE_UNQUOTED([LINKAT_SYMLINK_NOTSUP], [$LINKAT_SYMLINK_NOTSUP], [Define to 1 if linkat can create hardlinks to symlinks]) would emit code with an empty RHS. * m4/linkat.m4 (gl_FUNC_LINKAT): Move the setting of $LINKAT_SYMLINK_NOTSUP out of the AC_CACHE_CHECK code block. --- ChangeLog | 39 +++++++++++++++++++++++++++++++++++++++ m4/linkat.m4 | 21 ++++++++++----------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55259229a7..465bf0ef50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,42 @@ +2015-06-29 Jim Meyering + + linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X + It started like this when building coreutils' latest on OS X, + invoking ./configure with a nonempty --cache=.cache: + + lib/linkat.c:46:42: error: operator '||' has no right operand + lib/linkat.c: In function 'rpl_linkat': + lib/linkat.c:330:27: error: #if with no expression + + Here's linkat.c's line 46: + + #if !HAVE_LINKAT || LINKAT_SYMLINK_NOTSUP + + Here's some context: + + $ grep linkat_nofoll .cache + gl_cv_func_linkat_nofollow=${gl_cv_func_linkat_nofollow=no} + $ grep LINKAT_SYM lib/config.h + #define LINKAT_SYMLINK_NOTSUP + + The problem is that m4/linkat.m4's gl_FUNC_LINKAT + uses AC_CACHE_CHECK to set LINKAT_SYMLINK_NOTSUP, + but that violates a tenet of AC_CACHE_CHECK: it must + have no side effect other than setting its cache variable. + + What happens is that when the cache is set, we'd skip the + code in that AC_CACHE_CHECK call, and leave LINKAT_SYMLINK_NOTSUP + defined to whatever value it happened to have in configure's + environment. In my case, it was not defined, so this later code: + + AC_DEFINE_UNQUOTED([LINKAT_SYMLINK_NOTSUP], [$LINKAT_SYMLINK_NOTSUP], + [Define to 1 if linkat can create hardlinks to symlinks]) + + would emit code with an empty RHS. + + * m4/linkat.m4 (gl_FUNC_LINKAT): Move the setting of + $LINKAT_SYMLINK_NOTSUP out of the AC_CACHE_CHECK code block. + 2015-06-28 Jim Meyering mountlist: avoid an unused-label warning on OS X diff --git a/m4/linkat.m4 b/m4/linkat.m4 index 03cf23a2e4..9ed082db97 100644 --- a/m4/linkat.m4 +++ b/m4/linkat.m4 @@ -1,4 +1,4 @@ -# serial 6 +# serial 7 # See if we need to provide linkat replacement. dnl Copyright (C) 2009-2015 Free Software Foundation, Inc. @@ -35,21 +35,20 @@ AC_DEFUN([gl_FUNC_LINKAT], [return linkat (AT_FDCWD, "conftest.l1", AT_FDCWD, "conftest.l2", 0); ])], - [gl_cv_func_linkat_nofollow=yes - LINKAT_SYMLINK_NOTSUP=0], - [gl_cv_func_linkat_nofollow=no - LINKAT_SYMLINK_NOTSUP=1], + [gl_cv_func_linkat_nofollow=yes], + [gl_cv_func_linkat_nofollow=no], [case "$host_os" in - darwin*) - gl_cv_func_linkat_nofollow="guessing no" - LINKAT_SYMLINK_NOTSUP=1 ;; - *) - gl_cv_func_linkat_nofollow="guessing yes" - LINKAT_SYMLINK_NOTSUP=0 ;; + darwin*) gl_cv_func_linkat_nofollow="guessing no" ;; + *) gl_cv_func_linkat_nofollow="guessing yes" ;; esac]) rm -rf conftest.l1 conftest.l2]) + case $gl_cv_func_linkat_nofollow in + *no) LINKAT_SYMLINK_NOTSUP=1 ;; + *yes) LINKAT_SYMLINK_NOTSUP=0 ;; + esac + AC_CACHE_CHECK([whether linkat handles trailing slash correctly], [gl_cv_func_linkat_slash], [rm -rf conftest.a conftest.b conftest.c conftest.d conftest.e conftest.s -- 2.39.5