Change 27380 (HEK into the IV union failed to convert the code in the
[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 ;
642e522c 7use Config qw(%Config) ;
f4c6fd49 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 = '' ;
642e522c 25my $WALL = '' ;
26my $GZIP_OS_CODE = -1 ;
f4c6fd49 27
642e522c 28#$WALL = ' -pedantic ' if $Config{'cc'} =~ /gcc/ ;
1a6a8453 29#$WALL = ' -Wall -Wno-comment ' if $Config{'cc'} =~ /gcc/ ;
30
31unless($ENV{PERL_CORE}) {
32 $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
33}
844ffccc 34
f4c6fd49 35# don't ask if MM_USE_DEFAULT is set -- enables perl core building on cygwin
1a6a8453 36if ($^O =~ /cygwin/i and not ($ENV{PERL_MM_USE_DEFAULT} or $ENV{PERL_CORE}))
f4c6fd49 37{
38 print <<EOM ;
39
40I see you are running Cygwin.
41
42Please note that this module cannot be installed on Cygwin using the
43CPAN shell. The CPAN Shell uses Compress::Zlib internally and it is not
44possible to delete an active DLL.
45
46If you are running the CPAN shell, please exit it and install this module
47by hand by running 'make install' under the directory
48
49 ~/.cpan/build/Compress-Zlib-VERSION
50
51EOM
52
53 print "Do you want to continue? [Y/N]: " ;
54 my $answer = <STDIN> ;
55
56 if ($answer =~ /^yes|y/i)
57 {
58 print "continuing...\n"
59 }
60 else
61 {
62 print "exiting...\n" ;
63 exit 1 ;
64 }
65
66
67}
68
69ParseCONFIG() ;
70
642e522c 71my @files = ('Zlib.pm', 't/ZlibTestUtils.pm',
72 glob("t/*.t"),
1a6a8453 73 glob("t/*.pl"),
74 glob("lib/CompressPlugin/*.pm"),
75 glob("lib/UncompressPlugin/*.pm"),
642e522c 76 glob("lib/IO/Compress/*.pm"),
77 glob("lib/IO/Uncompress/*.pm"),
78 glob("lib/Compress/Zlib/*.pm"),
79 glob("lib/Compress/Gzip/*.pm"),
80 glob("lib/File/*.pm"),
1a6a8453 81 glob("bzip2/*.pm"),
642e522c 82 grep(!/\.bak$/, glob("examples/*"))) ;
83
1a6a8453 84UpDowngrade(@files) unless $ENV{PERL_CORE};
f4c6fd49 85
86WriteMakefile(
87 NAME => 'Compress::Zlib',
1a6a8453 88 VERSION_FROM => 'Zlib.pm',
89 #OPTIMIZE => '-g',
f4c6fd49 90 INC => "-I$ZLIB_INCLUDE" ,
642e522c 91 DEFINE => "$OLD_ZLIB $WALL -DGZIP_OS_CODE=$GZIP_OS_CODE" ,
1a6a8453 92 XS => { 'Zlib.xs' => 'Zlib.c'},
93 $ENV{PERL_CORE}
66bb7d15 94 ? (MAN3PODS => {})
95 : (PREREQ_PM => { 'Scalar::Util' => 0,
96 $] >= 5.005 && $] < 5.006 ? ('File::BSDGlob' => 0) : () }
1a6a8453 97 ),
f4c6fd49 98 'depend' => { 'Makefile' => 'config.in' },
99 'clean' => { FILES => '*.c constants.h constants.xs' },
100 'dist' => { COMPRESS => 'gzip',
101 SUFFIX => 'gz',
642e522c 102 DIST_DEFAULT => 'MyDoubleCheck downgrade tardist',
f4c6fd49 103 },
104 ($BUILD_ZLIB
105 ? zlib_files($ZLIB_LIB)
106 : (LIBS => [ "-L$ZLIB_LIB -lz " ])
107 ),
1a6a8453 108 $] >= 5.005
f4c6fd49 109 ? (ABSTRACT_FROM => 'Zlib.pm',
110 AUTHOR => 'Paul Marquess <pmqs@cpan.org>')
1a6a8453 111 : (),
112
f4c6fd49 113 ) ;
114
115my @names = qw(
116
117 DEF_WBITS
118 MAX_MEM_LEVEL
119 MAX_WBITS
120 OS_CODE
121
122 Z_ASCII
123 Z_BEST_COMPRESSION
124 Z_BEST_SPEED
125 Z_BINARY
642e522c 126 Z_BLOCK
f4c6fd49 127 Z_BUF_ERROR
128 Z_DATA_ERROR
129 Z_DEFAULT_COMPRESSION
130 Z_DEFAULT_STRATEGY
131 Z_DEFLATED
132 Z_ERRNO
133 Z_FILTERED
134 Z_FINISH
642e522c 135 Z_FIXED
f4c6fd49 136 Z_FULL_FLUSH
137 Z_HUFFMAN_ONLY
138 Z_MEM_ERROR
139 Z_NEED_DICT
140 Z_NO_COMPRESSION
141 Z_NO_FLUSH
142 Z_NULL
143 Z_OK
144 Z_PARTIAL_FLUSH
642e522c 145 Z_RLE
f4c6fd49 146 Z_STREAM_END
147 Z_STREAM_ERROR
148 Z_SYNC_FLUSH
149 Z_UNKNOWN
150 Z_VERSION_ERROR
642e522c 151
f4c6fd49 152 );
642e522c 153 #ZLIB_VERNUM
f4c6fd49 154
155if (eval {require ExtUtils::Constant; 1}) {
156 # Check the constants above all appear in @EXPORT in Zlib.pm
157 my %names = map { $_, 1} @names, 'ZLIB_VERSION';
158 open F, "<Zlib.pm" or die "Cannot open Zlib.pm: $!\n";
159 while (<F>)
160 {
161 last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
162 }
163
164 while (<F>)
165 {
166 last if /^\s*\)/ ;
167 /(\S+)/ ;
168 delete $names{$1} if defined $1 ;
169 }
170 close F ;
171
172 if ( keys %names )
173 {
174 my $missing = join ("\n\t", sort keys %names) ;
175 die "The following names are missing from \@EXPORT in Zlib.pm\n" .
176 "\t$missing\n" ;
177 }
178
179 push @names, {name => 'ZLIB_VERSION', type => 'PV' };
180
181 ExtUtils::Constant::WriteConstants(
182 NAME => 'Zlib',
183 NAMES => \@names,
184 C_FILE => 'constants.h',
185 XS_FILE => 'constants.xs',
1a6a8453 186
f4c6fd49 187 );
188}
189else {
642e522c 190 foreach my $name (qw( constants.h constants.xs ))
191 {
192 my $from = catfile('fallback', $name);
193 copy ($from, $name)
194 or die "Can't copy $from to $name: $!";
195 }
f4c6fd49 196}
197
76e6f389 198sub MY::libscan
199{
642e522c 200 my $self = shift;
201 my $path = shift;
76e6f389 202
203 return undef
642e522c 204 if $path =~ /(~|\.bak|_bak)$/ ||
1a6a8453 205 $path =~ /\..*\.sw(o|p)$/ ||
9237a471 206 $path =~ /\B\.svn\b/;
76e6f389 207
642e522c 208 return $path;
76e6f389 209}
210
f4c6fd49 211sub MY::postamble
212{
213 my $postamble = <<'EOM';
214
642e522c 215downgrade:
f4c6fd49 216 @echo Downgrading.
217 perl Makefile.PL -downgrade
218
219MyDoubleCheck:
220 @echo Checking config.in is setup for a release
642e522c 221 @(grep '^LIB *= *./zlib-src' config.in && \
222 grep '^INCLUDE *= *./zlib-src' config.in && \
f4c6fd49 223 grep '^OLD_ZLIB *= *False' config.in && \
642e522c 224 grep '^GZIP_OS_CODE *= *AUTO_DETECT' config.in && \
f4c6fd49 225 grep '^BUILD_ZLIB *= *True' config.in) >/dev/null || \
226 (echo config.in needs fixing ; exit 1)
227 @echo config.in is ok
228
229MyTrebleCheck:
230 @echo Checking for $$^W in files: '. "@files" . '
231 @perl -ne \' \
232 exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/; \
233 \' ' . " @files || " . ' \
234 (echo found unexpected $$^W ; exit 1)
235 @echo All is ok.
236
642e522c 237longtest:
238 @echo Running test suite with Devel::Cover
239 $(MAKE) test COMPRESS_ZLIB_RUN_ALL=1
240
241cover:
242 @echo Running test suite with Devel::Cover
243 HARNESS_PERL_SWITCHES=-MDevel::Cover $(MAKE) test
244
245longcover:
246 @echo Running test suite with Devel::Cover
247 HARNESS_PERL_SWITCHES=-MDevel::Cover $(MAKE) test COMPRESS_ZLIB_RUN_ALL=1
248
1a6a8453 249test-unicode:
250 @echo Running test suite with unicode support enabled
251 env PERL_UNICODE=63 $(MAKE) test
642e522c 252
253EOM
254
255 $postamble .= <<'EOM' if $^O eq 'linux' ;
256
257gcov:
258 @echo Running test suite with gcov and Devel::Cover [needs gcc 3.4?]
642e522c 259 rm -f *.o *.gcov *.da *.bbg *.bb *.gcno
1a6a8453 260 HARNESS_PERL_SWITCHES=-MDevel::Cover $(MAKE) test \
261 OPTIMIZE=-g \
262 CCFLAGS=-O0\ -fprofile-arcs\ -ftest-coverage \
263 OTHERLDFLAGS=-fprofile-arcs\ -ftest-coverage
264 gcov Zlib.xs
265 gcov2perl -db cover_db Zlib.xs.gcov
f4c6fd49 266EOM
267
268 return $postamble;
269
270}
271
272sub ParseCONFIG
273{
274 my ($k, $v) ;
275 my @badkey = () ;
276 my %Info = () ;
642e522c 277 my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB GZIP_OS_CODE ) ;
f4c6fd49 278 my %ValidOption = map {$_, 1} @Options ;
279 my %Parsed = %ValidOption ;
280 my $CONFIG = 'config.in' ;
281
282 print "Parsing $CONFIG...\n" ;
283
284 open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
285 while (<F>) {
286 s/^\s*|\s*$//g ;
287 next if /^\s*$/ or /^\s*#/ ;
288 s/\s*#\s*$// ;
289
290 ($k, $v) = split(/\s+=\s+/, $_, 2) ;
291 $k = uc $k ;
292 if ($ValidOption{$k}) {
293 delete $Parsed{$k} ;
294 $Info{$k} = $v ;
295 }
296 else {
297 push(@badkey, $k) ;
298 }
299 }
300 close F ;
301
302 print "Unknown keys in $CONFIG ignored [@badkey]\n"
303 if @badkey ;
304
305 # check parsed values
306 my @missing = () ;
307 die "The following keys are missing from $CONFIG [@missing]\n"
308 if @missing = keys %Parsed ;
309
310 $ZLIB_INCLUDE = $ENV{'ZLIB_INCLUDE'} || $Info{'INCLUDE'} ;
311 $ZLIB_LIB = $ENV{'ZLIB_LIB'} || $Info{'LIB'} ;
312
313 if ($^O eq 'VMS') {
314 $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE);
315 $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB);
316 }
317
318 my $y = $ENV{'OLD_ZLIB'} || $Info{'OLD_ZLIB'} ;
319 $OLD_ZLIB = '-DOLD_ZLIB' if $y and $y =~ /^yes|on|true|1$/i;
320
321 my $x = $ENV{'BUILD_ZLIB'} || $Info{'BUILD_ZLIB'} ;
322
323 if ($x and $x =~ /^yes|on|true|1$/i ) {
324
325 $BUILD_ZLIB = 1 ;
326
327 # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when
328 # BUILD_ZLIB is specified.
329 die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n"
330 if $ZLIB_LIB ne $ZLIB_INCLUDE ;
331
332 # Check the zlib source directory exists
333 die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n"
334 unless -d $ZLIB_LIB ;
335
336 # check for a well known file
337 die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n"
338 unless -e catfile($ZLIB_LIB, 'zlib.h') ;
339
340
f4c6fd49 341 # write the Makefile
342 print "Building Zlib enabled\n" ;
343 }
344
642e522c 345 $GZIP_OS_CODE = defined $ENV{'GZIP_OS_CODE'}
346 ? $ENV{'GZIP_OS_CODE'}
347 : $Info{'GZIP_OS_CODE'} ;
348
349 die "GZIP_OS_CODE not 'AUTO_DETECT' or a number between 0 and 255\n"
350 unless uc $GZIP_OS_CODE eq 'AUTO_DETECT'
351 || ( $GZIP_OS_CODE =~ /^(\d+)$/ && $1 >= 0 && $1 <= 255) ;
352
353 if (uc $GZIP_OS_CODE eq 'AUTO_DETECT')
354 {
355 print "Auto Detect Gzip OS Code..\n" ;
356 $GZIP_OS_CODE = getOSCode() ;
357 }
358
359 my $name = getOSname($GZIP_OS_CODE);
360 print "Setting Gzip OS Code to $GZIP_OS_CODE [$name]\n" ;
361
f4c6fd49 362 print <<EOM if 0 ;
642e522c 363 INCLUDE [$ZLIB_INCLUDE]
364 LIB [$ZLIB_LIB]
365 GZIP_OS_CODE [$GZIP_OS_CODE]
366 OLD_ZLIB [$OLD_ZLIB]
367 BUILD_ZLIB [$BUILD_ZLIB]
f4c6fd49 368
369EOM
370
371 print "Looks Good.\n" ;
372
373}
374
375sub UpDowngrade
376{
377 my @files = @_ ;
378
642e522c 379 # our and use bytes/utf8 is stable from 5.6.0 onward
f4c6fd49 380 # warnings is stable from 5.6.1 onward
381
382 # Note: this code assumes that each statement it modifies is not
383 # split across multiple lines.
384
385
386 my $warn_sub = '';
387 my $our_sub = '' ;
388
389 my $opt = shift @ARGV || '' ;
390 my $upgrade = ($opt =~ /^-upgrade/i);
391 my $downgrade = ($opt =~ /^-downgrade/i);
392 push @ARGV, $opt unless $downgrade || $upgrade;
393
394 if ($downgrade) {
395 # From: use|no warnings "blah"
396 # To: local ($^W) = 1; # use|no warnings "blah"
397 $warn_sub = sub {
398 s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ;
399 s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ;
400 };
401 }
402 elsif ($] >= 5.006001 || $upgrade) {
403 # From: local ($^W) = 1; # use|no warnings "blah"
404 # To: use|no warnings "blah"
405 $warn_sub = sub {
406 s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ;
407 };
408 }
409
410 if ($downgrade) {
411 $our_sub = sub {
412 if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) {
413 my $indent = $1;
414 my $vars = join ' ', split /\s*,\s*/, $2;
415 $_ = "${indent}use vars qw($vars);\n";
416 }
642e522c 417 elsif ( /^(\s*)((use|no)\s+(bytes|utf8)\s*;.*)$/)
418 {
419 $_ = "$1# $2\n";
420 }
f4c6fd49 421 };
422 }
423 elsif ($] >= 5.006000 || $upgrade) {
424 $our_sub = sub {
425 if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) {
426 my $indent = $1;
427 my $vars = join ', ', split ' ', $2;
428 $_ = "${indent}our ($vars);\n";
429 }
642e522c 430 elsif ( /^(\s*)#\s*((use|no)\s+(bytes|utf8)\s*;.*)$/)
431 {
432 $_ = "$1$2\n";
433 }
f4c6fd49 434 };
435 }
436
437 if (! $our_sub && ! $warn_sub) {
438 warn "Up/Downgrade not needed.\n";
439 if ($upgrade || $downgrade)
440 { exit 0 }
441 else
442 { return }
443 }
444
bdd93743 445 foreach (@files)
446 { doUpDown($our_sub, $warn_sub, $_) }
f4c6fd49 447
448 warn "Up/Downgrade complete.\n" ;
449 exit 0 if $upgrade || $downgrade;
450
451}
452
453
454sub doUpDown
455{
456 my $our_sub = shift;
457 my $warn_sub = shift;
458
642e522c 459 return if -d $_[0];
460
f4c6fd49 461 local ($^I) = ($^O eq 'VMS') ? "_bak" : ".bak";
462 local (@ARGV) = shift;
463
464 while (<>)
465 {
466 print, last if /^__(END|DATA)__/ ;
467
468 &{ $our_sub }() if $our_sub ;
469 &{ $warn_sub }() if $warn_sub ;
470 print ;
471 }
472
473 return if eof ;
474
475 while (<>)
476 { print }
477}
478
479
480sub zlib_files
481{
482 my $dir = shift ;
483
484 my @h_files = ();
485 my @c_files = ();
486
487 if (-f catfile($dir, "infback.c")) {
488 # zlib 1.2.0 or greater
489 #
490 @h_files = qw(crc32.h inffast.h inflate.h trees.h zconf.in.h
642e522c 491 zutil.h deflate.h inffixed.h inftrees.h zconf.h
492 zlib.h
f4c6fd49 493 );
494 @c_files = qw(adler32 crc32 infback inflate uncompr
642e522c 495 compress deflate inffast inftrees
496 trees zutil
f4c6fd49 497 );
498 }
499 else {
500 # zlib 1.1.x
501
502 @h_files = qw(deflate.h infcodes.h inftrees.h zconf.h zutil.h
642e522c 503 infblock.h inffast.h infutil.h zlib.h
f4c6fd49 504 );
642e522c 505 @c_files = qw(adler32 compress crc32 uncompr
506 deflate trees zutil inflate infblock
507 inftrees infcodes infutil inffast
f4c6fd49 508 );
509 }
510
511 @h_files = map { catfile($dir, $_) } @h_files ;
512 my @o_files = map { "$_\$(OBJ_EXT)" } 'Zlib', @c_files;
513 @c_files = map { "$_.c" } 'Zlib', @c_files ;
514
515 foreach my $file (@c_files)
516 { copy(catfile($dir, $file), '.') }
517
518 return (
519 #'H' => [ @h_files ],
520 'C' => [ @c_files ] ,
521 #'OBJECT' => qq[ @o_files ],
522 'OBJECT' => q[ $(O_FILES) ],
523
524
525 ) ;
526}
527
528
642e522c 529
530my @GZIP_OS_Names ;
531my %OSnames ;
532
533BEGIN
534{
535 @GZIP_OS_Names = (
536 [ '' => 0, 'MS-DOS' ],
537 [ 'amigaos' => 1, 'Amiga' ],
538 [ 'VMS' => 2, 'VMS' ],
539 [ '' => 3, 'Unix/Default' ],
540 [ '' => 4, 'VM/CMS' ],
541 [ '' => 5, 'Atari TOS' ],
542 [ 'os2' => 6, 'HPFS (OS/2, NT)' ],
543 [ 'MacOS' => 7, 'Macintosh' ],
544 [ '' => 8, 'Z-System' ],
545 [ '' => 9, 'CP/M' ],
546 [ '' => 10, 'TOPS-20' ],
547 [ '' => 11, 'NTFS (NT)' ],
548 [ '' => 12, 'SMS QDOS' ],
549 [ '' => 13, 'Acorn RISCOS' ],
550 [ 'MSWin32' => 14, 'VFAT file system (Win95, NT)' ],
551 [ '' => 15, 'MVS' ],
552 [ 'beos' => 16, 'BeOS' ],
553 [ '' => 17, 'Tandem/NSK' ],
554 [ '' => 18, 'THEOS' ],
555 [ '' => 255, 'Unknown OS' ],
556 );
557
558 %OSnames = map { $$_[1] => $$_[2] }
559 @GZIP_OS_Names ;
560}
561
562sub getOSCode
563{
564 my $default = 3 ; # Unix is the default
565
566 my $uname = $^O;
567
568 for my $h (@GZIP_OS_Names)
569 {
570 my ($pattern, $code, $name) = @$h;
571
572 return $code
573 if $pattern && $uname eq $pattern ;
574 }
575
576 return $default ;
577}
578
579sub getOSname
580{
581 my $code = shift ;
582
583 return $OSnames{$code} || 'Unknown OS' ;
584}
585
f4c6fd49 586# end of file Makefile.PL
587