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