3 # Debhelper option processing library.
5 # Joey Hess GPL copyright 1998.
7 package Debian::Debhelper::Dh_Getopt;
10 use Debian::Debhelper::Dh_Lib;
13 #use vars qw{@ISA @EXPORT};
15 #@EXPORT=qw(&aparseopts); # FIXME: for some reason, this doesn't work.
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;
34 elsif ($option eq 's' or $option eq 'same-arch') {
35 push @{$options{DOPACKAGES}}, GetPackages('same');
39 error("bad option $option - should never happen!\n");
43 # Add a package to a list of packages that should not be acted on.
44 sub ExcludePackage { my($option,$value)=@_;
45 $exclude_package{$value}=1;
48 # Add another item to the exclude list.
49 sub AddExclude { my($option,$value)=@_;
50 push @{$options{EXCLUDE}},$value;
53 # This collects non-options values.
55 push @{$options{ARGV}}, @_;
58 # Parse options and return a hash of the values.
63 "v" => \$options{VERBOSE},
64 "verbose" => \$options{VERBOSE},
67 "indep" => \&AddPackage,
70 "arch" => \&AddPackage,
72 "p=s" => \&AddPackage,
73 "package=s" => \&AddPackage,
76 "same-arch" => \&AddPackage,
78 "N=s" => \&ExcludePackage,
79 "no-package=s" => \&ExcludePackage,
81 "n" => \$options{NOSCRIPTS},
82 "noscripts" => \$options{NOSCRIPTS},
84 "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
85 "include-conffiles" => \$options{INCLUDE_CONFFILES},
87 "X=s" => \&AddExclude,
88 "exclude=s" => \&AddExclude,
90 "d" => \$options{D_FLAG},
91 "remove-d" => \$options{D_FLAG},
92 "dirs-only" => \$options{D_FLAG},
94 "r" => \$options{R_FLAG},
95 "no-restart-on-upgrade" => \$options{R_FLAG},
97 "k" => \$options{K_FLAG},
98 "keep" => \$options{K_FLAG},
100 "P=s" => \$options{TMPDIR},
101 "tmpdir=s" => \$options{TMPDIR},
103 "u=s", => \$options{U_PARAMS},
104 "update-rcd-params=s", => \$options{U_PARAMS},
105 "dpkg-shlibdeps-params=s", => \$options{U_PARAMS},
106 "dpkg-gencontrol-params=s", => \$options{U_PARAMS},
108 "l=s", => \$options{L_PARAMS},
110 "m=s", => \$options{M_PARAMS},
111 "major=s" => \$options{M_PARAMS},
113 "V:s", => \$options{V_FLAG},
114 "version-info:s" => \$options{V_FLAG},
116 "A" => \$options{PARAMS_ALL},
117 "all" => \$options{PARAMS_ALL},
119 "no-act" => \$options{NO_ACT},
121 "init-script=s" => \$options{INIT_SCRIPT},
123 "sourcedir=s" => \$options{SOURCEDIR},
125 "destdir=s" => \$options{DESTDIR},
127 "filename=s" => \$options{FILENAME},
129 "priority=i" => \$options{PRIORITY},
131 "flavor=s" => \$options{FLAVOR},
137 error("unknown option; aborting");
140 # Check to see if -V was specified. If so, but no parameters were
141 # passed, the variable will be defined but empty.
142 if (defined($options{V_FLAG})) {
143 $options{V_FLAG_SET}=1;
146 # If we have not been given any packages to act on, assume they
147 # want us to act on them all. Note we have to do this before excluding
148 # packages out, below.
149 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
150 if ($options{DOINDEP} || $options{DOARCH} || $options{DOSAME}) {
151 # User specified that all arch (in)dep package be
152 # built, and there are none of that type.
153 error("I have no package to build");
155 push @{$options{DOPACKAGES}},GetPackages();
158 # Remove excluded packages from the list of packages to act on.
161 foreach $package (@{$options{DOPACKAGES}}) {
162 if (! $exclude_package{$package}) {
163 push @package_list, $package;
166 @{$options{DOPACKAGES}}=@package_list;
168 # Generate EXCLUDE_FIND.
169 $options{EXCLUDE_FIND}='';
170 foreach (@{$options{EXCLUDE}}) {
171 $options{EXCLUDE_FIND}.="-regex .*".quotemeta($_).".* -or ";
173 $options{EXCLUDE_FIND}=~s/ -or $//;
175 # If there are no packages to act on now, it's an error.
176 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
177 error("I have no package to build");
180 # Anything left in @ARGV is options that appeared after a --
181 # These options are added to U_PARAMS, while the non-option
182 # values we collected replace them in @ARGV;
183 $options{U_PARAMS}.=join(' ', @ARGV);
184 @ARGV=@{$options{ARGV}} if exists $options{ARGV};
190 # Enable bundling of short command line options.
191 Getopt::Long::config("bundling");