progdoc 1.41 KB
Newer Older
1 2 3
#!/usr/bin/perl

$srcdir = $ARGV[0];
4
$out = $ARGV[1];
5

6
open(OUT, ">", $out) || die "Cannot create output file";
7
process($srcdir, "doc/prog-root");
8
close OUT;
9
gen_deps();
10 11
exit 0;

12 13
sub include {
  my $f = shift @_;
14 15
  open(IN, "$f") || die "Unable to find $f";
  push(@deps, "$f");
16 17 18 19 20 21
  while (<IN>) {
    print OUT;
  }
  close IN;
}

22 23
sub process {
  my $dir = shift @_;
24 25 26 27
  my $doc = "$dir/" . shift @_;
  print "$doc\n";
  open(IN, $doc) || die "Unable to read $doc";
  push(@deps, $doc);
28 29 30 31 32
  my @docfile = <IN>;
  close IN;
  foreach $_ (@docfile) {
    chomp;
    /^#/ && next;
33 34 35
    /^([A-Z]+)\s*(.*)/ || die "Parse error: $_";
    $cmd = $1;
    $arg = $2;
36
    if ($cmd eq "C") { process("$dir/$arg", "Doc"); }
37 38
    elsif ($cmd eq "H") {
      push @stack, "H";
39
      print OUT "<chapt>$arg\n";
40 41
    } elsif ($cmd eq "S") {
      print "    $arg\n";
42 43 44 45
      my @files = map("$dir/$_", split(' ', $arg));
      my $fargs = join(' ', @files);
      open(DOC, "$srcdir/doc/kernel-doc -bird $fargs |") || die "Unable to start kernel-doc";
      push(@deps, @files);
46
      while (<DOC>) { print OUT; }
47
      close DOC;
48 49
    } elsif ($cmd eq "D") {
      print "    $arg\n";
50
      include("$dir/$arg");
51 52 53
    } else { die "Unknown command: $cmd"; }
  }
}
54 55 56 57 58 59 60 61 62 63 64 65 66 67

sub gen_deps {
  open(DEP, ">", "$out.d");
  print DEP "$out:";
  foreach $f (@deps) {
    print DEP " \\\n  $f";
  }
  print DEP "\n\n";

  foreach $f (@deps) {
    print DEP "$f:\n\n";
  }
  close DEP;
}