push @{$dh{DOPACKAGES}}, getpackages('indep');
$dh{DOINDEP}=1;
}
- elsif ($option eq 'a' or $option eq 'arch') {
+ elsif ($option eq 'a' or $option eq 'arch' or
+ $option eq 's' or $option eq 'same-arch') {
push @{$dh{DOPACKAGES}}, getpackages('arch');
$dh{DOARCH}=1;
}
elsif ($option eq 'p' or $option eq 'package') {
push @{$dh{DOPACKAGES}}, $value;
}
- elsif ($option eq 's' or $option eq 'same-arch') {
- push @{$dh{DOPACKAGES}}, getpackages('same');
- $dh{DOSAME}=1;
- }
else {
error("bad option $option - should never happen!\n");
}
$dh{IGNORE}->{$file}=1;
}
-# Add an item to the with list.
-sub AddWith { my($option,$value)=@_;
- push @{$dh{WITH}},$value;
-}
-
# This collects non-options values.
sub NonOption {
push @{$dh{ARGV}}, @_;
}
-# Parse options and set %dh values.
-sub parseopts {
- my %options=%{shift()} if ref $_[0];
+sub getoptions {
+ my $array=shift;
+ my %params=@_;
- my $ret=GetOptions(
+ if (! exists $params{bundling} || $params{bundling}) {
+ Getopt::Long::config("bundling");
+ }
+
+ my @test;
+ my %options=(
"v" => \$dh{VERBOSE},
"verbose" => \$dh{VERBOSE},
+
+ "no-act" => \$dh{NO_ACT},
"i" => \&AddPackage,
"indep" => \&AddPackage,
"p=s" => \&AddPackage,
"package=s" => \&AddPackage,
+
+ "N=s" => \&ExcludePackage,
+ "no-package=s" => \&ExcludePackage,
+
+ "remaining-packages" => \$dh{EXCLUDE_LOGGED},
"dbg-package=s" => \&AddDebugPackage,
"s" => \&AddPackage,
"same-arch" => \&AddPackage,
- "N=s" => \&ExcludePackage,
- "no-package=s" => \&ExcludePackage,
-
"n" => \$dh{NOSCRIPTS},
"noscripts" => \$dh{NOSCRIPTS},
"o" => \$dh{ONLYSCRIPTS},
"onlyscripts" => \$dh{ONLYSCRIPTS},
- "x" => \$dh{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
- "include-conffiles" => \$dh{INCLUDE_CONFFILES},
-
"X=s" => \&AddExclude,
"exclude=s" => \&AddExclude,
- "ignore=s" => \&AddIgnore,
-
"d" => \$dh{D_FLAG},
- "remove-d" => \$dh{D_FLAG},
- "dirs-only" => \$dh{D_FLAG},
-
- "r" => \$dh{R_FLAG},
- "no-restart-on-upgrade" => \$dh{R_FLAG},
- "no-start" => \$dh{NO_START},
- "R|restart-after-upgrade" => \$dh{RESTART_AFTER_UPGRADE},
"k" => \$dh{K_FLAG},
"keep" => \$dh{K_FLAG},
- "keep-debug" => \$dh{K_FLAG},
"P=s" => \$dh{TMPDIR},
"tmpdir=s" => \$dh{TMPDIR},
"u=s", => \$dh{U_PARAMS},
- "update-rcd-params=s", => \$dh{U_PARAMS},
- "dpkg-shlibdeps-params=s", => \$dh{U_PARAMS},
- "dpkg-gencontrol-params=s", => \$dh{U_PARAMS},
-
- "l=s", => \$dh{L_PARAMS},
-
- "m=s", => \$dh{M_PARAMS},
- "major=s" => \$dh{M_PARAMS},
"V:s", => \$dh{V_FLAG},
- "version-info:s" => \$dh{V_FLAG},
"A" => \$dh{PARAMS_ALL},
"all" => \$dh{PARAMS_ALL},
-
- "no-act" => \$dh{NO_ACT},
- "init-script=s" => \$dh{INIT_SCRIPT},
-
- "sourcedir=s" => \$dh{SOURCEDIR},
-
- "destdir=s" => \$dh{DESTDIR},
-
- "filename=s" => \$dh{FILENAME},
-
"priority=s" => \$dh{PRIORITY},
- "flavor=s" => \$dh{FLAVOR},
-
- "autodest" => \$dh{AUTODEST},
-
"h|help" => \&showhelp,
"mainpackage=s" => \$dh{MAINPACKAGE},
- "list-missing" => \$dh{LIST_MISSING},
-
- "fail-missing" => \$dh{FAIL_MISSING},
-
- "L|libpackage=s" => \$dh{LIBPACKAGE},
-
"name=s" => \$dh{NAME},
-
+
"error-handler=s" => \$dh{ERROR_HANDLER},
- "add-udeb=s" => \$dh{SHLIBS_UDEB},
-
- "language=s" => \$dh{LANGUAGE},
-
- "until=s" => \$dh{UNTIL},
- "after=s" => \$dh{AFTER},
- "before=s" => \$dh{BEFORE},
- "remaining" => \$dh{REMAINING},
- "with=s" => \&AddWith,
+ "ignore=s" => \&AddIgnore,
- %options,
+ "O=s" => sub { push @test, $_[1] },
+
+ (ref $params{options} ? %{$params{options}} : ()) ,
"<>" => \&NonOption,
);
- if (!$ret) {
- error("unknown option; aborting");
+ 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;
+ }
+
+ 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 {
+ my $str=shift;
+ $str=~s/^\s+//;
+ return split(/\s+/,$str);
+}
+
+# Parse options and set %dh values.
+sub parseopts {
+ my %params=@_;
+
+ 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(/\x1e/, $ENV{DH_INTERNAL_OPTIONS});
+ 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, 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}) {
+ foreach my $package (getpackages()) {
+ if (! grep { $_ eq $package } @{$dh{DOPACKAGES}}) {
+ $exclude_package{$package}=1;
+ }
+ }
+ }
+ delete $dh{DOPACKAGES};
+ delete $dh{DOINDEP};
+ delete $dh{DOARCH};
}
+ # DH_OPTIONS can contain additional options to be parsed like @ARGV
+ if (defined $ENV{DH_OPTIONS}) {
+ @ARGV_extra=split_options_string($ENV{DH_OPTIONS});
+ my $ret=getoptions(\@ARGV_extra, %params);
+ if (!$ret) {
+ warning("warning: ignored unknown options in DH_OPTIONS");
+ }
+ }
+
+ my $ret=getoptions(\@ARGV, %params);
+ if (!$ret) {
+ if (! compat(7)) {
+ 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})) {
# want us to act on them all. Note we have to do this before excluding
# packages out, below.
if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
- if ($dh{DOINDEP} || $dh{DOARCH} || $dh{DOSAME}) {
+ if ($dh{DOINDEP} || $dh{DOARCH}) {
# 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();
+ push @{$dh{DOPACKAGES}},getpackages("both");
}
# Remove excluded packages from the list of packages to act on.
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}) {
# Anything left in @ARGV is options that appeared after a --
# These options are added to the U_PARAMS array, while the
# non-option values we collected replace them in @ARGV;
- push @{$dh{U_PARAMS}}, @ARGV;
+ push @{$dh{U_PARAMS}}, @ARGV, @ARGV_extra;
@ARGV=@{$dh{ARGV}} if exists $dh{ARGV};
}
-sub import {
- # Enable bundling of short command line options.
- Getopt::Long::config("bundling");
-}
-
1