Commit | Line | Data |
f4c6fd49 |
1 | #! perl -w |
2 | |
3 | use strict ; |
4 | require 5.004 ; |
5 | |
6 | use ExtUtils::MakeMaker 5.16 ; |
7 | use Config ; |
8 | use File::Copy ; |
9 | |
10 | BEGIN |
11 | { |
12 | eval { require File::Spec::Functions ; File::Spec::Functions->import() } ; |
13 | if ($@) |
14 | { |
15 | *catfile = sub { return "$_[0]/$_[1]" } |
16 | } |
17 | } |
18 | |
19 | require VMS::Filespec if $^O eq 'VMS'; |
20 | |
21 | my $ZLIB_LIB ; |
22 | my $ZLIB_INCLUDE ; |
23 | my $BUILD_ZLIB = 0 ; |
24 | my $OLD_ZLIB = '' ; |
25 | my $WALL = ''; |
26 | #$WALL = ' -Wall '; |
27 | |
844ffccc |
28 | unless($ENV{PERL_CORE}) { |
29 | $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV; |
30 | } |
31 | |
f4c6fd49 |
32 | # don't ask if MM_USE_DEFAULT is set -- enables perl core building on cygwin |
844ffccc |
33 | if ($^O =~ /cygwin/i and not $ENV{PERL_MM_USE_DEFAULT} and not $ENV{PERL_CORE}) |
f4c6fd49 |
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 |
40 | CPAN shell. The CPAN Shell uses Compress::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-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 | my @files = ('Zlib.pm', glob("t/*.t"), grep(!/\.bak$/, glob("examples/*"))) ; |
69 | UpDowngrade(@files); |
70 | |
71 | WriteMakefile( |
72 | NAME => 'Compress::Zlib', |
73 | VERSION_FROM => 'Zlib.pm', |
74 | INC => "-I$ZLIB_INCLUDE" , |
75 | DEFINE => "$OLD_ZLIB $WALL" , |
76 | XS => { 'Zlib.xs' => 'Zlib.c' }, |
77 | 'depend' => { 'Makefile' => 'config.in' }, |
78 | 'clean' => { FILES => '*.c constants.h constants.xs' }, |
79 | 'dist' => { COMPRESS => 'gzip', |
80 | SUFFIX => 'gz', |
81 | DIST_DEFAULT => 'MyDoubleCheck Downgrade tardist', |
82 | }, |
83 | ($BUILD_ZLIB |
84 | ? zlib_files($ZLIB_LIB) |
85 | : (LIBS => [ "-L$ZLIB_LIB -lz " ]) |
86 | ), |
87 | ($] >= 5.005 |
88 | ? (ABSTRACT_FROM => 'Zlib.pm', |
89 | AUTHOR => 'Paul Marquess <pmqs@cpan.org>') |
90 | : () |
91 | ), |
92 | ) ; |
93 | |
94 | my @names = qw( |
95 | |
96 | DEF_WBITS |
97 | MAX_MEM_LEVEL |
98 | MAX_WBITS |
99 | OS_CODE |
100 | |
101 | Z_ASCII |
102 | Z_BEST_COMPRESSION |
103 | Z_BEST_SPEED |
104 | Z_BINARY |
105 | Z_BUF_ERROR |
106 | Z_DATA_ERROR |
107 | Z_DEFAULT_COMPRESSION |
108 | Z_DEFAULT_STRATEGY |
109 | Z_DEFLATED |
110 | Z_ERRNO |
111 | Z_FILTERED |
112 | Z_FINISH |
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_STREAM_END |
123 | Z_STREAM_ERROR |
124 | Z_SYNC_FLUSH |
125 | Z_UNKNOWN |
126 | Z_VERSION_ERROR |
127 | ); |
128 | |
129 | if (eval {require ExtUtils::Constant; 1}) { |
130 | # Check the constants above all appear in @EXPORT in Zlib.pm |
131 | my %names = map { $_, 1} @names, 'ZLIB_VERSION'; |
132 | open F, "<Zlib.pm" or die "Cannot open Zlib.pm: $!\n"; |
133 | while (<F>) |
134 | { |
135 | last if /^\s*\@EXPORT\s+=\s+qw\(/ ; |
136 | } |
137 | |
138 | while (<F>) |
139 | { |
140 | last if /^\s*\)/ ; |
141 | /(\S+)/ ; |
142 | delete $names{$1} if defined $1 ; |
143 | } |
144 | close F ; |
145 | |
146 | if ( keys %names ) |
147 | { |
148 | my $missing = join ("\n\t", sort keys %names) ; |
149 | die "The following names are missing from \@EXPORT in Zlib.pm\n" . |
150 | "\t$missing\n" ; |
151 | } |
152 | |
153 | push @names, {name => 'ZLIB_VERSION', type => 'PV' }; |
154 | |
155 | ExtUtils::Constant::WriteConstants( |
156 | NAME => 'Zlib', |
157 | NAMES => \@names, |
158 | C_FILE => 'constants.h', |
159 | XS_FILE => 'constants.xs', |
160 | |
161 | ); |
162 | } |
163 | else { |
164 | copy ('fallback.h', 'constants.h') |
165 | or die "Can't copy fallback.h to constants.h: $!"; |
166 | copy ('fallback.xs', 'constants.xs') |
167 | or die "Can't copy fallback.xs to constants.xs: $!"; |
168 | } |
169 | |
170 | sub MY::postamble |
171 | { |
172 | my $postamble = <<'EOM'; |
173 | |
174 | Downgrade: |
175 | @echo Downgrading. |
176 | perl Makefile.PL -downgrade |
177 | |
178 | MyDoubleCheck: |
179 | @echo Checking config.in is setup for a release |
180 | @(grep '^LIB *= *./zlib' config.in && \ |
181 | grep '^INCLUDE *= *./zlib' config.in && \ |
182 | grep '^OLD_ZLIB *= *False' config.in && \ |
183 | grep '^BUILD_ZLIB *= *True' config.in) >/dev/null || \ |
184 | (echo config.in needs fixing ; exit 1) |
185 | @echo config.in is ok |
186 | |
187 | MyTrebleCheck: |
188 | @echo Checking for $$^W in files: '. "@files" . ' |
189 | @perl -ne \' \ |
190 | exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/; \ |
191 | \' ' . " @files || " . ' \ |
192 | (echo found unexpected $$^W ; exit 1) |
193 | @echo All is ok. |
194 | |
195 | Zlib.xs: typemap |
196 | @$(TOUCH) Zlib.xs |
197 | |
198 | EOM |
199 | |
200 | return $postamble; |
201 | |
202 | } |
203 | |
204 | sub ParseCONFIG |
205 | { |
206 | my ($k, $v) ; |
207 | my @badkey = () ; |
208 | my %Info = () ; |
209 | my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB ) ; |
210 | my %ValidOption = map {$_, 1} @Options ; |
211 | my %Parsed = %ValidOption ; |
212 | my $CONFIG = 'config.in' ; |
213 | |
214 | print "Parsing $CONFIG...\n" ; |
215 | |
216 | open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ; |
217 | while (<F>) { |
218 | s/^\s*|\s*$//g ; |
219 | next if /^\s*$/ or /^\s*#/ ; |
220 | s/\s*#\s*$// ; |
221 | |
222 | ($k, $v) = split(/\s+=\s+/, $_, 2) ; |
223 | $k = uc $k ; |
224 | if ($ValidOption{$k}) { |
225 | delete $Parsed{$k} ; |
226 | $Info{$k} = $v ; |
227 | } |
228 | else { |
229 | push(@badkey, $k) ; |
230 | } |
231 | } |
232 | close F ; |
233 | |
234 | print "Unknown keys in $CONFIG ignored [@badkey]\n" |
235 | if @badkey ; |
236 | |
237 | # check parsed values |
238 | my @missing = () ; |
239 | die "The following keys are missing from $CONFIG [@missing]\n" |
240 | if @missing = keys %Parsed ; |
241 | |
242 | $ZLIB_INCLUDE = $ENV{'ZLIB_INCLUDE'} || $Info{'INCLUDE'} ; |
243 | $ZLIB_LIB = $ENV{'ZLIB_LIB'} || $Info{'LIB'} ; |
244 | |
245 | if ($^O eq 'VMS') { |
246 | $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE); |
247 | $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB); |
248 | } |
249 | |
250 | my $y = $ENV{'OLD_ZLIB'} || $Info{'OLD_ZLIB'} ; |
251 | $OLD_ZLIB = '-DOLD_ZLIB' if $y and $y =~ /^yes|on|true|1$/i; |
252 | |
253 | my $x = $ENV{'BUILD_ZLIB'} || $Info{'BUILD_ZLIB'} ; |
254 | |
255 | if ($x and $x =~ /^yes|on|true|1$/i ) { |
256 | |
257 | $BUILD_ZLIB = 1 ; |
258 | |
259 | # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when |
260 | # BUILD_ZLIB is specified. |
261 | die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n" |
262 | if $ZLIB_LIB ne $ZLIB_INCLUDE ; |
263 | |
264 | # Check the zlib source directory exists |
265 | die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n" |
266 | unless -d $ZLIB_LIB ; |
267 | |
268 | # check for a well known file |
269 | die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n" |
270 | unless -e catfile($ZLIB_LIB, 'zlib.h') ; |
271 | |
272 | |
273 | # check Makefile.zlib has been copied to ZLIB_LIB |
274 | #copy 'Makefile.zlib', catfile($ZLIB_LIB, 'Makefile.PL') || |
275 | #die "Could not copy Makefile.zlib to " . catfile($ZLIB_LIB, 'Makefile.PL') . ": $!\n" ; |
276 | #print "Created a Makefile.PL for zlib\n" ; |
277 | |
278 | # write the Makefile |
279 | print "Building Zlib enabled\n" ; |
280 | } |
281 | |
282 | print <<EOM if 0 ; |
283 | INCLUDE [$ZLIB_INCLUDE] |
284 | LIB [$ZLIB_LIB] |
285 | |
286 | EOM |
287 | |
288 | print "Looks Good.\n" ; |
289 | |
290 | } |
291 | |
292 | sub UpDowngrade |
293 | { |
294 | my @files = @_ ; |
295 | |
296 | # our is stable from 5.6.0 onward |
297 | # warnings is stable from 5.6.1 onward |
298 | |
299 | # Note: this code assumes that each statement it modifies is not |
300 | # split across multiple lines. |
301 | |
302 | |
303 | my $warn_sub = ''; |
304 | my $our_sub = '' ; |
305 | |
306 | my $opt = shift @ARGV || '' ; |
307 | my $upgrade = ($opt =~ /^-upgrade/i); |
308 | my $downgrade = ($opt =~ /^-downgrade/i); |
309 | push @ARGV, $opt unless $downgrade || $upgrade; |
310 | |
311 | if ($downgrade) { |
312 | # From: use|no warnings "blah" |
313 | # To: local ($^W) = 1; # use|no warnings "blah" |
314 | $warn_sub = sub { |
315 | s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ; |
316 | s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ; |
317 | }; |
318 | } |
319 | elsif ($] >= 5.006001 || $upgrade) { |
320 | # From: local ($^W) = 1; # use|no warnings "blah" |
321 | # To: use|no warnings "blah" |
322 | $warn_sub = sub { |
323 | s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ; |
324 | }; |
325 | } |
326 | |
327 | if ($downgrade) { |
328 | $our_sub = sub { |
329 | if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) { |
330 | my $indent = $1; |
331 | my $vars = join ' ', split /\s*,\s*/, $2; |
332 | $_ = "${indent}use vars qw($vars);\n"; |
333 | } |
334 | }; |
335 | } |
336 | elsif ($] >= 5.006000 || $upgrade) { |
337 | $our_sub = sub { |
338 | if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) { |
339 | my $indent = $1; |
340 | my $vars = join ', ', split ' ', $2; |
341 | $_ = "${indent}our ($vars);\n"; |
342 | } |
343 | }; |
344 | } |
345 | |
346 | if (! $our_sub && ! $warn_sub) { |
347 | warn "Up/Downgrade not needed.\n"; |
348 | if ($upgrade || $downgrade) |
349 | { exit 0 } |
350 | else |
351 | { return } |
352 | } |
353 | |
354 | foreach (@files) |
355 | { doUpDown($our_sub, $warn_sub, $_) } |
356 | |
357 | warn "Up/Downgrade complete.\n" ; |
358 | exit 0 if $upgrade || $downgrade; |
359 | |
360 | } |
361 | |
362 | |
363 | sub doUpDown |
364 | { |
365 | my $our_sub = shift; |
366 | my $warn_sub = shift; |
367 | |
368 | local ($^I) = ($^O eq 'VMS') ? "_bak" : ".bak"; |
369 | local (@ARGV) = shift; |
370 | |
371 | while (<>) |
372 | { |
373 | print, last if /^__(END|DATA)__/ ; |
374 | |
375 | &{ $our_sub }() if $our_sub ; |
376 | &{ $warn_sub }() if $warn_sub ; |
377 | print ; |
378 | } |
379 | |
380 | return if eof ; |
381 | |
382 | while (<>) |
383 | { print } |
384 | } |
385 | |
386 | |
387 | sub zlib_files |
388 | { |
389 | my $dir = shift ; |
390 | |
391 | my @h_files = (); |
392 | my @c_files = (); |
393 | |
394 | if (-f catfile($dir, "infback.c")) { |
395 | # zlib 1.2.0 or greater |
396 | # |
397 | @h_files = qw(crc32.h inffast.h inflate.h trees.h zconf.in.h |
398 | zutil.h deflate.h inffixed.h inftrees.h zconf.h |
399 | zlib.h |
400 | ); |
401 | @c_files = qw(adler32 crc32 infback inflate uncompr |
402 | compress deflate gzio inffast inftrees |
403 | trees zutil |
404 | ); |
405 | } |
406 | else { |
407 | # zlib 1.1.x |
408 | |
409 | @h_files = qw(deflate.h infcodes.h inftrees.h zconf.h zutil.h |
410 | infblock.h inffast.h infutil.h zlib.h |
411 | ); |
412 | @c_files = qw(adler32 compress crc32 gzio uncompr |
413 | deflate trees zutil inflate infblock |
414 | inftrees infcodes infutil inffast |
415 | ); |
416 | } |
417 | |
418 | @h_files = map { catfile($dir, $_) } @h_files ; |
419 | my @o_files = map { "$_\$(OBJ_EXT)" } 'Zlib', @c_files; |
420 | @c_files = map { "$_.c" } 'Zlib', @c_files ; |
421 | |
422 | foreach my $file (@c_files) |
423 | { copy(catfile($dir, $file), '.') } |
424 | |
425 | return ( |
426 | #'H' => [ @h_files ], |
427 | 'C' => [ @c_files ] , |
428 | #'OBJECT' => qq[ @o_files ], |
429 | 'OBJECT' => q[ $(O_FILES) ], |
430 | |
431 | |
432 | ) ; |
433 | } |
434 | |
435 | |
436 | # end of file Makefile.PL |
437 | |