autoconf: {f77-name-mangling} (AC_OUTPUT_MAKE_DEFS): Change sed regexps to

From 3bb5f4cfcc856f35b419286e3627d9f2c9ac38fe Mon Sep 17 00:00:00 2001
From: "Matthew D. Langston" <[EMAIL REDACTED]>
Date: Wed, 2 Jun 1999 12:46:59 +0000
Subject: [PATCH] {f77-name-mangling} (AC_OUTPUT_MAKE_DEFS): Change sed regexps
 to recognize CPP macros that take arguments.  Reported, and based on a patch,
 by Steven G. Johnson <stevenj@alum.mit.edu>. (AC_OUTPUT_HEADER): Likewise.

---
 acgeneral.m4            | 14 ++++++++++++--
 lib/autoconf/general.m4 | 14 ++++++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/acgeneral.m4 b/acgeneral.m4
index 4e0eaedb..abeeb539 100644
--- a/acgeneral.m4
+++ b/acgeneral.m4
@@ -2147,9 +2147,16 @@ define(AC_OUTPUT_MAKE_DEFS,
 dnl Using a here document instead of a string reduces the quoting nightmare.
 # Protect against shell expansion while executing Makefile rules.
 # Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then we branch to the cleanup section.  Otherwise,
+# look for a macro that doesn't take arguments.
 cat > conftest.defs <<\EOF
 changequote(<<, >>)dnl
-s%<<#define>> \([^ 	][^ 	]*\) *\(.*\)%-D\1=\2%g
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\([^ 	(][^ 	(]*([^)]*)\)[ 	]*\(.*\)%-D\1=\2%g
+t cleanup
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\([^ 	][^ 	]*\)[ 	]*\(.*\)%-D\2=\3%g
+: cleanup
 s%[ 	`~<<#>>$^&*(){}\\|;'"<>?]%\\&%g
 s%\[%\\&%g
 s%\]%\\&%g
@@ -2359,7 +2366,10 @@ cat > conftest.hdr <<\EOF
 changequote(<<, >>)dnl
 s/[\\&%]/\\&/g
 s%[\\$`]%\\&%g
-s%<<#define>> \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\(\([^ 	(][^ 	(]*\)([^)]*)\)[ 	]*\(.*$\)%${ac_dA}\2${ac_dB}\1${ac_dC}\3${ac_dD}%gp
+t cleanup
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\([^ 	][^ 	]*\)[ 	]*\(.*$\)% ${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+: cleanup
 s%ac_d%ac_u%gp
 s%ac_u%ac_e%gp
 changequote([, ])dnl
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 4e0eaedb..abeeb539 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2147,9 +2147,16 @@ define(AC_OUTPUT_MAKE_DEFS,
 dnl Using a here document instead of a string reduces the quoting nightmare.
 # Protect against shell expansion while executing Makefile rules.
 # Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then we branch to the cleanup section.  Otherwise,
+# look for a macro that doesn't take arguments.
 cat > conftest.defs <<\EOF
 changequote(<<, >>)dnl
-s%<<#define>> \([^ 	][^ 	]*\) *\(.*\)%-D\1=\2%g
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\([^ 	(][^ 	(]*([^)]*)\)[ 	]*\(.*\)%-D\1=\2%g
+t cleanup
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\([^ 	][^ 	]*\)[ 	]*\(.*\)%-D\2=\3%g
+: cleanup
 s%[ 	`~<<#>>$^&*(){}\\|;'"<>?]%\\&%g
 s%\[%\\&%g
 s%\]%\\&%g
@@ -2359,7 +2366,10 @@ cat > conftest.hdr <<\EOF
 changequote(<<, >>)dnl
 s/[\\&%]/\\&/g
 s%[\\$`]%\\&%g
-s%<<#define>> \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\(\([^ 	(][^ 	(]*\)([^)]*)\)[ 	]*\(.*$\)%${ac_dA}\2${ac_dB}\1${ac_dC}\3${ac_dD}%gp
+t cleanup
+s%^[ 	]*<<#>>[ 	]*define[ 	][ 	]*\([^ 	][^ 	]*\)[ 	]*\(.*$\)% ${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+: cleanup
 s%ac_d%ac_u%gp
 s%ac_u%ac_e%gp
 changequote([, ])dnl