]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Getopt.pm
oops, only force qt4 when it's enabled
[debhelper.git] / Debian / Debhelper / Dh_Getopt.pm
index 0d0210720c57e36b60f3c78cec9584fcd52902ed..e4f3e4718fcab4b2e229c2e50c493348662d952a 100644 (file)
@@ -69,15 +69,13 @@ sub NonOption {
 sub getoptions {
        my $array=shift;
        my %params=@_;
-       my %options=%{$params{options}} if ref $params{options};
-       
-       my $oldwarn;
-       if ($params{ignore_unknown_options}) {
-               $oldwarn=$SIG{__WARN__};
-               $SIG{__WARN__}=sub {};
+
+       if (! exists $params{bundling} || $params{bundling}) {
+               Getopt::Long::config("bundling");
        }
 
-       my $ret=Getopt::Long::GetOptionsFromArray($array,
+       my @test;
+       my %options=(   
                "v" => \$dh{VERBOSE},
                "verbose" => \$dh{VERBOSE},
 
@@ -137,18 +135,41 @@ sub getoptions {
                
                "ignore=s" => \&AddIgnore,
 
-               %options,
+               "O=s" => sub { push @test, $_[1] },
+             
+               (ref $params{options} ? %{$params{options}} : ()) ,
 
                "<>" => \&NonOption,
        );
 
-       if ($params{ignore_unknown_options}) {
+       if ($params{test}) {
+               foreach my $key (keys %options) {
+                       $options{$key}=sub {};
+               }
+       }
+
+       my $oldwarn;
+       if ($params{test} || $params{ignore_unknown_options}) {
+               $oldwarn=$SIG{__WARN__};
+               $SIG{__WARN__}=sub {};
+       }
+       my $ret=Getopt::Long::GetOptionsFromArray($array, %options);
+       if ($oldwarn) {
                $SIG{__WARN__}=$oldwarn;
-               return 1;
        }
-       else {
-               return $ret;
+
+       foreach my $opt (@test) {
+               # Try to parse an option, and skip it
+               # if it is not known.
+               if (getoptions([$opt], %params,
+                               ignore_unknown_options => 0,
+                               test => 1)) {
+                       getoptions([$opt], %params);
+               }
        }
+
+       return 1 if $params{ignore_unknown_options};
+       return $ret;
 }
 
 sub split_options_string {
@@ -167,11 +188,11 @@ sub parseopts {
        # dh through an override target to a command.
        if (defined $ENV{DH_INTERNAL_OPTIONS}) {
                @ARGV_extra=split(/\x1e/, $ENV{DH_INTERNAL_OPTIONS});
-               getoptions(\@ARGV_extra, %params, ignore_unknown_options => 1);
+               getoptions(\@ARGV_extra, %params);
 
                # Avoid forcing acting on packages specified in
                # DH_INTERNAL_OPTIONS. This way, -p can be specified
-               # at the command line to act on a specific package, and if
+               # at the command line to act on a specific package, but when
                # nothing is specified, the excludes will cause the set of
                # packages DH_INTERNAL_OPTIONS specifies to be acted on.
                if (defined $dh{DOPACKAGES}) {
@@ -197,8 +218,9 @@ sub parseopts {
 
        my $ret=getoptions(\@ARGV, %params);
        if (!$ret) {
-               warning("warning: unknown options will be a fatal error in a future debhelper release");
-               #error("unknown option; aborting");
+               if (! compat(7)) {
+                       error("unknown option; aborting");
+               }
        }
 
        # Check to see if -V was specified. If so, but no parameters were
@@ -214,10 +236,12 @@ sub parseopts {
                if ($dh{DOINDEP} || $dh{DOARCH}) {
                        # User specified that all arch (in)dep package be
                        # built, and there are none of that type.
-                       warning("You asked that all arch in(dep) packages be built, but there are none of that type.");
+                       if (! $dh{BLOCK_NOOP_WARNINGS}) {
+                               warning("You asked that all arch in(dep) packages be built, but there are none of that type.");
+                       }
                        exit(0);
                }
-               push @{$dh{DOPACKAGES}},getpackages();
+               push @{$dh{DOPACKAGES}},getpackages("both");
        }
 
        # Remove excluded packages from the list of packages to act on.
@@ -241,7 +265,9 @@ sub parseopts {
        @{$dh{DOPACKAGES}}=@package_list;
 
        if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
-               warning("No packages to build.");
+               if (! $dh{BLOCK_NOOP_WARNINGS}) {
+                       warning("No packages to build.");
+               }
                exit(0);
        }
 
@@ -259,9 +285,4 @@ sub parseopts {
        @ARGV=@{$dh{ARGV}} if exists $dh{ARGV};
 }
 
-sub import {
-       # Enable bundling of short command line options.
-       Getopt::Long::config("bundling");
-}              
-
 1