3 # Debhelper option processing library.
5 # Joey Hess GPL copyright 1998.
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 # Parse options and return a hash of the values.
58 "v" => \$options{VERBOSE},
59 "verbose" => \$options{VERBOSE},
62 "indep" => \&AddPackage,
65 "arch" => \&AddPackage,
67 "p=s" => \&AddPackage,
68 "package=s" => \&AddPackage,
71 "same-arch" => \&AddPackage,
73 "N=s" => \&ExcludePackage,
74 "no-package=s" => \&ExcludePackage,
76 "n" => \$options{NOSCRIPTS},
77 "noscripts" => \$options{NOSCRIPTS},
79 "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
80 "include-conffiles" => \$options{INCLUDE_CONFFILES},
82 "X=s" => \&AddExclude,
83 "exclude=s" => \&AddExclude,
85 "d" => \$options{D_FLAG},
86 "remove-d" => \$options{D_FLAG},
87 "dirs-only" => \$options{D_FLAG},
89 "r" => \$options{R_FLAG},
90 "no-restart-on-upgrade" => \$options{R_FLAG},
92 "k" => \$options{K_FLAG},
93 "keep" => \$options{K_FLAG},
95 "P=s" => \$options{TMPDIR},
96 "tmpdir=s" => \$options{TMPDIR},
98 "u=s", => \$options{U_PARAMS},
99 "update-rcd-params=s", => \$options{U_PARAMS},
100 "dpkg-shlibdeps-params=s", => \$options{U_PARAMS},
101 "dpkg-gencontrol-params=s", => \$options{U_PARAMS},
103 "m=s", => \$options{M_PARAMS},
104 "major=s" => \$options{M_PARAMS},
106 "V:s", => \$options{V_FLAG},
107 "version-info:s" => \$options{V_FLAG},
109 "A" => \$options{PARAMS_ALL},
110 "all" => \$options{PARAMS_ALL},
112 "no-act" => \$options{NO_ACT},
114 "init-script=s" => \$options{INIT_SCRIPT},
116 "sourcedir=s" => \$options{SOURCEDIR},
118 "destdir=s" => \$options{DESTDIR},
122 error("unknown option; aborting");
125 # Check to see if -V was specified. If so, but no parameters were
126 # passed, the variable will be defined but empty.
127 if (defined($options{V_FLAG})) {
128 $options{V_FLAG_SET}=1;
131 # If we have not been given any packages to act on, assume they
132 # want us to act on them all. Note we have to do this before excluding
133 # packages out, below.
134 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
135 if ($options{DOINDEP} || $options{DOARCH} || $options{DOSAME}) {
136 # User specified that all arch (in)dep package be
137 # built, and there are none of that type.
138 error("I have no package to build");
140 push @{$options{DOPACKAGES}},GetPackages();
143 # Remove excluded packages from the list of packages to act on.
146 foreach $package (@{$options{DOPACKAGES}}) {
147 if (! $exclude_package{$package}) {
148 push @package_list, $package;
151 @{$options{DOPACKAGES}}=@package_list;
153 # Generate EXCLUDE_FIND.
154 $options{EXCLUDE_FIND}='';
155 foreach (@{$options{EXCLUDE}}) {
156 $options{EXCLUDE_FIND}.="-regex .*".quotemeta($_).".* -or ";
158 $options{EXCLUDE_FIND}=~s/ -or $//;
160 # If there are no packages to act on now, it's an error.
161 if (! defined $options{DOPACKAGES} || ! @{$options{DOPACKAGES}}) {
162 error("I have no package to build");
169 # Enable bundling of short command line options.
170 Getopt::Long::config("bundling");