The regex pattern in function scan_variable_expansions() fails to
report a portability warning when a dollar-escaped dollar sign
precedes the variable:

        foo_SOURCES = a.c $$$(patsubst a.c,a,b)
---
 lib/Automake/Variable.pm | 5 +++--
 t/dollarvar2.sh          | 9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm
index 4227baad9..4fe1e7284 100644
--- a/lib/Automake/Variable.pm
+++ b/lib/Automake/Variable.pm
@@ -746,9 +746,10 @@ sub scan_variable_expansions ($)
   $text =~ s/#.*$//;
 
   # Record each use of ${stuff} or $(stuff) that does not follow a $.
-  while ($text =~ /(?<!\$)\$(?:\{([^\}]*)\}|\(([^\)]*)\))/g)
+  while ($text =~ m{\$(?:\{([^\}]*)\}|\(([^\)]*)\)|(\$))}g)
     {
-      my $var = $1 || $2;
+      my $var = $1 || $2 || $3;
+      next if $var eq '$';
       # The occurrence may look like $(string1[:subst1=[subst2]]) but
       # we want only 'string1'.
       $var =~ s/:[^:=]*=[^=]*$//;
diff --git a/t/dollarvar2.sh b/t/dollarvar2.sh
index f347c5f1c..ed8833c13 100644
--- a/t/dollarvar2.sh
+++ b/t/dollarvar2.sh
@@ -83,4 +83,13 @@ AUTOMAKE_fails -Wno-portability -Wportability-recursive
 grep 'var-with-dash' stderr && exit 1
 grep 'recursive variable expansion' stderr
 
+#
+# Ensure that GNU make function calls give a portability warning
+# under a certain condition that older automake missed.
+#
+cat >Makefile.am <<'EOF'
+x = $$$(y z)
+EOF
+AUTOMAKE_fails -Wportability
+
 :
-- 
2.41.0


Reply via email to