generated from general-packages/pika-pkg-template
193 lines
5.0 KiB
Plaintext
193 lines
5.0 KiB
Plaintext
|
#!/usr/bin/perl -w
|
||
|
|
||
|
=head1 NAME
|
||
|
|
||
|
dh_dkms - correctly handle DKMS usage by a kernel module package
|
||
|
|
||
|
=cut
|
||
|
|
||
|
use strict;
|
||
|
use Debian::Debhelper::Dh_Lib;
|
||
|
|
||
|
=head1 SYNOPSIS
|
||
|
|
||
|
B<dh_dkms> [S<I<debhelper options>>] [S<B<-l>>] [S<B<-V>[I<version>]>] [S<B<--> I<file>>]
|
||
|
|
||
|
=head1 DESCRIPTION
|
||
|
|
||
|
dh_dkms is a debhelper program that is responsible for correctly setting
|
||
|
postinst, postrm and dependencies in kernel module packages using DKMS.
|
||
|
|
||
|
If a file named debian/package.dkms exists, then different actions are
|
||
|
performed, depending on its contents.
|
||
|
|
||
|
=head1 FILES
|
||
|
|
||
|
=over 4
|
||
|
|
||
|
=item debian/I<package>.dkms
|
||
|
|
||
|
=item debian/dkms
|
||
|
|
||
|
It can be a proper configuration file, and in this case it would be installed
|
||
|
in the proper directory as dkms.conf.
|
||
|
|
||
|
It can also point to another file (this should be used when the configuration
|
||
|
is provided by upstream), and in this case that file will be installed as dkms.conf
|
||
|
in the proper directory.
|
||
|
|
||
|
This file can only miss if a filename is provided when calling dh_dkms.
|
||
|
|
||
|
=back
|
||
|
|
||
|
=head1 OPTIONS
|
||
|
|
||
|
=over 4
|
||
|
|
||
|
=item B<-l>, B<--legacy>
|
||
|
|
||
|
Add code to also support DKMS versions < 2.1.0.0.
|
||
|
|
||
|
=item B<-V>, B<-V> I<version>
|
||
|
|
||
|
If C<PACKAGE_VERSION> in F<dkms.conf> is set to C<#MODULE_VERSION#>, set it to
|
||
|
the given I<version> or, if none is given, default to the upstream version of
|
||
|
the current package. Otherwise, leave the value specified in F<dkms.conf>.
|
||
|
|
||
|
=item B<--> I<file>
|
||
|
|
||
|
Don't look for debian/I<package>.dkms or debian/dkms, but install I<file> as dkms.conf.
|
||
|
|
||
|
=back
|
||
|
|
||
|
=head1 NOTES
|
||
|
|
||
|
Note that this command is not idempotent. L<dh_prep(1)> should be called
|
||
|
between invocations of this command. Otherwise, it may cause multiple
|
||
|
instances of the same text to be added to maintainer scripts.
|
||
|
|
||
|
=cut
|
||
|
|
||
|
# placeholder substituted at build time
|
||
|
# is shown along generated autoscripts
|
||
|
#VERSION#
|
||
|
|
||
|
init(options => {
|
||
|
"l|legacy" => \$dh{LEGACY_DKMS},
|
||
|
});
|
||
|
|
||
|
foreach my $package (@{$dh{DOPACKAGES}}) {
|
||
|
#next if is_udeb($package);
|
||
|
|
||
|
my $tmp = tmpdir($package);
|
||
|
my $dkms_dir = "/usr/lib/dkms/";
|
||
|
my $dkms_conf = pkgfile($package, "dkms");
|
||
|
my $is_snippet = 0;
|
||
|
my @other_conf;
|
||
|
my $name;
|
||
|
my $package_name;
|
||
|
my $package_version;
|
||
|
my $build_exclusive_config;
|
||
|
|
||
|
if ($dkms_conf) {
|
||
|
# let's see if it's a proper snippet
|
||
|
open(IN, "< $dkms_conf");
|
||
|
while (my $l = <IN>) {
|
||
|
$l =~ /PACKAGE_NAME=(["'])(.*)\1/ && ($is_snippet = 1);
|
||
|
}
|
||
|
close(IN);
|
||
|
|
||
|
if ($is_snippet) {
|
||
|
$name = $dkms_conf;
|
||
|
}
|
||
|
else {
|
||
|
my @search_dirs = ($dh{SOURCEDIR} // '.', default_sourcedir($package));
|
||
|
@other_conf = filearray($dkms_conf, \@search_dirs);
|
||
|
if ($#other_conf > 1) {
|
||
|
error "cannot list more than one file in $dkms_conf!";
|
||
|
}
|
||
|
else {
|
||
|
$name = $other_conf[0];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
elsif ($#ARGV == 0) {
|
||
|
$name = $ARGV[0];
|
||
|
}
|
||
|
else {
|
||
|
next;
|
||
|
}
|
||
|
verbose_print "installing $name as dkms.conf";
|
||
|
|
||
|
# now, parse our configuration file
|
||
|
open(IN, "< $name") || error("cannot read $name: $!");
|
||
|
while (my $l = <IN>) {
|
||
|
$l =~ /PACKAGE_NAME=(["']?)(.*)\1/ && ($is_snippet = 1 && $package_name = $2);
|
||
|
$l =~ /PACKAGE_VERSION=(["']?)(.*)\1/ && ($package_version = $2);
|
||
|
$l =~ /BUILD_EXCLUSIVE_CONFIG=(["']?)(.*)\1/ && ($build_exclusive_config = $2);
|
||
|
$l =~ /BUILD_EXCLUSIVE_KERNEL_MIN=(["']?)(.*)\1/ && ($build_exclusive_config = "yes");
|
||
|
$l =~ /BUILD_EXCLUSIVE_KERNEL_MAX=(["']?)(.*)\1/ && ($build_exclusive_config = "yes");
|
||
|
}
|
||
|
close(IN);
|
||
|
|
||
|
#$ENV{DH_AUTOSCRIPTDIR} = "debian/scripts/";
|
||
|
if ($build_exclusive_config) {
|
||
|
addsubstvar($package, "misc:Depends", "dkms", ">= 3.0.11");
|
||
|
}
|
||
|
elsif ($dh{LEGACY_DKMS}) {
|
||
|
doit("install", "-p", "-D", "-m755", "$dkms_dir/common.postinst", "$tmp/usr/share/$package/postinst");
|
||
|
addsubstvar($package, "misc:Depends", "dkms");
|
||
|
}
|
||
|
else {
|
||
|
addsubstvar($package, "misc:Depends", "dkms", ">= 2.1.0.0");
|
||
|
}
|
||
|
|
||
|
if ($dh{V_FLAG_SET} || $package_version eq "#MODULE_VERSION#") {
|
||
|
$package_version = $dh{V_FLAG} || "";
|
||
|
if ($package_version eq "") {
|
||
|
# Call isnative because it sets $dh{VERSION}
|
||
|
# as a side effect.
|
||
|
isnative($package);
|
||
|
$package_version = $dh{VERSION};
|
||
|
# Remove the Debian revision
|
||
|
$package_version =~ s/-[^-]+$//;
|
||
|
# Remove the Debian epoch
|
||
|
$package_version =~ s/^\d+://;
|
||
|
}
|
||
|
|
||
|
my $old_name = $name;
|
||
|
$name = "debian/".pkgext($package)."dkms.debhelper";
|
||
|
doit("cp", "-a", $old_name, $name);
|
||
|
doit("sed", "-i", "s/#MODULE_VERSION#/$package_version/g", $name);
|
||
|
}
|
||
|
|
||
|
error "could not determine package name"
|
||
|
unless defined($package_name);
|
||
|
|
||
|
error "could not determine package version"
|
||
|
unless defined($package_version);
|
||
|
|
||
|
error "invalid package version '$package_version'"
|
||
|
unless $package_version =~ /^[-+.~:0-9a-zA-Z]+$/;
|
||
|
|
||
|
autoscript($package, "prerm", "prerm-dkms",
|
||
|
"s/#MODULE_NAME#/$package_name/;s/#MODULE_VERSION#/$package_version/");
|
||
|
autoscript($package, "postinst", "postinst-dkms",
|
||
|
"s/#MODULE_NAME#/$package_name/;s/#MODULE_VERSION#/$package_version/");
|
||
|
doit("install", "-p", "-D", "-m644", "$name", "$tmp/usr/src/$package_name-$package_version/dkms.conf");
|
||
|
}
|
||
|
|
||
|
=head1 SEE ALSO
|
||
|
|
||
|
L<debhelper(1)>
|
||
|
|
||
|
This program is part of the Debian DKMS package.
|
||
|
|
||
|
L<dkms(8)>
|
||
|
|
||
|
=head1 AUTHOR
|
||
|
|
||
|
David Paleino <dapal@debian.org>
|
||
|
|
||
|
=cut
|