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, 11 Feb 2001 20:02:45 +0000 (GMT)

Hello,

Here is an updated patsubst patch against CVS automake. Any patsubst
style variables are now staticly expanded by automake, thus avoiding
make portability problems.

I have included tests for both the normal and conditional cases of
variable expansion.

Please consider this for checkin.

Regards,
Alex Hornby

diff -r -P -u --exclude-from=/tmp/diff_exclude.9118 
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 11 19:55:33 2001
@@ -0,0 +1,11 @@
+2000-11-17  Alex Hornby <address@hidden>
+
+       * automake.in ($expand_patsubst): add new global to determine 
+       patsubst expansion
+       (handle_options): add new option "no-expand-patsubst"
+       (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. Add extra call to handle_options, otherwise options
+       are set after they have effect.
diff -r -P -u --exclude-from=/tmp/diff_exclude.9118 automake-cvs/automake.in 
automake-patsubst/automake.in
--- automake-cvs/automake.in    Sun Feb 11 17:12:31 2001
+++ automake-patsubst/automake.in       Sun Feb 11 19:44:31 2001
@@ -101,6 +101,9 @@
 # included in generated Makefile.in.
 $cmdline_use_dependencies = 1;
 
+# This is TRUE if variables are to have patsubst expressions expanded
+$expand_patsubst = 1;
+
 # TRUE if in verbose mode.
 $verbose = 0;
 
@@ -775,6 +778,10 @@
            {
                $use_dependencies = 0;
            }
+           elsif ($_ eq 'no-expand-patsubst' )
+           {
+               $expand_patsubst = 0;
+           }
            elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
            {
                # Got a version number.
@@ -6432,6 +6439,27 @@
     }
 }
 
+sub expand_contents
+{
+    local ($var, $value, $cond) = @_;
+    local ($ret) = $value;
+    
+    if ( $value =~ m/([^%]*)%([^%]*)%/ ) 
+    {
+       if ( $expand_patsubst ) 
+       {
+           local @curval = &variable_value_as_list ($var, $cond);
+           local ( $val ); 
+           $ret = '';
+           foreach $val ( @curval )
+           {
+               $ret .= $val . " ";
+           }
+       } 
+    }
+    return $ret;
+}
+
 # Read main am file.
 sub read_main_am_file
 {
@@ -6464,6 +6492,12 @@
     $output_vars = '';
     &read_am_file ($amfile);
 
+    if (&handle_options)
+    {
+       # Fatal error.  Just return, so we can continue with next file.
+       return;
+    }
+
     # Now dump the variables that were defined.  We do it in the same
     # order in which they were defined (skipping duplicates).
     local (%done);
@@ -6480,6 +6514,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);
@@ -6493,8 +6528,9 @@
        }
        else
        {
+           local ($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.9118 
automake-cvs/tests/ChangeLog.patsubst automake-patsubst/tests/ChangeLog.patsubst
--- automake-cvs/tests/ChangeLog.patsubst       Thu Jan  1 01:00:00 1970
+++ automake-patsubst/tests/ChangeLog.patsubst  Sun Feb 11 19:44:31 2001
@@ -0,0 +1,7 @@
+2000-10-25  Alex Hornby <address@hidden>
+
+       * patsubst.test: add test for new patsubst expansion
+
+       * patsubst2.test: add test for conditional patsubst expansion
+
+       * Makefile.am: reference patsubst.test and patsubst2.test
diff -r -P -u --exclude-from=/tmp/diff_exclude.9118 
automake-cvs/tests/Makefile.am automake-patsubst/tests/Makefile.am
--- automake-cvs/tests/Makefile.am      Sun Feb 11 17:12:52 2001
+++ automake-patsubst/tests/Makefile.am Sun Feb 11 19:44:31 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.9118 
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 11 19:44:31 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.9118 
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 11 19:44:31 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@' Makefile.in || exit 1
+exit 0




reply via email to

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