Re: non recursive includes proof of concept #2

2003-12-19 Thread Robert Collins
On Sat, 2003-12-20 at 00:41, Alexandre Duret-Lutz wrote:
> >>> "Robert" == Robert Collins <[EMAIL PROTECTED]> writes:
> 
> [...]
> 
>  Robert> It transforms macros and paths in an included file (called
>  Robert> Makefile.rules for now) , to make them suitable for a non-recursive
>  Robert> build.
> 
> I'm skeptical about whether this approach can be made to work
> intuitively.  More precisely I don't think it is generally
> possible to let users write a subdir Makefile.am fragment as if
> it would be run locally in the subdirectory, and translate
> *anything* so it actually works from another directory.  Let's
> mention user-defined rules referring rewritten variables, or
> flag variables including things such as -I.

Right. To have both in-dir and top-level Makefiles work may not be
possible. My key goal is the top level Makefile assembled from the
included fragments though - if the dual approach won't work.. it won't.
That said, if the user can do it with only minor hoops to jump
through...

> Anyway you asked for comments on the patch so here are some.
> (I'm sorry I had to be brief in the end, because I have a train
> to catch in one hour.  I'll be away for one week.)
> 
> I don't see what in your changes require the file to be named
> Makefile.rules.

It isn't required to be named that now - my original proof of concept 2
odd years ago started out with a fixed name, which I removed even before
posting back then. So - no requirement.

> This sounds neat.  But AFAICT no test case really cd into that
> given dir and perform the build.

I'll add a test case.

> [...]

> Judging from the comments, I understand that 
> bin_PROGRAMS = foo does not become path/foo?
> Or is it a typo in the example of @canonised_macro_lists?

ah. It's 
bin_PROGRAMS = foo
foo_SOURCES = bar.c
->
bin_PROGRAMS = path/foo
path_foo_SOURCES = path/bar.c

> Since these variables will be used for member ship check, better
> use a hash

Ok, will try this out.


> Is this required?  `include' automatically distributes it's
> argument, I presume you've preserved this for `subdir_include'.

Right, so it won't be required.

> Please use GNU-like 2-space indentation for new code (see HACKING).
> 
> The tail of all Perl files already setups the indentation style
> for Emacs.  Maybe you can submit similar hints for your editor.

Hmm, I thought I had.

I'll stop replying here - I'm going to implement your suggestions as I
get time.

(an aside: some of the issues are holdovers from the 2 year old patch
I'd resurrected).

I'll drop a note here when I've done your suggestions.

Cheers
Rob

-- 
GPG key available at: .





Re: non recursive includes proof of concept #2

2003-12-19 Thread Alexandre Duret-Lutz
>>> "Robert" == Robert Collins <[EMAIL PROTECTED]> writes:

[...]

 Robert> It transforms macros and paths in an included file (called
 Robert> Makefile.rules for now) , to make them suitable for a non-recursive
 Robert> build.

I'm skeptical about whether this approach can be made to work
intuitively.  More precisely I don't think it is generally
possible to let users write a subdir Makefile.am fragment as if
it would be run locally in the subdirectory, and translate
*anything* so it actually works from another directory.  Let's
mention user-defined rules referring rewritten variables, or
flag variables including things such as -I.

Anyway you asked for comments on the patch so here are some.
(I'm sorry I had to be brief in the end, because I have a train
to catch in one hour.  I'll be away for one week.)

I don't see what in your changes require the file to be named
Makefile.rules.

 Robert> As show by the test cases, this allows a couple of neat things:
 Robert> 1) A stub Makefile.am 
 Robert> ===
 Robert> include \$(srcdir)/Makefile.rules
 Robert> ===
 Robert> is all that is needed in a given subdirectory to generate a full
 Robert> makefile. (Useful if you want to be able to cd to a given dir and
 Robert> perform builds just in that dir).

This sounds neat.  But AFAICT no test case really cd into that
given dir and perform the build.

[...]

 Robert> +# Canonised variable suffixes
 Robert> +my @canonised_macro_names =
 Robert> +qw(SOURCES);
 Robert> +# Canonised variable contents (foo->path/foo)
 Robert> +my @canonised_macro_values = 
 Robert> +qw(SOURCES);
 Robert> +# Canonised macro lists (foo ->path_foo)
 Robert> +my @canonised_macro_lists = 
 Robert> +qw(PROGRAMS);

Judging from the comments, I understand that 
bin_PROGRAMS = foo does not become path/foo?
Or is it a typo in the example of @canonised_macro_lists?

Since these variables will be used for member ship check, better
use a hash
  my %canonised_macro_names = (SOURCES => 1);
and latter
  if (exists $canonised_macro_names{$_}) ...
instead of those greps.

 Robert> # Match `-d' as a command-line argument in a string.
 Robert> my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
 Robert> @@ -216,7 +232,7 @@ my @common_files =
 Robert> ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
 Robert> configure configure.ac configure.in depcomp elisp-comp
 Robert> install-sh libversion.in mdate-sh missing mkinstalldirs
 Robert> -  py-compile texinfo.tex ylwrap),
 Robert> +  py-compile texinfo.tex ylwrap Makefile.rules),

