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