X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=Dh_Lib.pm;h=61d807afc06fb798df705fef285c95d116d7b1d3;hb=9bbed39d6d27346d4092f5869b36b8ec93426d18;hp=49e337a9f8df0450708added56e2590084b34f64;hpb=03d1a2e0c10456c65fbf36e1f38619803f4f2bfd;p=debhelper.git diff --git a/Dh_Lib.pm b/Dh_Lib.pm index 49e337a..61d807a 100644 --- a/Dh_Lib.pm +++ b/Dh_Lib.pm @@ -15,9 +15,14 @@ use vars qw(@ISA @EXPORT %dh); %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) { @@ -49,10 +54,10 @@ sub init { 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"); @@ -70,11 +75,19 @@ sub init { # 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; } @@ -123,13 +136,18 @@ sub error { my $message=shift; # 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; } @@ -212,19 +230,18 @@ sub pkgext { my $package=shift; # 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 { @@ -233,7 +250,7 @@ sub autoscript { my $package=shift; my $script=shift; my $filename=shift; my $se } # 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"); } @@ -252,14 +269,23 @@ sub filearray { my $file=shift; } # 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,") { chomp; @@ -274,6 +300,7 @@ sub GetPackages { my $type=shift; 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="";