File Coverage

File:config/auto/arch.pm
Coverage:93.0%

linestmtbrancondsubcode
1# Copyright (C) 2001-2011, Parrot Foundation.
2
3 - 16
=head1 NAME

config/auto/arch - Determine CPU architecture and operating system

=head1 DESCRIPTION

Determines the CPU architecture, the operating system.

This code was formerly part of configuration step class auto::jit.

TODO #356: This checks for the perl5 architecture, not for possible
commandline overrides, such as -m64, -m32 or -Wl,-melf_x86_64.

=cut
17
18package auto::arch;
19
20
2
2
2
use strict;
21
2
2
2
use warnings;
22
23
24
2
2
2
use base qw(Parrot::Configure::Step);
25
26sub _init {
27
13
    my $self = shift;
28
13
    my %data;
29
13
    $data{description} = q{Determine CPU architecture and OS};
30
13
    $data{result} = q{};
31
13
    my $unamep;
32
13
    eval {
33
13
       chomp( $unamep = `uname -p` ) unless ($^O eq 'MSWin32');
34    };
35
13
    $data{unamep} = (! $@ and $unamep)
36        ? $unamep
37        : undef;
38
13
    return \%data;
39}
40
41sub runstep {
42
13
    my ( $self, $conf ) = @_;
43
44
13
    $conf->debug("\n");
45
46
13
    my $archname = $conf->data->get('archname');
47    # This was added to convert IA64.ARCHREV_0 on HP-UX, TT #645, TT #653
48
13
    $archname =~ s|\.|_|g;
49
13
    my ( $cpuarch, $osname ) = split( /-/, $archname );
50
51
52
13
    $conf->debug(
53        "determining operating system and cpu architecture\n",
54        "archname: $archname\n")
55    ;
56
57
13
    if ( !defined $osname ) {
58
3
        ( $osname, $cpuarch ) = ( $cpuarch, q{} );
59    }
60
61    # This was added to convert 9000/800 to 9000_800 on HP-UX
62
13
    $cpuarch =~ s|/|_|g;
63
64    # On OS X if you are using the Perl that shipped with the system
65    # the above split fails because archname is "darwin-thread-multi-2level".
66
13
    if ( $cpuarch =~ /darwin/ ) {
67
2
        $osname = 'darwin';
68
2
        $cpuarch = ( $self->{unamep} eq 'powerpc' )
69            ? 'ppc'
70            : 'i386';
71    }
72
73    # cpuarch and osname are reversed in archname on windows
74    elsif ( $cpuarch =~ /MSWin32/ ) {
75
2
        $cpuarch = ( $osname =~ /x64/ ) ? 'amd64' : 'i386';
76
2
        $osname = 'MSWin32';
77    }
78    elsif ( $osname =~ /cygwin/i || $cpuarch =~ /cygwin/i ) {
79
2
        $cpuarch = 'i386';
80
2
        $osname = 'cygwin';
81    }
82    elsif ( $osname =~ /msys/i || $cpuarch =~ /msys/i ) {
83        # msys-perl is 32bit-only, so we use the information provided by
84        # the OS. Might be incorrect in case of mingw32 on 64bit hardware.
85
1
        $cpuarch = lc (
86            $ENV{PROCESSOR_ARCHITEW6432} ||
87            $ENV{PROCESSOR_ARCHITECTURE} ||
88            'x86'
89        );
90
1
        $osname = 'msys';
91    }
92    elsif ( $cpuarch eq 'i86pc' and $osname eq 'solaris' ) {
93        # That's only the perl value, and is the same for both i386
94        # and amd64. Use uname -p instead to find the processor type.
95
1
        chomp($archname = `uname -p`);
96
1
        $cpuarch = $archname;
97    }
98
99
13
    if ( $archname =~ m/powerpc/ ) {
100
1
        $cpuarch = 'ppc';
101    }
102
103
13
    $cpuarch =~ s/armv[34]l?/arm/i;
104
13
    $cpuarch =~ s/i[456]86/i386/i;
105
13
    $cpuarch =~ s/x86_64/amd64/i;
106
13
    $cpuarch =~ s/x86/i386/i;
107
108
13
    $conf->data->set(
109        cpuarch => $cpuarch,
110        osname => $osname
111    );
112
113
13
    $conf->data->set( 'platform' => $self->_get_platform( $conf ) );
114
13
    $conf->data->set( 'osvers' => $conf->data->get('osvers_provisional') )
115        unless $conf->data->get('osvers');
116
117
13
    _report_verbose( $conf );
118
119
13
    return 1;
120}
121
122sub _get_platform {
123
18
    my ($self, $conf) = @_;
124
18
    my $platform = lc ( $conf->data->get('osname') );
125
126
18
    $platform = "win32" if $platform =~ /^msys/;
127
18
    $platform = "win32" if $platform =~ /^mingw/;
128
18
    $platform =~ s/^ms//;
129
130
18
    if ( ( split m/-/, $conf->data->get('archname'), 2 )[0] eq 'ia64' ) {
131
1
        $platform = 'ia64';
132    }
133
134
18
    $platform = 'generic' unless -d "src/platform/$platform";
135
136
18
    return $platform;
137}
138
139sub _report_verbose {
140
14
    my ($conf) = @_;
141
14
    $conf->debug(
142        "osname: ", $conf->data->get('osname'), "\n",
143        "cpuarch: ", $conf->data->get('cpuarch'), "\n",
144        "platform: ", $conf->data->get('platform'), "\n",
145    );
146
14
    return 1;
147}
148
1491;
150
151# Local Variables:
152# mode: cperl
153# cperl-indent-level: 4
154# fill-column: 100
155# End:
156# vim: expandtab shiftwidth=4: