1 |
###############################################################
|
2 |
# setarchitecture #
|
3 |
###############################################################
|
4 |
# modified : Fri Jul 12 13:55:16 2002 / SFA #
|
5 |
# params : none #
|
6 |
# : #
|
7 |
# : #
|
8 |
# : #
|
9 |
# function : Set the architecture variable. Use simple uname #
|
10 |
# : query for Sun: for Linux, also try libc checking.#
|
11 |
# : #
|
12 |
# : #
|
13 |
###############################################################
|
14 |
|
15 |
BEGIN
|
16 |
{
|
17 |
die "Utilities::setarchitecture: I AM still used!!","\n";
|
18 |
};
|
19 |
|
20 |
package setarchitecture;
|
21 |
require 5.001;
|
22 |
require Exporter;
|
23 |
@ISA = qw(Exporter);
|
24 |
@EXPORT = qw(setarch);
|
25 |
|
26 |
# Currently, this is only used for UNIX systems. Not entirely sure what
|
27 |
# happens on Windows (most people tend to use CYGWIN). Eventually, this
|
28 |
# will need to be improved for non-UNIX architectures:
|
29 |
sub setarch
|
30 |
{
|
31 |
my $uname=`uname -a`;
|
32 |
my ($OSname, $hostname, $OSversion, @rest) = split / /, $uname;
|
33 |
my $lddcmd="ldd /bin/ls";
|
34 |
|
35 |
# Retain only the first two version digits
|
36 |
# of os version from uname:
|
37 |
if ( $OSname =~ SunOS )
|
38 |
{
|
39 |
$OSversion =~ s/^(.\..)\..*/\1/;
|
40 |
}
|
41 |
# Linux:
|
42 |
elsif ( $OSname =~ Linux )
|
43 |
{
|
44 |
# Firstly we check for the kernel version.
|
45 |
$OSversion =~ s/^(.\..)\..*/\1/;
|
46 |
# Now, we also check for the libc version to confirm (or otherwise)
|
47 |
# the choice determined by the previous step:
|
48 |
# Open the ldd command as a pipe:
|
49 |
my $pid = open(LDD,"$lddcmd 2>&1 |");
|
50 |
|
51 |
# Check that we were able to fork:
|
52 |
if (defined($pid))
|
53 |
{
|
54 |
# Loop over lines of output:
|
55 |
while (<LDD>)
|
56 |
{
|
57 |
chomp $_;
|
58 |
# Grab something that looks like "libc.*":
|
59 |
if (my ($libc) = ($_ =~ /\s+libc\.so.*\s.*\s(.*)\s.*/))
|
60 |
{
|
61 |
# Check if this libc thing is a soft link (it should be), then
|
62 |
# find out what the thingy is that the link points to:
|
63 |
if ( -l $libc && defined($value = readlink $libc))
|
64 |
{
|
65 |
# Extract the useful numeric info from this:
|
66 |
my ($libcmaj,$libcmin,$libcpatch) = ($value =~ /^libc-([0-9])\.([0-9])\.([0-9])\.so/);
|
67 |
|
68 |
# Set the arch accordingly:
|
69 |
if ($libcmaj == 2 && $libcmin == 1 && $libcpatch >= 3)
|
70 |
{
|
71 |
$ENV{SCRAM_ARCH}="Linux__2.2";
|
72 |
}
|
73 |
|
74 |
if ($libcmaj == 2 && $libcmin == 2 && $libcpatch >= 4)
|
75 |
{
|
76 |
$ENV{SCRAM_ARCH}="Linux__2.4";
|
77 |
}
|
78 |
}
|
79 |
# No need to check other lines:
|
80 |
last;
|
81 |
}
|
82 |
}
|
83 |
}
|
84 |
else
|
85 |
# Fork failed, so we must fall back to
|
86 |
# the normal mechanism to define the arch:
|
87 |
{
|
88 |
$ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
|
89 |
}
|
90 |
}
|
91 |
else
|
92 |
{
|
93 |
# At this point it looks like the platform is "other".
|
94 |
# Set SCRAM_ARCH anyway to the default:
|
95 |
$ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
|
96 |
}
|
97 |
|
98 |
# Set arch flag to [OS type]__[OSversion] if not set by now:
|
99 |
if ( ! defined $ENV{SCRAM_ARCH} )
|
100 |
{
|
101 |
$ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
|
102 |
}
|
103 |
|
104 |
return (0);
|
105 |
}
|