1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License, Version 1.0 only 6# (the "License"). You may not use this file except in compliance 7# with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22#!perl -w 23 24BEGIN { require 5.004 } 25use strict; 26use Config qw(%Config); 27use ExtUtils::MakeMaker; 28 29my $PERL_CORE = grep $_ eq "PERL_CORE=1", @ARGV; 30 31my @extra; 32@extra = (DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment(); 33 34if ($^O eq 'VMS') { 35 if (defined($Config{ccname})) { 36 if (grep(/VMS_VAX/, @INC) && ($Config{ccname} eq 'DEC')) { 37 # VAX compiler optimizer even as late as v6.4 gets stuck 38 push(@extra, OPTIMIZE => "/Optimize=(NODISJOINT)"); 39 } 40 } 41} 42 43push(@extra, 'INSTALLDIRS' => 'perl') if $] >= 5.008; 44push(@extra, 'MAN3PODS' => {}) if $PERL_CORE; # Pods built by installman. 45 46WriteMakefile( 47 'NAME' => 'Digest::MD5', 48 'VERSION_FROM' => 'MD5.pm', 49 'PREREQ_PM' => { 'File::Spec' => 0, 50 'Digest::base' => '1.00', 51 }, 52 @extra, 53 'dist' => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, 54); 55 56 57 58sub free_u32_alignment 59{ 60 $|=1; 61 if (exists $Config{d_u32align}) { 62 print "Perl's config says that U32 access must "; 63 print "not " unless $Config{d_u32align}; 64 print "be aligned.\n"; 65 return !$Config{d_u32align}; 66 } 67 68 if ($^O eq 'VMS' || $^O eq 'MSWin32') { 69 print "Assumes that $^O implies free alignment for U32 access.\n"; 70 return 1; 71 } 72 73 if ($^O eq 'hpux' && $Config{osvers} < 11.0) { 74 print "Will not test for free alignment on older HP-UX.\n"; 75 return 0; 76 } 77 78 print "Testing alignment requirements for U32... "; 79 open(ALIGN_TEST, ">u32align.c") or die "$!"; 80 print ALIGN_TEST <<'EOT'; close(ALIGN_TEST); 81/*--------------------------------------------------------------*/ 82/* This program allocates a buffer of U8 (char) and then tries */ 83/* to access it through a U32 pointer at every offset. The */ 84/* program is expected to die with a bus error/seg fault for */ 85/* machines that do not support unaligned integer read/write */ 86/*--------------------------------------------------------------*/ 87 88#include <stdio.h> 89#include "EXTERN.h" 90#include "perl.h" 91 92#ifdef printf 93 #undef printf 94#endif 95 96int main(int argc, char** argv, char** env) 97{ 98#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321 99 U8 buf[] = "\0\0\0\1\0\0\0\0"; 100 U32 *up; 101 int i; 102 103 if (sizeof(U32) != 4) { 104 printf("sizeof(U32) is not 4, but %d\n", sizeof(U32)); 105 exit(1); 106 } 107 108 fflush(stdout); 109 110 for (i = 0; i < 4; i++) { 111 up = (U32*)(buf + i); 112 if (! ((*up == 1 << (8*i)) || /* big-endian */ 113 (*up == 1 << (8*(3-i))) /* little-endian */ 114 ) 115 ) 116 { 117 printf("read failed (%x)\n", *up); 118 exit(2); 119 } 120 } 121 122 /* write test */ 123 for (i = 0; i < 4; i++) { 124 up = (U32*)(buf + i); 125 *up = 0xBeef; 126 if (*up != 0xBeef) { 127 printf("write failed (%x)\n", *up); 128 exit(3); 129 } 130 } 131 132 printf("no restrictions\n"); 133 exit(0); 134#else 135 printf("unusual byteorder, playing safe\n"); 136 exit(1); 137#endif 138 return 0; 139} 140/*--------------------------------------------------------------*/ 141EOT 142 143 my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE"; 144 my $exe = "u32align$Config{exe_ext}"; 145 $cc_cmd .= " -o $exe"; 146 my $rc; 147 $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}"); 148 if ($rc) { 149 print "Can't compile test program. Will ensure alignment to play safe.\n\n"; 150 unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); 151 return 0; 152 } 153 154 $rc = system("./$exe"); 155 unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); 156 157 return 1 unless $rc; 158 159 if ($rc > 0x80) { 160 $rc >>= 8; 161 print "Test program exit status was $rc\n"; 162 } else { 163 if ($rc & 0x80) { 164 $rc &= ~0x80; 165 print "Core dump deleted\n"; 166 unlink("core"); 167 } 168 print "signal $rc\n"; 169 } 170 return 0; 171} 172