| File: | config/auto/msvc.pm |
| Coverage: | 79.1% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2005-2007, Parrot Foundation. | ||||
| 2 | |||||
| 3 - 11 | =head1 NAME config/auto/msvc.pm - Microsoft Visual C++ Compiler =head1 DESCRIPTION Determines whether the C compiler is actually Visual C++. =cut | ||||
| 12 | |||||
| 13 | package auto::msvc; | ||||
| 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 | 5 | my $self = shift; | |||
| 25 | 5 | my %data; | |||
| 26 | 5 | $data{description} = q{Is your C compiler actually Visual C++}; | |||
| 27 | 5 | $data{result} = q{}; | |||
| 28 | 5 | return \%data; | |||
| 29 | } | ||||
| 30 | |||||
| 31 | sub runstep { | ||||
| 32 | 1 | my ( $self, $conf ) = ( shift, shift ); | |||
| 33 | |||||
| 34 | 1 | if ($conf->data->get('gccversion')) { | |||
| 35 | 1 | $conf->debug(" (skipped) "); | |||
| 36 | 1 | $self->set_result('skipped'); | |||
| 37 | 1 | $conf->data->set( msvcversion => undef ); | |||
| 38 | 1 | return 1; | |||
| 39 | } | ||||
| 40 | 0 | my $msvcref = _probe_for_msvc($conf); | |||
| 41 | |||||
| 42 | 0 | $self->_evaluate_msvc($conf, $msvcref); | |||
| 43 | |||||
| 44 | 0 | return 1; | |||
| 45 | } | ||||
| 46 | |||||
| 47 | sub _probe_for_msvc { | ||||
| 48 | 0 | my $conf = shift; | |||
| 49 | 0 | $conf->cc_gen("config/auto/msvc/test_c.in"); | |||
| 50 | 0 | $conf->cc_build(); | |||
| 51 | 0 | my %msvc = eval $conf->cc_run() or die "Can't run the test program: $!"; | |||
| 52 | 0 | $conf->cc_clean(); | |||
| 53 | 0 | return \%msvc; | |||
| 54 | } | ||||
| 55 | |||||
| 56 | sub _evaluate_msvc { | ||||
| 57 | 2 | my ($self, $conf, $msvcref) = @_; | |||
| 58 | # Set msvcversion to undef. This will also trigger any hints-file | ||||
| 59 | # callbacks that depend on knowing whether or not we're using Visual C++. | ||||
| 60 | |||||
| 61 | # This key should always exist unless the program couldn't be run, | ||||
| 62 | # which should have been caught by the 'die' above. | ||||
| 63 | # Therefore, test if it's defined to see if MSVC's installed. | ||||
| 64 | # return 'no' if it's not. | ||||
| 65 | 2 | unless ( defined $msvcref->{_MSC_VER} ) { | |||
| 66 | 0 | $self->set_result('no'); | |||
| 67 | 0 | $conf->data->set( msvcversion => undef ); | |||
| 68 | 0 | return 1; | |||
| 69 | } | ||||
| 70 | |||||
| 71 | 2 | my $major = int( $msvcref->{_MSC_VER} / 100 ); | |||
| 72 | 2 | my $minor = $msvcref->{_MSC_VER} % 100; | |||
| 73 | 2 | my $status = $self->_handle_not_msvc($conf, $major, $minor); | |||
| 74 | 2 | return 1 if $status; | |||
| 75 | |||||
| 76 | 2 | my $msvcversion = $self->_compose_msvcversion($major, $minor); | |||
| 77 | |||||
| 78 | 2 | $conf->data->set( msvcversion => $msvcversion ); | |||
| 79 | |||||
| 80 | # Add Visual C++ specifics here | ||||
| 81 | 2 | if ( $msvcversion >= 14.00 ) { | |||
| 82 | |||||
| 83 | # Version 14 (aka Visual C++ 2005) warns about unsafe, deprecated | ||||
| 84 | # functions with the following message. | ||||
| 85 | # | ||||
| 86 | # This function or variable may be unsafe. Consider using xxx_s instead. | ||||
| 87 | # To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help | ||||
| 88 | # for details. | ||||
| 89 | 1 | $conf->data->add( " ", "ccflags", "-D_CRT_SECURE_NO_DEPRECATE" ); | |||
| 90 | } | ||||
| 91 | |||||
| 92 | 2 | $conf->data->set( noinline => '__declspec(noinline)' ); | |||
| 93 | |||||
| 94 | 2 | return 1; | |||
| 95 | } | ||||
| 96 | |||||
| 97 | sub _handle_not_msvc { | ||||
| 98 | 6 | my $self = shift; | |||
| 99 | 6 | my ($conf, $major, $minor) = @_; | |||
| 100 | 6 | my $status; | |||
| 101 | 6 | unless ( defined $major && defined $minor ) { | |||
| 102 | 3 | $conf->debug(" (no) "); | |||
| 103 | 3 | $self->set_result('no'); | |||
| 104 | 3 | $conf->data->set( msvcversion => undef ); | |||
| 105 | 3 | $status++; | |||
| 106 | } | ||||
| 107 | 6 | return $status; | |||
| 108 | } | ||||
| 109 | |||||
| 110 | sub _compose_msvcversion { | ||||
| 111 | 4 | my $self = shift; | |||
| 112 | 4 | my ($major, $minor) = @_; | |||
| 113 | 4 | my $msvcversion = "$major.$minor"; | |||
| 114 | 4 | $self->set_result("yes, $msvcversion"); | |||
| 115 | 4 | return $msvcversion; | |||
| 116 | } | ||||
| 117 | |||||
| 118 | 1; | ||||
| 119 | |||||
| 120 | # Local Variables: | ||||
| 121 | # mode: cperl | ||||
| 122 | # cperl-indent-level: 4 | ||||
| 123 | # fill-column: 100 | ||||
| 124 | # End: | ||||
| 125 | # vim: expandtab shiftwidth=4: | ||||