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(1)\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},
105 "k" => \$options{K_FLAG},
106 "keep" => \$options{K_FLAG},
108 "P=s" => \$options{TMPDIR},
109 "tmpdir=s" => \$options{TMPDIR},
111 "u=s", => \$options{U_PARAMS},
112 "update-rcd-params=s", => \$options{U_PARAMS},
113 "dpkg-shlibdeps-params=s", => \$options{U_PARAMS},
114 "dpkg-gencontrol-params=s", => \$options{U_PARAMS},
116 "l=s", => \$options{L_PARAMS},
118 "m=s", => \$options{M_PARAMS},
119 "major=s" => \$options{M_PARAMS},
121 "V:s", => \$options{V_FLAG},
122 "version-info:s" => \$options{V_FLAG},
124 "A" => \$options{PARAMS_ALL},
125 "all" => \$options{PARAMS_ALL},
127 "no-act" => \$options{NO_ACT},
129 "init-script=s" => \$options{INIT_SCRIPT},
131 "sourcedir=s" => \$options{SOURCEDIR},
133 "destdir=s" => \$options{DESTDIR},
135 "filename=s" => \$options{FILENAME},
137 "priority=i" => \$options{PRIORITY},
139 "flavor=s" => \$options{FLAVOR},
141 "autodest" => \$options{AUTODEST},
143 "h|help" => \&showhelp,
149 error("unknown option; aborting");
152 # Check to see if -V was specified. If so, but no parameters were
153 # passed, the variable will be defined but empty.
154 if (defined($options{V_FLAG})) {
155 $options{V_FLAG_SET}=1;
158 # If we have not been given any packages to act on, assume they
159 # want us to act on them all. Note we have to do this before excluding
160 # packages out, below.
161 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
162 if ($options{DOINDEP} || $options{DOARCH} || $options{DOSAME}) {
163 # User specified that all arch (in)dep package be
164 # built, and there are none of that type.
165 error("I have no package to build");
167 push @{$options{DOPACKAGES}},GetPackages();
170 # Remove excluded packages from the list of packages to act on.
173 foreach $package (@{$options{DOPACKAGES}}) {
174 if (! $exclude_package{$package}) {
175 push @package_list, $package;
178 @{$options{DOPACKAGES}}=@package_list;
180 # If there are no packages to act on now, it's an error.
181 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
182 error("I have no package to build");
185 if (defined $options{U_PARAMS}) {
186 # Split the U_PARAMS up into an array.
187 my $u=$options{U_PARAMS};
188 undef $options{U_PARAMS};
189 push @{$options{U_PARAMS}}, split(/\s+/,$u);
192 # Anything left in @ARGV is options that appeared after a --
193 # These options are added to the U_PARAMS array, while the
194 # non-option values we collected replace them in @ARGV;
195 push @{$options{U_PARAMS}}, @ARGV;
196 @ARGV=@{$options{ARGV}} if exists $options{ARGV};
202 # Enable bundling of short command line options.
203 Getopt::Long::config("bundling");