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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#! perl -w
use strict ;
use ExtUtils::MakeMaker 5.16 ;
use Config ;
my $VER_INFO ;
my $LIB_DIR ;
my $INC_DIR ;
my $DB_NAME ;
my $LIBS ;
my $COMPAT185 = "" ;
my @files = ('DB_File.pm', glob "t/*.t") ;
# See if warnings is available
eval 'use warnings;';
if ($@) {
# not there, so write a dummy warnings.pm
oldWarnings(@files) ;
} else {
# is there,
newWarnings(@files) ;
}
ParseCONFIG() ;
if (defined $DB_NAME)
{ $LIBS = $DB_NAME }
else {
if ($^O eq 'MSWin32')
{ $LIBS = '-llibdb' }
else
{ $LIBS = '-ldb' }
}
# Solaris is special.
#$LIBS .= " -lthread" if $^O eq 'solaris' ;
# OS2 is a special case, so check for it now.
my $OS2 = "" ;
$OS2 = "-DOS2" if $Config{'osname'} eq 'os2' ;
WriteMakefile(
NAME => 'DB_File',
LIBS => ["-L${LIB_DIR} $LIBS"],
MAN3PODS => ' ', # Pods will be built by installman.
INC => "-I$INC_DIR",
VERSION_FROM => 'DB_File.pm',
XSPROTOARG => '-noprototypes',
DEFINE => "$OS2 $VER_INFO $COMPAT185",
OBJECT => 'version$(OBJ_EXT) DB_File$(OBJ_EXT)',
OPTIMIZE => '-g',
'macro' => { INSTALLDIRS => 'perl' },
'dist' => {COMPRESS=>'gzip', SUFFIX=>'gz'},
);
sub MY::postamble {
'
version$(OBJ_EXT): version.c
$(NAME).xs: typemap
@$(TOUCH) $(NAME).xs
Makefile: config.in
' ;
}
sub ParseCONFIG
{
my ($k, $v) ;
my @badkey = () ;
my %Info = () ;
my @Options = qw( INCLUDE LIB PREFIX HASH DBNAME COMPAT185 ) ;
my %ValidOption = map {$_, 1} @Options ;
my %Parsed = %ValidOption ;
my $CONFIG = 'config.in' ;
print "Parsing $CONFIG...\n" ;
# DBNAME & COMPAT185 are optional, so pretend they have
# been parsed.
delete $Parsed{'DBNAME'} ;
delete $Parsed{'COMPAT185'} ;
$Info{COMPAT185} = "No" ;
open(F, "$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
while (<F>) {
s/^\s*|\s*$//g ;
next if /^\s*$/ or /^\s*#/ ;
s/\s*#\s*$// ;
($k, $v) = split(/\s+=\s+/, $_, 2) ;
$k = uc $k ;
if ($ValidOption{$k}) {
delete $Parsed{$k} ;
$Info{$k} = $v ;
}
else {
push(@badkey, $k) ;
}
}
close F ;
print "Unknown keys in $CONFIG ignored [@badkey]\n"
if @badkey ;
# check parsed values
my @missing = () ;
die "The following keys are missing from $CONFIG file: [@missing]\n"
if @missing = keys %Parsed ;
$INC_DIR = $ENV{'DB_FILE_INCLUDE'} || $Info{'INCLUDE'} ;
$LIB_DIR = $ENV{'DB_FILE_LIB'} || $Info{'LIB'} ;
$DB_NAME = $Info{'DBNAME'} if defined $Info{'DBNAME'} ;
$COMPAT185 = "-DCOMPAT185 -DDB_LIBRARY_COMPATIBILITY_API"
if (defined $ENV{'DB_FILE_COMPAT185'} &&
$ENV{'DB_FILE_COMPAT185'} =~ /^\s*(on|true|1)\s*$/i) ||
$Info{'COMPAT185'} =~ /^\s*(on|true|1)\s*$/i ;
my $PREFIX = $Info{'PREFIX'} ;
my $HASH = $Info{'HASH'} ;
$VER_INFO = "-DmDB_Prefix_t=${PREFIX} -DmDB_Hash_t=${HASH}" ;
print <<EOM if 0 ;
INCLUDE [$INC_DIR]
LIB [$LIB_DIR]
HASH [$HASH]
PREFIX [$PREFIX]
DBNAME [$DB_NAME]
EOM
print "Looks Good.\n" ;
}
sub oldWarnings
{
local ($^I) = ".bak" ;
local (@ARGV) = @_ ;
while (<>)
{
if (/^__END__/)
{
print ;
my $this = $ARGV ;
while (<>)
{
last if $ARGV ne $this ;
print ;
}
}
s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ;
s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ;
print ;
}
}
sub newWarnings
{
local ($^I) = ".bak" ;
local (@ARGV) = @_ ;
while (<>)
{
if (/^__END__/)
{
my $this = $ARGV ;
print ;
while (<>)
{
last if $ARGV ne $this ;
print ;
}
}
s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ;
print ;
}
}
# end of file Makefile.PL
|