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

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

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

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;
}