ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/setarchitecture.pm
Revision: 1.8
Committed: Fri Jul 12 16:37:10 2002 UTC (22 years, 10 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.7: +51 -25 lines
Log Message:
Added glibc checks to setarchitecture sub. Assumes v2.1.3 for RH61, 2.2.4 for RH72.

File Contents

# User Rev Content
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 sashby 1.8 my $lddcmd="ldd /bin/ls";
28 sashby 1.7
29 sashby 1.8 # Retain only the first two version digits
30     # of os version from uname:
31 sashby 1.7 if ( $OSname =~ SunOS )
32     {
33     $OSversion =~ s/^(.\..)\..*/\1/;
34     }
35 sashby 1.8 # Linux:
36     elsif ( $OSname =~ Linux )
37 sashby 1.7 {
38     # Firstly we check for the kernel version.
39     $OSversion =~ s/^(.\..)\..*/\1/;
40     # Now, we also check for the libc version to confirm (or otherwise)
41     # the choice determined by the previous step:
42     # Open the ldd command as a pipe:
43 sashby 1.8 my $pid = open(LDD,"$lddcmd 2>&1 |");
44 sashby 1.7
45 sashby 1.8 # Check that we were able to fork:
46     if (defined($pid))
47     {
48     # Loop over lines of output:
49     while (<LDD>)
50     {
51     chomp $_;
52     # Grab something that looks like "libc.*":
53     if (my ($libc) = ($_ =~ /\s+libc\.so.*\s.*\s(.*)\s.*/))
54     {
55     # Check if this libc thing is a soft link (it should be), then
56     # find out what the thingy is that the link points to:
57     if ( -l $libc && defined($value = readlink $libc))
58     {
59     # Extract the useful numeric info from this:
60     my ($libcmaj,$libcmin,$libcpatch) = ($value =~ /^libc-([0-9])\.([0-9])\.([0-9])\.so/);
61 sashby 1.7
62 sashby 1.8 # Set the arch accordingly:
63     if ($libcmaj == 2 && $libcmin == 1 && $libcpatch >= 3)
64     {
65     $ENV{SCRAM_ARCH}="Linux__2.2";
66     }
67    
68     if ($libcmaj == 2 && $libcmin == 2 && $libcpatch >= 4)
69     {
70     $ENV{SCRAM_ARCH}="Linux__2.4";
71     }
72     }
73     # No need to check other lines:
74     last;
75     }
76     }
77     }
78     else
79     # Fork failed, so we must fall back to
80     # the normal mechanism to define the arch:
81     {
82     $ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
83     }
84     }
85     else
86     {
87     # At this point it looks like the platform is "other".
88     # Set SCRAM_ARCH anyway to the default:
89     $ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
90 sashby 1.7 }
91    
92 sashby 1.8 # Set arch flag to [OS type]__[OSversion] if not set by now:
93 sashby 1.7 if ( ! defined $ENV{SCRAM_ARCH} )
94     {
95     $ENV{SCRAM_ARCH}="${OSname}__${OSversion}";
96     }
97    
98     return (0);
99     }