Upgrade to Compress::Zlib 1.38
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / Makefile.PL
CommitLineData
f4c6fd49 1#! perl -w
2
3use strict ;
4require 5.004 ;
5
6use ExtUtils::MakeMaker 5.16 ;
7use Config ;
8use File::Copy ;
9
10BEGIN
11{
12 eval { require File::Spec::Functions ; File::Spec::Functions->import() } ;
13 if ($@)
14 {
15 *catfile = sub { return "$_[0]/$_[1]" }
16 }
17}
18
19require VMS::Filespec if $^O eq 'VMS';
20
21my $ZLIB_LIB ;
22my $ZLIB_INCLUDE ;
23my $BUILD_ZLIB = 0 ;
24my $OLD_ZLIB = '' ;
5993747c 25my $EXTRA_DEFINE = '';
f4c6fd49 26my $WALL = '';
27#$WALL = ' -Wall ';
28
844ffccc 29unless($ENV{PERL_CORE}) {
30 $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
31}
32
f4c6fd49 33# don't ask if MM_USE_DEFAULT is set -- enables perl core building on cygwin
844ffccc 34if ($^O =~ /cygwin/i and not $ENV{PERL_MM_USE_DEFAULT} and not $ENV{PERL_CORE})
f4c6fd49 35{
36 print <<EOM ;
37
38I see you are running Cygwin.
39
40Please note that this module cannot be installed on Cygwin using the
41CPAN shell. The CPAN Shell uses Compress::Zlib internally and it is not
42possible to delete an active DLL.
43
44If you are running the CPAN shell, please exit it and install this module
45by hand by running 'make install' under the directory
46
47 ~/.cpan/build/Compress-Zlib-VERSION
48
49EOM
50
51 print "Do you want to continue? [Y/N]: " ;
52 my $answer = <STDIN> ;
53
54 if ($answer =~ /^yes|y/i)
55 {
56 print "continuing...\n"
57 }
58 else
59 {
60 print "exiting...\n" ;
61 exit 1 ;
62 }
63
64
65}
66
67ParseCONFIG() ;
68
69my @files = ('Zlib.pm', glob("t/*.t"), grep(!/\.bak$/, glob("examples/*"))) ;
5993747c 70UpDowngrade(@files) unless $ENV{PERL_CORE} ;
f4c6fd49 71
72WriteMakefile(
73 NAME => 'Compress::Zlib',
74 VERSION_FROM => 'Zlib.pm',
75 INC => "-I$ZLIB_INCLUDE" ,
5993747c 76 DEFINE => "$OLD_ZLIB $WALL $EXTRA_DEFINE" ,
f4c6fd49 77 XS => { 'Zlib.xs' => 'Zlib.c' },
78 'depend' => { 'Makefile' => 'config.in' },
79 'clean' => { FILES => '*.c constants.h constants.xs' },
80 'dist' => { COMPRESS => 'gzip',
81 SUFFIX => 'gz',
82 DIST_DEFAULT => 'MyDoubleCheck Downgrade tardist',
83 },
84 ($BUILD_ZLIB
85 ? zlib_files($ZLIB_LIB)
86 : (LIBS => [ "-L$ZLIB_LIB -lz " ])
87 ),
88 ($] >= 5.005
89 ? (ABSTRACT_FROM => 'Zlib.pm',
90 AUTHOR => 'Paul Marquess <pmqs@cpan.org>')
91 : ()
92 ),
93 ) ;
94
95my @names = qw(
96
97 DEF_WBITS
98 MAX_MEM_LEVEL
99 MAX_WBITS
100 OS_CODE
101
102 Z_ASCII
103 Z_BEST_COMPRESSION
104 Z_BEST_SPEED
105 Z_BINARY
106 Z_BUF_ERROR
107 Z_DATA_ERROR
108 Z_DEFAULT_COMPRESSION
109 Z_DEFAULT_STRATEGY
110 Z_DEFLATED
111 Z_ERRNO
112 Z_FILTERED
113 Z_FINISH
114 Z_FULL_FLUSH
115 Z_HUFFMAN_ONLY
116 Z_MEM_ERROR
117 Z_NEED_DICT
118 Z_NO_COMPRESSION
119 Z_NO_FLUSH
120 Z_NULL
121 Z_OK
122 Z_PARTIAL_FLUSH
123 Z_STREAM_END
124 Z_STREAM_ERROR
125 Z_SYNC_FLUSH
126 Z_UNKNOWN
127 Z_VERSION_ERROR
128 );
129
130if (eval {require ExtUtils::Constant; 1}) {
131 # Check the constants above all appear in @EXPORT in Zlib.pm
132 my %names = map { $_, 1} @names, 'ZLIB_VERSION';
133 open F, "<Zlib.pm" or die "Cannot open Zlib.pm: $!\n";
134 while (<F>)
135 {
136 last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
137 }
138
139 while (<F>)
140 {
141 last if /^\s*\)/ ;
142 /(\S+)/ ;
143 delete $names{$1} if defined $1 ;
144 }
145 close F ;
146
147 if ( keys %names )
148 {
149 my $missing = join ("\n\t", sort keys %names) ;
150 die "The following names are missing from \@EXPORT in Zlib.pm\n" .
151 "\t$missing\n" ;
152 }
153
154 push @names, {name => 'ZLIB_VERSION', type => 'PV' };
155
156 ExtUtils::Constant::WriteConstants(
157 NAME => 'Zlib',
158 NAMES => \@names,
159 C_FILE => 'constants.h',
160 XS_FILE => 'constants.xs',
161
162 );
163}
164else {
165 copy ('fallback.h', 'constants.h')
166 or die "Can't copy fallback.h to constants.h: $!";
167 copy ('fallback.xs', 'constants.xs')
168 or die "Can't copy fallback.xs to constants.xs: $!";
169}
170
76e6f389 171sub MY::libscan
172{
173 my $self = shift ;
174 my $path = shift ;
175
176 return undef
177 if $path =~ /(~|\.bak|_bak)$/ ||
178 $path =~ /^\..*\.swp$/ ;
179
180 return $path;
181}
182
183
f4c6fd49 184sub MY::postamble
185{
186 my $postamble = <<'EOM';
187
188Downgrade:
189 @echo Downgrading.
190 perl Makefile.PL -downgrade
191
192MyDoubleCheck:
193 @echo Checking config.in is setup for a release
194 @(grep '^LIB *= *./zlib' config.in && \
195 grep '^INCLUDE *= *./zlib' config.in && \
196 grep '^OLD_ZLIB *= *False' config.in && \
197 grep '^BUILD_ZLIB *= *True' config.in) >/dev/null || \
198 (echo config.in needs fixing ; exit 1)
199 @echo config.in is ok
200
201MyTrebleCheck:
202 @echo Checking for $$^W in files: '. "@files" . '
203 @perl -ne \' \
204 exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/; \
205 \' ' . " @files || " . ' \
206 (echo found unexpected $$^W ; exit 1)
207 @echo All is ok.
208
f4c6fd49 209EOM
210
211 return $postamble;
212
213}
214
215sub ParseCONFIG
216{
217 my ($k, $v) ;
218 my @badkey = () ;
219 my %Info = () ;
220 my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB ) ;
221 my %ValidOption = map {$_, 1} @Options ;
222 my %Parsed = %ValidOption ;
223 my $CONFIG = 'config.in' ;
224
225 print "Parsing $CONFIG...\n" ;
226
227 open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
228 while (<F>) {
229 s/^\s*|\s*$//g ;
230 next if /^\s*$/ or /^\s*#/ ;
231 s/\s*#\s*$// ;
232
233 ($k, $v) = split(/\s+=\s+/, $_, 2) ;
234 $k = uc $k ;
235 if ($ValidOption{$k}) {
236 delete $Parsed{$k} ;
237 $Info{$k} = $v ;
238 }
239 else {
240 push(@badkey, $k) ;
241 }
242 }
243 close F ;
244
245 print "Unknown keys in $CONFIG ignored [@badkey]\n"
246 if @badkey ;
247
248 # check parsed values
249 my @missing = () ;
250 die "The following keys are missing from $CONFIG [@missing]\n"
251 if @missing = keys %Parsed ;
252
253 $ZLIB_INCLUDE = $ENV{'ZLIB_INCLUDE'} || $Info{'INCLUDE'} ;
254 $ZLIB_LIB = $ENV{'ZLIB_LIB'} || $Info{'LIB'} ;
255
256 if ($^O eq 'VMS') {
257 $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE);
258 $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB);
259 }
260
5993747c 261 $EXTRA_DEFINE = $ENV{EXTRA_DEFINE} if defined $ENV{EXTRA_DEFINE};
262
f4c6fd49 263 my $y = $ENV{'OLD_ZLIB'} || $Info{'OLD_ZLIB'} ;
264 $OLD_ZLIB = '-DOLD_ZLIB' if $y and $y =~ /^yes|on|true|1$/i;
265
266 my $x = $ENV{'BUILD_ZLIB'} || $Info{'BUILD_ZLIB'} ;
267
268 if ($x and $x =~ /^yes|on|true|1$/i ) {
269
270 $BUILD_ZLIB = 1 ;
271
272 # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when
273 # BUILD_ZLIB is specified.
274 die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n"
275 if $ZLIB_LIB ne $ZLIB_INCLUDE ;
276
277 # Check the zlib source directory exists
278 die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n"
279 unless -d $ZLIB_LIB ;
280
281 # check for a well known file
282 die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n"
283 unless -e catfile($ZLIB_LIB, 'zlib.h') ;
284
285
286 # check Makefile.zlib has been copied to ZLIB_LIB
287 #copy 'Makefile.zlib', catfile($ZLIB_LIB, 'Makefile.PL') ||
288 #die "Could not copy Makefile.zlib to " . catfile($ZLIB_LIB, 'Makefile.PL') . ": $!\n" ;
289 #print "Created a Makefile.PL for zlib\n" ;
290
291 # write the Makefile
292 print "Building Zlib enabled\n" ;
293 }
294
295 print <<EOM if 0 ;
296 INCLUDE [$ZLIB_INCLUDE]
297 LIB [$ZLIB_LIB]
298
299EOM
300
301 print "Looks Good.\n" ;
302
303}
304
305sub UpDowngrade
306{
307 my @files = @_ ;
308
309 # our is stable from 5.6.0 onward
310 # warnings is stable from 5.6.1 onward
311
312 # Note: this code assumes that each statement it modifies is not
313 # split across multiple lines.
314
315
316 my $warn_sub = '';
317 my $our_sub = '' ;
318
319 my $opt = shift @ARGV || '' ;
320 my $upgrade = ($opt =~ /^-upgrade/i);
321 my $downgrade = ($opt =~ /^-downgrade/i);
322 push @ARGV, $opt unless $downgrade || $upgrade;
323
324 if ($downgrade) {
325 # From: use|no warnings "blah"
326 # To: local ($^W) = 1; # use|no warnings "blah"
327 $warn_sub = sub {
328 s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ;
329 s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ;
330 };
331 }
332 elsif ($] >= 5.006001 || $upgrade) {
333 # From: local ($^W) = 1; # use|no warnings "blah"
334 # To: use|no warnings "blah"
335 $warn_sub = sub {
336 s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ;
337 };
338 }
339
340 if ($downgrade) {
341 $our_sub = sub {
342 if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) {
343 my $indent = $1;
344 my $vars = join ' ', split /\s*,\s*/, $2;
345 $_ = "${indent}use vars qw($vars);\n";
346 }
347 };
348 }
349 elsif ($] >= 5.006000 || $upgrade) {
350 $our_sub = sub {
351 if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) {
352 my $indent = $1;
353 my $vars = join ', ', split ' ', $2;
354 $_ = "${indent}our ($vars);\n";
355 }
356 };
357 }
358
359 if (! $our_sub && ! $warn_sub) {
360 warn "Up/Downgrade not needed.\n";
361 if ($upgrade || $downgrade)
362 { exit 0 }
363 else
364 { return }
365 }
366
bdd93743 367 foreach (@files)
368 { doUpDown($our_sub, $warn_sub, $_) }
f4c6fd49 369
370 warn "Up/Downgrade complete.\n" ;
371 exit 0 if $upgrade || $downgrade;
372
373}
374
375
376sub doUpDown
377{
378 my $our_sub = shift;
379 my $warn_sub = shift;
380
381 local ($^I) = ($^O eq 'VMS') ? "_bak" : ".bak";
382 local (@ARGV) = shift;
383
384 while (<>)
385 {
386 print, last if /^__(END|DATA)__/ ;
387
388 &{ $our_sub }() if $our_sub ;
389 &{ $warn_sub }() if $warn_sub ;
390 print ;
391 }
392
393 return if eof ;
394
395 while (<>)
396 { print }
397}
398
399
400sub zlib_files
401{
402 my $dir = shift ;
403
404 my @h_files = ();
405 my @c_files = ();
406
407 if (-f catfile($dir, "infback.c")) {
408 # zlib 1.2.0 or greater
409 #
410 @h_files = qw(crc32.h inffast.h inflate.h trees.h zconf.in.h
411 zutil.h deflate.h inffixed.h inftrees.h zconf.h
412 zlib.h
413 );
414 @c_files = qw(adler32 crc32 infback inflate uncompr
415 compress deflate gzio inffast inftrees
416 trees zutil
417 );
418 }
419 else {
420 # zlib 1.1.x
421
422 @h_files = qw(deflate.h infcodes.h inftrees.h zconf.h zutil.h
423 infblock.h inffast.h infutil.h zlib.h
424 );
425 @c_files = qw(adler32 compress crc32 gzio uncompr
426 deflate trees zutil inflate infblock
427 inftrees infcodes infutil inffast
428 );
429 }
430
431 @h_files = map { catfile($dir, $_) } @h_files ;
432 my @o_files = map { "$_\$(OBJ_EXT)" } 'Zlib', @c_files;
433 @c_files = map { "$_.c" } 'Zlib', @c_files ;
434
435 foreach my $file (@c_files)
436 { copy(catfile($dir, $file), '.') }
437
438 return (
439 #'H' => [ @h_files ],
440 'C' => [ @c_files ] ,
441 #'OBJECT' => qq[ @o_files ],
442 'OBJECT' => q[ $(O_FILES) ],
443
444
445 ) ;
446}
447
448
449# end of file Makefile.PL
450