1 |
sashby |
1.7 |
###############################################################
|
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, alos try libc checking.#
|
11 |
|
|
# : #
|
12 |
|
|
# : #
|
13 |
|
|
###############################################################
|
14 |
williamc |
1.1 |
package setarchitecture;
|
15 |
williamc |
1.2 |
require 5.001;
|
16 |
williamc |
1.1 |
require Exporter;
|
17 |
|
|
@ISA = qw(Exporter);
|
18 |
|
|
@EXPORT = qw(setarch);
|
19 |
|
|
|
20 |
sashby |
1.7 |
# Currently, this is only used for UNIX systems. Not entirely sure what
|
21 |
|
|
# happens on Windows (most people tend to use CYGWIN). Eventually, this
|
22 |
|
|
# will need to be improved for non-UNIX architectures:
|
23 |
|
|
sub setarch
|
24 |
|
|
{
|
25 |
|
|
my $uname=`uname -a`;
|
26 |
|
|
my ($OSname, $hostname, $OSversion, @rest) = split / /, $uname;
|
27 |
|
|
|
28 |
|
|
# Retain only the first two version digits:
|
29 |
|
|
if ( $OSname =~ SunOS )
|
30 |
|
|
{
|
31 |
|
|
$OSversion =~ s/^(.\..)\..*/\1/;
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
if ( $OSname =~ Linux )
|
35 |
|
|
{
|
36 |
|
|
# Firstly we check for the kernel version.
|
37 |
|
|
$OSversion =~ s/^(.\..)\..*/\1/;
|
38 |
|
|
# Now, we also check for the libc version to confirm (or otherwise)
|
39 |
|
|
# 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.*/);
|
42 |
|
|
# Open the ldd command as a pipe:
|
43 |
|
|
# my $pid=open(LDD,"$lddcmd 2>&1 |");
|
44 |
|
|
# exit(1) unless (defined($pid));
|
45 |
|
|
|
46 |
|
|
# Loop over lines of output:
|
47 |
|
|
# while (<LDD>)
|
48 |
|
|
# {
|
49 |
|
|
# chomp $_;
|
50 |
|
|
# if (my ($match) = ($_ =~ /\s+libc\.so.*\s.*\s(.*)\s.*/))
|
51 |
|
|
# {
|
52 |
|
|
# print "> LDD Match: ",$match,"\n";
|
53 |
|
|
# last;
|
54 |
|
|
# }
|
55 |
|
|
# }
|
56 |
|
|
#
|
57 |
|
|
# Grab something that looks like "libc.*":
|
58 |
|
|
|
59 |
|
|
# Check if this libc thing is a soft link (it should be):
|
60 |
|
|
|
61 |
|
|
# Find out what the thingy is that the link points to:
|
62 |
williamc |
1.6 |
|
63 |
sashby |
1.7 |
#
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
# Set arch flag to [OS type]__[OSversion]:
|
67 |
|
|
if ( ! defined $ENV{SCRAM_ARCH} )
|
68 |
|
|
{
|
69 |
|
|
$ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
return (0);
|
73 |
|
|
}
|