use strict;
-our $root = [ '.', [ ] ];
-# each node is [ 'relative subdir name', \@children ]
-
-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;
- }
- }
-}
-
-
+our @allsubdirs = @ARGV;
sub write_makefile ($$) {
- my ($subdir,$depth) = @_;
+ my ($subdir,$depth)
start_output_file("Makefile");
my $cd = $depth ? join('/', ('..',) x $depth) : '.';
print O <<END;
+# autogenerated - do not edit
%:
- $(MAKE) -C $cd $subdir/$@
+ \$(MAKE) -C $cd $subdir/\$@
END
}
+sub require_subdir ($) {
+ # => list of descendant subdirs
+ my ($here) = (@_);
+ my $prefix = $here eq '.' ? qr{} : qr{$prefix/};
+ my @children = grep { m{^$prefix[^/]+$} } @allsubdirs;
+ my @descendants;
+ foreach my $child (@children) {
+ push @descendants, require_subdir(
+
+ $subdir, grep { $_ =~ m{^$subdir/} }
+ printf O "include $_/Subdir.mk"
+
+
+
sub process_subdir ($$) {
my ($subdir) = @_;
my $depth = $subdir eq '.' ? 0 : scalar split m{/+}, $subdir;
write_makefile($subdir,$depth);
- filter_subdir_mk();
+ require_subdir($subdir);
}
-build_tree();
+foreach (@allsubdirs) { process_subdir($_); }