summaryrefslogtreecommitdiff
path: root/dh_gencontrol
blob: f5944805e2a6acd2fd7a498560c75ba5c58c0e32 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/perl

=head1 NAME

dh_gencontrol - generate and install control file

=cut

use strict;
use warnings;
use Debian::Debhelper::Dh_Lib;

=head1 SYNOPSIS

B<dh_gencontrol> [S<I<debhelper options>>] [S<B<--> I<params>>]

=head1 DESCRIPTION

B<dh_gencontrol> is a debhelper program that is responsible for generating
control files, and installing them into the I<DEBIAN> directory with the
proper permissions.

This program is merely a wrapper around L<dpkg-gencontrol(1)>, which
calls it once for each package being acted on (plus related ddebs),
and passes in some additional useful flags.

B<Note> that if you use B<dh_gencontrol>, you must also use
L<dh_builddeb(1)> to build the packages.  Otherwise, your build may
fail to build as B<dh_gencontrol> (via L<dpkg-gencontrol(1)>) declares
which packages are built.  As debhelper automatically generates ddebs,
it some times adds additional packages, which will be built by L<dh_builddeb(1)>.


=head1 OPTIONS

=over 4

=item B<--> I<params>

Pass I<params> to L<dpkg-gencontrol(1)>.

=item B<-u>I<params>, B<--dpkg-gencontrol-params=>I<params>

This is another way to pass I<params> to L<dpkg-gencontrol(1)>.
It is deprecated; use B<--> instead.

=back

=cut

init(options => {
	"dpkg-gencontrol-params=s", => \$dh{U_PARAMS},
});


my $src_pkg;

foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmp=tmpdir($package);
	my $ext=pkgext($package);
	my $ddeb_info_dir = "debian/.debhelper/${package}";
	my $ddeb_tmp = "${ddeb_info_dir}/ddeb-root";

	my $substvars="debian/${ext}substvars";
	
	my $changelog=pkgfile($package,'changelog');
	if (! $changelog) {
		$changelog='debian/changelog';
	}

	if ( ! -d "$tmp/DEBIAN" ) {
		install_dir("$tmp/DEBIAN");
	}

	# avoid gratuitous warning
	if (! -e $substvars || system("grep -q '^misc:Depends=' $substvars") != 0) {
		complex_doit("echo misc:Depends= >> $substvars");
	}
	# avoid (another) gratuitous warning
	if (! -e $substvars || system("grep -q '^misc:Pre-Depends=' $substvars") != 0) {
		complex_doit("echo misc:Pre-Depends= >> $substvars");
	}
	

	if ( -d $ddeb_tmp) {
		my $multiarch = package_multiarch($package);
		my $replaces = read_ddeb_migration($ddeb_info_dir);
		$src_pkg = sourcepackage() if not defined($src_pkg);

		# Remove and override more or less every standard field.
		my @ddeb_options = (qw(
			-UPre-Depends -URecommends -USuggests -UEnhances -UProvides -UEssential
			-UConflicts -DPriority=extra -DSection=debugsym
			),
			 "-DPackage=${package}-dbgsym",
			 "-DDepends=${package} (= \${binary:Version})",
			 "-DDescription=Debug symbols for ${package}",
			 "-DSource=${src_pkg}",
		);
		# Disable multi-arch unless the original package is an
		# multi-arch: same package.  In all other cases, we do not
		# need a multi-arch value.
		if ($multiarch ne 'same') {
			push(@ddeb_options, '-UMulti-Arch');
		}
		# If the ddeb is replacing an existing -dbg package, then
		# declare the necessary Breaks + Replaces.  Otherwise, clear
		# the fields.
		if ($replaces) {
			push(@ddeb_options, "-DReplaces=${replaces}",
				 "-DBreaks=${replaces}");
		} else {
			push(@ddeb_options, '-UReplaces', '-UBreaks');
		}
		if ( ! -d "${ddeb_tmp}/DEBIAN" ) {
			install_dir("${ddeb_tmp}/DEBIAN");
		}
		doit("dpkg-gencontrol", "-p${package}", "-l$changelog", "-T$substvars",
			"-P${ddeb_tmp}",@{$dh{U_PARAMS}}, @ddeb_options);

		doit("chmod","0644","${ddeb_tmp}/DEBIAN/control");
		doit("chown","0:0","${ddeb_tmp}/DEBIAN/control");
	}

	# Generate and install control file.
	doit("dpkg-gencontrol", "-p$package", "-l$changelog", "-T$substvars",
		"-P$tmp",@{$dh{U_PARAMS}});

	# This chmod is only necessary if the user sets the umask to
	# something odd.
	doit("chmod","0644","$tmp/DEBIAN/control");
	
	doit("chown","0:0","$tmp/DEBIAN/control");
}

sub read_ddeb_migration {
	my ($ddeb_info_dir) = @_;
	my $ddeb_migration = "${ddeb_info_dir}/ddeb-migration";
	my $result;
	if (-f $ddeb_migration) {
		open(my $fd, '<', $ddeb_migration)
			or error("open $ddeb_migration failed: $!");
		chomp($result = <$fd>);
		close($fd);
	}
	return $result;
}

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of debhelper.

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut

# Local Variables:
# indent-tabs-mode: t
# tab-width: 4
# cperl-indent-level: 4
# End: