chiark / gitweb /
BFORE NOT QUAD
[subdirmk.git] / build-aux / subdirmk-setup
index 6822fe12aa27d8d285b1775dbbc7bbebcd242ad9..11d0f26c8b131d459951ec3a393accf47ae7b7d3 100644 (file)
@@ -10,14 +10,27 @@ use strict;
 
 our @allsubdirs = @ARGV;
 
-sub write_makefile () {
+sub write_makefile ($$) {
+    my ($subdir,$depth)
     start_output_file("Makefile");
+    my $cd = $depth ? join('/', ('..',) x $depth) : '.';
     print O <<END;
+# autogenerated - do not edit
 %:
-       $(MAKE) -C @top $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(
 
-    my @thesedirs = $subdir, grep { $_ =~ m{^$subdir/} } @allsubdirs;
+       $subdir, grep { $_ =~ m{^$subdir/} } 
     printf O "include $_/Subdir.mk"
        
 
@@ -26,7 +39,7 @@ sub process_subdir ($$) {
     my ($subdir) = @_;
     my $depth = $subdir eq '.' ? 0 : scalar split m{/+}, $subdir;
     write_makefile($subdir,$depth);
-    filter_subdir_mk();
+    require_subdir($subdir);
 }
 
 foreach (@allsubdirs) { process_subdir($_); }