summaryrefslogtreecommitdiff
path: root/dh_installchangelogs
blob: 2a82442b12fe8c2554cc9257222b3d2f7e07faaa (plain)
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
#!/usr/bin/perl -w
#
# Installs debian/changelog. If another filename is passed to it, installs
# that file as the upstream changelog.
#
# Looks at debian/control to determine if this is a native debian package,
# if so, the debian changelog is just installed as "changelog", and it is an 
# error to specify an upstream changelog on the command line.

use strict;
use Debian::Debhelper::Dh_Lib;
init();

my $upstream=shift;

if (isnative($dh{MAINPACKAGE}) && defined $upstream) {
	error("Cannot specify an upstream changelog for a native debian package.");
}

my $changelog_name="changelog.Debian";
if (isnative($dh{MAINPACKAGE})) {
	$changelog_name='changelog';
}

foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmp=tmpdir($package);
	my $changelog=pkgfile($package,"changelog");

	if (!$changelog) {
		$changelog="debian/changelog";
	}

	if (! -e $changelog) {
		error("could not find changelog $changelog");
	}

	if (! -d "$tmp/usr/share/doc/$package") {
		# If it is a dangling symlink, then don't do anything.
		# Think multi-binary packages that depend on each other and
		# want to link doc dirs.
		next if -l "$tmp/usr/share/doc/$package";

		doit("install","-d","$tmp/usr/share/doc/$package");
	}
	doit("install","-o",0,"-g",0,"-p","-m644",$changelog,
		"$tmp/usr/share/doc/$package/$changelog_name");

	if ($upstream) {
		my $link_to;
		if ($upstream=~m/\.html?$/i) {
			# HTML changelog
			doit("install","-o",0,"-g",0,"-p","-m644",
				$upstream,"$tmp/usr/share/doc/$package/changelog.html");
			complex_doit("lynx -dump $upstream > $tmp/usr/share/doc/$package/changelog");
			$link_to='changelog.html';
		}
		else {
			doit("install","-o",0,"-g",0,"-p","-m644",
				$upstream,"$tmp/usr/share/doc/$package/changelog");
			$link_to='changelog';
		}
		if ($dh{K_FLAG}) {
			# Install symlink to original name of the upstream changelog file.
			# Use basename in case original file was in a subdirectory or something.
			doit("ln","-sf",$link_to,"$tmp/usr/share/doc/$package/".basename($upstream));
		}
	}
}