3 # Debhelper option processing library.
5 # Joey Hess GPL copyright 1998.
12 my @EXPORT=qw(&parseopts);
17 my (%options, %exclude_package);
19 # Passed an option name and an option value, adds packages to the list
20 # of packages. We need this so the list will be built up in the right
22 sub AddPackage { my($option,$value)=@_;
23 if ($option eq 'i' or $option eq 'indep') {
24 push @{$options{DOPACKAGES}}, GetPackages('indep');
27 elsif ($option eq 'a' or $option eq 'arch') {
28 push @{$options{DOPACKAGES}}, GetPackages('arch');
31 elsif ($option eq 'p' or $option eq 'package') {
32 push @{$options{DOPACKAGES}}, $value;
35 error("bad option $option - should never happen!\n");
39 # Add a package to a list of packages that should not be acted on.
40 sub ExcludePackage { my($option,$value)=@_;
41 $exclude_package{$value}=1;
44 # Add another item to the exclude list.
45 sub AddExclude { my($option,$value)=@_;
46 push @{$options{EXCLUDE}},$value;
50 # Enable bundling of short command line options.
51 Getopt::Long::config("bundling");
54 # Parse options and return a hash of the values.
59 "v" => \$options{VERBOSE},
60 "verbose" => \$options{VERBOSE},
63 "indep" => \&AddPackage,
66 "arch" => \&AddPackage,
68 "p=s" => \&AddPackage,
69 "package=s" => \&AddPackage,
71 "N=s" => \&ExcludePackage,
72 "no-package=s" => \&ExcludePackage,
74 "n" => \$options{NOSCRIPTS},
75 # "noscripts" => \$options(NOSCRIPTS},
77 "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
78 "include-conffiles" => \$options{INCLUDE_CONFFILES},
80 "X=s" => \&AddExclude,
81 "exclude=s" => \&AddExclude,
83 "d" => \$options{D_FLAG},
84 "remove-d" => \$options{D_FLAG},
86 "r" => \$options{R_FLAG},
87 "no-restart-on-upgrade" => \$options{R_FLAG},
89 "k" => \$options{K_FLAG},
90 "keep" => \$options{K_FLAG},
92 "P=s" => \$options{TMPDIR},
93 "tmpdir=s" => \$options{TMPDIR},
95 "u=s", => \$options{U_PARAMS},
96 "update-rcd-params=s", => \$options{U_PARAMS},
97 "dpkg-shlibdeps-params=s", => \$options{U_PARAMS},
99 "m=s", => \$options{M_PARAMS},
100 "major=s" => \$options{M_PARAMS},
102 "V:s", => \$options{V_FLAG},
103 "version-info:s" => \$options{V_FLAG},
105 "A" => \$options{PARAMS_ALL},
106 "all" => \$options{PARAMS_ALL},
108 "no-act" => \$options{NO_ACT},
110 "init-script=s" => \$options{INIT_SCRIPT},
114 error("unknown option; aborting");
117 # Check to see if -V was specified. If so, but no parameters were
118 # passed, the variable will be defined but empty.
119 if (defined($options{V_FLAG})) {
120 $options{V_FLAG_SET}=1;
123 # Check to see if DH_VERBOSE environment variable was set, if so,
124 # make sure verbose is on.
125 if ($ENV{DH_VERBOSE} ne undef) {
129 # Check to see if DH_NO_ACT environment variable was set, if so,
130 # make sure no act mode is on.
131 if ($ENV{DH_NO_ACT} ne undef) {
135 # Remove excluded packages from the list of packages to act on.
138 foreach $package (@{$options{DOPACKAGES}}) {
139 if (! $exclude_package{$package}) {
140 push @package_list, $package;
143 @{$options{DOPACKAGES}}=@package_list;