summaryrefslogtreecommitdiff
path: root/dh_installchangelogs
blob: e14eba68b3f700e8e706c95a726c3a1a590c326f (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
69
#!/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 Debian::Debhelper::Dh_Lib;
init();

$upstream=shift;

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

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

foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
	$TMP=tmpdir($PACKAGE);
	$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/".Debian::Debhelper::Dh_Lib::basename($upstream));
		}
	}
}