]> 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 it is a symlink to a documentation directory from the same
123         # source package, then don't do anything. Think multi-binary
124         # packages that depend on each other and want to link doc dirs.
125         if (-l "$tmp/usr/share/doc/$package") {
126                 my $linkval=readlink("$tmp/usr/share/doc/$package");
127                 my %allpackages=map { $_ => 1 } getpackages();
128                 if ($allpackages{basename($linkval)}) {
129                         next;
130                 }
131                 # Even if the target doesn't seem to be a doc dir from the
132                 # same source package, don't do anything if it's a dangling
133                 # symlink.
134                 next unless -d "$tmp/usr/share/doc/$package";
135         }
136
137         if (! -d "$tmp/usr/share/doc/$package") {
138                 doit("install","-d","$tmp/usr/share/doc/$package");
139         }
140         doit("install","-o",0,"-g",0,"-p","-m644",$changelog,
141                 "$tmp/usr/share/doc/$package/$changelog_name");
142         if (-e $news) {
143                 doit("install","-o",0,"-g",0,"-p","-m644",$news,
144                         "$tmp/usr/share/doc/$package/$news_name");
145         }
146
147         if (defined $upstream) {
148                 my $link_to;
149                 if ($upstream=~m/\.html?$/i) {
150                         # HTML changelog
151                         doit("install","-o",0,"-g",0,"-p","-m644",
152                                 $upstream,"$tmp/usr/share/doc/$package/changelog.html");
153                         doit("html2text","-nobs","-o","$tmp/usr/share/doc/$package/changelog",$upstream);
154                         $link_to='changelog.html';
155                 }
156                 else {
157                         doit("install","-o",0,"-g",0,"-p","-m644",
158                                 $upstream,"$tmp/usr/share/doc/$package/changelog");
159                         $link_to='changelog';
160                 }
161                 if ($dh{K_FLAG}) {
162                         # Install symlink to original name of the upstream changelog file.
163                         # Use basename in case original file was in a subdirectory or something.
164                         doit("ln","-sf",$link_to,"$tmp/usr/share/doc/$package/".basename($upstream));
165                 }
166         }
167 }
168
169 =head1 SEE ALSO
170
171 L<debhelper(7)>
172
173 This program is a part of debhelper.
174
175 =head1 AUTHOR
176
177 Joey Hess <joeyh@debian.org>
178
179 =cut