ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/setarchitecture.pm
Revision: 1.9.2.1
Committed: Fri Feb 27 15:34:56 2004 UTC (21 years, 2 months ago) by sashby
Content type: text/plain
Branch: SCRAM_V1_BRANCH
CVS Tags: V1_pre0, SCRAM_V1, SCRAMV1_IMPORT
Branch point for: V1_pre1
Changes since 1.9: +93 -52 lines
Log Message:
First import of new SCRAM packages into CMS cvs repos.

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 package setarchitecture;
15 require 5.001;
16 require Exporter;
17 @ISA = qw(Exporter);
18 @EXPORT = qw(setarch);
19
20 # 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 # Merge in fix from WIN32 branch:
26 if ($^O =~ /(MSWin32|cygwin)/)
27 {
28 $ENV{SCRAM_ARCH}=$1;
29 }
30 #irm: ux part below
31 else
32 {
33 my $uname=`uname -a`;
34 my ($OSname, $hostname, $OSversion, @rest) = split / /, $uname;
35 my $lddcmd="ldd /bin/ls";
36
37 # Retain only the first two version digits
38 # of os version from uname:
39 if ( $OSname =~ SunOS )
40 {
41 $OSversion =~ s/^(.\..)\..*/\1/;
42 $ENV{SCRAM_ARCH}=$OSname."__".$OSversion;
43 }
44 # Linux:
45 elsif ( $OSname =~ Linux )
46 {
47 # Firstly we check for the kernel version.
48 $OSversion =~ s/^(.\..)\..*/\1/;
49 # Now, we also check for the libc version to confirm (or otherwise)
50 # the choice determined by the previous step:
51 # Open the ldd command as a pipe:
52 my $pid = open(LDD,"$lddcmd 2>&1 |");
53
54 # Check that we were able to fork:
55 if (defined($pid))
56 {
57 # Loop over lines of output:
58 while (<LDD>)
59 {
60 chomp $_;
61 # Grab something that looks like "libc.*":
62 if (my ($libc) = ($_ =~ /\s+libc\.so.*\s.*\s(.*)\s.*/))
63 {
64 # Check if this libc thing is a soft link (it should be), then
65 # find out what the thingy is that the link points to:
66 if ( -l $libc && defined($value = readlink $libc))
67 {
68 # Extract the useful numeric info from this:
69 my ($libcmaj,$libcmin,$libcpatch) = ($value =~ /^libc-([0-9])\.([0-9])\.([0-9])\.so/);
70
71 # Set the arch accordingly:
72 if ($libcmaj == 2 && $libcmin == 1 && $libcpatch >= 3)
73 {
74 $ENV{SCRAM_ARCH}="Linux__2.2";
75 }
76
77 if ($libcmaj == 2 && $libcmin == 2 && $libcpatch >= 4)
78 {
79 $ENV{SCRAM_ARCH}="Linux__2.4";
80 }
81
82 if ($libcmaj == 2 && $libcmin == 3 && $libcpatch >= 2)
83 {
84 $ENV{SCRAM_ARCH}="Linux__2.4";
85 }
86
87 }
88 # No need to check other lines:
89 last;
90 }
91 }
92 }
93 else
94 # Fork failed, so we must fall back to
95 # the normal mechanism to define the arch:
96 {
97 $ENV{SCRAM_ARCH}=$OSname."__".$OSversion;
98 }
99 }
100 else
101 {
102 # At this point it looks like the platform is "other".
103 # Set SCRAM_ARCH anyway to the default:
104 $ENV{SCRAM_ARCH}=$OSname."__".$OSversion;
105 }
106 }
107 # Set arch flag to [OS type]__[OSversion] if not set by now:
108 if ( ! defined $ENV{SCRAM_ARCH} )
109 {
110 $ENV{SCRAM_ARCH}=$OSname."__".$OSversion;
111 }
112
113 # Now translate this arch to something else if defined in arch.map:
114 parse_map();
115
116 return (0);
117 }
118
119 # This subrtn parses an architecture map file found in config dir.
120 # The ides is to translate the architecture that scram determines automatically into
121 # some other string that will then become the recognised SCRAM_ARCH for the project:
122 sub parse_map()
123 {
124 my $configdir=$ENV{LOCALTOP}."/config"; # This is fine in most cases
125 my $mapfile=$configdir."/arch.map";
126
127 # Only swap archs in project areas:
128 if ( defined $ENV{LOCALTOP} )
129 {
130 if ( -f $mapfile )
131 {
132 open(ARCHMAP,"< $mapfile") || die "Unable to open architecture map file: $!","\n";
133 while (<ARCHMAP>)
134 {
135 my ($scram_arch,$req_arch) = ($_ =~ /^(.*)?->(.*)?/);
136 print "SCRAM_ARCH ",$scram_arch," becomes ",$req_arch,"\n";
137 }
138 }
139 }
140 }