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