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