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