File Coverage

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

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