summaryrefslogtreecommitdiff
path: root/dh_getopt.pl
blob: 4d1d39039567294d2f7dddc55b2c55d996aa20a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
#
# Because the getopt() program is so horribly broken, I wrote my own argument
# processer that uses the find Getopt::Long module. This is used by all
# debhelper shell scripts.
#
# Joey Hess, GPL copyright 1998.

BEGIN { push @INC, "debian", "/usr/lib/debhelper" }
use strict;
use Dh_Getopt;

# This is a tricky (and nasty) bit: override the error() function, which
# comes from Dh_Lib, with one of our own so we print out the list of errors
# to the shell, which can do what it wants with them.
sub Dh_Getopt::error { my $message=shift;
	print "DH_PARSE_ERROR='$message'\n";
	exit 1;
}

# Parse options.
my %options=Dh_Getopt::parseopts();

# Change a few lists in %options into strings,
# generate some options that only need to be visible to the
# shell scripts so Dh_Getopt doesn't bother generating.
$options{DOPACKAGES}=join " ",@{$options{DOPACKAGES}};
if ($#{$options{EXCLUDE}} > -1) {
	$options{EXCLUDE_GREP}=join '|', @{$options{EXCLUDE}};
}
$options{EXCLUDE}=join " ",@{$options{EXCLUDE}};

# Check to see if DH_VERBOSE environment variable was set, if so,
# make sure verbose is on.
if (defined $main::ENV{DH_VERBOSE}) {
	if ($main::ENV{DH_VERBOSE} ne undef) {
		$options{VERBOSE}=1;
	}
}

# Check to see if DH_NO_ACT environment variable was set, if so, 
# make sure no act mode is on.
if (defined $main::ENV{DH_NO_ACT}) {
	if ($main::ENV{DH_NO_ACT} ne undef) {
		$options{NO_ACT}=1;
	}
}

# Now output everything, in a format suitable for a shell to eval it.
foreach (keys(%options)) {
	if (defined $options{$_}) {
		print "DH_$_='$options{$_}'\n";
	}
}

# This sets $@ in the shell to whatever arguements remain.
print "set -- @ARGV\n"