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
|
#! /usr/bin/perl
# gen_contents_index, written for Debian by Kari Pahula
# Copyright 2009 Kari Pahula
# Licensed under BSD3, see /usr/share/common-licenses/BSD
my @ifaces;
my %pkgs;
# Only do something if we actually have /usr/share/doc
exit 0 unless (-d "/usr/share/doc/ghc-doc/html/libraries/" and -r "/usr/share/doc/ghc-doc/html/libraries/prologue.txt");
# Add everything from the global Cabal registry to index.
if (-e '/usr/bin/ghc-pkg') {
open CABAL, 'ghc-pkg dump --global |' or warn "ghc-pkg dump failed: $!";
addInfo (\*CABAL, \%pkgs, \@ifaces);
close CABAL;
}
exec ('haddock', '--gen-index', '--gen-contents',
'-o', '/usr/share/doc/ghc-doc/html/libraries/',
'-t'. 'Haskell Hierarchical Libraries',
'-p', '/usr/share/doc/ghc-doc/html/libraries/prologue.txt',
@ifaces);
sub addInfo {
my $fh = shift;
my %dat;
while (<$fh>) {
if (/^name: (.*)/) {
$dat{pkg} = $1;
} elsif (/^version: (.*)/) {
$dat{ver} = $1;
} elsif (/^haddock-interfaces: (.*)/) {
$dat{ifaces} = $1;
} elsif (/^haddock-html: (.*)/) {
$dat{html} = $1;
} elsif (/^---/) {
process(\%dat, @_);
%dat = ();
}
}
process(\%dat, @_);
}
sub process {
my $dat = shift;
my $pkgs = shift;
my $ifaces = shift;
my $path;
return undef if $$dat{pkg} eq 'ghc';
my $p = $$dat{pkg}.'-'.$$dat{ver};
return undef if (exists $$pkgs{$p});
if ($$dat{html} =~ m,^/usr/share/doc/ghc-doc/html/libraries/(.*),) {
$path = $1;
} elsif ($$dat{html} =~ m,^/usr/share/doc/([^/]*-doc/html/.*),) {
$path = "../../../$1";
}
if (defined $path && -r $$dat{ifaces}) {
$$pkgs{$p} = 1;
push @ifaces, "--read-interface=$path,$$dat{ifaces}";
}
}
|