Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / tools / progdoc @ 6b3f1a54

History | View | Annotate | Download (1.38 KB)

1
#!/usr/bin/perl
2

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

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

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

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

    
54
sub gen_deps {
55
  open(DEP, ">", "$out.d");
56
  print DEP "$out:";
57
  foreach $f (@deps) {
58
    print DEP " \\\n  $f";
59
  }
60
  print DEP "\n\n";
61

    
62
  foreach $f (@deps) {
63
    print DEP "$f:\n\n";
64
  }
65
  close DEP;
66
}