chiark / gitweb /
generate: Handle nodes with no own Subdir.sd.mk
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Dec 2019 19:52:10 +0000 (19:52 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Dec 2019 22:19:08 +0000 (22:19 +0000)
If a directory is not mentioned on the command line, we would assume
it had a Subdir.sd.mk anyway.  Instead, expect it not to have one.

We do still generate a per-subdirectory fragment for such unmentioned
nodes: this serves to wire its children ino the parent, make running
`make' in that directory possible, etc.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
generate

index fe3e3f5866674bcf17fa69ea6addaba1225cb3bb..14deda4e281dc35c42272019a76af253bec22b3e 100755 (executable)
--- a/generate
+++ b/generate
@@ -32,8 +32,8 @@ our @subdirs = @ARGV;
 
 s{/+$}{} foreach @subdirs;
 
-our $root = [ '.', [ ] ];
-# each node is [ 'relative subdir name', \@children ]
+our $root = [ '.', [ ], 1 ];
+# each node is [ 'relative subdir name', \@children, $mentioned ]
 
 sub build_tree () {
     foreach my $subdir (@subdirs) {
@@ -47,6 +47,7 @@ sub build_tree () {
            }
            $node = $c;
        }
+       $node->[2] = 1;
     }
 }
 
@@ -244,8 +245,18 @@ sub process_subtree ($$) {
     }
     start_output_file("${dir_prefix}Subdir.mk.tmp");
 
-    filter_subdir_mk($dir_prefix, $dir_suffix, $dir_name,
-                    $var_prefix, \%targets);
+    if ($node->[2]) {
+       filter_subdir_mk($dir_prefix, $dir_suffix, $dir_name,
+                        $var_prefix, \%targets);
+    } else {
+       my $sdmk = "${dir_prefix}Subdir.sd.mk";
+       if (stat $sdmk) {
+           die "$sdmk unexpectedly exists (${dir_prefix} not mentioned)";
+       } elsif ($!==ENOENT) {
+       } else {
+           die "stat $sdmk: $!";
+       }
+    }
 
     o "\n";