File Coverage

File:config/auto/gcc.pm
Coverage:97.9%

linestmtbrancondsubcode
1# Copyright (C) 2001-2007, Parrot Foundation.
2# $Id: gcc.pm 44098 2010-02-17 16:02:09Z coke $
3
4 - 12
=head1 NAME

config/auto/gcc.pm - GNU C Compiler

=head1 DESCRIPTION

Determines whether the C compiler is actually C<gcc>.

=cut
13
14package auto::gcc;
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
21
81
81
81
use Parrot::Configure::Utils ':auto';
22
23
24sub _init {
25
92
    my $self = shift;
26
92
    my %data;
27
92
    $data{description} = q{Is your C compiler actually gcc};
28
92
    $data{result} = q{};
29
92
    return \%data;
30}
31
32sub runstep {
33
81
    my ( $self, $conf ) = @_;
34
81
    my $gnucref = _probe_for_gcc($conf);
35
81
    my $rv = $self->_evaluate_gcc($conf, $gnucref);
36
81
    return $rv;
37}
38
39sub _probe_for_gcc {
40
81
    my $conf = shift;
41
81
    $conf->cc_gen("config/auto/gcc/test_c.in");
42
81
    $conf->cc_build();
43
81
    my %gnuc = eval $conf->cc_run() or die "Can't run the test program: $!";
44
81
    $conf->cc_clean();
45
81
    return \%gnuc;
46}
47
48sub _evaluate_gcc {
49
92
    my ($self, $conf, $gnucref) = @_;
50
51    # Set gccversion to undef. This will also trigger any hints-file
52    # callbacks that depend on knowing whether or not we're using gcc.
53
54    # This key should always exist unless the program couldn't be run,
55    # which should have been caught by the 'die' above.
56
92
    unless ( exists $gnucref->{__GNUC__} ) {
57
1
        $conf->data->set( gccversion => undef );
58
1
        return 1;
59    }
60
61
91
    my $major = $gnucref->{__GNUC__};
62
91
    my $minor = $gnucref->{__GNUC_MINOR__};
63
91
    my $intel = $gnucref->{__INTEL_COMPILER};
64
65
91
    my $verbose = $conf->options->get('verbose');
66
91
    if ( defined $intel || !defined $major ) {
67
3
        print " (no) " if $verbose;
68
3
        $self->set_result('no');
69
3
        $conf->data->set( gccversion => undef );
70
3
        return 1;
71    }
72
88
    if ( $major =~ tr/0-9//c ) {
73
2
        undef $major; # Don't use it
74    }
75
88
    if ( defined $minor and $minor =~ tr/0-9//c ) {
76
1
        undef $minor; # Don't use it
77    }
78
88
    if ( ! defined $major ) {
79
2
        print " (no) " if $verbose;
80
2
        $self->set_result('no');
81
2
        $conf->data->set( gccversion => undef );
82
2
        return 1;
83    }
84
86
    my $gccversion = $major;
85
86
    $gccversion .= ".$minor" if defined $minor;
86
86
    $self->set_result("yes, $gccversion");
87
88
86
    $conf->data->set( sym_export => '__attribute__ ((visibility("default")))' )
89        if $gccversion >= 4.0 && !$conf->data->get('sym_export');
90
91    # sneaky check for g++
92
86
    my $gpp = (index($conf->data->get('cc'), '++') > 0) ? 1 : 0;
93
94
86
    $conf->data->set(
95        gccversion => $gccversion,
96        'g++' => $gpp,
97    );
98
86
    return 1;
99}
100
1011;
102
103# Local Variables:
104# mode: cperl
105# cperl-indent-level: 4
106# fill-column: 100
107# End:
108# vim: expandtab shiftwidth=4: