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