]> git.donarmstrong.com Git - debhelper.git/blob - dh_installchangelogs
r594: * dh_installchangelogs: Install debian/NEWS as NEWS.Debian, even for native
[debhelper.git] / dh_installchangelogs
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installchangelogs - install changelogs into package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_installchangelogs> [<S<I<debhelper options>>] [B<-k>] [I<upstream>]
15
16 =head1 DESCRIPTION
17
18 dh_installchangelogs is a debhelper program that is responsible for
19 installing changelogs into package build directories.
20
21 dh_installchangelogs determines if the package is a debian native package,
22 and if so, it installs debian/changelog into usr/share/doc/package/changelog
23 in the package build directory. Otherwise, it installs debian/changelog
24 into usr/share/doc/package/changelog.Debian in the package build directory. (If
25 files named debian/package.changelog exist, they will be used in preference
26 to debian/changelog.)
27
28 Parallelling the debian changelog handling, this program also takes care of
29 NEWS.Debian files. If there is a debian/NEWS file, it is installed as
30 usr/share/doc/package/NEWS.Debian. debian/package.NEWS files can also be
31 used.
32
33 If an upstream changelog file is specified as an option, and the package is
34 not a native debian package, then this upstream changelog will be installed
35 as usr/share/doc/package/changelog in the package build directory. If the
36 changelog is a html file (determined by file extension), it will be
37 installed as usr/share/doc/package/changelog.html instead, and will be
38 converted to plain text with html2text to generate
39 usr/share/doc/package/changelog.
40
41 =head1 OPTIONS
42
43 =over 4
44
45 =item B<-k>, B<--keep>
46
47 Keep the original name of the upstream changelog. This will be accomplished
48 by installing the upstream changelog as "changelog", and making a symlink from
49 that to the original name of the changelog file. This can be useful if the
50 upstream changelog has an unusual name, or if other documentation in the
51 package refers to the changelog file.
52
53 =item I<upstream>
54
55 Install this file as the upstream changelog.
56
57 =back
58
59 =head1 NOTES
60
61 It is an error to specify an upstream changelog file for a debian native
62 package.
63
64 =cut
65
66 init();
67
68 my $upstream=shift;
69
70 if (isnative($dh{MAINPACKAGE}) && defined $upstream) {
71         error("Cannot specify an upstream changelog for a native debian package.");
72 }
73
74 my $changelog_name="changelog.Debian";
75 if (isnative($dh{MAINPACKAGE})) {
76         $changelog_name='changelog';
77 }
78 my $news_name="NEWS.Debian";
79
80 foreach my $package (@{$dh{DOPACKAGES}}) {
81         my $tmp=tmpdir($package);
82         my $changelog=pkgfile($package,"changelog");
83         my $news=pkgfile($package,"NEWS");
84
85         if (!$changelog) {
86                 $changelog="debian/changelog";
87         }
88         if (!$news) {
89                 $news="debian/NEWS";
90         }
91
92         if (! -e $changelog) {
93                 error("could not find changelog $changelog");
94         }
95
96         if (! -d "$tmp/usr/share/doc/$package") {
97                 # If it is a dangling symlink, then don't do anything.
98                 # Think multi-binary packages that depend on each other and
99                 # want to link doc dirs.
100                 next if -l "$tmp/usr/share/doc/$package";
101
102                 doit("install","-d","$tmp/usr/share/doc/$package");
103         }
104         doit("install","-o",0,"-g",0,"-p","-m644",$changelog,
105                 "$tmp/usr/share/doc/$package/$changelog_name");
106         if (-e $news) {
107                 doit("install","-o",0,"-g",0,"-p","-m644",$news,
108                         "$tmp/usr/share/doc/$package/$news_name");
109         }
110
111         if ($upstream) {
112                 my $link_to;
113                 if ($upstream=~m/\.html?$/i) {
114                         # HTML changelog
115                         doit("install","-o",0,"-g",0,"-p","-m644",
116                                 $upstream,"$tmp/usr/share/doc/$package/changelog.html");
117                         doit("html2text","-nobs","-o","$tmp/usr/share/doc/$package/changelog",$upstream);
118                         $link_to='changelog.html';
119                 }
120                 else {
121                         doit("install","-o",0,"-g",0,"-p","-m644",
122                                 $upstream,"$tmp/usr/share/doc/$package/changelog");
123                         $link_to='changelog';
124                 }
125                 if ($dh{K_FLAG}) {
126                         # Install symlink to original name of the upstream changelog file.
127                         # Use basename in case original file was in a subdirectory or something.
128                         doit("ln","-sf",$link_to,"$tmp/usr/share/doc/$package/".basename($upstream));
129                 }
130         }
131 }
132
133 =head1 SEE ALSO
134
135 L<debhelper(7)>
136
137 This program is a part of debhelper.
138
139 =head1 AUTHOR
140
141 Joey Hess <joeyh@debian.org>
142
143 =cut