sub getoptions {
my $array=shift;
- my %options=%{shift()} if ref $_[0];
+ my $extraoptions=shift;
- Getopt::Long::GetOptionsFromArray($array,
+ my %options=(
"v" => \$dh{VERBOSE},
"verbose" => \$dh{VERBOSE},
"N=s" => \&ExcludePackage,
"no-package=s" => \&ExcludePackage,
+ "remaining-packages" => \$dh{EXCLUDE_LOGGED},
+
"dbg-package=s" => \&AddDebugPackage,
"s" => \&AddPackage,
"ignore=s" => \&AddIgnore,
- %options,
-
"<>" => \&NonOption,
- )
+ );
+
+ # Merge extra options and cancel default ones as needed (undef)
+ if (defined $extraoptions) {
+ for my $opt (keys %$extraoptions) {
+ if (defined $extraoptions->{$opt}) {
+ $options{$opt}=$extraoptions->{$opt};
+ }
+ else {
+ delete $options{$opt};
+ }
+ }
+ }
+
+ Getopt::Long::GetOptionsFromArray($array, %options);
+}
+
+sub split_options_string {
+ my $str=shift;
+
+ $str=~s/^\s+//;
+ return map { $_=~s/\\(\s)/$1/g; $_=~s/\s+$//g; $_ } split(/(?<!\\)\s+/,$str);
}
# Parse options and set %dh values.
sub parseopts {
my $options=shift;
+ my $extra_args=shift;
+
+ my @ARGV_extra;
+
+ # DH_INTERNAL_OPTIONS is used to pass additional options from
+ # dh through an override target to a command.
+ if (defined $ENV{DH_INTERNAL_OPTIONS}) {
+ @ARGV_extra=split_options_string($ENV{DH_INTERNAL_OPTIONS});
+ my $ret=getoptions(\@ARGV_extra, $options);
+ if (!$ret) {
+ warning("warning: unknown options will be a fatal error in a future debhelper release");
+ #error("unknown option; aborting");
+ }
+
+ # 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
+ # nothing is specified, the excludes will cause the set of
+ # packages DH_INTERNAL_OPTIONS specifies to be acted on.
+ if (defined $dh{DOPACKAGES}) {
+ foreach my $package (getpackages()) {
+ if (! grep { $_ eq $package } @{$dh{DOPACKAGES}}) {
+ $exclude_package{$package}=1;
+ }
+ }
+ }
+ delete $dh{DOPACKAGES};
+ delete $dh{DOINDEP};
+ delete $dh{DOARCH};
+ delete $dh{DOSAME};
+ }
# DH_OPTIONS can contain additional options
# to be parsed like @ARGV, but with unknown options
# skipped.
- my @ARGV_extra;
if (defined $ENV{DH_OPTIONS}) {
- $ENV{DH_OPTIONS}=~s/^\s+//;
- $ENV{DH_OPTIONS}=~s/\s+$//;
- @ARGV_extra=split(/\s+/,$ENV{DH_OPTIONS});
+ @ARGV_extra=split_options_string($ENV{DH_OPTIONS});
my $ret=getoptions(\@ARGV_extra, $options);
if (!$ret) {
warning("warning: ignored unknown options in DH_OPTIONS");
}
}
- # DH_INTERNAL_OPTIONS is used to pass additional options from
- # dh through an override target to a command.
- if (defined $ENV{DH_INTERNAL_OPTIONS}) {
- $ENV{DH_INTERNAL_OPTIONS}=~s/^\s+//;
- $ENV{DH_INTERNAL_OPTIONS}=~s/\s+$//;
- unshift @ARGV, split(/\s+/,$ENV{DH_INTERNAL_OPTIONS});
+ if (defined $extra_args) {
+ my @extra_opts=split_options_string($extra_args);
+ my $ret=getoptions(\@extra_opts, $options);
+ if (!$ret) {
+ warning("warning: ignored unknown options");
+ }
+ push @ARGV_extra, @extra_opts;
}
my $ret=getoptions(\@ARGV, $options);
warning("warning: unknown options will be a fatal error in a future debhelper release");
#error("unknown option; aborting");
}
-
+
# Check to see if -V was specified. If so, but no parameters were
# passed, the variable will be defined but empty.
if (defined($dh{V_FLAG})) {
if ($dh{DOINDEP} || $dh{DOARCH} || $dh{DOSAME}) {
# User specified that all arch (in)dep package be
# built, and there are none of that type.
- warning("I have no package to build");
+ warning("You asked that all arch in(dep) packages be built, but there are none of that type.");
exit(0);
}
push @{$dh{DOPACKAGES}},getpackages();
my $package;
my %packages_seen;
foreach $package (@{$dh{DOPACKAGES}}) {
+ if (defined($dh{EXCLUDE_LOGGED}) &&
+ grep { $_ eq basename($0) } load_log($package)) {
+ $exclude_package{$package}=1;
+ }
if (! $exclude_package{$package}) {
if (! exists $packages_seen{$package}) {
$packages_seen{$package}=1;
}
@{$dh{DOPACKAGES}}=@package_list;
- # If there are no packages to act on now, it's an error.
if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
- error("I have no package to build");
+ warning("No packages to build.");
+ exit(0);
}
if (defined $dh{U_PARAMS}) {