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