6 use ExtUtils::MakeMaker 5.16 ;
7 use Config qw(%Config) ;
12 eval { require File::Spec::Functions ; File::Spec::Functions->import() } ;
15 *catfile = sub { return "$_[0]/$_[1]" }
19 require VMS::Filespec if $^O eq 'VMS';
26 my $GZIP_OS_CODE = -1 ;
28 #$WALL = ' -pedantic ' if $Config{'cc'} =~ /gcc/ ;
29 $WALL = ' -Wall ' if $Config{'cc'} =~ /gcc/ ;
31 # don't ask if MM_USE_DEFAULT is set -- enables perl core building on cygwin
32 if ($^O =~ /cygwin/i and not $ENV{PERL_MM_USE_DEFAULT})
36 I see you are running Cygwin.
38 Please note that this module cannot be installed on Cygwin using the
39 CPAN shell. The CPAN Shell uses Compress::Zlib internally and it is not
40 possible to delete an active DLL.
42 If you are running the CPAN shell, please exit it and install this module
43 by hand by running 'make install' under the directory
45 ~/.cpan/build/Compress-Zlib-VERSION
49 print "Do you want to continue? [Y/N]: " ;
50 my $answer = <STDIN> ;
52 if ($answer =~ /^yes|y/i)
54 print "continuing...\n"
58 print "exiting...\n" ;
67 my @files = ('Zlib.pm', 't/ZlibTestUtils.pm',
69 glob("lib/IO/Compress/*.pm"),
70 glob("lib/IO/Uncompress/*.pm"),
71 glob("lib/Compress/Zlib/*.pm"),
72 glob("lib/Compress/Gzip/*.pm"),
73 glob("lib/File/*.pm"),
74 grep(!/\.bak$/, glob("examples/*"))) ;
76 my $PERL_CORE = grep { $_ eq 'PERL_CORE=1' } @ARGV;
77 UpDowngrade(@files) unless $PERL_CORE;
80 NAME => 'Compress::Zlib',
81 VERSION_FROM => 'Zlib.pm',
82 INC => "-I$ZLIB_INCLUDE" ,
83 DEFINE => "$OLD_ZLIB $WALL -DGZIP_OS_CODE=$GZIP_OS_CODE" ,
84 XS => { 'Zlib.xs' => 'Zlib.c' },
87 : (PREREQ_PM => { 'Scalar::Util' => 0,
88 $] >= 5.005 && $] < 5.006 ? ('File::BSDGlob' => 0) : () }
90 'depend' => { 'Makefile' => 'config.in' },
91 'clean' => { FILES => '*.c constants.h constants.xs' },
92 'dist' => { COMPRESS => 'gzip',
94 DIST_DEFAULT => 'MyDoubleCheck downgrade tardist',
97 ? zlib_files($ZLIB_LIB)
98 : (LIBS => [ "-L$ZLIB_LIB -lz " ])
101 ? (ABSTRACT_FROM => 'Zlib.pm',
102 AUTHOR => 'Paul Marquess <pmqs@cpan.org>')
121 Z_DEFAULT_COMPRESSION
147 if (eval {require ExtUtils::Constant; 1}) {
148 # Check the constants above all appear in @EXPORT in Zlib.pm
149 my %names = map { $_, 1} @names, 'ZLIB_VERSION';
150 open F, "<Zlib.pm" or die "Cannot open Zlib.pm: $!\n";
153 last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
160 delete $names{$1} if defined $1 ;
166 my $missing = join ("\n\t", sort keys %names) ;
167 die "The following names are missing from \@EXPORT in Zlib.pm\n" .
171 push @names, {name => 'ZLIB_VERSION', type => 'PV' };
173 ExtUtils::Constant::WriteConstants(
176 C_FILE => 'constants.h',
177 XS_FILE => 'constants.xs',
182 foreach my $name (qw( constants.h constants.xs ))
184 my $from = catfile('fallback', $name);
186 or die "Can't copy $from to $name: $!";
196 if $path =~ /(~|\.bak|_bak)$/ ||
197 $path =~ /\..*\.swp$/ ;
204 my $postamble = <<'EOM';
208 perl Makefile.PL -downgrade
211 @echo Checking config.in is setup for a release
212 @(grep '^LIB *= *./zlib-src' config.in && \
213 grep '^INCLUDE *= *./zlib-src' config.in && \
214 grep '^OLD_ZLIB *= *False' config.in && \
215 grep '^GZIP_OS_CODE *= *AUTO_DETECT' config.in && \
216 grep '^BUILD_ZLIB *= *True' config.in) >/dev/null || \
217 (echo config.in needs fixing ; exit 1)
218 @echo config.in is ok
221 @echo Checking for $$^W in files: '. "@files" . '
223 exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/; \
224 \' ' . " @files || " . ' \
225 (echo found unexpected $$^W ; exit 1)
229 @echo Running test suite with Devel::Cover
230 $(MAKE) test COMPRESS_ZLIB_RUN_ALL=1
233 @echo Running test suite with Devel::Cover
234 HARNESS_PERL_SWITCHES=-MDevel::Cover $(MAKE) test
237 @echo Running test suite with Devel::Cover
238 HARNESS_PERL_SWITCHES=-MDevel::Cover $(MAKE) test COMPRESS_ZLIB_RUN_ALL=1
241 @echo Running test suite with utf-8 enabled
242 env LC_ALL=en_GB.UTF-8 $(MAKE) test
245 @echo Running test suite with utf-8 and non-english enabled
246 env LC_ALL=de_DE.UTF-8 $(MAKE) test
250 $postamble .= <<'EOM' if $^O eq 'linux' ;
253 @echo Running test suite with gcov and Devel::Cover [needs gcc 3.4?]
254 #@test "${CC}" = "gcc" || (echo 'gcov' needs gcc, you have ${CC} ; exit 1)
255 rm -f *.o *.gcov *.da *.bbg *.bb *.gcno
256 $(MAKE) OPTIMIZE=-g DEFINE="-fprofile-arcs -ftest-coverage"
257 HARNESS_PERL_SWITCHES=-MDevel::Cover $(MAKE) test
259 #gcov2perl -db cover_db Zlib.xs.gcov
272 my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB GZIP_OS_CODE ) ;
273 my %ValidOption = map {$_, 1} @Options ;
274 my %Parsed = %ValidOption ;
275 my $CONFIG = 'config.in' ;
277 print "Parsing $CONFIG...\n" ;
279 open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
282 next if /^\s*$/ or /^\s*#/ ;
285 ($k, $v) = split(/\s+=\s+/, $_, 2) ;
287 if ($ValidOption{$k}) {
297 print "Unknown keys in $CONFIG ignored [@badkey]\n"
300 # check parsed values
302 die "The following keys are missing from $CONFIG [@missing]\n"
303 if @missing = keys %Parsed ;
305 $ZLIB_INCLUDE = $ENV{'ZLIB_INCLUDE'} || $Info{'INCLUDE'} ;
306 $ZLIB_LIB = $ENV{'ZLIB_LIB'} || $Info{'LIB'} ;
309 $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE);
310 $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB);
313 my $y = $ENV{'OLD_ZLIB'} || $Info{'OLD_ZLIB'} ;
314 $OLD_ZLIB = '-DOLD_ZLIB' if $y and $y =~ /^yes|on|true|1$/i;
316 my $x = $ENV{'BUILD_ZLIB'} || $Info{'BUILD_ZLIB'} ;
318 if ($x and $x =~ /^yes|on|true|1$/i ) {
322 # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when
323 # BUILD_ZLIB is specified.
324 die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n"
325 if $ZLIB_LIB ne $ZLIB_INCLUDE ;
327 # Check the zlib source directory exists
328 die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n"
329 unless -d $ZLIB_LIB ;
331 # check for a well known file
332 die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n"
333 unless -e catfile($ZLIB_LIB, 'zlib.h') ;
337 print "Building Zlib enabled\n" ;
340 $GZIP_OS_CODE = defined $ENV{'GZIP_OS_CODE'}
341 ? $ENV{'GZIP_OS_CODE'}
342 : $Info{'GZIP_OS_CODE'} ;
344 die "GZIP_OS_CODE not 'AUTO_DETECT' or a number between 0 and 255\n"
345 unless uc $GZIP_OS_CODE eq 'AUTO_DETECT'
346 || ( $GZIP_OS_CODE =~ /^(\d+)$/ && $1 >= 0 && $1 <= 255) ;
348 if (uc $GZIP_OS_CODE eq 'AUTO_DETECT')
350 print "Auto Detect Gzip OS Code..\n" ;
351 $GZIP_OS_CODE = getOSCode() ;
354 my $name = getOSname($GZIP_OS_CODE);
355 print "Setting Gzip OS Code to $GZIP_OS_CODE [$name]\n" ;
358 INCLUDE [$ZLIB_INCLUDE]
360 GZIP_OS_CODE [$GZIP_OS_CODE]
362 BUILD_ZLIB [$BUILD_ZLIB]
366 print "Looks Good.\n" ;
374 # our and use bytes/utf8 is stable from 5.6.0 onward
375 # warnings is stable from 5.6.1 onward
377 # Note: this code assumes that each statement it modifies is not
378 # split across multiple lines.
384 my $opt = shift @ARGV || '' ;
385 my $upgrade = ($opt =~ /^-upgrade/i);
386 my $downgrade = ($opt =~ /^-downgrade/i);
387 push @ARGV, $opt unless $downgrade || $upgrade;
390 # From: use|no warnings "blah"
391 # To: local ($^W) = 1; # use|no warnings "blah"
393 s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ;
394 s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ;
397 elsif ($] >= 5.006001 || $upgrade) {
398 # From: local ($^W) = 1; # use|no warnings "blah"
399 # To: use|no warnings "blah"
401 s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ;
407 if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) {
409 my $vars = join ' ', split /\s*,\s*/, $2;
410 $_ = "${indent}use vars qw($vars);\n";
412 elsif ( /^(\s*)((use|no)\s+(bytes|utf8)\s*;.*)$/)
418 elsif ($] >= 5.006000 || $upgrade) {
420 if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) {
422 my $vars = join ', ', split ' ', $2;
423 $_ = "${indent}our ($vars);\n";
425 elsif ( /^(\s*)#\s*((use|no)\s+(bytes|utf8)\s*;.*)$/)
432 if (! $our_sub && ! $warn_sub) {
433 warn "Up/Downgrade not needed.\n";
434 if ($upgrade || $downgrade)
441 { doUpDown($our_sub, $warn_sub, $_) }
443 warn "Up/Downgrade complete.\n" ;
444 exit 0 if $upgrade || $downgrade;
452 my $warn_sub = shift;
456 local ($^I) = ($^O eq 'VMS') ? "_bak" : ".bak";
457 local (@ARGV) = shift;
461 print, last if /^__(END|DATA)__/ ;
463 &{ $our_sub }() if $our_sub ;
464 &{ $warn_sub }() if $warn_sub ;
482 if (-f catfile($dir, "infback.c")) {
483 # zlib 1.2.0 or greater
485 @h_files = qw(crc32.h inffast.h inflate.h trees.h zconf.in.h
486 zutil.h deflate.h inffixed.h inftrees.h zconf.h
489 @c_files = qw(adler32 crc32 infback inflate uncompr
490 compress deflate inffast inftrees
497 @h_files = qw(deflate.h infcodes.h inftrees.h zconf.h zutil.h
498 infblock.h inffast.h infutil.h zlib.h
500 @c_files = qw(adler32 compress crc32 uncompr
501 deflate trees zutil inflate infblock
502 inftrees infcodes infutil inffast
506 @h_files = map { catfile($dir, $_) } @h_files ;
507 my @o_files = map { "$_\$(OBJ_EXT)" } 'Zlib', @c_files;
508 @c_files = map { "$_.c" } 'Zlib', @c_files ;
510 foreach my $file (@c_files)
511 { copy(catfile($dir, $file), '.') }
514 #'H' => [ @h_files ],
515 'C' => [ @c_files ] ,
516 #'OBJECT' => qq[ @o_files ],
517 'OBJECT' => q[ $(O_FILES) ],
531 [ '' => 0, 'MS-DOS' ],
532 [ 'amigaos' => 1, 'Amiga' ],
533 [ 'VMS' => 2, 'VMS' ],
534 [ '' => 3, 'Unix/Default' ],
535 [ '' => 4, 'VM/CMS' ],
536 [ '' => 5, 'Atari TOS' ],
537 [ 'os2' => 6, 'HPFS (OS/2, NT)' ],
538 [ 'MacOS' => 7, 'Macintosh' ],
539 [ '' => 8, 'Z-System' ],
541 [ '' => 10, 'TOPS-20' ],
542 [ '' => 11, 'NTFS (NT)' ],
543 [ '' => 12, 'SMS QDOS' ],
544 [ '' => 13, 'Acorn RISCOS' ],
545 [ 'MSWin32' => 14, 'VFAT file system (Win95, NT)' ],
547 [ 'beos' => 16, 'BeOS' ],
548 [ '' => 17, 'Tandem/NSK' ],
549 [ '' => 18, 'THEOS' ],
550 [ '' => 255, 'Unknown OS' ],
553 %OSnames = map { $$_[1] => $$_[2] }
559 my $default = 3 ; # Unix is the default
563 for my $h (@GZIP_OS_Names)
565 my ($pattern, $code, $name) = @$h;
568 if $pattern && $uname eq $pattern ;
578 return $OSnames{$code} || 'Unknown OS' ;
581 # end of file Makefile.PL