e151ac9afced9bb127199bef75e182bc1f8a84dc
[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     (
87       $BUILD_ZLIB
88         ? zlib_files($ZLIB_LIB)
89         : (LIBS => [ "-L$ZLIB_LIB -lz " ])
90     ),
91       
92     (
93       $] >= 5.005
94         ? (ABSTRACT_FROM => 'lib/Compress/Raw/Zlib.pm',
95             AUTHOR       => 'Paul Marquess <pmqs@cpan.org>')
96         : ()
97     ),
98
99     ((ExtUtils::MakeMaker->VERSION() gt '6.30') ?
100         ('LICENSE'  => 'perl')         : ()),    
101
102 ) ;
103
104 my @names = qw(
105
106     DEF_WBITS
107     MAX_MEM_LEVEL
108     MAX_WBITS
109     OS_CODE
110
111     Z_ASCII
112     Z_BEST_COMPRESSION
113     Z_BEST_SPEED
114     Z_BINARY
115     Z_BLOCK
116     Z_BUF_ERROR
117     Z_DATA_ERROR
118     Z_DEFAULT_COMPRESSION
119     Z_DEFAULT_STRATEGY
120     Z_DEFLATED
121     Z_ERRNO
122     Z_FILTERED
123     Z_FINISH
124     Z_FIXED
125     Z_FULL_FLUSH
126     Z_HUFFMAN_ONLY
127     Z_MEM_ERROR
128     Z_NEED_DICT
129     Z_NO_COMPRESSION
130     Z_NO_FLUSH
131     Z_NULL
132     Z_OK
133     Z_PARTIAL_FLUSH
134     Z_RLE
135     Z_STREAM_END
136     Z_STREAM_ERROR
137     Z_SYNC_FLUSH
138     Z_UNKNOWN
139     Z_VERSION_ERROR
140
141 );
142     #ZLIB_VERNUM
143
144 if (eval {require ExtUtils::Constant; 1}) {
145     # Check the constants above all appear in @EXPORT in Zlib.pm
146     my %names = map { $_, 1} @names, 'ZLIB_VERSION';
147     open F, "<lib/Compress/Raw/Zlib.pm" or die "Cannot open Zlib.pm: $!\n";
148     while (<F>)
149     {
150         last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
151     }
152
153     while (<F>)
154     {
155         last if /^\s*\)/ ;
156         /(\S+)/ ;
157         delete $names{$1} if defined $1 ;
158     }
159     close F ;
160
161     if ( keys %names )
162     {
163         my $missing = join ("\n\t", sort keys %names) ;
164         die "The following names are missing from \@EXPORT in Zlib.pm\n" .
165             "\t$missing\n" ;
166     }
167     
168     push @names, {name => 'ZLIB_VERSION', type => 'PV' };
169
170     ExtUtils::Constant::WriteConstants(
171                                      NAME => 'Zlib',
172                                      NAMES => \@names,
173                                      C_FILE  => 'constants.h',
174                                      XS_FILE  => 'constants.xs',
175                                                                        
176                                     );
177
178 else {
179     foreach my $name (qw( constants.h constants.xs ))
180     {
181         my $from = catfile('fallback', $name);
182         copy ($from, $name)
183           or die "Can't copy $from to $name: $!";
184     }
185 }
186
187 sub ParseCONFIG
188 {
189     my ($k, $v) ;
190     my @badkey = () ;
191     my %Info = () ;
192     my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB GZIP_OS_CODE ) ;
193     my %ValidOption = map {$_, 1} @Options ;
194     my %Parsed = %ValidOption ;
195     my $CONFIG = 'config.in' ;
196
197     print "Parsing $CONFIG...\n" ;
198
199     open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
200     while (<F>) {
201         s/^\s*|\s*$//g ;
202         next if /^\s*$/ or /^\s*#/ ;
203         s/\s*#\s*$// ;
204
205         ($k, $v) = split(/\s+=\s+/, $_, 2) ;
206         $k = uc $k ;
207         if ($ValidOption{$k}) {
208             delete $Parsed{$k} ;
209             $Info{$k} = $v ;
210         }
211         else {
212             push(@badkey, $k) ;
213         }
214     }
215     close F ;
216
217     print "Unknown keys in $CONFIG ignored [@badkey]\n"
218         if @badkey ;
219
220     # check parsed values
221     my @missing = () ;
222     die "The following keys are missing from $CONFIG  [@missing]\n" 
223         if @missing = keys %Parsed ;
224
225     $ZLIB_INCLUDE = $ENV{'ZLIB_INCLUDE'} || $Info{'INCLUDE'} ;
226     $ZLIB_LIB = $ENV{'ZLIB_LIB'} || $Info{'LIB'} ;
227
228     if ($^O eq 'VMS') {
229         $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE);
230         $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB);
231     }
232
233     my $y = $ENV{'OLD_ZLIB'} || $Info{'OLD_ZLIB'} ;
234     $OLD_ZLIB = '-DOLD_ZLIB' if $y and $y =~ /^yes|on|true|1$/i;
235
236     my $x = $ENV{'BUILD_ZLIB'} || $Info{'BUILD_ZLIB'} ;
237
238     if ($x and $x =~ /^yes|on|true|1$/i ) {
239
240         $BUILD_ZLIB = 1 ;
241
242         # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when 
243         # BUILD_ZLIB is specified.
244         die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n"
245             if $ZLIB_LIB ne $ZLIB_INCLUDE ;
246
247         # Check the zlib source directory exists
248         die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n"
249            unless -d $ZLIB_LIB ;
250
251         # check for a well known file
252         die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n"
253            unless -e catfile($ZLIB_LIB, 'zlib.h') ;
254
255
256         # write the Makefile
257         print "Building Zlib enabled\n" ;
258     }
259
260     $GZIP_OS_CODE = defined $ENV{'GZIP_OS_CODE'} 
261                           ? $ENV{'GZIP_OS_CODE'} 
262                           : $Info{'GZIP_OS_CODE'} ;
263
264         die "GZIP_OS_CODE not 'AUTO_DETECT' or a number between 0 and 255\n"
265            unless uc $GZIP_OS_CODE eq 'AUTO_DETECT'
266                     || ( $GZIP_OS_CODE =~ /^(\d+)$/ && $1 >= 0 && $1 <= 255) ;
267
268     if (uc $GZIP_OS_CODE eq 'AUTO_DETECT')
269     {
270         print "Auto Detect Gzip OS Code..\n" ;
271         $GZIP_OS_CODE = getOSCode() ;
272     }
273     
274     my $name = getOSname($GZIP_OS_CODE);
275     print "Setting Gzip OS Code to $GZIP_OS_CODE [$name]\n" ;
276
277     print <<EOM if 0 ;
278     INCLUDE         [$ZLIB_INCLUDE]
279     LIB             [$ZLIB_LIB]
280     GZIP_OS_CODE    [$GZIP_OS_CODE]
281     OLD_ZLIB        [$OLD_ZLIB]
282     BUILD_ZLIB      [$BUILD_ZLIB]
283
284 EOM
285
286     print "Looks Good.\n" ;
287
288 }
289
290
291
292 sub zlib_files
293 {
294     my $dir = shift ;
295
296     my @h_files = ();
297     my @c_files = ();
298     
299     if (-f catfile($dir, "infback.c")) {
300         # zlib 1.2.0 or greater
301         #
302         @h_files = qw(crc32.h    inffast.h inflate.h  trees.h    zconf.in.h 
303                       zutil.h    deflate.h inffixed.h inftrees.h zconf.h  
304                       zlib.h 
305                  );
306         @c_files = qw(adler32  crc32   infback  inflate  uncompr
307                       compress deflate inffast  inftrees  
308                       trees    zutil 
309                  );
310     }
311     else {
312         # zlib 1.1.x
313     
314         @h_files = qw(deflate.h  infcodes.h inftrees.h zconf.h zutil.h
315                       infblock.h inffast.h  infutil.h  zlib.h
316                  );
317         @c_files = qw(adler32  compress crc32    uncompr
318                       deflate  trees    zutil    inflate infblock
319                       inftrees infcodes infutil  inffast
320                  );
321     }
322     
323     @h_files = map { catfile($dir, $_)  } @h_files ;
324     my @o_files = map { "$_\$(OBJ_EXT)" } 'Zlib', @c_files;
325     @c_files = map { "$_.c" } 'Zlib', @c_files ;
326
327     foreach my $file (@c_files)
328       { copy(catfile($dir, $file), '.') }
329     
330     return (
331         #'H'         =>  [ @h_files ],
332         'C'         =>  [ @c_files ] ,
333         #'OBJECT'    => qq[ @o_files ],
334         'OBJECT'    => q[ $(O_FILES) ],
335         
336
337            ) ;
338 }
339
340
341
342 use vars qw ( @GZIP_OS_Names  %OSnames) ;
343
344 BEGIN
345 {
346   @GZIP_OS_Names = (
347     [ ''        => 0,    'MS-DOS'                       ],
348     [ 'amigaos' => 1,    'Amiga'                        ],
349     [ 'VMS'     => 2,    'VMS'                          ],
350     [ ''        => 3,    'Unix/Default'                 ],
351     [ ''        => 4,    'VM/CMS'                       ],
352     [ ''        => 5,    'Atari TOS'                    ],
353     [ 'os2'     => 6,    'HPFS (OS/2, NT)'              ],
354     [ 'MacOS'   => 7,    'Macintosh'                    ],
355     [ ''        => 8,    'Z-System'                     ],
356     [ ''        => 9,    'CP/M'                         ],
357     [ ''        => 10,   'TOPS-20'                      ],
358     [ ''        => 11,   'NTFS (NT)'                    ],
359     [ ''        => 12,   'SMS QDOS'                     ],
360     [ ''        => 13,   'Acorn RISCOS'                 ],
361     [ 'MSWin32' => 14,   'VFAT file system (Win95, NT)' ],
362     [ ''        => 15,   'MVS'                          ],
363     [ 'beos'    => 16,   'BeOS'                         ],
364     [ ''        => 17,   'Tandem/NSK'                   ],
365     [ ''        => 18,   'THEOS'                        ],
366     [ ''        => 255,  'Unknown OS'                   ],
367   );
368
369   %OSnames = map { $$_[1] => $$_[2] }  
370              @GZIP_OS_Names ;
371 }
372
373 sub getOSCode
374 {
375     my $default = 3 ; # Unix is the default
376
377     my $uname = $^O;
378
379     for my $h (@GZIP_OS_Names)
380     {
381         my ($pattern, $code, $name) = @$h;
382
383         return $code
384             if $pattern && $uname eq $pattern ;
385     }
386
387     return $default ;
388 }
389
390 sub getOSname
391 {
392     my $code = shift ;
393
394     return $OSnames{$code} || 'Unknown OS' ;
395 }
396
397 # end of file Makefile.PL
398