]> git.ipfire.org Git - thirdparty/bird.git/blame - tools/progdoc
Merge remote-tracking branch 'origin/master' into mq-filter-stack
[thirdparty/bird.git] / tools / progdoc
CommitLineData
c7d7794b
MM
1#!/usr/bin/perl
2
3$srcdir = $ARGV[0];
7152e5ef 4$out = $ARGV[1];
c7d7794b 5
7152e5ef 6open(OUT, ">", $out) || die "Cannot create output file";
1e0fccd1 7process($srcdir, "doc/prog-root");
c7d7794b 8close OUT;
7152e5ef 9gen_deps();
c7d7794b
MM
10exit 0;
11
6be13de7
MM
12sub include {
13 my $f = shift @_;
7152e5ef
JMM
14 open(IN, "$f") || die "Unable to find $f";
15 push(@deps, "$f");
6be13de7
MM
16 while (<IN>) {
17 print OUT;
18 }
19 close IN;
20}
21
c7d7794b
MM
22sub process {
23 my $dir = shift @_;
1e0fccd1
OZ
24 my $doc = "$dir/" . shift @_;
25 print "$doc\n";
26 open(IN, $doc) || die "Unable to read $doc";
27 push(@deps, $doc);
c7d7794b 28 my @docfile = <IN>;
c7d7794b 29 close IN;
c7d7794b
MM
30 foreach $_ (@docfile) {
31 chomp;
32 /^#/ && next;
6be13de7
MM
33 /^([A-Z]+)\s*(.*)/ || die "Parse error: $_";
34 $cmd = $1;
35 $arg = $2;
3a2a3c73 36 if ($cmd eq "C") { process("$dir/$arg", "Doc"); }
c7d7794b
MM
37 elsif ($cmd eq "H") {
38 push @stack, "H";
371adba6 39 print OUT "<chapt>$arg\n";
c7d7794b
MM
40 } elsif ($cmd eq "S") {
41 print " $arg\n";
7152e5ef
JMM
42 my @files = map("$dir/$_", split(' ', $arg));
43 my $fargs = join(' ', @files);
44 open(DOC, "$srcdir/doc/kernel-doc -bird $fargs |") || die "Unable to start kernel-doc";
45 push(@deps, @files);
6be13de7 46 while (<DOC>) { print OUT; }
c7d7794b 47 close DOC;
6be13de7
MM
48 } elsif ($cmd eq "D") {
49 print " $arg\n";
42b3daa0 50 include("$dir/$arg");
c7d7794b
MM
51 } else { die "Unknown command: $cmd"; }
52 }
53}
7152e5ef
JMM
54
55sub gen_deps {
56 open(DEP, ">", "$out.d");
57 print DEP "$out:";
58 foreach $f (@deps) {
59 print DEP " \\\n $f";
60 }
61 print DEP "\n\n";
62
63 foreach $f (@deps) {
64 print DEP "$f:\n\n";
65 }
66 close DEP;
67}