| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
dh_ppp - calculate ppp dependencies |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
use strict; |
| 10 |
use warnings; |
| 11 |
use Debian::Debhelper::Dh_Lib; |
| 12 |
use Dpkg::Shlibs::Objdump; |
| 13 |
use File::Find; |
| 14 |
|
| 15 |
=head1 SYNOPSIS |
| 16 |
|
| 17 |
B<dh_ppp> [S<I<debhelper options>>] [B<--breaks>] [B<--force>] [B<--plugin-dir>] |
| 18 |
|
| 19 |
=head1 DESCRIPTION |
| 20 |
|
| 21 |
B<dh_ppp> is a debhelper program that adds appropriate ppp dependencies on |
| 22 |
packages that build pppd plugins. |
| 23 |
|
| 24 |
By default, some entries are added to B<misc:Depends> that ensure that |
| 25 |
packages which contain plugins that are loaded into pppd depend on an |
| 26 |
appropriate version of the ppp package. |
| 27 |
|
| 28 |
You may prefer to use a B<Breaks> relationship instead, for example if your |
| 29 |
package supplies a pppd plugin but does not require it for normal operation. In |
| 30 |
that case you should supply the B<--breaks> option and B<misc:Breaks> will be |
| 31 |
populated instead of B<misc:Depends>. |
| 32 |
|
| 33 |
Substvars entries are only added if a pppd plugin is detected in the build |
| 34 |
products, unless B<--force> is specified. Plugins are detected by searching a |
| 35 |
package's build products for libraries with a symbol named B<plugin_init>. |
| 36 |
|
| 37 |
A warning is emitted if a plugin is found that does not also contain a |
| 38 |
B<pppd_version> symbol. |
| 39 |
|
| 40 |
Please note there is a B<dh> addon named B<ppp> which can be used to |
| 41 |
automatically invoke B<dh_ppp> for you. |
| 42 |
|
| 43 |
=head1 FILES |
| 44 |
|
| 45 |
=over 4 |
| 46 |
|
| 47 |
=item /usr/share/ppp-dev/substvars |
| 48 |
|
| 49 |
Template substitution variables. The values in this file are used when |
| 50 |
populating the B<misc:Depends> or B<misc:Breaks> substition variables, or they |
| 51 |
may be manually copied into a package's substvars if one wishes not to use |
| 52 |
B<dh_ppp>. |
| 53 |
|
| 54 |
=back |
| 55 |
|
| 56 |
=head1 OPTIONS |
| 57 |
|
| 58 |
=over 4 |
| 59 |
|
| 60 |
=item B<--breaks> |
| 61 |
|
| 62 |
Rather than populating B<misc:Depends> to ensure an appropriate version of |
| 63 |
B<ppp> is used, populate B<misc:Breaks> such that a inappropriate version of |
| 64 |
B<ppp> may not be used. |
| 65 |
|
| 66 |
=item B<--force> |
| 67 |
|
| 68 |
Do not try to detect pppd plugins in the package, and always assume that a |
| 69 |
plugin is present. This will cause B<misc:Depends> (or B<misc:Breaks>) to |
| 70 |
always be populated. |
| 71 |
|
| 72 |
=item B<--plugin-dir> |
| 73 |
|
| 74 |
Simply outputs the path to the pppd plugins directory for the current ABI |
| 75 |
version. When this flag is specified, B<dh_ppp> makes no attempt to detect any |
| 76 |
plugins nor does it update any substitution variables. |
| 77 |
|
| 78 |
=back |
| 79 |
|
| 80 |
=head1 NOTES |
| 81 |
|
| 82 |
Note that this command is not idempotent. L<dh_prep(1)> should be called |
| 83 |
between invocations of this command (with the same arguments). Otherwise, it |
| 84 |
may cause multiple instances of the same text to be added to the substition |
| 85 |
variables. |
| 86 |
|
| 87 |
Note that B<dh_ppp> should be run before B<dh_gencontrol>. The B<ppp> sequence |
| 88 |
addon for B<dh> does the right thing, this note is only relevant when you are |
| 89 |
calling B<dh_ppp> manually. |
| 90 |
|
| 91 |
=cut |
| 92 |
|
| 93 |
init(options => { |
| 94 |
"breaks" => \$dh{BREAKS}, |
| 95 |
"force" => \$dh{FORCE}, |
| 96 |
"plugin-dir" => \$dh{PLUGIN_DIR}, |
| 97 |
}); |
| 98 |
|
| 99 |
sub detect_plugins { |
| 100 |
my $package = shift; |
| 101 |
my $tmpdir = tmpdir($package); |
| 102 |
my @shared_objects; |
| 103 |
my @plugins; |
| 104 |
|
| 105 |
find({ |
| 106 |
wanted => sub { |
| 107 |
my $name = $File::Find::name; |
| 108 |
return unless -f $name; |
| 109 |
return unless $name =~ m,^$tmpdir/usr/lib/.*\.so$,; |
| 110 |
push @shared_objects, $name; |
| 111 |
}, |
| 112 |
no_chdir => 1, |
| 113 |
}, $tmpdir); |
| 114 |
|
| 115 |
my $od = new Dpkg::Shlibs::Objdump(); |
| 116 |
|
| 117 |
for my $so (@shared_objects) { |
| 118 |
verbose_print("Scanning $so for symbol information"); |
| 119 |
|
| 120 |
my $objid = $od->analyze($so); |
| 121 |
unless (defined($objid) && $objid) { |
| 122 |
warning("Dpkg::Shlibs::Objdump couldn't parse $so"); |
| 123 |
next; |
| 124 |
} |
| 125 |
|
| 126 |
my $object = $od->get_object($objid); |
| 127 |
|
| 128 |
my $init = $object->get_symbol("plugin_init"); |
| 129 |
if (!defined($init)) { |
| 130 |
verbose_print("File $so does not look like a pppd " . |
| 131 |
"plugin. Ignoring."); |
| 132 |
next; |
| 133 |
} |
| 134 |
|
| 135 |
push @plugins, $so; |
| 136 |
|
| 137 |
my $ver = $object->get_symbol("pppd_version"); |
| 138 |
if (!defined($ver)) { |
| 139 |
warning("File $so looks like a pppd plugin but " . |
| 140 |
"lacks a pppd_version symbol!"); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
return @plugins; |
| 145 |
} |
| 146 |
|
| 147 |
my %substvars; |
| 148 |
sub load_substvars { |
| 149 |
return if %substvars; |
| 150 |
|
| 151 |
open(VARS, '<', '/usr/share/ppp-dev/substvars') or |
| 152 |
error("Failed to load template substvars"); |
| 153 |
while (<VARS>) { |
| 154 |
chomp; |
| 155 |
my ($var, $value) = split /=/, $_, 2; |
| 156 |
my @pkgs = split /, /, $value; |
| 157 |
$substvars{$var} = \@pkgs; |
| 158 |
} |
| 159 |
close(VARS); |
| 160 |
|
| 161 |
for my $var (qw(ppp:Depends ppp:Breaks)) { |
| 162 |
error("$var not defined in substvars template") |
| 163 |
unless defined($substvars{$var}); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
if ($dh{PLUGIN_DIR}) { |
| 168 |
inhibit_log(); |
| 169 |
load_substvars(); |
| 170 |
|
| 171 |
print join(', ', @{$substvars{'ppp:PluginDir'}}) . "\n"; |
| 172 |
exit 0; |
| 173 |
} |
| 174 |
|
| 175 |
foreach my $package (@{$dh{DOPACKAGES}}) { |
| 176 |
next unless $dh{FORCE} or detect_plugins($package); |
| 177 |
|
| 178 |
load_substvars(); |
| 179 |
|
| 180 |
my $var = $dh{BREAKS} ? 'Breaks' : 'Depends'; |
| 181 |
for my $pkg (@{$substvars{"ppp:$var"}}) { |
| 182 |
addsubstvar($package, "misc:$var", $pkg); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
=head1 SEE ALSO |
| 187 |
|
| 188 |
L<debhelper(7)> |
| 189 |
|
| 190 |
=head1 AUTHORS |
| 191 |
|
| 192 |
Chris Boot <[email protected]> |
| 193 |
|
| 194 |
=cut |