| 1 | #!perl -w |
| 2 | |
| 3 | use strict; |
| 4 | use Config qw(%Config); |
| 5 | use ExtUtils::MakeMaker; |
| 6 | |
| 7 | my @extra; |
| 8 | @extra = (DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment(); |
| 9 | |
| 10 | if ($^O eq 'VMS') { |
| 11 | if (defined($Config{ccname})) { |
| 12 | if (grep(/VMS_VAX/, @INC) && ($Config{ccname} eq 'DEC')) { |
| 13 | # VAX compiler optimizer even as late as v6.4 gets stuck |
| 14 | push(@extra, OPTIMIZE => "/Optimize=(NODISJOINT)"); |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | |
| 20 | WriteMakefile( |
| 21 | 'NAME' => 'Digest::MD5', |
| 22 | 'VERSION_FROM' => 'MD5.pm', |
| 23 | 'ABSTRACT' => 'Perl interface to the MD-5 algorithm', |
| 24 | 'AUTHOR' => 'Gisle Aas <gisle@activestate.com>', |
| 25 | 'LICENSE' => 'perl', |
| 26 | 'MIN_PERL_VERSION' => 5.008, |
| 27 | 'PREREQ_PM' => { 'File::Spec' => 0, |
| 28 | 'Digest::base' => '1.00', |
| 29 | 'XSLoader' => 0, |
| 30 | }, |
| 31 | 'META_MERGE' => { |
| 32 | resources => { |
| 33 | repository => 'http://github.com/gisle/digest-md5', |
| 34 | } |
| 35 | }, |
| 36 | 'INSTALLDIRS' => 'perl', |
| 37 | @extra, |
| 38 | ); |
| 39 | |
| 40 | |
| 41 | |
| 42 | sub free_u32_alignment |
| 43 | { |
| 44 | $|=1; |
| 45 | if (exists $Config{d_u32align}) { |
| 46 | print "Perl's config says that U32 access must "; |
| 47 | print "not " unless $Config{d_u32align}; |
| 48 | print "be aligned.\n"; |
| 49 | return !$Config{d_u32align}; |
| 50 | } |
| 51 | |
| 52 | if ($^O eq 'VMS' || $^O eq 'MSWin32') { |
| 53 | print "Assumes that $^O implies free alignment for U32 access.\n"; |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | if ($^O eq 'hpux' && $Config{osvers} < 11.0) { |
| 58 | print "Will not test for free alignment on older HP-UX.\n"; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | print "Testing alignment requirements for U32... "; |
| 63 | open(ALIGN_TEST, ">u32align.c") or die "$!"; |
| 64 | print ALIGN_TEST <<'EOT'; close(ALIGN_TEST); |
| 65 | /*--------------------------------------------------------------*/ |
| 66 | /* This program allocates a buffer of U8 (char) and then tries */ |
| 67 | /* to access it through a U32 pointer at every offset. The */ |
| 68 | /* program is expected to die with a bus error/seg fault for */ |
| 69 | /* machines that do not support unaligned integer read/write */ |
| 70 | /*--------------------------------------------------------------*/ |
| 71 | |
| 72 | #include <stdio.h> |
| 73 | #include "EXTERN.h" |
| 74 | #include "perl.h" |
| 75 | |
| 76 | #ifdef printf |
| 77 | #undef printf |
| 78 | #endif |
| 79 | |
| 80 | int main(int argc, char** argv, char** env) |
| 81 | { |
| 82 | #if BYTEORDER == 0x1234 || BYTEORDER == 0x4321 |
| 83 | volatile U8 buf[] = "\0\0\0\1\0\0\0\0"; |
| 84 | volatile U32 *up; |
| 85 | int i; |
| 86 | |
| 87 | if (sizeof(U32) != 4) { |
| 88 | printf("sizeof(U32) is not 4, but %d\n", sizeof(U32)); |
| 89 | exit(1); |
| 90 | } |
| 91 | |
| 92 | fflush(stdout); |
| 93 | |
| 94 | for (i = 0; i < 4; i++) { |
| 95 | up = (U32*)(buf + i); |
| 96 | if (! ((*up == 1 << (8*i)) || /* big-endian */ |
| 97 | (*up == 1 << (8*(3-i))) /* little-endian */ |
| 98 | ) |
| 99 | ) |
| 100 | { |
| 101 | printf("read failed (%x)\n", *up); |
| 102 | exit(2); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /* write test */ |
| 107 | for (i = 0; i < 4; i++) { |
| 108 | up = (U32*)(buf + i); |
| 109 | *up = 0xBeef; |
| 110 | if (*up != 0xBeef) { |
| 111 | printf("write failed (%x)\n", *up); |
| 112 | exit(3); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | printf("no restrictions\n"); |
| 117 | exit(0); |
| 118 | #else |
| 119 | printf("unusual byteorder, playing safe\n"); |
| 120 | exit(1); |
| 121 | #endif |
| 122 | return 0; |
| 123 | } |
| 124 | /*--------------------------------------------------------------*/ |
| 125 | EOT |
| 126 | |
| 127 | my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE"; |
| 128 | my $exe = "u32align$Config{exe_ext}"; |
| 129 | $cc_cmd .= " -o $exe"; |
| 130 | my $rc; |
| 131 | $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}"); |
| 132 | if ($rc) { |
| 133 | print "Can't compile test program. Will ensure alignment to play safe.\n\n"; |
| 134 | unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | $rc = system("./$exe"); |
| 139 | unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); |
| 140 | |
| 141 | return 1 unless $rc; |
| 142 | |
| 143 | if ($rc > 0x80) { |
| 144 | (my $cp = $rc) >>= 8; |
| 145 | print "Test program exit status was $cp\n"; |
| 146 | } |
| 147 | if ($rc & 0x80) { |
| 148 | $rc &= ~0x80; |
| 149 | unlink("core") && print "Core dump deleted\n"; |
| 150 | } |
| 151 | print "signal $rc\n" if $rc && $rc < 0x80; |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | BEGIN { |
| 156 | # compatibility with older versions of MakeMaker |
| 157 | my $developer = -d ".git"; |
| 158 | my %mm_req = ( |
| 159 | LICENCE => 6.31, |
| 160 | META_MERGE => 6.45, |
| 161 | META_ADD => 6.45, |
| 162 | MIN_PERL_VERSION => 6.48, |
| 163 | ); |
| 164 | undef(*WriteMakefile); |
| 165 | *WriteMakefile = sub { |
| 166 | my %arg = @_; |
| 167 | for (keys %mm_req) { |
| 168 | unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) { |
| 169 | warn "$_ $@" if $developer; |
| 170 | delete $arg{$_}; |
| 171 | } |
| 172 | } |
| 173 | ExtUtils::MakeMaker::WriteMakefile(%arg); |
| 174 | }; |
| 175 | } |