Update to Digest::MD5 2.31
[p5sagit/p5-mst-13.2.git] / ext / Digest / MD5 / Makefile.PL
1 #!perl -w
2
3 BEGIN { require 5.004 }
4 use strict;
5 use Config qw(%Config);
6 use ExtUtils::MakeMaker;
7
8 my @extra;
9 @extra = (DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment();
10
11 if ($^O eq 'VMS') {
12     if (defined($Config{ccname})) {
13         if (grep(/VMS_VAX/, @INC) && ($Config{ccname} eq 'DEC')) {
14             # VAX compiler optimizer even as late as v6.4 gets stuck
15             push(@extra, OPTIMIZE => "/Optimize=(NODISJOINT)");
16         }
17     }
18 }
19
20 push(@extra, 'INSTALLDIRS'  => 'perl') if $] >= 5.008;
21
22 WriteMakefile(
23     'NAME'         => 'Digest::MD5',
24     'VERSION_FROM' => 'MD5.pm',
25     'PREREQ_PM'    => { 'File::Spec' => 0,
26                         'Digest::base' => '1.00',
27                       },
28     @extra,
29     'dist'         => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
30 );
31
32
33
34 sub free_u32_alignment
35 {
36     $|=1;
37     print "Testing alignment requirements for U32... ";
38     return 1 if $^O eq 'VMS';
39     return 1 if $^O eq 'MSWin32';
40
41     open(ALIGN_TEST, ">u32align.c") or die "$!";
42     print ALIGN_TEST <<'EOT'; close(ALIGN_TEST);
43 /*--------------------------------------------------------------*/
44 /*  This program allocates a buffer of U8 (char) and then tries */
45 /*  to access it through a U32 pointer at every offset.  The    */
46 /*  program  is expected to die with a bus error/seg fault for  */
47 /*  machines that do not support unaligned integer read/write   */
48 /*--------------------------------------------------------------*/
49
50 #include <stdio.h>
51 #include "EXTERN.h"
52 #include "perl.h"
53
54 #ifdef printf
55  #undef printf
56 #endif
57
58 int main(int argc, char** argv, char** env)
59 {
60 #if BYTEORDER == 0x1234 || BYTEORDER == 0x4321
61     U8 buf[] = "\0\0\0\1\0\0\0\0";
62     U32 *up;
63     int i;
64
65     if (sizeof(U32) != 4) {
66         printf("sizeof(U32) is not 4, but %d\n", sizeof(U32));
67         exit(1);
68     }
69
70     fflush(stdout);
71
72     for (i = 0; i < 4; i++) {
73         up = (U32*)(buf + i);
74         if (! ((*up == 1 << (8*i)) ||   /* big-endian */
75                (*up == 1 << (8*(3-i)))  /* little-endian */
76               )
77            )
78         {
79             printf("read failed (%x)\n", *up);
80             exit(2);
81         }
82     }
83
84     /* write test */
85     for (i = 0; i < 4; i++) {
86         up = (U32*)(buf + i);
87         *up = 0xBeef;
88         if (*up != 0xBeef) {
89             printf("write failed (%x)\n", *up);
90             exit(3);
91         }
92     }
93
94     printf("no restrictions\n");
95     exit(0);
96 #else
97     printf("unusual byteorder, playing safe\n");
98     exit(1);
99 #endif
100     return 0;
101 }
102 /*--------------------------------------------------------------*/
103 EOT
104
105     my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE";
106     my $exe = "u32align$Config{exe_ext}";
107     $cc_cmd .= " -o $exe";
108     my $rc;
109     $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}");
110     if ($rc) {
111         print "Can't compile test program.  Will ensure alignment to play safe.\n\n";
112         unlink("u32align.c", $exe, "u32align$Config{obj_ext}");
113         return 0;
114     }
115
116     $rc = system("./$exe");
117     unlink("u32align.c", $exe, "u32align$Config{obj_ext}");
118
119     return 1 unless $rc;
120
121     if ($rc > 0x80) {
122         $rc >>= 8;
123         print "Test program exit status was $rc\n";
124     } else {
125         if ($rc & 0x80) {
126             $rc &= ~0x80;
127             print "Core dump deleted\n";
128             unlink("core");
129         }
130         print "signal $rc\n";
131     }
132     return 0;
133 }