summaryrefslogtreecommitdiff
path: root/tools/progdoc
blob: 9b27d14e84e18e160c5c916e7fac799b6bf1d23a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl

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

open(OUT, ">", $out) || die "Cannot create output file";
process($srcdir);
close OUT;
gen_deps();
exit 0;

sub include {
  my $f = shift @_;
  open(IN, "$f") || die "Unable to find $f";
  push(@deps, "$f");
  while (<IN>) {
    print OUT;
  }
  close IN;
}

sub process {
  my $dir = shift @_;
  print "$dir/progdoc\n";
  open(IN, "$dir/progdoc") || die "Unable to read $dir/progdoc";
  push(@deps, "$dir/progdoc");
  my @docfile = <IN>;
  close IN;
  foreach $_ (@docfile) {
    chomp;
    /^#/ && next;
    /^([A-Z]+)\s*(.*)/ || die "Parse error: $_";
    $cmd = $1;
    $arg = $2;
    if ($cmd eq "C") { process("$dir/$arg"); }
    elsif ($cmd eq "H") {
      push @stack, "H";
      print OUT "<chapt>$arg\n";
    } elsif ($cmd eq "S") {
      print "    $arg\n";
      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);
      while (<DOC>) { print OUT; }
      close DOC;
    } elsif ($cmd eq "D") {
      print "    $arg\n";
      include("$dir/$arg");
    } else { die "Unknown command: $cmd"; }
  }
}

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