Is this required?  `include' automatically distributes it's
argument, I presume you've preserved this for `subdir_include'.

 Robert> @libtool_files, @libtool_sometimes);
 
 Robert> # Commonly used files we auto-include, but only sometimes.
 Robert> @@ -1697,6 +1713,38 @@ sub handle_single_transform_list (@)
 Robert> return @result;
 Robert> }
 
 Robert> +# $VALUE
 Robert> +# transform_file_list ($PREPEND, @FILES)
 Robert> +# 
 Robert> +# insert $PREPEND before every file path that is not absolute
 Robert> +#
 Robert> +sub transform_file_list ($$)
 Robert> +{
 Robert> +  my ($prepend, $tmpfiles) = @_;
 Robert> +  my $result = "";

Please use GNU-like 2-space indentation for new code (see HACKING).

The tail of all Perl files already setups the indentation style
for Emacs.  Maybe you can submit similar hints for your editor.

 Robert> +  my @files = ();
 Robert> +  @files = split(/ /, $tmpfiles); 
 Robert> +  while (scalar @files > 0)
 Robert> +  {
 Robert> +  $_ = shift @files;

can be shortened to

foreach (split(/ /, $tmpfiles))
  {

[...]

 Robert> @@ -2145,7 +2193,7 @@ sub handle_programs
 Robert> # Canonicalize names and check for misspellings.
 Robert> my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
 Robert> '_SOURCES', '_OBJECTS',
 Robert> -   '_DEPENDENCIES');
 Robert> +   '_DEPENDENCIES', '_CFLAGS');
 
 Robert> $where->push_context ("while processing program `$one_file'");
 Robert> $where->set (INTERNAL->get);
 Robert> @@ -2250,7 +2298,7 @@ sub handle_libraries
 Robert> # Canonicalize names and check for misspellings.
 Robert> my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
 Robert> '_OBJECTS', '_DEPENDENCIES',
 Robert> -  '_AR');
 Robert> +  '_AR', '_CFLAGS');
 
 Robert> if (! var ($xlib . '_AR'))
 Robert> {
 Robert> @@ -2371,7 +2419,20 @@ sub handle_ltlibraries
 Robert> # Canonicalize names and check for misspellings.
 Robert> my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
 Robert> '_SOURCES', '_OBJECTS',
 Robert> -  '_DEPENDENCIES');
 Robert> +  '_DEPENDENCIES', '_CFLAGS');

It's not clear to me how this relates to the rest

Re: non recursive includes proof of concept #2

2003-12-01 Thread Jirka Hanika
On Mon, Dec 01, 2003 at 07:52:37PM +1100, Robert Collins wrote:
> It transforms macros and paths in an included file (called
> Makefile.rules for now) , to make them suitable for a non-recursive
> build.
> 
> As show by the test cases, this allows a couple of neat things:
> 1) A stub Makefile.am 
> ===
> include \$(srcdir)/Makefile.rules
> ===
> is all that is needed in a given subdirectory to generate a full
> makefile. (Useful if you want to be able to cd to a given dir and
> perform builds just in that dir).
> 
> 2) File paths, and canonical macro names are conveniently short - just
> what Bob F has been (rightfully IMO) complaining about.
> 
> 3) You don't end up with a huge Makefile.am to support, rather each part
> of the project has a small rules file.

At the first sight this looks exactly the same scheme I was always
longing for.  Is there any reason why this code couldn't be included
in the mainstream automake (in the 1.9 direction)?

Jirka





non recursive includes proof of concept #2

2003-12-01 Thread Robert Collins
Well, I finally snuck in a little time to update my proof of concept for
non recursive includes.

Still, I don't code perl - and it shows ;).

How to use?

Grab CVS automake, apply thepatch, drop the test files into tests
subdir.

Have a look at the test cases to see how to use it.

What does it do?

It transforms macros and paths in an included file (called
Makefile.rules for now) , to make them suitable for a non-recursive
build.

