tagged release 0.6.4
[parrot.git] / config / auto / headers.pm
blob4b389f8288b8f82c3896593b4191da6a017270ae
1 # Copyright (C) 2001-2003, The Perl Foundation.
2 # $Id$
4 =head1 NAME
6 config/auto/headers.pm - C headers
8 =head1 DESCRIPTION
10 Probes for various C headers.
12 =cut
14 package auto::headers;
16 use strict;
17 use warnings;
19 use base qw(Parrot::Configure::Step);
20 use Parrot::Configure::Utils ':auto';
22 sub _init {
23 my $self = shift;
24 my %data;
25 $data{description} = q{Probing for C headers};
26 $data{result} = q{};
27 return \%data;
30 sub runstep {
31 my ( $self, $conf ) = @_;
33 if ( $conf->options->get('miniparrot') ) {
34 $self->set_result('skipped');
35 return 1;
38 _set_from_Config($conf);
40 my @extra_headers = _list_extra_headers($conf);
42 my @found_headers;
43 foreach my $header (@extra_headers) {
44 my $pass = 0;
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/ ) {
62 $pass = 1;
63 push @found_headers, $header;
65 $conf->cc_clean();
66 last if $pass;
69 my $flag = "i_$header";
70 $flag =~ s/\.h$//g;
71 $flag =~ s/\///g;
72 print "$flag: $pass\n" if defined $conf->options->get('verbose');
73 $conf->data->set( $flag => $pass ? 'define' : undef );
76 return 1;
79 sub _set_from_Config {
80 my $conf = shift;
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
83 # probing ourselves
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 {
92 my $conf = shift;
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,
95 # for instance).
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
103 # the header.
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;
118 # Local Variables:
119 # mode: cperl
120 # cperl-indent-level: 4
121 # fill-column: 100
122 # End:
123 # vim: expandtab shiftwidth=4: