| File: | config/auto/headers.pm |
| Coverage: | 97.5% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2001-2003, Parrot Foundation. | ||||
| 2 | # $Id: headers.pm 42899 2009-12-05 02:45:27Z jkeenan $ | ||||
| 3 | |||||
| 4 - 12 | =head1 NAME config/auto/headers.pm - C headers =head1 DESCRIPTION Probes for various C headers. =cut | ||||
| 13 | |||||
| 14 | package auto::headers; | ||||
| 15 | |||||
| 16 | 81 81 81 | use strict; | |||
| 17 | 81 81 81 | use warnings; | |||
| 18 | |||||
| 19 | 81 81 81 | use base qw(Parrot::Configure::Step); | |||
| 20 | 81 81 81 | use Parrot::Configure::Utils ':auto'; | |||
| 21 | |||||
| 22 | sub _init { | ||||
| 23 | 83 | my $self = shift; | |||
| 24 | 83 | my %data; | |||
| 25 | 83 | $data{description} = q{Probe for C headers}; | |||
| 26 | 83 | $data{result} = q{}; | |||
| 27 | 83 | return \%data; | |||
| 28 | } | ||||
| 29 | |||||
| 30 | sub runstep { | ||||
| 31 | 82 | my ( $self, $conf ) = @_; | |||
| 32 | |||||
| 33 | 82 | _set_from_Config($conf); | |||
| 34 | |||||
| 35 | 82 | my @extra_headers = _list_extra_headers($conf); | |||
| 36 | |||||
| 37 | 82 | my @found_headers; | |||
| 38 | 82 | foreach my $header (@extra_headers) { | |||
| 39 | 984 | my $pass = 0; | |||
| 40 | |||||
| 41 | # First try with just the header. If that fails, try with all the | ||||
| 42 | # headers we found so far. This is somewhat a hack, but makes probing | ||||
| 43 | # work on *BSD where some headers are documented as relying on others | ||||
| 44 | # being included first. | ||||
| 45 | 984 | foreach my $use_headers ( [$header], [ @found_headers, $header ] ) { | |||
| 46 | 1886 | $conf->data->set( TEMP_testheaders => | |||
| 47 | 1066 | join( '', map { "#include <$_>\n" } @$use_headers ) ); | |||
| 48 | 1066 | $conf->data->set( TEMP_testheader => $header ); | |||
| 49 | |||||
| 50 | 1066 | $conf->cc_gen('config/auto/headers/test_c.in'); | |||
| 51 | |||||
| 52 | 1066 | $conf->data->set( TEMP_testheaders => undef ); | |||
| 53 | 1066 | $conf->data->set( TEMP_testheader => undef ); | |||
| 54 | |||||
| 55 | 1066 1066 | eval { $conf->cc_build(); }; | |||
| 56 | 1066 | if ( !$@ && $conf->cc_run() =~ /^$header OK/ ) { | |||
| 57 | 902 | $pass = 1; | |||
| 58 | 902 | push @found_headers, $header; | |||
| 59 | } | ||||
| 60 | 1066 | $conf->cc_clean(); | |||
| 61 | 1066 | last if $pass; | |||
| 62 | } | ||||
| 63 | |||||
| 64 | 984 | my $flag = "i_$header"; | |||
| 65 | 984 | $flag =~ s/\.h$//g; | |||
| 66 | 984 | $flag =~ s/\///g; | |||
| 67 | 984 | print "$flag: $pass\n" if defined $conf->options->get('verbose'); | |||
| 68 | 984 | $conf->data->set( $flag => $pass ? 'define' : undef ); | |||
| 69 | } | ||||
| 70 | |||||
| 71 | 82 | return 1; | |||
| 72 | } | ||||
| 73 | |||||
| 74 | sub _set_from_Config { | ||||
| 75 | 83 | my $conf = shift; | |||
| 76 | # Perl 5's Configure system doesn't call this by its full name, which may | ||||
| 77 | # confuse use later, particularly once we break free and start doing all | ||||
| 78 | # probing ourselves | ||||
| 79 | 83 | my %mapping = ( i_niin => "i_netinetin" ); | |||
| 80 | |||||
| 81 | 83 6960 | for ( grep { /^i_/ } $conf->data->keys_p5() ) { | |||
| 82 | 6960 | $conf->data->set( $mapping{$_} || $_ => $conf->data->get_p5($_) ); | |||
| 83 | } | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub _list_extra_headers { | ||||
| 87 | 84 | my $conf = shift; | |||
| 88 | # some headers may not be probed-for by Perl 5, or might not be | ||||
| 89 | # properly reflected in %Config (i_fcntl seems to be wrong on my machine, | ||||
| 90 | # for instance). | ||||
| 91 | # | ||||
| 92 | # FreeBSD wants this order: | ||||
| 93 | #include <sys/types.h> | ||||
| 94 | #include <sys/socket.h> | ||||
| 95 | #include <netinet/in.h> | ||||
| 96 | #include <arpa/inet.h> | ||||
| 97 | # hence add sys/types.h to the reprobe list, and have 2 goes at getting | ||||
| 98 | # the header. | ||||
| 99 | 84 | my @extra_headers = qw(malloc.h fcntl.h setjmp.h pthread.h signal.h | |||
| 100 | sys/types.h sys/socket.h netinet/in.h arpa/inet.h | ||||
| 101 | sys/stat.h sysexit.h limits.h); | ||||
| 102 | |||||
| 103 | # more extra_headers needed on mingw/msys; *BSD fails if they are present | ||||
| 104 | 84 | if ( $conf->data->get('OSNAME_provisional') eq "msys" ) { | |||
| 105 | 1 | push @extra_headers, qw(sysmman.h netdb.h); | |||
| 106 | } | ||||
| 107 | |||||
| 108 | 84 | if ( $conf->data->get('OSNAME_provisional') eq "MSWin32" ) { | |||
| 109 | # Microsoft provides two annotations mechanisms. __declspec, which | ||||
| 110 | # has been around for a while, and Microsoft's standard source code | ||||
| 111 | # annotation language (SAL), introduced with Visual C++ 8.0. See | ||||
| 112 | # <http://msdn2.microsoft.com/en-us/library/ms235402(VS.80).aspx>, | ||||
| 113 | # <http://msdn2.microsoft.com/en-us/library/dabb5z75(VS.80).aspx>. | ||||
| 114 | 1 | push @extra_headers, qw(sal.h); | |||
| 115 | } | ||||
| 116 | |||||
| 117 | 84 | return @extra_headers; | |||
| 118 | } | ||||
| 119 | |||||
| 120 | |||||
| 121 | 1; | ||||
| 122 | |||||
| 123 | # Local Variables: | ||||
| 124 | # mode: cperl | ||||
| 125 | # cperl-indent-level: 4 | ||||
| 126 | # fill-column: 100 | ||||
| 127 | # End: | ||||
| 128 | # vim: expandtab shiftwidth=4: | ||||