%dh);
sub init {
+ # If DH_OPTIONS is set, prepend it @ARGV.
+ if (defined($ENV{DH_OPTIONS})) {
+ unshift @ARGV,split(/\s+/,$ENV{DH_OPTIONS});
+ }
+
# Check to see if an argument on the command line starts with a dash.
- # if so, we need to pass this off to the resource intensive Getopt::Long,
- # which I'd prefer to avoid loading at all if possible.
+ # if so, we need to pass this off to the resource intensive
+ # Getopt::Long, which I'd prefer to avoid loading at all if possible.
my $parseopt=undef;
my $arg;
foreach $arg (@ARGV) {
my @allpackages=GetPackages();
$dh{MAINPACKAGE}=$allpackages[0];
- # Check if packages to build have been specified, if not, fall back to
+ # Check if packages to build have been specified, if not, fall back to
# the default, doing them all.
if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
- if ($dh{DOINDEP} || $dh{DOARCH}) {
+ if ($dh{DOINDEP} || $dh{DOARCH} || $dh{DOSAME}) {
# User specified that all arch (in)dep package be
# built, and there are none of that type.
error("I have no package to build");
# This package gets special treatement: files and directories specified on
# the command line may affect it.
$dh{FIRSTPACKAGE}=${$dh{DOPACKAGES}}[0];
+
+ # Split the U_PARAMS up into an array.
+ my $u=$dh{U_PARAMS};
+ undef $dh{U_PARAMS};
+ if (defined $u) {
+ push @{$dh{U_PARAMS}}, split(/\s+/,$u);
+ }
}
# Escapes out shell metacharacters in a word of shell script.
sub escape_shell { my $word=shift;
- $word=~s/([\s><&!\[\]\{\}\(\)\$])/\\$1/g;
+ # This list is from _Unix in a Nutshell_. (except '#')
+ $word=~s/([\s!"\$()*+#;<>?@\[\]\\`|~])/\\$1/g;
return $word;
}
# Output a warning.
sub warning { my $message=shift;
- print STDERR basename().": $message\n";
+ print STDERR basename($0).": $message\n";
}
-# Returns the basename of the program.
-sub basename {
- my $fn=$0;
- $fn=~s:.*/(.*?):$1:;
+# Returns the basename of the argument passed to it.
+sub basename { my $fn=shift;
+ $fn=~s:^.*/(.*?)$:$1:;
+ return $fn;
+}
+
+# Returns the directory name of the argument passed to it.
+sub dirname { my $fn=shift;
+ $fn=~s:^(.*)/.*?$:$1:;
return $fn;
}
# 2: script to add to
# 3: filename of snippet
# 4: sed to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
-sub autoscript { my $package=shift; my $script=shift; my $filename=shift; my $sed=shift;
- error "autoscript() not yet implemented (lazy, lazy!)";
-
+sub autoscript { my $package=shift; my $script=shift; my $filename=shift; my $sed=shift || "";
# This is the file we will append to.
my $outfile="debian/".pkgext($package)."$script.debhelper";
# Figure out what shell script snippet to use.
my $infile;
- if ( -e "$main::ENV{DH_AUTOSCRIPTDIR}/$filename" ) {
- $infile="$main::ENV{DH_AUTOSCRIPTDIR}/$filename";
+ if (defined($ENV{DH_AUTOSCRIPTDIR}) &&
+ -e "$ENV{DH_AUTOSCRIPTDIR}/$filename") {
+ $infile="$ENV{DH_AUTOSCRIPTDIR}/$filename";
}
else {
- if ( -e "/usr/lib/debhelper/autoscripts/$filename" ) {
+ if (-e "/usr/lib/debhelper/autoscripts/$filename") {
$infile="/usr/lib/debhelper/autoscripts/$filename";
}
else {
}
# TODO: do this in perl, perhaps?
- complex_doit("echo \"# Automatically added by ".basename().">> $outfile");
+ complex_doit("echo \"# Automatically added by ".basename($0)."\">> $outfile");
complex_doit("sed \"$sed\" $infile >> $outfile");
complex_doit("echo '# End automatically added section' >> $outfile");
}
}
# Returns a list of packages in the control file.
-# Must pass "arch" or "indep" to specify arch-dependant or -independant
-# packages. If nothing is specified, returns all packages.
+# Must pass "arch" or "indep" or "same" to specify arch-dependant or
+# -independant or same arch packages. If nothing is specified, returns all
+# packages.
sub GetPackages { my $type=shift;
$type="" if ! defined $type;
+
+ # Look up the build arch if we need to.
+ my$buildarch='';
+ if ($type eq 'same') {
+ $buildarch=`dpkg --print-architecture` || error($!);
+ chomp $buildarch;
+ }
+
my $package="";
my $arch="";
my @list=();
- open (CONTROL,"<debian/control") ||
+ open (CONTROL,"<debian/control") ||
error("cannot read debian/control: $!\n");
while (<CONTROL>) {
chomp;
if ($package &&
(($type eq 'indep' && $arch eq 'all') ||
($type eq 'arch' && $arch ne 'all') ||
+ ($type eq 'same' && ($arch eq 'any' || $arch =~ /\b$buildarch\b/)) ||
! $type)) {
push @list, $package;
$package="";