]> git.donarmstrong.com Git - debhelper.git/blob - dh_installchangelogs
Merge branch 'master' of ssh://git.debian.org/git/debhelper/debhelper
[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>] [B<-X>I<item>] [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 An upstream changelog file may be specified as an option. If none is
22 specified, a few common filenames are tried. (In compatibility level 7 and
23 above.)
24
25 If there is an upstream changelog file, it will be be installed as
26 usr/share/doc/package/changelog in the package build directory. If the
27 changelog is a html file (determined by file extension), it will be
28 installed as usr/share/doc/package/changelog.html instead, and will be
29 converted to plain text with html2text to generate
30 usr/share/doc/package/changelog.
31
32 =head1 FILES
33
34 =over 4
35
36 =item debian/changelog
37
38 =item debian/NEWS
39
40 =item debian/I<package>.changelog
41
42 =item debian/I<package>.NEWS
43
44 Automatically installed into usr/share/doc/I<package>/
45 in the package build directory.
46
47 Use the package specific name if I<package> needs a different
48 NEWS or changelog file.
49
50 The changelog file is installed with a name of changelog
51 for native packages, and changelog.Debian for non-native packages.
52 The NEWS file is always installed with a name of NEWS.Debian.
53
54 =back
55
56 =head1 OPTIONS
57
58 =over 4
59
60 =item B<-k>, B<--keep>
61
62 Keep the original name of the upstream changelog. This will be accomplished
63 by installing the upstream changelog as "changelog", and making a symlink from
64 that to the original name of the changelog file. This can be useful if the
65 upstream changelog has an unusual name, or if other documentation in the
66 package refers to the changelog file.
67
68 =item B<-Xitem>, B<--exclude=item>
69
70 Exclude upstream changelog files that contain "item" anywhere in their
71 filename from being installed.
72
73 =item I<upstream>
74
75 Install this file as the upstream changelog.
76
77 =back
78
79 =cut
80
81 init();
82
83 my $upstream=shift;
84 my $changelog_name="changelog.Debian";
85 if (! defined $upstream) {
86         if (! isnative($dh{MAINPACKAGE}) && !compat(6)) {
87                 my @files=sort glob("*");
88                 foreach my $name (qw{changelog changes changelog.txt changes.txt}) {
89                         my @matches=grep {
90                                 lc $_ eq $name && -s $_ && ! excludefile($_)
91                         } @files;
92                         if (@matches) {
93                                 $upstream=shift @matches;
94                                 last;
95                         }
96                 }
97         }
98         if (isnative($dh{MAINPACKAGE})) {
99                 $changelog_name='changelog';
100         }
101 }
102 my $news_name="NEWS.Debian";
103
104 foreach my $package (@{$dh{DOPACKAGES}}) {
105         next if is_udeb($package);
106         
107         my $tmp=tmpdir($package);
108         my $changelog=pkgfile($package,"changelog");
109         my $news=pkgfile($package,"NEWS");
110
111         if (!$changelog) {
112                 $changelog="debian/changelog";
113         }
114         if (!$news) {
115                 $news="debian/NEWS";
116         }
117
118         if (! -e $changelog) {
119                 error("could not find changelog $changelog");
120         }
121
122         if (! -d "$tmp/usr/share/doc/$package") {
123                 # If it is a dangling symlink, then don't do anything.
124                 # Think multi-binary packages that depend on each other and
125                 # want to link doc dirs.
126                 next if -l "$tmp/usr/share/doc/$package";
127
128                 doit("install","-d","$tmp/usr/share/doc/$package");
129         }
130         doit("install","-o",0,"-g",0,"-p","-m644",$changelog,
131                 "$tmp/usr/share/doc/$package/$changelog_name");
132         if (-e $news) {
133                 doit("install","-o",0,"-g",0,"-p","-m644",$news,
134                         "$tmp/usr/share/doc/$package/$news_name");
135         }
136
137         if (defined $upstream) {
138                 my $link_to;
139                 if ($upstream=~m/\.html?$/i) {
140                         # HTML changelog
141                         doit("install","-o",0,"-g",0,"-p","-m644",
142                                 $upstream,"$tmp/usr/share/doc/$package/changelog.html");
143                         doit("html2text","-nobs","-o","$tmp/usr/share/doc/$package/changelog",$upstream);
144                         $link_to='changelog.html';
145                 }
146                 else {
147                         doit("install","-o",0,"-g",0,"-p","-m644",
148                                 $upstream,"$tmp/usr/share/doc/$package/changelog");
149                         $link_to='changelog';
150                 }
151                 if ($dh{K_FLAG}) {
152                         # Install symlink to original name of the upstream changelog file.
153                         # Use basename in case original file was in a subdirectory or something.
154                         doit("ln","-sf",$link_to,"$tmp/usr/share/doc/$package/".basename($upstream));
155                 }
156         }
157 }
158
159 =head1 SEE ALSO
160
161 L<debhelper(7)>
162
163 This program is a part of debhelper.
164
165 =head1 AUTHOR
166
167 Joey Hess <joeyh@debian.org>
168
169 =cut