1# Copyright (C) 2010, Parrot Foundation.
2
3=head1 NAME
4
5config/auto/stat.pm - stat extension detection
6
7=head1 DESCRIPTION
8
9Determining if the system has BSD stat extensions.
10
11=cut
12
13package auto::stat;
14
15use strict;
16use warnings;
17
18use base qw(Parrot::Configure::Step);
19
20use Parrot::Configure::Utils ':auto';
21
22sub _init {
23    my $self = shift;
24    my %data;
25    $data{description} = q{Detect stat type};
26    $data{result}      = q{};
27    return \%data;
28}
29
30sub runstep {
31    my ( $self, $conf ) = @_;
32
33    my $bsd_stat = 0;
34
35    $conf->cc_gen('config/auto/stat/test_c.in');
36    eval { $conf->cc_build(); };
37    if (!$@) {
38        my $output = eval { $conf->cc_run() };
39        if (!$@ && $output =~ /OK/) {
40            $bsd_stat = 1;
41        }
42    }
43
44    $self->_handle_bsd_stat($conf, $bsd_stat);
45    $conf->cc_clean();
46
47    my $stat_atim = 0;
48
49    $conf->cc_gen('config/auto/stat/test_atim_c.in');
50    eval { $conf->cc_build(); };
51    if (!$@) {
52        my $output = eval { $conf->cc_run() };
53        if (!$@ && $output =~ /OK/) {
54            $stat_atim = 1;
55        }
56    }
57    $conf->cc_clean();
58
59    $conf->data->set( HAS_STAT_ATIM => $stat_atim );
60
61    my $stat_atimespec = 0;
62
63    $conf->cc_gen('config/auto/stat/test_atimespec_c.in');
64    eval { $conf->cc_build(); };
65    if (!$@) {
66        my $output = eval { $conf->cc_run() };
67        if (!$@ && $output =~ /OK/) {
68            $stat_atimespec = 1;
69        }
70    }
71    $conf->cc_clean();
72
73    $conf->data->set( HAS_STAT_ATIMESPEC => $stat_atimespec );
74
75    my $stat_st_timespec_t = 0;
76
77    $conf->cc_gen('config/auto/stat/test_st_timespec_t_c.in');
78    eval { $conf->cc_build(); };
79    if (!$@) {
80        my $output = eval { $conf->cc_run() };
81        if (!$@ && $output =~ /OK/) {
82            $stat_st_timespec_t = 1;
83        }
84    }
85    $conf->cc_clean();
86
87    $conf->data->set( HAS_STAT_ST_TIMESPEC_T => $stat_st_timespec_t );
88
89    return 1;
90}
91
92sub _handle_bsd_stat {
93    my ($self, $conf, $bsd_stat) = @_;
94    if ($bsd_stat) {
95        $conf->data->set( HAS_BSD_STAT_EXTN => 1 );
96        $self->set_result('bsd');
97    }
98    else {
99        $conf->data->set( HAS_BSD_STAT_EXTN => 0 );
100        $self->set_result('posix');
101    }
102}
103
1041;
105
106# Local Variables:
107#   mode: cperl
108#   cperl-indent-level: 4
109#   fill-column: 100
110# End:
111# vim: expandtab shiftwidth=4:
112
113