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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
#!/usr/bin/perl
# Copyright © 2011 Jakub Wilk <jwilk@debian.org>
# Copyright © 2013 Helmut Grohne <helmut@subdivi.de>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=head1 NAME
dh_doxygen - helps with packaging doxygen-generated documentation
=head1 SYNOPSIS
dh_doxygen [S<I<debhelper options>>] [B<-X>I<item>] [I<directory>...]
=head1 DESCRIPTION
B<dh_doxygen> is a debhelper program that prepares doxygen-generated
documentation for inclusion in a Debian package. More specifically:
=over 4
=item *
It replaces known F<*.js> files with symlinks to F</usr/share/javascript/>
and generates B<${doxygen:Depends}> substitution variable.
=item *
It removes F<*.md5> and F<*.map> files. These are created by doxygen to speed
up incremental runs.
=item *
It generates a B<${doxygen:Built-Using}> substitution variable.
=back
=head1 OPTIONS
=over 4
=item I<directory>
By default, B<dh_doxygen> scans your package looking for directories looking
like they contain doxygen-generated documentation. However, if you explicitly
provide one or more directories, only they will be processed.
=item B<-X>I<item>, B<--exclude=>I<item>
Exclude files that contain I<item> anywhere in their filename from
being symlinked, removed or checked for existence.
=back
=head1 BUGS
Probably.
=cut
use strict;
use warnings;
use File::Find;
use Debian::Debhelper::Dh_Lib;
sub looks_like_doxygen_doc($)
{
my ($path) = @_;
return 0 unless -f "$path/doxygen.css";
return 0 unless -f "$path/doxygen.png";
return 0 unless -f "$path/index.html";
return 1;
}
sub ln_sf($$)
{
my ($orig_target, $orig_source) = my ($target, $source) = @_;
$source =~ s{^debian/[^/]++/+}{} or die;
$target =~ s{^/++}{} or die;
my @source = split(m{/++}, $source);
my @target = split(m{/++}, $target);
@source > 0 and @target > 0 or die;
if ($source[0] eq $target[0])
{
# Make the symlink relative, as per Policy 10.5.
while (@source > 0 and @target > 0 and $source[0] eq $target[0])
{
shift @source;
shift @target;
}
$target = ('../' x $#source) . join('/', @target);
}
else
{
# Keep the symlink absolute, as per Policy 10.5.
$target = $orig_target;
}
doit('ln', '-sf', $target, $orig_source);
}
sub fix_symlinks($)
{
my %deps = ();
my ($path) = @_;
if(-f "$path/jquery.js") {
ln_sf("/usr/share/javascript/jquery/jquery.js", "$path/jquery.js");
$deps{"libjs-jquery"} = 1;
}
return keys %deps;
}
sub drop_cruft($)
{
my ($path) = @_;
my $find_options = "";
if(defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '')
{
$find_options = "! \\( $dh{EXCLUDE_FIND} \\) -a";
}
complex_doit("find $path $find_options -type f -a \\
\\( -name '*.md5' -o -name '*.map' \\) -delete");
}
sub fix_doxygen_doc($$)
{
my ($package, $path) = @_;
return 0 if not looks_like_doxygen_doc($path);
my @deps = fix_symlinks($path);
drop_cruft($path);
map { addsubstvar($package, "doxygen:Depends", $_) } @deps;
my $doxygen_version = `dpkg-query -W -f '\${Source:Version}' doxygen`;
$doxygen_version or die("failed to query version of installed doxygen");
addsubstvar($package, "doxygen:Built-Using", "doxygen (= $doxygen_version)");
return 1;
}
init();
my @paths = @ARGV;
@paths = (undef) unless @paths;
foreach my $path (@paths)
{
my $done = 0;
foreach my $package (@{$dh{DOPACKAGES}})
{
my $pkgpath = tmpdir($package);
if (defined $path)
{
next if -l $path;
$pkgpath .= "/$path";
$done += fix_doxygen_doc($package, $pkgpath);
}
else
{
$pkgpath .= '/usr/share/doc/';
next unless -d $pkgpath;
find({
wanted => sub {
return unless -d;
return if -l;
return if excludefile($_);
$done += fix_doxygen_doc($package, $_);
},
no_chdir => 1
}, $pkgpath);
}
}
if ($done == 0)
{
my $message = 'Doxygen documentation not found';
$message .= " at $path" if defined $path;
error($message);
}
}
=head1 SEE ALSO
L<debhelper(7)>, L<dh(1)>.
This program is meant to be used together with debhelper.
=head1 AUTHORS
Jakub Wilk <jwilk@debian.org>
Helmut Grohne <helmut@subdivi.de>
=cut
# vim:ts=4 sw=4 et
|