X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?p=subdirmk.git;a=blobdiff_plain;f=build-aux%2Fsubdirmk-setup;h=1de88302fbd546bcf6efebf5066c8094ff6e96fa;hp=c1866f6bcb29ae5f48858a6c3353e691972046dd;hb=d0e8af365b964715b605cd4c81ca179c9208d9f9;hpb=d952e6bb30f6bfb1f1100a6b8ec263fc08073d51 diff --git a/build-aux/subdirmk-setup b/build-aux/subdirmk-setup index c1866f6..1de8830 100644 --- a/build-aux/subdirmk-setup +++ b/build-aux/subdirmk-setup @@ -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 <) { + 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 <