]> git.donarmstrong.com Git - debhelper.git/blob - dh_getopt.pl
r108: Initial Import
[debhelper.git] / dh_getopt.pl
1 #!/usr/bin/perl
2 #
3 # Because the getopt() program is so horribly broken, I wrote my own argument
4 # processer that uses the find Getopt::Long module. This is used by all
5 # debhelper shell scripts.
6 #
7 # Joey Hess, GPL copyright 1998.
8
9 BEGIN { push @INC, "debian", "/usr/lib/debhelper" }
10 use Dh_Getopt;
11
12 # This is a tricky (and nasty) bit: override the error() function, which
13 # comes from Dh_Lib, with one of our own so we print out the list of errors
14 # to the shell, which can do what it wants with them.
15 sub Dh_Getopt::error { my $message=shift;
16         print "DH_PARSE_ERROR='$message'\n";
17         exit 1;
18 }
19
20 # Parse options.
21 %options=Dh_Getopt::parseopts();
22
23 # Change a few lists in %options into strings,
24 # generate some options that only need to be visible to the
25 # shell scripts so Dh_Getopt doesn't bother generating.
26 $options{DOPACKAGES}=join " ",@{$options{DOPACKAGES}};
27 if ($#{$options{EXCLUDE}} > -1) {
28         $options{EXCLUDE_GREP}=join '|', @{$options{EXCLUDE}};
29         foreach (@{$options{EXCLUDE}}) {
30                 $options{EXCLUDE_FIND}.="-regex .*".quotemeta($_).".* -or ";
31         }
32         $options{EXCLUDE_FIND}=~s/ -or $//;
33 }
34 $options{EXCLUDE}=join " ",@{$options{EXCLUDE}};
35
36 # Now output everything, in a format suitable for a shell to eval it.
37 foreach (keys(%options)) { print "DH_$_='$options{$_}'\n" };
38
39 # This sets $@ in the shell to whatever arguements remain.
40 print "set -- @ARGV\n"