compression modules update to version 2.005
[p5sagit/p5-mst-13.2.git] / ext / Compress / Raw / Zlib / Makefile.PL
1 #! perl -w
2
3 use strict ;
4 require 5.004 ;
5
6 use private::MakeUtil;
7 use ExtUtils::MakeMaker 5.16 ;
8 use ExtUtils::Install (); # only needed to check for version
9
10 my $ZLIB_LIB ;
11 my $ZLIB_INCLUDE ;
12 my $BUILD_ZLIB = 0 ;
13 my $OLD_ZLIB = '' ;
14 my $WALL = '' ;
15 my $GZIP_OS_CODE = -1 ;
16 my $USE_PPPORT_H = ($ENV{PERL_CORE}) ? '' : '-DUSE_PPPORT_H';
17
18 #$WALL = ' -pedantic ' if $Config{'cc'} =~ /gcc/ ;
19 #$WALL = ' -Wall -Wno-comment ' if $Config{'cc'} =~ /gcc/ ;
20
21 # Ticket #18986 says that ExtUtils::Install 1.39 fixes the in-use issue
22 # on win32/cygwin, so make the code below conditional on the version of
23 # ExtUtils::Install.
24
25 # Don't ask if MM_USE_DEFAULT is set -- enables perl core building on cygwin
26 if ($^O =~ /cygwin/i and $ExtUtils::Install::VERSION < 1.39 
27         and not ($ENV{PERL_MM_USE_DEFAULT} or $ENV{PERL_CORE}))
28 {
29     print <<EOM ;
30
31 I see you are running Cygwin.
32
33 Please note that this module cannot be installed on Cygwin using the CPAN
34 shell. The CPAN Shell uses Compress::Raw::Zlib internally and it is not
35 possible to delete an active DLL.
36
37 If you are running the CPAN shell, please exit it and install this module
38 by hand by running 'make install' under the directory
39
40     ~/.cpan/build/Compress-Raw-Zlib-VERSION
41
42 EOM
43
44     print "Do you want to continue? [Y/N]: " ;
45     my $answer = <STDIN> ;
46
47     if ($answer =~ /^yes|y/i)
48     {
49         print "continuing...\n" 
50     }
51     else
52     {
53         print "exiting...\n" ;
54         exit 1 ;
55     }
56
57
58 }
59
60 ParseCONFIG() ;
61
62 UpDowngrade(getPerlFiles('MANIFEST')) 
63     unless $ENV{PERL_CORE};
64
65 WriteMakefile( 
66     NAME         => 'Compress::Raw::Zlib',
67     VERSION_FROM => 'lib/Compress/Raw/Zlib.pm',
68     INC          => "-I$ZLIB_INCLUDE" ,
69     DEFINE       => "$OLD_ZLIB $WALL -DGZIP_OS_CODE=$GZIP_OS_CODE $USE_PPPORT_H" ,
70     XS           => { 'Zlib.xs' => 'Zlib.c'},
71     'depend'     => { 'Makefile'   => 'config.in' },
72     'clean'      => { FILES        => '*.c constants.h constants.xs' },
73     'dist'       => { COMPRESS     => 'gzip', 
74                       TARFLAGS     => '-chvf',
75                       SUFFIX       => 'gz',
76                       DIST_DEFAULT => 'MyTrebleCheck tardist',
77                     },
78
79     (
80       $ENV{SKIP_FOR_CORE}
81         ? (MAN3PODS    => {})
82         : ()
83     ),
84        
85     (
86       $BUILD_ZLIB
87         ? zlib_files($ZLIB_LIB)
88         : (LIBS => [ "-L$ZLIB_LIB -lz " ])
89     ),
90       
91     (
92       $] >= 5.005
93         ? (ABSTRACT_FROM => 'lib/Compress/Raw/Zlib.pm',
94             AUTHOR       => 'Paul Marquess <pmqs@cpan.org>')
95         : ()
96     ),
97
98     ((ExtUtils::MakeMaker->VERSION() gt '6.30') ?
99         ('LICENSE'  => 'perl')         : ()),    
100
101 ) ;
102
103 my @names = qw(
104
105     DEF_WBITS
106     MAX_MEM_LEVEL
107     MAX_WBITS
108     OS_CODE
109
110     Z_ASCII
111     Z_BEST_COMPRESSION
112     Z_BEST_SPEED
113     Z_BINARY
114     Z_BLOCK
115     Z_BUF_ERROR
116     Z_DATA_ERROR
117     Z_DEFAULT_COMPRESSION
118     Z_DEFAULT_STRATEGY
119     Z_DEFLATED
120     Z_ERRNO
121     Z_FILTERED
122     Z_FINISH
123     Z_FIXED
124     Z_FULL_FLUSH
125     Z_HUFFMAN_ONLY
126     Z_MEM_ERROR
127     Z_NEED_DICT
128     Z_NO_COMPRESSION
129     Z_NO_FLUSH
130     Z_NULL
131     Z_OK
132     Z_PARTIAL_FLUSH
133     Z_RLE
134     Z_STREAM_END
135     Z_STREAM_ERROR
136     Z_SYNC_FLUSH
137     Z_UNKNOWN
138     Z_VERSION_ERROR
139
140 );
141     #ZLIB_VERNUM
142
143 if (eval {require ExtUtils::Constant; 1}) {
144     # Check the constants above all appear in @EXPORT in Zlib.pm
145     my %names = map { $_, 1} @names, 'ZLIB_VERSION';
146     open F, "<lib/Compress/Raw/Zlib.pm" or die "Cannot open Zlib.pm: $!\n";
147     while (<F>)
148     {
149         last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
150     }
151
152     while (<F>)
153     {
154         last if /^\s*\)/ ;
155         /(\S+)/ ;
156         delete $names{$1} if defined $1 ;
157     }
158     close F ;
159
160     if ( keys %names )
161     {
162         my $missing = join ("\n\t", sort keys %names) ;
163         die "The following names are missing from \@EXPORT in Zlib.pm\n" .
164             "\t$missing\n" ;
165     }
166     
167     push @names, {name => 'ZLIB_VERSION', type => 'PV' };
168
169     ExtUtils::Constant::WriteConstants(
170                                      NAME => 'Zlib',
171                                      NAMES => \@names,
172                                      C_FILE  => 'constants.h',
173                                      XS_FILE  => 'constants.xs',
174                                                                        
175                                     );
176
177 else {
178     foreach my $name (qw( constants.h constants.xs ))
179     {
180         my $from = catfile('fallback', $name);
181         copy ($from, $name)
182           or die "Can't copy $from to $name: $!";
183     }
184 }
185
186 sub ParseCONFIG
187 {
188     my ($k, $v) ;
189     my @badkey = () ;
190     my %Info = () ;
191     my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB GZIP_OS_CODE ) ;
192     my %ValidOption = map {$_, 1} @Options ;
193     my %Parsed = %ValidOption ;
194     my $CONFIG = 'config.in' ;
195
196     print "Parsing $CONFIG...\n" ;
197
198     open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
199     while (<F>) {
200         s/^\s*|\s*$//g ;
201         next if /^\s*$/ or /^\s*#/ ;
202         s/\s*#\s*$// ;
203
204         ($k, $v) = split(/\s+=\s+/, $_, 2) ;
205         $k = uc $k ;
206         if ($ValidOption{$k}) {
207             delete $Parsed{$k} ;
208             $Info{$k} = $v ;
209         }
210         else {
211             push(@badkey, $k) ;
212         }
213     }
214     close F ;
215
216     print "Unknown keys in $CONFIG ignored [@badkey]\n"
217         if @badkey ;
218
219     # check parsed values
220     my @missing = () ;
221     die "The following keys are missing from $CONFIG  [@missing]\n" 
222         if @missing = keys %Parsed ;
223
224     $ZLIB_INCLUDE = $ENV{'ZLIB_INCLUDE'} || $Info{'INCLUDE'} ;
225     $ZLIB_LIB = $ENV{'ZLIB_LIB'} || $Info{'LIB'} ;
226
227     if ($^O eq 'VMS') {
228         $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE);
229         $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB);
230     }
231
232     my $y = $ENV{'OLD_ZLIB'} || $Info{'OLD_ZLIB'} ;
233     $OLD_ZLIB = '-DOLD_ZLIB' if $y and $y =~ /^yes|on|true|1$/i;
234
235     my $x = $ENV{'BUILD_ZLIB'} || $Info{'BUILD_ZLIB'} ;
236
237     if ($x and $x =~ /^yes|on|true|1$/i ) {
238
239         $BUILD_ZLIB = 1 ;
240
241         # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when 
242         # BUILD_ZLIB is specified.
243         die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n"
244             if $ZLIB_LIB ne $ZLIB_INCLUDE ;
245
246         # Check the zlib source directory exists
247         die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n"
248            unless -d $ZLIB_LIB ;
249
250         # check for a well known file
251         die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n"
252            unless -e catfile($ZLIB_LIB, 'zlib.h') ;
253
254
255         # write the Makefile
256         print "Building Zlib enabled\n" ;
257     }
258
259     $GZIP_OS_CODE = defined $ENV{'GZIP_OS_CODE'} 
260                           ? $ENV{'GZIP_OS_CODE'} 
261                           : $Info{'GZIP_OS_CODE'} ;
262
263         die "GZIP_OS_CODE not 'AUTO_DETECT' or a number between 0 and 255\n"
264            unless uc $GZIP_OS_CODE eq 'AUTO_DETECT'
265                     || ( $GZIP_OS_CODE =~ /^(\d+)$/ && $1 >= 0 && $1 <= 255) ;
266
267     if (uc $GZIP_OS_CODE eq 'AUTO_DETECT')
268     {
269         print "Auto Detect Gzip OS Code..\n" ;
270         $GZIP_OS_CODE = getOSCode() ;
271     }
272     
273     my $name = getOSname($GZIP_OS_CODE);
274     print "Setting Gzip OS Code to $GZIP_OS_CODE [$name]\n" ;
275
276     print <<EOM if 0 ;
277     INCLUDE         [$ZLIB_INCLUDE]
278     LIB             [$ZLIB_LIB]
279     GZIP_OS_CODE    [$GZIP_OS_CODE]
280     OLD_ZLIB        [$OLD_ZLIB]
281     BUILD_ZLIB      [$BUILD_ZLIB]
282
283 EOM
284
285     print "Looks Good.\n" ;
286
287 }
288
289
290
291 sub zlib_files
292 {
293     my $dir = shift ;
294
295     my @h_files = ();
296     my @c_files = ();
297     
298     if (-f catfile($dir, "infback.c")) {
299         # zlib 1.2.0 or greater
300         #
301         @h_files = qw(crc32.h    inffast.h inflate.h  trees.h    zconf.in.h 
302                       zutil.h    deflate.h inffixed.h inftrees.h zconf.h  
303                       zlib.h 
304                  );
305         @c_files = qw(adler32  crc32   infback  inflate  uncompr
306                       compress deflate inffast  inftrees  
307                       trees    zutil 
308                  );
309     }
310     else {
311         # zlib 1.1.x
312     
313         @h_files = qw(deflate.h  infcodes.h inftrees.h zconf.h zutil.h
314                       infblock.h inffast.h  infutil.h  zlib.h
315                  );
316         @c_files = qw(adler32  compress crc32    uncompr
317                       deflate  trees    zutil    inflate infblock
318                       inftrees infcodes infutil  inffast
319                  );
320     }
321     
322     @h_files = map { catfile($dir, $_)  } @h_files ;
323     my @o_files = map { "$_\$(OBJ_EXT)" } 'Zlib', @c_files;
324     @c_files = map { "$_.c" } 'Zlib', @c_files ;
325
326     foreach my $file (@c_files)
327       { copy(catfile($dir, $file), '.') }
328     
329     return (
330         #'H'         =>  [ @h_files ],
331         'C'         =>  [ @c_files ] ,
332         #'OBJECT'    => qq[ @o_files ],
333         'OBJECT'    => q[ $(O_FILES) ],
334         
335
336            ) ;
337 }
338
339
340
341 use vars qw ( @GZIP_OS_Names  %OSnames) ;
342
343 BEGIN
344 {
345   @GZIP_OS_Names = (
346     [ ''        => 0,    'MS-DOS'                       ],
347     [ 'amigaos' => 1,    'Amiga'                        ],
348     [ 'VMS'     => 2,    'VMS'                          ],
349     [ ''        => 3,    'Unix/Default'                 ],
350     [ ''        => 4,    'VM/CMS'                       ],
351     [ ''        => 5,    'Atari TOS'                    ],
352     [ 'os2'     => 6,    'HPFS (OS/2, NT)'              ],
353     [ 'MacOS'   => 7,    'Macintosh'                    ],
354     [ ''        => 8,    'Z-System'                     ],
355     [ ''        => 9,    'CP/M'                         ],
356     [ ''        => 10,   'TOPS-20'                      ],
357     [ ''        => 11,   'NTFS (NT)'                    ],
358     [ ''        => 12,   'SMS QDOS'                     ],
359     [ ''        => 13,   'Acorn RISCOS'                 ],
360     [ 'MSWin32' => 14,   'VFAT file system (Win95, NT)' ],
361     [ ''        => 15,   'MVS'                          ],
362     [ 'beos'    => 16,   'BeOS'                         ],
363     [ ''        => 17,   'Tandem/NSK'                   ],
364     [ ''        => 18,   'THEOS'                        ],
365     [ ''        => 255,  'Unknown OS'                   ],
366   );
367
368   %OSnames = map { $$_[1] => $$_[2] }  
369              @GZIP_OS_Names ;
370 }
371
372 sub getOSCode
373 {
374     my $default = 3 ; # Unix is the default
375
376     my $uname = $^O;
377
378     for my $h (@GZIP_OS_Names)
379     {
380         my ($pattern, $code, $name) = @$h;
381
382         return $code
383             if $pattern && $uname eq $pattern ;
384     }
385
386     return $default ;
387 }
388
389 sub getOSname
390 {
391     my $code = shift ;
392
393     return $OSnames{$code} || 'Unknown OS' ;
394 }
395
396 # end of file Makefile.PL
397