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