Git fork
1#!/usr/bin/perl
2
3my ($build_dir) = @ARGV;
4my %include = ();
5my %included = ();
6
7for 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???
23my $changed = 1;
24while ($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
43foreach 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}