1# Copyright 2001 Abhijit Menon-Sen <ams@toroid.org> 2 3use Config; 4use File::Spec; 5use ExtUtils::MakeMaker; 6 7($stdint = <<"TEST") =~ s/^\| {0,3}//gm; 8| #include <stdint.h> 9| int main(void) { 10| printf("%d%d", sizeof(uint16_t), sizeof(uint32_t)); 11| return 0; 12| } 13TEST 14($inttypes = $stdint) =~ s/stdint/inttypes/; 15 16print "Searching for uint*_t... "; 17 18if (ftest($inttypes) eq "24") { 19 print "inttypes.h"; 20 $def = "#include <inttypes.h>"; 21} elsif (ftest($stdint) eq "24") { 22 print "stdint.h"; 23 $def = "#include <stdint.h>"; 24} else { 25 print "no"; 26 foreach (qw(short int long)) { 27 my $size = $Config{"${_}size"}; 28 $sixteen ||= "unsigned $_" if ($size == 2); 29 $thirtytwo ||= "unsigned $_" if ($size == 4); 30 } 31 $def = "typedef $sixteen uint16_t;\ntypedef $thirtytwo uint32_t;"; 32} 33 34print "\n"; 35 36($text = <<"PLATFORM") =~ s/^\| {0,3}//gm; 37| /* Automatically generated by "perl Makefile.PL" */ 38| 39| #ifndef _PLATFORM_H_ 40| #define _PLATFORM_H_ 41| 42| $def 43| 44| #endif 45PLATFORM 46 47open(F, ">platform.h") || die "platform.h: $!\n"; 48print F $text; 49close F; 50 51WriteMakefile( 52 NAME => 'Crypt::TEA', 53 OBJECT => 'TEA.o _tea.o', 54 VERSION_FROM => 'TEA.pm', 55 ABSTRACT_FROM => 'TEA.pm', 56); 57 58# Compile and run a program to test for a particular feature. 59sub ftest 60{ 61 my $null = File::Spec->devnull; 62 my $result = 0; 63 64 open(F, ">ftest.c") || die "ftest.c: $!\n"; 65 print F $_[0]; 66 close F; 67 68 unlink("ftest"); 69 open OLDERR, ">&STDERR" || die; 70 open OLDOUT, ">&STDOUT" || die; 71 open STDOUT, ">$null" || die; 72 open STDERR, ">$null" || die; 73 74 if (system("$Config{cc} $Config{ccflags} -o ftest ftest.c") == 0) { 75 open STDOUT, ">&OLDOUT" || die; 76 open (F, "./ftest |") && do { 77 local $/; 78 $result = <F>; 79 }; 80 } 81 82 open STDERR, ">&OLDERR" || die; 83 open STDOUT, ">&OLDOUT" || die; 84 unlink("ftest", "ftest.c"); 85 86 return $result; 87} 88