Hi,

While testing a configure script built with Autoconf git HEAD, I saw that
on AIX the './configure' output ends with

  sort: warning: missing NEWLINE added at EOF

whereas on Solaris 10 it ends with

  sort: missing NEWLINE added at end of input file STDIN

The part of the configure script that this 'sort' diagnostic comes from is

## Output variables. ##
## ----------------- ##
...
    echo
    for ac_var in $ac_subst_vars
    do
      eval ac_val=\$$ac_var
      case $ac_val in
      *\'\''*) ac_val=`printf '%s\n' "$ac_val" | sed 
"s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      esac
      printf '%s\n' "$ac_var='\''$ac_val'\''"
    done | sort           <== HERE
    echo

Here the output of the 'for' loop looks like this:
am__EXEEXT_FALSE=''nam__EXEEXT_TRUE='#'nLTLIBOBJS=''nLIBOBJS=''nam__fastdepCC_FALSE=''nam__fastdepCC_TRUE='#'nCCDEPMODE='depmode=none'nam__nodep='_no'nAMDEPBACKSLASH='\'nAMDEP_FALSE='#'nAMDEP_TRUE=''nam__include='include'nDEPDIR='.deps'nOBJEXT='o'nEXEEXT=''nac_ct_CC='cc
 -D_STDC_C99= -xarch=generic64 -O'nCPPFLAGS=''nLDFLAGS=''nCFLAGS='-g'nCC='cc 
-D_STDC_C99= -xarch=generic64 -O'nam__xargs_n='xargs 
-n'nam__rm_f_notfound=''nAM_BACKSLASH='\'nAM_DEFAULT_VERBOSITY='1'nAM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'nAM_V='$(V)'nCSCOPE='cscope'nETAGS='etags'nCTAGS='ctags'nam__untar='$${TAR-tar}
 xf -'nam__tar='$${TAR-tar} chof - 
"$$tardir"'nAMTAR='$${TAR-tar}'nam__leading_dot='.'nSET_MAKE=''nAWK='gawk'nmkdir_p='$(MKDIR_P)'nMKDIR_P='/opt/csw/bin/gmkdir
 -p'nINSTALL_STRIP_PROGRAM='$(install_sh) -c -s'nSTRIP=''ninstall_sh='${SHELL} 
/home/haible/minos/install-sh'nMAKEINFO=''nAUTOHEADER=''nAUTOMAKE=''nAUTOCONF=''nACLOCAL=''nVERSION='0'nPACKAGE='foo'nCYGPATH_W='echo'nam__isrc=''nINSTALL_DATA='${INSTALL}
 -m 
644'nINSTALL_SCRIPT='${INSTALL}'nINSTALL_PROGRAM='${INSTALL}'nECHO_T=''nECHO_N='-n'nECHO_C=''ntarget_alias=''nhost_alias=''nbuild_alias=''nLIBS=''nDEFS='-DPACKAGE_NAME=\"foo\"
 -DPACKAGE_TARNAME=\"foo\" -DPACKAGE_VERSION=\"0\" -DPACKAGE_STRING=\"foo\ 0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"foo\" -DVERSION=\"0\" 
-DHAVE_STDIO_H=1 ...

So, obviously, there is a quoting problem in the (huge!) 'trap' command
Namely, the
  printf '%s\n'
invocations violate the
  # WARNING: Use '\'' to represent an apostrophe within the trap.
requirement.

It is caused by commit a245b8525a55363546c2fae383c9616fccd78995 on 2024-08-04.

I first attempted to fix the problem by expanding
  AS_ECHO
to
  printf '%s\n'
inline. This can be done for the direct AS_ECHO invocations and for the
indirect ones from AS_BOX. But the for the indirect ones from _AC_CACHE_DUMP
I did not succeed to make it work.

So, here's a patch with a different approach: It moves the bulk of this shell
code to shell functions, and the invocation of such a shell function does
not require apostrophes any more.

I've tested this fix, also with "make check".

>From 2684314f899749827e6560f92e340cea700cf2ba Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Mon, 26 May 2025 15:17:57 +0200
Subject: [PATCH] Fix quoting in trap command (regression 2024-08-04).

* lib/autoconf/general.m4 (_AC_INIT_PREPARE): Emit functions ac_cache_dump,
ac_dump_debugging_info. In the trap command, invoke ac_dump_debugging_info.
(AC_CACHE_SAVE): Invoke ac_cache_dump instead of expanding _AC_CACHE_DUMP a
second time.
---
 lib/autoconf/general.m4 | 101 +++++++++++++++++++++-------------------
 1 file changed, 54 insertions(+), 47 deletions(-)

diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index dccddbe1..cbc997f1 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -1309,62 +1309,69 @@ done
 AS_UNSET(ac_configure_args0)
 AS_UNSET(ac_configure_args1)
 
-# When interrupted or exit'd, cleanup temporary files, and complete
-# config.log.  We remove comments because anyway the quotes in there
-# would cause problems or look ugly.
-# WARNING: Use '\'' to represent an apostrophe within the trap.
-# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
-trap 'exit_status=$?
-  # Sanitize IFS.
-  IFS=" ""	$as_nl"
-  # Save into config.log some information that might help in debugging.
-  {
-    echo
-
-    AS_BOX([Cache variables.])
-    echo
-    m4_bpatsubsts(m4_defn([_AC_CACHE_DUMP]),
-		  [^ *\(#.*\)?
-],                [],
-		  ['], ['\\''])
-    echo
+# Dump the cache to stdout.  It can be in a pipe (this is a requirement).
+ac_cache_dump ()
+{
+  _AC_CACHE_DUMP
+}
+
+# Print debugging info to stdout.
+ac_dump_debugging_info ()
+{
+  echo
+
+  AS_BOX([Cache variables.])
+  echo
+  ac_cache_dump
+  echo
+
+  AS_BOX([Output variables.])
+  echo
+  for ac_var in $ac_subst_vars
+  do
+    eval ac_val=\$$ac_var
+    case $ac_val in
+    *\'*) ac_val=`AS_ECHO(["$ac_val"]) | sed "s/'/'\\\\\\\\''/g"`;;
+    esac
+    AS_ECHO(["$ac_var='$ac_val'"])
+  done | sort
+  echo
 
-    AS_BOX([Output variables.])
+  if test -n "$ac_subst_files"; then
+    AS_BOX([File substitutions.])
     echo
-    for ac_var in $ac_subst_vars
+    for ac_var in $ac_subst_files
     do
       eval ac_val=\$$ac_var
       case $ac_val in
-      *\'\''*) ac_val=`AS_ECHO(["$ac_val"]) | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      *\'*) ac_val=`AS_ECHO(["$ac_val"]) | sed "s/'/'\\\\\\\\''/g"`;;
       esac
