@ISA=qw(Exporter);
@EXPORT=qw(&init &doit &complex_doit &verbose_print &error &warning &tmpdir
&pkgfile &pkgext &isnative &autoscript &filearray &GetPackages
+ &xargs
%dh);
+my $max_compat=2;
+
sub init {
# If DH_OPTIONS is set, prepend it @ARGV.
if (defined($ENV{DH_OPTIONS})) {
}
}
+# Run a command that may have a huge number of arguments, like xargs does.
+# Pass in a reference to an array containing the arguments, and then other
+# parameters that are the command and any parameters that should be passed to
+# it each time.
+sub xargs {
+ my $args=shift;
+
+ # The kernel can accept command lines up to 20k worth of characters.
+ my $command_max=20000;
+
+ # Figure out length of static portion of command.
+ my $static_length=0;
+ foreach (@_) {
+ $static_length+=length($_)+1;
+ }
+
+ my @collect=();
+ my $length=$static_length;
+ foreach (@$args) {
+ if (length($_) + 1 + $static_length > $command_max) {
+ error("This command is greater than the maximum command size allowed by the kernel, and cannot be split up further. What on earth are you doing? \"@_ $_\"");
+ }
+ $length+=length($_) + 1;
+ if ($length < $command_max) {
+ push @collect, $_;
+ }
+ else {
+ doit(@_,@collect) if $#collect > -1;
+ @collect=();
+ $length=$static_length;
+ }
+ }
+ doit(@_,@collect) if $#collect > -1;
+}
+
# Print something if the verbose flag is on.
sub verbose_print { my $message=shift;
if ($dh{VERBOSE}) {
return $fn;
}
+# Pass in a number, will return true iff the current compatability level
+# is equal to that number.
+sub compat {
+ my $num=shift;
+
+ my $c=1;
+ if (defined $ENV{DH_COMPAT}) {
+ $c=$ENV{DH_COMPAT};
+ }
+
+ if ($c > $max_compat) {
+ error("Sorry, but $max_compat is the highest compatability level of debhelper currently supported.");
+ }
+
+ return ($c == $num);
+}
+
# Pass it a name of a binary package, it returns the name of the tmp dir to
# use, for that package.
-# This is for back-compatability with the debian/tmp tradition.
sub tmpdir { my $package=shift;
if ($dh{TMPDIR}) {
return $dh{TMPDIR};
}
- elsif ($package eq $dh{MAINPACKAGE}) {
+ elsif (compat(1) && $package eq $dh{MAINPACKAGE}) {
+ # This is for back-compatability with the debian/tmp tradition.
return "debian/tmp";
}
else {
# the main package, it will look for debian/foo, and if found, return that.
# Failing that, it will return nothing.
sub pkgfile { my $package=shift; my $filename=shift;
- if (-e "debian/$package.$filename") {
+ if (-f "debian/$package.$filename") {
return "debian/$package.$filename";
}
- elsif ($package eq $dh{MAINPACKAGE} && -e "debian/$filename") {
+ elsif ($package eq $dh{MAINPACKAGE} && -f "debian/$filename") {
return "debian/$filename";
}
return "";
$infile="$ENV{DH_AUTOSCRIPTDIR}/$filename";
}
else {
- if (-e "/usr/lib/debhelper/autoscripts/$filename") {
- $infile="/usr/lib/debhelper/autoscripts/$filename";
+ if (-e "/usr/share/debhelper/autoscripts/$filename") {
+ $infile="/usr/share/debhelper/autoscripts/$filename";
}
else {
- error("/usr/lib/debhelper/autoscripts/$filename does not exist");
+ error("/usr/share/debhelper/autoscripts/$filename does not exist");
}
}
my @ret;
open (DH_FARRAY_IN,"<$file") || error("cannot read $file: $1");
while (<DH_FARRAY_IN>) {
- push @ret,split(/\s/,$_);
+ push @ret,split(' ',$_);
}
close DH_FARRAY_IN;