ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/setarchitecture.pm
Revision: 1.13
Committed: Fri Dec 14 09:04:17 2007 UTC (17 years, 5 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: V1_1_7, V1_1_6, V1_1_5, V1_1_4, V1_1_3, V1_1_2, V1_1_0_reltag8, V1_1_0_reltag7, V1_1_0_reltag6, V1_1_1, V1_1_0_reltag5, V1_1_0_reltag4, V1_1_0_reltag3, V1_1_0_reltag2, V1_1_0_reltag1, V1_1_0_reltag, V1_1_0, V1_1_0_cand3, V1_1_0_cand2, V1_1_0_cand1
Branch point for: forBinLess_SCRAM
Changes since 1.12: +0 -0 lines
Log Message:
replace head with xml branch

File Contents

# Content
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 }