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 # Adds packages to the list of debug packages.
52 sub AddDebugPackage { my($option,$value)=@_;
53 push @{$options{DEBUGPACKAGES}}, $value;
56 # Add a package to a list of packages that should not be acted on.
57 sub ExcludePackage { my($option,$value)=@_;
58 $exclude_package{$value}=1;
61 # Add another item to the exclude list.
62 sub AddExclude { my($option,$value)=@_;
63 push @{$options{EXCLUDE}},$value;
66 # Add a file to the ignore list.
67 sub AddIgnore { my($option,$file)=@_;
68 $options{IGNORE}->{$file}=1;
71 # This collects non-options values.
73 push @{$options{ARGV}}, @_;
76 # Parse options and return a hash of the values.
81 "v" => \$options{VERBOSE},
82 "verbose" => \$options{VERBOSE},
85 "indep" => \&AddPackage,
88 "arch" => \&AddPackage,
90 "p=s" => \&AddPackage,
91 "package=s" => \&AddPackage,
93 "dbg-package=s" => \&AddDebugPackage,
96 "same-arch" => \&AddPackage,
98 "N=s" => \&ExcludePackage,
99 "no-package=s" => \&ExcludePackage,
101 "n" => \$options{NOSCRIPTS},
102 "noscripts" => \$options{NOSCRIPTS},
103 "o" => \$options{ONLYSCRIPTS},
104 "onlyscripts" => \$options{ONLYSCRIPTS},
106 "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
107 "include-conffiles" => \$options{INCLUDE_CONFFILES},
109 "X=s" => \&AddExclude,
110 "exclude=s" => \&AddExclude,
112 "ignore=s" => \&AddIgnore,
114 "d" => \$options{D_FLAG},
115 "remove-d" => \$options{D_FLAG},
116 "dirs-only" => \$options{D_FLAG},
118 "r" => \$options{R_FLAG},
119 "no-restart-on-upgrade" => \$options{R_FLAG},
120 "no-start" => \$options{NO_START},
122 "k" => \$options{K_FLAG},
123 "keep" => \$options{K_FLAG},
125 "P=s" => \$options{TMPDIR},
126 "tmpdir=s" => \$options{TMPDIR},
128 "u=s", => \$options{U_PARAMS},
129 "update-rcd-params=s", => \$options{U_PARAMS},
130 "dpkg-shlibdeps-params=s", => \$options{U_PARAMS},
131 "dpkg-gencontrol-params=s", => \$options{U_PARAMS},
133 "l=s", => \$options{L_PARAMS},
135 "m=s", => \$options{M_PARAMS},
136 "major=s" => \$options{M_PARAMS},
138 "V:s", => \$options{V_FLAG},
139 "version-info:s" => \$options{V_FLAG},
141 "A" => \$options{PARAMS_ALL},
142 "all" => \$options{PARAMS_ALL},
144 "no-act" => \$options{NO_ACT},
146 "init-script=s" => \$options{INIT_SCRIPT},
148 "sourcedir=s" => \$options{SOURCEDIR},
150 "destdir=s" => \$options{DESTDIR},
152 "filename=s" => \$options{FILENAME},
154 "priority=s" => \$options{PRIORITY},
156 "flavor=s" => \$options{FLAVOR},
158 "autodest" => \$options{AUTODEST},
160 "h|help" => \&showhelp,
162 "mainpackage=s" => \$options{MAINPACKAGE},
164 "list-missing" => \$options{LIST_MISSING},
166 "fail-missing" => \$options{FAIL_MISSING},
168 "L|libpackage=s" => \$options{LIBPACKAGE},
170 "name=s" => \$options{NAME},
172 "keep-debug" => \$options{KEEP_DEBUG},
174 "error-handler=s" => \$options{ERROR_HANDLER},
176 "add-udeb=s" => \$options{SHLIBS_UDEB},
178 "language=s" => \$options{LANGUAGE},
184 error("unknown option; aborting");
187 # Check to see if -V was specified. If so, but no parameters were
188 # passed, the variable will be defined but empty.
189 if (defined($options{V_FLAG})) {
190 $options{V_FLAG_SET}=1;
193 # If we have not been given any packages to act on, assume they
194 # want us to act on them all. Note we have to do this before excluding
195 # packages out, below.
196 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
197 if ($options{DOINDEP} || $options{DOARCH} || $options{DOSAME}) {
198 # User specified that all arch (in)dep package be
199 # built, and there are none of that type.
200 warning("I have no package to build");
203 push @{$options{DOPACKAGES}},getpackages();
206 # Remove excluded packages from the list of packages to act on.
207 # Also unique the list, in case some options were specified that
208 # added a package to it twice.
212 foreach $package (@{$options{DOPACKAGES}}) {
213 if (! $exclude_package{$package}) {
214 if (! exists $packages_seen{$package}) {
215 $packages_seen{$package}=1;
216 push @package_list, $package;
220 @{$options{DOPACKAGES}}=@package_list;
222 # If there are no packages to act on now, it's an error.
223 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
224 error("I have no package to build");
227 if (defined $options{U_PARAMS}) {
228 # Split the U_PARAMS up into an array.
229 my $u=$options{U_PARAMS};
230 undef $options{U_PARAMS};
231 push @{$options{U_PARAMS}}, split(/\s+/,$u);
234 # Anything left in @ARGV is options that appeared after a --
235 # These options are added to the U_PARAMS array, while the
236 # non-option values we collected replace them in @ARGV;
237 push @{$options{U_PARAMS}}, @ARGV;
238 @ARGV=@{$options{ARGV}} if exists $options{ARGV};
244 # Enable bundling of short command line options.
245 Getopt::Long::config("bundling");