As show by the test cases, this allows a couple of neat things:
1) A stub Makefile.am 
===
include \$(srcdir)/Makefile.rules
===
is all that is needed in a given subdirectory to generate a full
makefile. (Useful if you want to be able to cd to a given dir and
perform builds just in that dir).

2) File paths, and canonical macro names are conveniently short - just
what Bob F has been (rightfully IMO) complaining about.

3) You don't end up with a huge Makefile.am to support, rather each part
of the project has a small rules file.

Rob

-- 
GPG key available at: .
Index: automake.in
===
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1523
diff -u -p -r1.1523 automake.in
--- automake.in	30 Nov 2003 17:00:36 -	1.1523
+++ automake.in	1 Dec 2003 08:41:24 -
@@ -181,11 +181,27 @@ my $ELSE_PATTERN =
 my $ENDIF_PATTERN =
   '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
 my $PATH_PATTERN = '(\w|[/.-])+';
+my $INCLUDE_KEYWORD = 'include';
+my $SUBDIR_INCLUDE_KEYWORD = 'subdir_include';
 # This will pass through anything not of the prescribed form.
-my $INCLUDE_PATTERN = ('^include\s+'
+my $INCLUDE_PATTERN = ('^' . $INCLUDE_KEYWORD . '\s+'
 		   . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
 		   . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
 		   . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
+my $SUBDIR_INCLUDE_PATTERN = ('^' . $SUBDIR_INCLUDE_KEYWORD . '\s+'
+		   . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
+		   . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
+		   . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
+
+# Canonised variable suffixes
+my @canonised_macro_names =
+qw(SOURCES);
+# Canonised variable contents (foo->path/foo)
+my @canonised_macro_values = 
+qw(SOURCES);
+# Canonised macro lists (foo ->path_foo)
+my @canonised_macro_lists = 
+qw(PROGRAMS);
 
 # Match `-d' as a command-line argument in a string.
 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
@@ -216,7 +232,7 @@ my @common_files =
 	ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
 	configure configure.ac configure.in depcomp elisp-comp
 	install-sh libversion.in mdate-sh missing mkinstalldirs
-	py-compile texinfo.tex ylwrap),
+	py-compile texinfo.tex ylwrap Makefile.rules),
  @libtool_files, @libtool_sometimes);
 
 # Commonly used files we auto-include, but only sometimes.
@@ -1697,6 +1713,38 @@ sub handle_single_transform_list (@)
 return @result;
 }
 
+# $VALUE
+# transform_file_list ($PREPEND, @FILES)
+# 
+# insert $PREPEND before every file path that is not absolute
+#
+sub transform_file_list ($$)
+{
+  my ($prepend, $tmpfiles) = @_;
+  my $result = "";
+  my @files = ();
+  @files = split(/ /, $tmpfiles); 
+  while (scalar @files > 0)
+  {
+	$_ = shift @files;
+
+	if ($_ =~ s/^\$\(top_srcdir\)\///)
+	  {
+	$result .= " \$\(top_srcdir\)\/" . $_;
+	  }
+	  elsif ( $_ =~ s/^\$\(srcdir\)\///)
+	  {
+	$result .= " \$\(srcdir\)\/$prepend" . $_;
+	  }
+	  else
+	  {
+	$result .= " $prepend" . $_;
+	  }
+  }
+  verb "transformed value: '$result'\n";
+  return $result . "\n";
+}
+
 
 # $LINKER
 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
@@ -2145,7 +2193,7 @@ sub handle_programs
   # Canonicalize names and check for misspellings.
   my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
 	 '_SOURCES', '_OBJECTS',
-	 '_DEPENDENCIES');
+	 '_DEPENDENCIES', '_CFLAGS');
 
   $where->push_context ("while processing program `$one_file'");
   $where->set (INTERNAL->get);
@@ -2250,7 +2298,7 @@ sub handle_libraries
   # Canonicalize names and check for misspellings.
   my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
 	'_OBJECTS', '_DEPENDENCIES',
-	'_AR');
+	'_AR', '_CFLAGS');
 
   if (! var ($xlib . '_AR'))
 	{
@@ -2371,7 +2419,20 @@ sub handle_ltlibraries
   # Canonicalize names and check for misspellings.
   my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
 	'_SOURCES', '_OBJECTS',
-	'_DEPENDENCIES');
+	'_DEPENDENCIES', '_CFLAGS');
+
+# Tell the source code what library we are building
+#	my $tempvariable = '';
+#	if ( &variable_defined ($xlib . '_CFLAGS'))
+#	{
+#	# Define the lib_CFLAGS variable.
+#	$tempvariable .= &variable