X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?p=subdirmk.git;a=blobdiff_plain;f=build-aux%2Fsubdirmk-setup;h=c1866f6bcb29ae5f48858a6c3353e691972046dd;hp=9f3c8c62a43ae7858af834a8595db26e7c245d38;hb=a423046ad42c0fbdf7fd3afad88dfe57dfbd30ca;hpb=3fc89ce9c0395620a92340e8290c18e156ca367e diff --git a/build-aux/subdirmk-setup b/build-aux/subdirmk-setup index 9f3c8c6..c1866f6 100644 --- a/build-aux/subdirmk-setup +++ b/build-aux/subdirmk-setup @@ -8,25 +8,41 @@ use strict; -our @allsubdirs = @ARGV; +our $root = [ '.', [ ] ]; +# each node is [ 'relative subdir name', \@children ] -sub write_makefile () { +sub build_tree () { + foreach my $subdir (@ARGV) { + my @path = $subdir eq '.' ? () : split m{/+}, $subdir; + my $node = $root; + foreach my $d (@path) { + my ($c,) = grep { $_->[0] eq $d } @{ $node->[1] }; + if (!$c) { + $c = [ $d, [ ] ]; + push @{ $node->[1] }, $c; + } + $node = $c; + } + } +} + + + +sub write_makefile ($$) { + my ($subdir,$depth) = @_; start_output_file("Makefile"); + my $cd = $depth ? join('/', ('..',) x $depth) : '.'; print O <