1 # Copyright (C) 2001-2003, The Perl Foundation.
6 config/auto/headers.pm - C headers
10 Probes for various C headers.
14 package auto
::headers
;
19 use base
qw(Parrot::Configure::Step);
20 use Parrot
::Configure
::Utils
':auto';
25 $data{description
} = q{Probing for C headers};
31 my ( $self, $conf ) = @_;
33 if ( $conf->options->get('miniparrot') ) {
34 $self->set_result('skipped');
38 _set_from_Config
($conf);
40 my @extra_headers = _list_extra_headers
($conf);
43 foreach my $header (@extra_headers) {
46 # First try with just the header. If that fails, try with all the
47 # headers we found so far. This is somewhat a hack, but makes probing
48 # work on *BSD where some headers are documented as relying on others
49 # being included first.
50 foreach my $use_headers ( [$header], [ @found_headers, $header ] ) {
51 $conf->data->set( testheaders
=>
52 join( '', map { "#include <$_>\n" } @
$use_headers ) );
53 $conf->data->set( testheader
=> $header );
55 $conf->cc_gen('config/auto/headers/test_c.in');
57 $conf->data->set( testheaders
=> undef );
58 $conf->data->set( testheader
=> undef );
60 eval { $conf->cc_build(); };
61 if ( !$@
&& $conf->cc_run() =~ /^$header OK/ ) {
63 push @found_headers, $header;
69 my $flag = "i_$header";
72 print "$flag: $pass\n" if defined $conf->options->get('verbose');
73 $conf->data->set( $flag => $pass ?
'define' : undef );
79 sub _set_from_Config
{
81 # perl5's Configure system doesn't call this by its full name, which may
82 # confuse use later, particularly once we break free and start doing all
84 my %mapping = ( i_niin
=> "i_netinetin" );
86 for ( grep { /^i_/ } $conf->data->keys_p5() ) {
87 $conf->data->set( $mapping{$_} || $_ => $conf->data->get_p5($_) );
91 sub _list_extra_headers
{
93 # some headers may not be probed-for by perl 5, or might not be
94 # properly reflected in %Config (i_fcntl seems to be wrong on my machine,
97 # FreeBSD wants this order:
98 #include <sys/types.h>
99 #include <sys/socket.h>
100 #include <netinet/in.h>
101 #include <arpa/inet.h>
102 # hence add sys/types.h to the reprobe list, and have 2 goes at getting
104 my @extra_headers = qw(malloc.h fcntl.h setjmp.h pthread.h signal.h
105 sys/types.h sys/socket.h netinet/in.h arpa/inet.h
106 sys/stat.h sysexit.h limits.h);
108 # more extra_headers needed on mingw/msys; *BSD fails if they are present
109 if ( $conf->data->get_p5('OSNAME') eq "msys" ) {
110 push @extra_headers, qw(sysmman.h netdb.h);
112 return @extra_headers;
120 # cperl-indent-level: 4
123 # vim: expandtab shiftwidth=4: