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