3 # Debhelper option processing library.
5 # Joey Hess GPL copyright 1998-2002
7 package Debian::Debhelper::Dh_Getopt;
10 use Debian::Debhelper::Dh_Lib;
16 my $prog=basename($0);
17 print "Usage: $prog [options]\n\n";
18 print " $prog is a part of debhelper. See debhelper(7)\n";
19 print " and $prog(1) for complete usage instructions.\n";
23 # Passed an option name and an option value, adds packages to the list
24 # of packages. We need this so the list will be built up in the right
26 sub AddPackage { my($option,$value)=@_;
27 if ($option eq 'i' or $option eq 'indep') {
28 push @{$dh{DOPACKAGES}}, getpackages('indep');
31 elsif ($option eq 'a' or $option eq 'arch') {
32 push @{$dh{DOPACKAGES}}, getpackages('arch');
35 elsif ($option eq 'p' or $option eq 'package') {
36 push @{$dh{DOPACKAGES}}, $value;
38 elsif ($option eq 's' or $option eq 'same-arch') {
39 push @{$dh{DOPACKAGES}}, getpackages('same');
43 error("bad option $option - should never happen!\n");
47 # Adds packages to the list of debug packages.
48 sub AddDebugPackage { my($option,$value)=@_;
49 push @{$dh{DEBUGPACKAGES}}, $value;
52 # Add a package to a list of packages that should not be acted on.
53 sub ExcludePackage { my($option,$value)=@_;
54 $exclude_package{$value}=1;
57 # Add another item to the exclude list.
58 sub AddExclude { my($option,$value)=@_;
59 push @{$dh{EXCLUDE}},$value;
62 # Add a file to the ignore list.
63 sub AddIgnore { my($option,$file)=@_;
64 $dh{IGNORE}->{$file}=1;
67 # Add an item to the with list.
68 sub AddWith { my($option,$value)=@_;
69 push @{$dh{WITH}},$value;
72 # This collects non-options values.
74 push @{$dh{ARGV}}, @_;
77 # Parse options and set %dh values.
79 my %options=%{shift()} if ref $_[0];
83 "verbose" => \$dh{VERBOSE},
86 "indep" => \&AddPackage,
89 "arch" => \&AddPackage,
91 "p=s" => \&AddPackage,
92 "package=s" => \&AddPackage,
94 "dbg-package=s" => \&AddDebugPackage,
97 "same-arch" => \&AddPackage,
99 "N=s" => \&ExcludePackage,
100 "no-package=s" => \&ExcludePackage,
102 "n" => \$dh{NOSCRIPTS},
103 "noscripts" => \$dh{NOSCRIPTS},
104 "o" => \$dh{ONLYSCRIPTS},
105 "onlyscripts" => \$dh{ONLYSCRIPTS},
107 "x" => \$dh{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
108 "include-conffiles" => \$dh{INCLUDE_CONFFILES},
110 "X=s" => \&AddExclude,
111 "exclude=s" => \&AddExclude,
113 "ignore=s" => \&AddIgnore,
116 "remove-d" => \$dh{D_FLAG},
117 "dirs-only" => \$dh{D_FLAG},
120 "no-restart-on-upgrade" => \$dh{R_FLAG},
121 "no-start" => \$dh{NO_START},
122 "R|restart-after-upgrade" => \$dh{RESTART_AFTER_UPGRADE},
125 "keep" => \$dh{K_FLAG},
126 "keep-debug" => \$dh{K_FLAG},
128 "P=s" => \$dh{TMPDIR},
129 "tmpdir=s" => \$dh{TMPDIR},
131 "u=s", => \$dh{U_PARAMS},
132 "update-rcd-params=s", => \$dh{U_PARAMS},
133 "dpkg-shlibdeps-params=s", => \$dh{U_PARAMS},
134 "dpkg-gencontrol-params=s", => \$dh{U_PARAMS},
136 "l=s", => \$dh{L_PARAMS},
138 "m=s", => \$dh{M_PARAMS},
139 "major=s" => \$dh{M_PARAMS},
141 "V:s", => \$dh{V_FLAG},
142 "version-info:s" => \$dh{V_FLAG},
144 "A" => \$dh{PARAMS_ALL},
145 "all" => \$dh{PARAMS_ALL},
147 "no-act" => \$dh{NO_ACT},
149 "init-script=s" => \$dh{INIT_SCRIPT},
151 "sourcedir=s" => \$dh{SOURCEDIR},
153 "destdir=s" => \$dh{DESTDIR},
155 "filename=s" => \$dh{FILENAME},
157 "priority=s" => \$dh{PRIORITY},
159 "flavor=s" => \$dh{FLAVOR},
161 "autodest" => \$dh{AUTODEST},
163 "h|help" => \&showhelp,
165 "mainpackage=s" => \$dh{MAINPACKAGE},
167 "list-missing" => \$dh{LIST_MISSING},
169 "fail-missing" => \$dh{FAIL_MISSING},
171 "L|libpackage=s" => \$dh{LIBPACKAGE},
173 "name=s" => \$dh{NAME},
175 "error-handler=s" => \$dh{ERROR_HANDLER},
177 "add-udeb=s" => \$dh{SHLIBS_UDEB},
179 "language=s" => \$dh{LANGUAGE},
181 "until=s" => \$dh{UNTIL},
182 "after=s" => \$dh{AFTER},
183 "before=s" => \$dh{BEFORE},
184 "remaining" => \$dh{REMAINING},
185 "with=s" => \&AddWith,
193 error("unknown option; aborting");
196 # Check to see if -V was specified. If so, but no parameters were
197 # passed, the variable will be defined but empty.
198 if (defined($dh{V_FLAG})) {
202 # If we have not been given any packages to act on, assume they
203 # want us to act on them all. Note we have to do this before excluding
204 # packages out, below.
205 if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
206 if ($dh{DOINDEP} || $dh{DOARCH} || $dh{DOSAME}) {
207 # User specified that all arch (in)dep package be
208 # built, and there are none of that type.
209 warning("I have no package to build");
212 push @{$dh{DOPACKAGES}},getpackages();
215 # Remove excluded packages from the list of packages to act on.
216 # Also unique the list, in case some options were specified that
217 # added a package to it twice.
221 foreach $package (@{$dh{DOPACKAGES}}) {
222 if (! $exclude_package{$package}) {
223 if (! exists $packages_seen{$package}) {
224 $packages_seen{$package}=1;
225 push @package_list, $package;
229 @{$dh{DOPACKAGES}}=@package_list;
231 # If there are no packages to act on now, it's an error.
232 if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
233 error("I have no package to build");
236 if (defined $dh{U_PARAMS}) {
237 # Split the U_PARAMS up into an array.
240 push @{$dh{U_PARAMS}}, split(/\s+/,$u);
243 # Anything left in @ARGV is options that appeared after a --
244 # These options are added to the U_PARAMS array, while the
245 # non-option values we collected replace them in @ARGV;
246 push @{$dh{U_PARAMS}}, @ARGV;
247 @ARGV=@{$dh{ARGV}} if exists $dh{ARGV};
251 # Enable bundling of short command line options.
252 Getopt::Long::config("bundling");