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