automake
[Top][All Lists]
Advanced

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

Re: PATCH: patsubst support


From: Alex Hornby
Subject: Re: PATCH: patsubst support
Date: Sun, 18 Feb 2001 17:25:04 +0000 (GMT)

Here is a new version of the patsubst patch against cvs HEAD. 

It is now smaller due to the removal of a superflous option, and has
my instead of local etc. Also the conditional test is improved.

After applying the patch remember to make the .test files
executable. That has caught me out on more than one occasion :)

Cheers,
Alex.

diff -r -P -u --exclude-from=/tmp/diff_exclude.1207 
automake-cvs/ChangeLog.patsubst automake-patsubst/ChangeLog.patsubst
--- automake-cvs/ChangeLog.patsubst     Thu Jan  1 01:00:00 1970
+++ automake-patsubst/ChangeLog.patsubst        Sun Feb 18 17:07:23 2001
@@ -0,0 +1,15 @@
+2001-02-18  Alex Hornby <address@hidden>
+
+       * automake.in (expand_contents): add new function to perform
+       the patsubst expansion
+       (value_to_list): add support for patsubst style variable
+       substitution.
+       (read_main_am_file): call expand_contents to output
+       variables.
+
+       * tests/patsubst.test: add test for patsubst expansion
+
+       * tests/patsubst2.test: add test for conditional patsubst
+       expansion
+
+       * tests/Makefile.am: reference patsubst.test and patsubst2.test
diff -r -P -u --exclude-from=/tmp/diff_exclude.1207 automake-cvs/automake.in 
automake-patsubst/automake.in
--- automake-cvs/automake.in    Sun Feb 18 16:22:53 2001
+++ automake-patsubst/automake.in       Sun Feb 18 17:07:23 2001
@@ -5826,16 +5826,34 @@
            {
                $varname = $1;
                $to = $3;
-               ($from = $2) =~ s/(\W)/\\$1/g;
+               ($from = $2) =~ s/(\W)/$1/g;
            }
 
            # Find the value.
            @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
 
            # Now rewrite the value if appropriate.
-           if ($from)
+           if ($from =~ '^([^%]*)%([^%]*)')
            {
-               grep (s/$from$/$to/, @temp_list);
+               # patsubst style substitution
+               my ($prefrom, $suffrom, $preto, $sufto);
+               $prefrom = $1;
+               $suffrom = $2;
+
+               if ( $to =~  '^([^%]*)%([^%]*)')
+               {
+                   $preto = $1;
+                   $sufto = $2;
+               }
+               grep { 
+                   s/^$prefrom/$preto/;
+                   s/$suffrom$/$sufto/;
+               } @temp_list;
+           }
+           elsif ($from)
+           {
+               # standard substitution reference style
+               grep (s/$from$/$to/, @temp_list);
            }
 
            push (@result, @temp_list);
@@ -6453,6 +6471,24 @@
     }
 }
 
+sub expand_contents
+{
+    my ($var, $value, $cond) = @_;
+    my ($ret) = $value;
+    
+    if ( $value =~ m/([^%]*)%([^%]*)%/ ) 
+    {
+       my @curval = &variable_value_as_list ($var, $cond);
+       my ( $val ); 
+       $ret = '';
+       foreach $val ( @curval )
+       {
+           $ret .= $val . " ";
+       }
+    }
+    return $ret;
+}
+
 # Read main am file.
 sub read_main_am_file
 {
@@ -6501,6 +6537,7 @@
            {
                local ($vcond) = shift (@cond_vals);
                local ($val) = &unquote_cond_val (shift (@cond_vals));
+               $val = expand_contents ($curs, $val, $vcond);
                $output_vars .= ($vcond . $curs . ' '
                                 . $def_type{$curs} . "= ");
                local ($line);
@@ -6514,8 +6551,9 @@
        }
        else
        {
+           my ($val) = expand_contents($curs, $contents{$curs}, '');
            $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
-                            . $contents{$curs} . "\n");
+                            . $val . "\n");
        }
     }
 
diff -r -P -u --exclude-from=/tmp/diff_exclude.1207 
automake-cvs/tests/Makefile.am automake-patsubst/tests/Makefile.am
--- automake-cvs/tests/Makefile.am      Sun Feb 18 16:23:02 2001
+++ automake-patsubst/tests/Makefile.am Sun Feb 18 17:07:23 2001
@@ -188,6 +188,8 @@
 output5.test \
 package.test \
 parse.test \
+patsubst.test \
+patsubst2.test \
 pluseq.test \
 pluseq2.test \
 pluseq3.test \
diff -r -P -u --exclude-from=/tmp/diff_exclude.1207 
automake-cvs/tests/patsubst.test automake-patsubst/tests/patsubst.test
--- automake-cvs/tests/patsubst.test    Thu Jan  1 01:00:00 1970
+++ automake-patsubst/tests/patsubst.test       Sun Feb 18 17:07:23 2001
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+# Test `patsubst expansion' functionality.
+# There should be no patsubst constructs in the Makefile.in
+
+. $srcdir/defs || exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+BASENAMES = zar doz
+zardoz_SOURCES = ${BASENAMES:%=%.c}
+END
+
+: > zar.c
+: > doz.c
+
+$AUTOMAKE || exit 1
+fgrep 'zar.o doz.o' Makefile.in &&
+if fgrep '${BASENAMES:%=%.c}' Makefile.in; then
+  exit 1
+fi
diff -r -P -u --exclude-from=/tmp/diff_exclude.1207 
automake-cvs/tests/patsubst2.test automake-patsubst/tests/patsubst2.test
--- automake-cvs/tests/patsubst2.test   Thu Jan  1 01:00:00 1970
+++ automake-patsubst/tests/patsubst2.test      Sun Feb 18 17:07:23 2001
@@ -0,0 +1,26 @@
+#! /bin/sh
+
+# Test `patsubst expansion' functionality with conditionals
+# There should be no patsubst constructs in the Makefile.in
+
+. $srcdir/defs || exit 1
+
+cat > configure.in << 'END'
+AM_INIT_AUTOMAKE(nonesuch, nonesuch)
+AM_CONDITIONAL(TEST, true)
+AC_OUTPUT(Makefile)
+END
+
+cat > Makefile.am << 'END'
+BASENAMES = zar doz
+if TEST
+VAR = ${BASENAMES:%=%.c}
+else
+VAR = false
+endif
+END
+
+$AUTOMAKE || exit 1
+
+grep 'address@hidden@VAR = @address@hidden doz.c' Makefile.in || exit 1
+exit 0



reply via email to

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