7 |
|
# : # |
8 |
|
# : # |
9 |
|
# function : Set the architecture variable. Use simple uname # |
10 |
< |
# : query for Sun: for Linux, alos try libc checking.# |
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; |
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: |
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 |
< |
|
42 |
< |
if ( $OSname =~ Linux ) |
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: |
40 |
– |
# my $lddcmd="ldd /bin/ls"; |
41 |
– |
# my ($match) = (`$lddcmd|grep libc` =~ /\s+libc\.so.*\s\=.*\s(.*)\s.*/); |
48 |
|
# Open the ldd command as a pipe: |
49 |
< |
# my $pid=open(LDD,"$lddcmd 2>&1 |"); |
44 |
< |
# exit(1) unless (defined($pid)); |
49 |
> |
my $pid = open(LDD,"$lddcmd 2>&1 |"); |
50 |
|
|
51 |
< |
# Loop over lines of output: |
52 |
< |
# while (<LDD>) |
53 |
< |
# { |
54 |
< |
# chomp $_; |
55 |
< |
# if (my ($match) = ($_ =~ /\s+libc\.so.*\s.*\s(.*)\s.*/)) |
56 |
< |
# { |
57 |
< |
# print "> LDD Match: ",$match,"\n"; |
58 |
< |
# last; |
59 |
< |
# } |
60 |
< |
# } |
61 |
< |
# |
62 |
< |
# Grab something that looks like "libc.*": |
63 |
< |
|
64 |
< |
# Check if this libc thing is a soft link (it should be): |
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 |
< |
# Find out what the thingy is that the link points to: |
69 |
< |
|
70 |
< |
# |
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]: |
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}"; |