This is the mail archive of the automake@gnu.org mailing list for the automake project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: patsubst support



Akim,

Okay, here is patsubst patch v2. New since last time:

* ChangeLog entry formatting
* NEWS entry
* Documentation (first texinfo usage, please beware!)

The _PROGRAMS based example in the documentation needs a patsubst
supporting make (e.g. GNU and Solaris work). This is because the
program target writes prog_SOURCES to the Makefile.in without any
variable expansions.

The real reason I want patsubst (user specified dependency files)
doesn't impose any new make requirements when used, as the patsubst
expressions are expanded before being written to Makefile.in.

Until then, the PROGRAM targets are the only obvious route to
Automake's variable expansion, so thats what I used to give an
example.

Alex.


diff -r -P -u automake/ChangeLog.entry automake-patsubst/ChangeLog.entry
--- automake/ChangeLog.entry	Thu Jan  1 01:00:00 1970
+++ automake-patsubst/ChangeLog.entry	Wed Oct 25 15:41:28 2000
@@ -0,0 +1,5 @@
+2000-10-25  Alex Hornby <alex@anvil.co.uk>
+
+	* automake.in (value_to_list): Add support for patsubst
+ 	style variable substitution.
+
diff -r -P -u automake/NEWS.entry automake-patsubst/NEWS.entry
--- automake/NEWS.entry	Thu Jan  1 01:00:00 1970
+++ automake-patsubst/NEWS.entry	Wed Oct 25 15:44:28 2000
@@ -0,0 +1 @@
+* Patsubst style variable expansion is now available.
diff -r -P -u automake/automake.in automake-patsubst/automake.in
--- automake/automake.in	Wed Oct 25 11:25:01 2000
+++ automake-patsubst/automake.in	Wed Oct 25 14:20:07 2000
@@ -5902,16 +5902,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
+	        local ($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);
diff -r -P -u automake/automake.texi automake-patsubst/automake.texi
--- automake/automake.texi	Tue Oct 17 09:49:13 2000
+++ automake-patsubst/automake.texi	Wed Oct 25 16:42:13 2000
@@ -1605,6 +1605,23 @@
 cause an invalid value for @samp{@var{prog}_DEPENDENCIES} to be
 generated.
 
+@cindex Variables, patsubst expansion
+
+Sometimes it can be useful to derive @samp{@var{prog}_SOURCES} from
+another variable. This can be done using patsubst style expansion to
+rewrite a variable:
+
+@example
+MODULES = Account Bank Currency @dots{}
+bin_PROGRAMS = account_server
+account_server_SOURCES = $@{MODULES:%=%.c@}
+@end example
+
+Currently this feature requires the use of a @code{make} with patsubst
+support (such as GNU @code{make}). It may become possible in the future
+to expand all patsubst variable definitions before they are written to
+@file{ Makefile.in}. In the meantime if you use this feature you may get
+a error from non-GNU make.
 
 @node A Library, LIBOBJS, A Program, Programs
 @section Building a library
diff -r -P -u automake/tests/ChangeLog.entry automake-patsubst/tests/ChangeLog.entry
--- automake/tests/ChangeLog.entry	Thu Jan  1 01:00:00 1970
+++ automake-patsubst/tests/ChangeLog.entry	Wed Oct 25 15:41:59 2000
@@ -0,0 +1,5 @@
+2000-10-25  Alex Hornby <alex@anvil.co.uk>
+
+	* patsubst.test: Add test for patsubst variable expansion.
+
+	* Makefile.am: Reference patsubst.test.
Only in automake/tests: Makefile
diff -r -P -u automake/tests/Makefile.am automake-patsubst/tests/Makefile.am
--- automake/tests/Makefile.am	Wed Oct 25 11:25:02 2000
+++ automake-patsubst/tests/Makefile.am	Wed Oct 25 14:13:05 2000
@@ -181,6 +181,7 @@
 output5.test \
 package.test \
 parse.test \
+patsubst.test \
 pluseq.test \
 pluseq2.test \
 pluseq3.test \
diff -r -P -u automake/tests/patsubst.test automake-patsubst/tests/patsubst.test
--- automake/tests/patsubst.test	Thu Jan  1 01:00:00 1970
+++ automake-patsubst/tests/patsubst.test	Wed Oct 25 14:13:01 2000
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+# Test `patsubst expansion' functionality.
+
+. $srcdir/defs || exit 1
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+BASENAMES = zar doz
+zardoz_SOURCES = ${BASENAMES:%=%.c}
+END
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+END
+
+: > zar.c
+: > doz.c
+
+$AUTOMAKE || exit 1
+fgrep 'zar.o doz.o' Makefile.in




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]