Debian Codegraph @

lang/perl/DB_File/Makefile.PL

raw
1 #! perl -w
2
3 use strict ;
4 use ExtUtils::MakeMaker 5.16 ;
5 use Config ;
6
7 die "DB_File needs Perl 5.004_05 or better. This is $]\n"
8 if $] <= 5.00404;
9
10 my $VER_INFO ;
11 my $LIB_DIR ;
12 my $INC_DIR ;
13 my $DB_NAME ;
14 my $LIBS ;
15 my $COMPAT185 = "" ;
16
17 ParseCONFIG() ;
18
19 my @files = ('DB_File.pm', glob "t/*.t") ;
20 UpDowngrade(@files);
21
22 if (defined $DB_NAME)
23 { $LIBS = $DB_NAME }
24 else {
25 if ($^O eq 'MSWin32')
26 { $LIBS = $Config{cc} =~ /gcc/ ? '-ldb' : '-llibdb' }
27 else
28 { $LIBS = '-ldb' }
29 }
30
31 # Solaris is special.
32 #$LIBS .= " -lthread" if $^O eq 'solaris' ;
33
34 # AIX is special.
35 $LIBS .= " -lpthread" if $^O eq 'aix' ;
36
37 # OS2 is a special case, so check for it now.
38 my $OS2 = "" ;
39 $OS2 = "-DOS2" if $Config{'osname'} eq 'os2' ;
40
41 my $WALL = '' ;
42 #$WALL = ' -Wall ';
43
44 WriteMakefile(
45 NAME => 'DB_File',
46 LIBS => ["-L${LIB_DIR} $LIBS"],
47 INC => "-I$INC_DIR",
48 VERSION_FROM => 'DB_File.pm',
49 XS_VERSION => eval MM->parse_version('DB_File.pm'),
50 XSPROTOARG => '-noprototypes',
51 DEFINE => "-D_NOT_CORE $OS2 $VER_INFO $COMPAT185 $WALL",
52 OBJECT => 'version$(OBJ_EXT) DB_File$(OBJ_EXT)',
53 ((ExtUtils::MakeMaker->VERSION() gt '6.30')
54 ? ('LICENSE' => 'perl')
55 : ()
56 ),
57 (
58 $] >= 5.005
59 ? (ABSTRACT_FROM => 'DB_File.pm',
60 AUTHOR => 'Paul Marquess <[email protected]>')
61 : ()
62 ),
63
64
65 #OPTIMIZE => '-g',
66 'depend' => { 'Makefile' => 'config.in',
67 'version$(OBJ_EXT)' => 'version.c'},
68 'clean' => { FILES => 'constants.h constants.xs' },
69 'macro' => { INSTALLDIRS => 'perl', my_files => "@files" },
70 'dist' => { COMPRESS => 'gzip', SUFFIX => 'gz',
71 DIST_DEFAULT => 'MyDoubleCheck tardist'},
72 );
73
74
75 my @names = qw(
76 BTREEMAGIC
77 BTREEVERSION
78 DB_LOCK
79 DB_SHMEM
80 DB_TXN
81 HASHMAGIC
82 HASHVERSION
83 MAX_PAGE_NUMBER
84 MAX_PAGE_OFFSET
85 MAX_REC_NUMBER
86 RET_ERROR
87 RET_SPECIAL
88 RET_SUCCESS
89 R_CURSOR
90 R_DUP
91 R_FIRST
92 R_FIXEDLEN
93 R_IAFTER
94 R_IBEFORE
95 R_LAST
96 R_NEXT
97 R_NOKEY
98 R_NOOVERWRITE
99 R_PREV
100 R_RECNOSYNC
101 R_SETCURSOR
102 R_SNAPSHOT
103 __R_UNUSED
104 );
105
106 if (eval {require ExtUtils::Constant; 1}) {
107 # Check the constants above all appear in @EXPORT in DB_File.pm
108 my %names = map { $_, 1} @names;
109 open F, "<DB_File.pm" or die "Cannot open DB_File.pm: $!\n";
110 while (<F>)
111 {
112 last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
113 }
114
115 while (<F>)
116 {
117 last if /^\s*\)/ ;
118 /(\S+)/ ;
119 delete $names{$1} if defined $1 ;
120 }
121 close F ;
122
123 if ( keys %names )
124 {
125 my $missing = join ("\n\t", sort keys %names) ;
126 die "The following names are missing from \@EXPORT in DB_File.pm\n" .
127 "\t$missing\n" ;
128 }
129
130
131 ExtUtils::Constant::WriteConstants(
132 NAME => 'DB_File',
133 NAMES => \@names,
134 C_FILE => 'constants.h',
135 XS_FILE => 'constants.xs',
136
137 );
138 }
139 else {
140 use File::Copy;
141 copy ('fallback.h', 'constants.h')
142 or die "Can't copy fallback.h to constants.h: $!";
143 copy ('fallback.xs', 'constants.xs')
144 or die "Can't copy fallback.xs to constants.xs: $!";
145 }
146
147 exit;
148
149
150 sub MY::libscan
151 {
152 my $self = shift ;
153 my $path = shift ;
154
155 return undef
156 if $path =~ /(~|\.bak)$/ ||
157 $path =~ /^\..*\.swp$/ ;
158
159 return $path;
160 }
161
162
163 sub MY::postamble { <<'EOM' } ;
164
165 MyDoubleCheck:
166 @echo Checking config.in is setup for a release
167 @(grep "^LIB.*/usr/local/BerkeleyDB" config.in && \
168 grep "^INCLUDE.*/usr/local/BerkeleyDB" config.in && \
169 grep "^#DBNAME.*" config.in) >/dev/null || \
170 (echo config.in needs fixing ; exit 1)
171 @echo config.in is ok
172 @echo
173 @echo Checking DB_File.xs is ok for a release.
174 @(perl -ne ' exit 1 if /^\s*#\s*define\s+TRACE/ ; ' DB_File.xs || \
175 (echo DB_File.xs needs fixing ; exit 1))
176 @echo DB_File.xs is ok
177 @echo
178 @echo Checking for $$^W in files: $(my_files)
179 @perl -ne ' \
180 exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/;' $(my_files) || \
181 (echo found unexpected $$^W ; exit 1)
182 @echo No $$^W found.
183 @echo
184 @echo Checking for 'use vars' in files: $(my_files)
185 @perl -ne ' \
186 exit 0 if /^__(DATA|END)__/; \
187 exit 1 if /^\s*use\s+vars/;' $(my_files) || \
188 (echo found unexpected "use vars"; exit 1)
189 @echo No 'use vars' found.
190 @echo
191 @echo All files are OK for a release.
192 @echo
193
194 EOM
195
196
197
198 sub ParseCONFIG
199 {
200 my ($k, $v) ;
201 my @badkey = () ;
202 my %Info = () ;
203 my @Options = qw( INCLUDE LIB PREFIX HASH DBNAME COMPAT185 ) ;
204 my %ValidOption = map {$_, 1} @Options ;
205 my %Parsed = %ValidOption ;
206 my $CONFIG = 'config.in' ;
207
208 print "Parsing $CONFIG...\n" ;
209
210 # DBNAME & COMPAT185 are optional, so pretend they have
211 # been parsed.
212 delete $Parsed{'DBNAME'} ;
213 delete $Parsed{'COMPAT185'} ;
214 $Info{COMPAT185} = "No" ;
215
216
217 open(F, "$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
218 while (<F>) {
219 s/^\s*|\s*$//g ;
220 next if /^\s*$/ or /^\s*#/ ;
221 s/\s*#\s*$// ;
222
223 ($k, $v) = split(/\s+=\s+/, $_, 2) ;
224 $k = uc $k ;
225 if ($ValidOption{$k}) {
226 delete $Parsed{$k} ;
227 $Info{$k} = $v ;
228 }
229 else {
230 push(@badkey, $k) ;
231 }
232 }
233 close F ;
234
235 print "Unknown keys in $CONFIG ignored [@badkey]\n"
236 if @badkey ;
237
238 # check parsed values
239 my @missing = () ;
240 die "The following keys are missing from $CONFIG file: [@missing]\n"
241 if @missing = keys %Parsed ;
242
243 $INC_DIR = $ENV{'DB_FILE_INCLUDE'} || $Info{'INCLUDE'} ;
244 $LIB_DIR = $ENV{'DB_FILE_LIB'} || $Info{'LIB'} ;
245 $DB_NAME = $ENV{'DB_FILE_NAME'} || $Info{'DBNAME'} ;
246 $COMPAT185 = "-DCOMPAT185 -DDB_LIBRARY_COMPATIBILITY_API"
247 if (defined $ENV{'DB_FILE_COMPAT185'} &&
248 $ENV{'DB_FILE_COMPAT185'} =~ /^\s*(on|true|1)\s*$/i) ||
249 $Info{'COMPAT185'} =~ /^\s*(on|true|1)\s*$/i ;
250 my $PREFIX = $Info{'PREFIX'} ;
251 my $HASH = $Info{'HASH'} ;
252
253 $VER_INFO = "-DmDB_Prefix_t=${PREFIX} -DmDB_Hash_t=${HASH}" ;
254
255 print <<EOM if 0 ;
256 INCLUDE [$INC_DIR]
257 LIB [$LIB_DIR]
258 HASH [$HASH]
259 PREFIX [$PREFIX]
260 DBNAME [$DB_NAME]
261
262 EOM
263
264 print "Looks Good.\n" ;
265
266 }
267
268 sub UpDowngrade
269 {
270 my @files = @_ ;
271
272 # our is stable from 5.6.0 onward
273 # warnings is stable from 5.6.1 onward
274
275 # Note: this code assumes that each statement it modifies is not
276 # split across multiple lines.
277
278
279 my $warn_sub ;
280 my $our_sub ;
281
282 if ($] < 5.006001) {
283 # From: use|no warnings "blah"
284 # To: local ($^W) = 1; # use|no warnings "blah"
285 #
286 # and
287 #
288 # From: warnings::warnif(x,y);
289 # To: $^W && carp(y); # warnif -- x
290 $warn_sub = sub {
291 s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ;
292 s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ;
293
294 s/^(\s*)warnings::warnif\s*\((.*?)\s*,\s*(.*?)\)\s*;/${1}\$^W && carp($3); # warnif - $2/ ;
295 };
296 }
297 else {
298 # From: local ($^W) = 1; # use|no warnings "blah"
299 # To: use|no warnings "blah"
300 #
301 # and
302 #
303 # From: $^W && carp(y); # warnif -- x
304 # To: warnings::warnif(x,y);
305 $warn_sub = sub {
306 s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ;
307 s/^(\s*)\$\^W\s+\&\&\s*carp\s*\((.*?)\)\s*;\s*#\s*warnif\s*-\s*(.*)/${1}warnings::warnif($3, $2);/ ;
308 };
309 }
310
311 if ($] < 5.006000) {
312 $our_sub = sub {
313 if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) {
314 my $indent = $1;
315 my $vars = join ' ', split /\s*,\s*/, $2;
316 $_ = "${indent}use vars qw($vars);\n";
317 }
318 };
319 }
320 else {
321 $our_sub = sub {
322 if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) {
323 my $indent = $1;
324 my $vars = join ', ', split ' ', $2;
325 $_ = "${indent}our ($vars);\n";
326 }
327 };
328 }
329
330 foreach (@files)
331 { doUpDown($our_sub, $warn_sub, $_) }
332 }
333
334
335 sub doUpDown
336 {
337 my $our_sub = shift;
338 my $warn_sub = shift;
339
340 local ($^I) = ".bak" ;
341 local (@ARGV) = shift;
342
343 while (<>)
344 {
345 print, last if /^__(END|DATA)__/ ;
346
347 &{ $our_sub }();
348 &{ $warn_sub }();
349 print ;
350 }
351
352 return if eof ;
353
354 while (<>)
355 { print }
356 }
357
358 # end of file Makefile.PL