3 # Debhelper option processing library.
5 # Joey Hess GPL copyright 1998-2002
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);
20 my $prog=basename($0);
21 print "Usage: $prog [options]\n\n";
22 print " $prog is a part of debhelper. See debhelper(7)\n";
23 print " and $prog(1) for complete usage instructions.\n";
27 # Passed an option name and an option value, adds packages to the list
28 # of packages. We need this so the list will be built up in the right
30 sub AddPackage { my($option,$value)=@_;
31 if ($option eq 'i' or $option eq 'indep') {
32 push @{$options{DOPACKAGES}}, GetPackages('indep');
35 elsif ($option eq 'a' or $option eq 'arch') {
36 push @{$options{DOPACKAGES}}, GetPackages('arch');
39 elsif ($option eq 'p' or $option eq 'package') {
40 push @{$options{DOPACKAGES}}, $value;
42 elsif ($option eq 's' or $option eq 'same-arch') {
43 push @{$options{DOPACKAGES}}, GetPackages('same');
47 error("bad option $option - should never happen!\n");
51 # Add a package to a list of packages that should not be acted on.
52 sub ExcludePackage { my($option,$value)=@_;
53 $exclude_package{$value}=1;
56 # Add another item to the exclude list.
57 sub AddExclude { my($option,$value)=@_;
58 push @{$options{EXCLUDE}},$value;
61 # This collects non-options values.
63 push @{$options{ARGV}}, @_;
66 # Parse options and return a hash of the values.
71 "v" => \$options{VERBOSE},
72 "verbose" => \$options{VERBOSE},
75 "indep" => \&AddPackage,
78 "arch" => \&AddPackage,
80 "p=s" => \&AddPackage,
81 "package=s" => \&AddPackage,
84 "same-arch" => \&AddPackage,
86 "N=s" => \&ExcludePackage,
87 "no-package=s" => \&ExcludePackage,
89 "n" => \$options{NOSCRIPTS},
90 "noscripts" => \$options{NOSCRIPTS},
92 "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
93 "include-conffiles" => \$options{INCLUDE_CONFFILES},
95 "X=s" => \&AddExclude,
96 "exclude=s" => \&AddExclude,
98 "d" => \$options{D_FLAG},
99 "remove-d" => \$options{D_FLAG},
100 "dirs-only" => \$options{D_FLAG},
102 "r" => \$options{R_FLAG},
103 "no-restart-on-upgrade" => \$options{R_FLAG},
104 "no-start" => \$options{NO_START},
106 "k" => \$options{K_FLAG},
107 "keep" => \$options{K_FLAG},
109 "P=s" => \$options{TMPDIR},
110 "tmpdir=s" => \$options{TMPDIR},
112 "u=s", => \$options{U_PARAMS},
113 "update-rcd-params=s", => \$options{U_PARAMS},
114 "dpkg-shlibdeps-params=s", => \$options{U_PARAMS},
115 "dpkg-gencontrol-params=s", => \$options{U_PARAMS},
117 "l=s", => \$options{L_PARAMS},
119 "m=s", => \$options{M_PARAMS},
120 "major=s" => \$options{M_PARAMS},
122 "V:s", => \$options{V_FLAG},
123 "version-info:s" => \$options{V_FLAG},
125 "A" => \$options{PARAMS_ALL},
126 "all" => \$options{PARAMS_ALL},
128 "no-act" => \$options{NO_ACT},
130 "init-script=s" => \$options{INIT_SCRIPT},
132 "sourcedir=s" => \$options{SOURCEDIR},
134 "destdir=s" => \$options{DESTDIR},
136 "filename=s" => \$options{FILENAME},
138 "priority=i" => \$options{PRIORITY},
140 "flavor=s" => \$options{FLAVOR},
142 "autodest" => \$options{AUTODEST},
144 "h|help" => \&showhelp,
146 "mainpackage=s" => \$options{MAINPACKAGE},
148 "list-missing" => \$options{LIST_MISSING},
150 "L|libpackage=s" => \$options{LIBPACKAGE},
152 "name=s" => \$options{NAME},
158 error("unknown option; aborting");
161 # Check to see if -V was specified. If so, but no parameters were
162 # passed, the variable will be defined but empty.
163 if (defined($options{V_FLAG})) {
164 $options{V_FLAG_SET}=1;
167 # If we have not been given any packages to act on, assume they
168 # want us to act on them all. Note we have to do this before excluding
169 # packages out, below.
170 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
171 if ($options{DOINDEP} || $options{DOARCH} || $options{DOSAME}) {
172 # User specified that all arch (in)dep package be
173 # built, and there are none of that type.
174 error("I have no package to build");
176 push @{$options{DOPACKAGES}},GetPackages();
179 # Remove excluded packages from the list of packages to act on.
180 # Also unique the list, in case some options were specified that
181 # added a package to it twice.
185 foreach $package (@{$options{DOPACKAGES}}) {
186 if (! $exclude_package{$package}) {
187 if (! exists $packages_seen{$package}) {
188 $packages_seen{$package}=1;
189 push @package_list, $package;
193 @{$options{DOPACKAGES}}=@package_list;
195 # If there are no packages to act on now, it's an error.
196 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
197 error("I have no package to build");
200 if (defined $options{U_PARAMS}) {
201 # Split the U_PARAMS up into an array.
202 my $u=$options{U_PARAMS};
203 undef $options{U_PARAMS};
204 push @{$options{U_PARAMS}}, split(/\s+/,$u);
207 # Anything left in @ARGV is options that appeared after a --
208 # These options are added to the U_PARAMS array, while the
209 # non-option values we collected replace them in @ARGV;
210 push @{$options{U_PARAMS}}, @ARGV;
211 @ARGV=@{$options{ARGV}} if exists $options{ARGV};
217 # Enable bundling of short command line options.
218 Getopt::Long::config("bundling");