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