chiark / gitweb /
BEFORE CHANGE &&
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Nov 2019 19:24:39 +0000 (19:24 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Nov 2019 19:24:39 +0000 (19:24 +0000)
NOTES
build-aux/subdirmk-setup

diff --git a/NOTES b/NOTES
index fcb4e9505de16160bfbf1c5f79bcd92dadbcecfc..e5cdd0a28d8ca071d25e78382e9ff5fa4d64e184 100644 (file)
--- a/NOTES
+++ b/NOTES
@@ -1,20 +1,21 @@
-&=                     =>      subdir
-&_                     =>      subdir_
-&/                     =>      subdir/
-&CAPS                  =>      subdir_CAPS     _ counts
-&lc                    =>      subdir/lc       _ counts
+&CAPS          =>      subdir_CAPS                     or TOP_CAPS
+&lc            =>      subdir/lc                       or lc
 
-&,= &,_ &,/ &,CAPS &,lc                prefixes $(top_srcdir)/subdir
-&;= &;_ &;/ &;CAPS &;lc                prefixes $(abs_top_srcdir)/subdir
+&_             =>      subdir_                         or TOP_
+&/             =>      subdir/                         or nothing
+&=_            =>      subdir                          or TOP
+&=/            =>      subdir                          or .
+&^             =>      $(top_srcdir)/subdir            or $(top_srcdir)
+&~             =>      $(abs_top_srcdir)/subdir        or $(abs_top_srcdir)
 
-&.                     =>      $(top_srcdir)
-&:                     =>      $(abs_top_srcdir)
+&&                     =>      &
 
-& thing thing          =>      like &thing &thing (until EOL)
-                               (edits only `thing's which are CAPS or lc
-                               and follow a space)
+& thing thing... &     =>      each thing prefixed by &/ &^ &~ resp
+& ^ thing thing... &           each thing is any non-ws
+& ~ thing thing... &           & may be omitted before EOL or before \EOL
 
-&&                     =>      &
+CAPS is [A-Z][0-9_A-Z]*(?!\w)
+lc is [a-z][-+,0-9_a-z]*(?!\w)
 
 &! spc         disables & *until* EOL
 
@@ -32,3 +33,5 @@ eg
 &TARGETS[_things]              is handled specially
                                must be spelled precisely this way
                                if no _things, means _all
+
+Also, `all' is weird in that it is present even if not specified
index c1866f6bcb29ae5f48858a6c3353e691972046dd..1de88302fbd546bcf6efebf5066c8094ff6e96fa 100644 (file)
@@ -26,18 +26,108 @@ sub build_tree () {
     }
 }
 
-
-
 sub write_makefile ($$) {
     my ($subdir,$depth) = @_;
-    start_output_file("Makefile");
+    start_output_file("$subdir/Makefile");
     my $cd = $depth ? join('/', ('..',) x $depth) : '.';
-    print O <<END;
+    o <<END;
+default: all
 %:
        $(MAKE) -C $cd $subdir/$@
 END
 }
 
+sub filter_subdir_mk ($) {
+    my ($subdir) = @_;
+    my $in = "$srcdir/$subdir/Subdir.mk.in";
+    open I, '<' $in or die "open $in: $!\n";
+    my $caps_re = qr{[A-Z][0-9_A-Z]*(?!\w)};
+    my $lc_e = qr{[a-z][-+,0-9_a-z]*(?!\w)};
+    my $esclit = '&';
+    my $esc = '\\&';
+    while (<I>) {
+       for (;;) {
+           s{^(.*?)(?=$esc)}{};
+           o $1;
+           last if m{^\n};
+           s{^$esc}{} or die "$_ ?";
+           if (s{^$esc}{}) {
+               o $esclit;
+           }
+           elsif (m{^(?=$caps_re)}) { o "${for_var}_" }
+           elsif (m{^(?=$lc_re)}) { o $dir_prefix }
+           elsif (s{^_}{}) { o "${for_var}_" }
+           elsif (s{^/}{}) { o $dir_prefix }
+           elsif (s{^=_}{}) { o $for_var }
+           elsif (s{^=/}{}) { o $dir_name }
+           elsif (s{^\^}{}) { o "\$(top_srcdir)${dir_suffix}" }
+           elsif (s{^\}}{}) { o "\$(abs_top_srcdir)${dir_suffix}" }
+           elsif (m{^[ \t]}) {
+               for (;;) {
+                   if (s{^[ \t]+($caps_re)}{}) {
+                       o "
+
+                   s{^
+       } else 
+       } 
+                    s{^~}{$dir_name} ||
+               
+
+[A-Z][0-9A-Z_](?!\w
+(=?)([/.~])}{}) {
+               my ($val, 
+               o $subdir;
+           } elsif (s{^[_/]}{}) {
+               o 
+    }
+}
+
+sub process_subtree ($$) {
+    # => list of descendants (in form SUBDIR/)
+    # recursive, children first
+    my ($node, $path);
+    my $dprefix = join '', map { "${_}/" } @$path;
+    my $vprefix = join '', map { "${_}_" } @$path;
+    my $subdir = @$path ? (join '/', @$path) : '.';
+    write_makefile($subdir, scalar @$path);
+
+    my %targets = qw(all 1);
+    my @child_subdirs;
+    foreach my $child (@{ $node->[1] }) {
+       my @childpath = (@$path, $child->[0]);
+       push @child_subdirs, join '/', @childpath;
+       $targets{$_}++ foreach
+           process_subtree($child, [  ]);
+    }
+    start_output_file("$subdir/Subdir.mk.tmp");
+
+    filter_subdir_mk();
+
+    $targets{$_}++ foreach
+       write_subdir($child);
+
+    my @targets = sort keys %targets;
+    foreach my $target (@targets) {
+       $vsuffix = $target eq 'all' ? '' : "_$target";
+       print O <<END;
+${dprefix}${target}: \$(${vprefix}TARGETS${vsuffix})
+END
+       if (@child_subdirs) {
+           print O "${dprefix}${target}:";
+           foreach my $child_subdir (@child_subdirs) {
+               print O " $child_subdir/$target";
+           }
+           print O "\n";
+       }
+    }
+    
+
+    foreach my $descendant (@descendants) {
+       foreach my $target (@$targets) {
+    print O <<END;
+END
+
+
 sub process_subdir ($$) {
     my ($subdir) = @_;
     my $depth = $subdir eq '.' ? 0 : scalar split m{/+}, $subdir;
@@ -45,4 +135,7 @@ sub process_subdir ($$) {
     filter_subdir_mk();
 }
 
+
+    
 build_tree();
+process_subtree($root, [ ]);