]> git.donarmstrong.com Git - debhelper.git/blob - dh_getopt.pl
r245: 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 strict;
11 use Dh_Getopt;
12
13 # This is a tricky (and nasty) bit: override the error() function, which
14 # comes from Dh_Lib, with one of our own so we print out the list of errors
15 # to the shell, which can do what it wants with them.
16 sub Dh_Getopt::error { my $message=shift;
17         print "DH_PARSE_ERROR='$message'\n";
18         exit 1;
19 }
20
21 # Parse options.
22 my %options=Dh_Getopt::parseopts();
23
24 # Change a few lists in %options into strings,
25 # generate some options that only need to be visible to the
26 # shell scripts so Dh_Getopt doesn't bother generating.
27 $options{DOPACKAGES}=join " ",@{$options{DOPACKAGES}};
28 if ($#{$options{EXCLUDE}} > -1) {
29         $options{EXCLUDE_GREP}=join '|', @{$options{EXCLUDE}};
30 }
31 $options{EXCLUDE}=join " ",@{$options{EXCLUDE}};
32
33 # Check to see if DH_VERBOSE environment variable was set, if so,
34 # make sure verbose is on.
35 if (defined $main::ENV{DH_VERBOSE}) {
36         if ($main::ENV{DH_VERBOSE} ne undef) {
37                 $options{VERBOSE}=1;
38         }
39 }
40
41 # Check to see if DH_NO_ACT environment variable was set, if so, 
42 # make sure no act mode is on.
43 if (defined $main::ENV{DH_NO_ACT}) {
44         if ($main::ENV{DH_NO_ACT} ne undef) {
45                 $options{NO_ACT}=1;
46         }
47 }
48
49 # Now output everything, in a format suitable for a shell to eval it.
50 foreach (keys(%options)) {
51         if (defined $options{$_}) {
52                 print "DH_$_='$options{$_}'\n";
53         }
54 }
55
56 # This sets $@ in the shell to whatever arguements remain.
57 print "set -- @ARGV\n"