autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[committed PATCH] config.status: handle CRLF line endings in AC_CONFIG_H


From: Zack Weinberg
Subject: [committed PATCH] config.status: handle CRLF line endings in AC_CONFIG_HEADERS input
Date: Fri, 15 Dec 2023 11:13:59 -0500

On systems that normally use Unix line endings, if config.h.in has
somehow been generated with DOS line endings, then awk will treat
each CR character as part of the line.  This breaks the regular
expressions used to edit config.h.in into config.h

To fix, manually strip trailing CRs from each “input record” before
any other processing.  For consistency I also made this change to the
code dealing with AC_CONFIG_FILES substitutions.  On systems that use
DOS line endings, both changes should be no-ops.

Reported by David Allsopp in <https://savannah.gnu.org/support/?110554>.
He offered a different patch, which also worked on my machine, but it
used a regular expression as the third argument to ‘split’, which
might not be portable across awk implementations (the gawk manual is
unclear).  Also, it could produce a config.h with _inconsistent_ line
endings.

* lib/autoconf/status.m4 (_AC_OUTPUT_HEADERS_PREPARE): In the awk
  script, strip a trailing CR from each record as the first action.
  (_AC_OUTPUT_FILES_PREPARE): Likewise.
* tests/torture.at (CRLF line endings in .in files): New test.

Co-authored-by: David Allsopp <david@davidallsopp.com>
---
 lib/autoconf/status.m4 |  2 ++
 tests/torture.at       | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index 2bfaf32b..e5eb67bf 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -503,6 +503,7 @@ cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
 }
 {
   line = $ 0
+  sub(/\r\$/, "", line)
   nfields = split(line, field, "@")
   substed = 0
   len = length(field[1])
@@ -824,6 +825,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
   for (key in D) D_is_set[key] = 1
   FS = ""
 }
+{ sub(/\r\$/, "", \$ 0) }
 /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
   line = \$ 0
   split(line, arg, " ")
diff --git a/tests/torture.at b/tests/torture.at
index ba52e12d..4e81d0dc 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -1093,6 +1093,35 @@ AT_CHECK_DEFINES([[#define foo one
 
 AT_CLEANUP
 
+## ------------------- ##
+## CRLF line endings.  ##
+## ------------------- ##
+
+AT_SETUP([CRLF line endings in .in files])
+
+AT_CONFIGURE_AC([[
+AC_DEFINE([MACRO], [1], [Define MACRO as 1 always.])
+AC_SUBST([VARIABLE], [value])
+AC_CONFIG_FILES([config.out:config.oin])
+]])
+
+# Shell `printf` should understand \r.
+AT_CHECK([printf '%s\r\n' \
+  '/* Define MACRO as 1 always. */' \
+  '#undef MACRO' \
+  > config.hin])
+AT_CHECK([printf '%s\r\n' \
+  'VARIABLE=@VARIABLE@' \
+  > config.oin])
+
+AT_SKIP_IF([grep '\\r' config.hin > /dev/null])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK([grep '#define MACRO 1' config.h > /dev/null])
+AT_CHECK([grep 'VARIABLE=value' config.out > /dev/null])
+
+AT_CLEANUP
 
 ## ------------------------------------ ##
 ## AC_SUBST: variable name validation.  ##
-- 
2.41.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]