| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | my ($build_dir) = @ARGV; |
| 4 | my %include = (); |
| 5 | my %included = (); |
| 6 | |
| 7 | for my $adoc (<*.adoc>) { |
| 8 | open I, '<', $adoc || die "cannot read: $adoc"; |
| 9 | while (<I>) { |
| 10 | if (/^include::/) { |
| 11 | chomp; |
| 12 | s/^include::\s*//; |
| 13 | s/\[\]//; |
| 14 | s/{build_dir}/${build_dir}/; |
| 15 | $include{$adoc}{$_} = 1; |
| 16 | $included{$_} = 1; |
| 17 | } |
| 18 | } |
| 19 | close I; |
| 20 | } |
| 21 | |
| 22 | # Do we care about chained includes??? |
| 23 | my $changed = 1; |
| 24 | while ($changed) { |
| 25 | $changed = 0; |
| 26 | while (my ($adoc, $included) = each %include) { |
| 27 | for my $i (keys %$included) { |
| 28 | # $adoc has include::$i; if $i includes $j |
| 29 | # $adoc indirectly includes $j. |
| 30 | if (exists $include{$i}) { |
| 31 | for my $j (keys %{$include{$i}}) { |
| 32 | if (!exists $include{$adoc}{$j}) { |
| 33 | $include{$adoc}{$j} = 1; |
| 34 | $included{$j} = 1; |
| 35 | $changed = 1; |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | foreach my $adoc (sort keys %include) { |
| 44 | my $included = $include{$adoc}; |
| 45 | if (! exists $included{$adoc} && |
| 46 | (my $base = $adoc) =~ s/\.adoc$//) { |
| 47 | print "$base.html $base.xml : ", join(" ", sort keys %$included), "\n"; |
| 48 | } |
| 49 | } |