1# Copyright (C) 2001-2014, Parrot Foundation.
2
3=head1 NAME
4
5config/auto/inline.pm - Inline Compiler Support
6
7=head1 DESCRIPTION
8
9Determines whether the compiler supports C<inline>.
10
11=cut
12
13package auto::inline;
14
15use strict;
16use warnings;
17
18use base qw(Parrot::Configure::Step);
19
20use Parrot::Configure::Utils ':auto';
21
22
23sub _init {
24    my $self = shift;
25    my %data;
26    $data{description} = q{Does your compiler support inline};
27    $data{result}      = q{};
28    return \%data;
29}
30
31sub runstep {
32    my ( $self, $conf ) = @_;
33
34    my $inline = $conf->options->get(qw(inline));
35    if ( defined $inline ) {
36        $conf->data->set( inline => $inline );
37        return 1;
38    }
39
40    my $test = $self->_first_probe_for_inline($conf);
41    unless ($test) {
42        $test = $self->_second_probe_for_inline($conf, $test);
43    }
44
45    $self->_evaluate_inline($conf, $test);
46    return 1;
47}
48
49sub _first_probe_for_inline {
50    my $self = shift;
51    my $conf = shift;
52    my $test = '';
53    $conf->cc_gen('config/auto/inline/test1_c.in');
54    eval { $conf->cc_build(); };
55    if ( !$@ ) {
56        $test = $conf->cc_run_capture();
57        chomp $test if $test;
58    }
59    $conf->cc_clean();
60    return $test eq "inline" ? $test : '';
61}
62
63sub _second_probe_for_inline {
64    my $self = shift;
65    my $conf = shift;
66    my $test = shift;
67    if ( !$test ) {
68        $conf->cc_gen('config/auto/inline/test2_c.in');
69        eval { $conf->cc_build(); };
70        if ( !$@ ) {
71            $test = $conf->cc_run_capture();
72            chomp $test if $test;
73        }
74        $conf->cc_clean();
75    }
76    return $test eq "__inline" ? $test : '';
77}
78
79sub _evaluate_inline {
80    my ($self, $conf, $test) = @_;
81    if ($test) {
82        $conf->debug(" ($test) ");
83        $self->set_result('yes');
84    }
85    else {
86        $conf->debug(" no ");
87        $self->set_result('no');
88        $test = '';
89    }
90    $conf->data->set( inline => $test );
91    return 1;
92}
93
941;
95
96# Local Variables:
97#   mode: cperl
98#   cperl-indent-level: 4
99#   fill-column: 100
100# End:
101# vim: expandtab shiftwidth=4:
102