-      AS_ECHO(["$ac_var='\''$ac_val'\''"])
+      AS_ECHO(["$ac_var='$ac_val'"])
     done | sort
     echo
+  fi
 
-    if test -n "$ac_subst_files"; then
-      AS_BOX([File substitutions.])
-      echo
-      for ac_var in $ac_subst_files
-      do
-	eval ac_val=\$$ac_var
-	case $ac_val in
-	*\'\''*) ac_val=`AS_ECHO(["$ac_val"]) | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
-	esac
-	AS_ECHO(["$ac_var='\''$ac_val'\''"])
-      done | sort
-      echo
-    fi
+  if test -s confdefs.h; then
+    AS_BOX([confdefs.h.])
+    echo
+    cat confdefs.h
+    echo
+  fi
+  test "$ac_signal" != 0 &&
+    AS_ECHO(["$as_me: caught signal $ac_signal"])
+  AS_ECHO(["$as_me: exit $exit_status"])
+}
 
-    if test -s confdefs.h; then
-      AS_BOX([confdefs.h.])
-      echo
-      cat confdefs.h
-      echo
-    fi
-    test "$ac_signal" != 0 &&
-      AS_ECHO(["$as_me: caught signal $ac_signal"])
-    AS_ECHO(["$as_me: exit $exit_status"])
-  } >&AS_MESSAGE_LOG_FD
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Sanitize IFS.
+  IFS=" ""	$as_nl"
+  # Save into config.log some information that might help in debugging.
+  ac_dump_debugging_info >&AS_MESSAGE_LOG_FD
   eval "rm -f $ac_clean_CONFIG_STATUS core *.core core.conftest.*" &&
     rm -f -r conftest* confdefs* conf$[$]* $ac_clean_files &&
     exit $exit_status
@@ -2253,7 +2260,7 @@ m4_define([AC_CACHE_SAVE],
 
 _ACEOF
 
-_AC_CACHE_DUMP() |
+ac_cache_dump |
   sed ['
      /^ac_cv_env_/b end
      t clear
-- 
2.43.0

Reply via email to