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