-
Notifications
You must be signed in to change notification settings - Fork 9
/
osrelease.pl
executable file
·192 lines (177 loc) · 6.16 KB
/
osrelease.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env perl
# Generate a string specific to the current platform for
# purposes of separating and distributing binaries.
#
# The output will have the form:
#
# OS_flavor##-processor-gcc##
#
# Some examples:
#
# Linux_RHEL5-i686-gcc4.1.2
# Linux_RHEL4-i686-gcc3.4.3
# Linux_FC6-i686-gcc4.1.1
# Linux_Fedora9-i686-gcc4.3.0
# Darwin_macosx10.4-i386-gcc4.0.1
# Linux_Ubuntu6.06-unknown-gcc4.0.3
#
# Errors are printed to stderr and some
# attempt is made to return a reasonable
# string for the system such that the script
# will never fail.
#
# This first section sets the uname and release variables
# which hold the "OS" and "_flavor##" parts of the string.
$uname = `uname`;
chomp $uname;
if ($uname eq 'Linux') {
if (-e '/etc/fedora-release') {
$release_string = `cat /etc/fedora-release`;
if ($release_string =~ /^Fedora release/) {
@token = split(/\s+/, $release_string);
$release = "_Fedora$token[2]";
} elsif ($release_string =~ /^Fedora Core release 6.*/) {
$release = '_FC6';
} else {
print STDERR "unrecognized Fedora release\n";
$release = '_Fedora';
}
} elsif (-e '/etc/redhat-release') {
$release_string = `cat /etc/redhat-release`;
if ($release_string =~ /^Red Hat Enterprise Linux WS release 3.*/) {
$release = '_RHEL3';
} elsif ($release_string =~ /^Red Hat Enterprise Linux WS release 4.*/) {
$release = '_RHEL4';
} elsif ($release_string =~ /^Red Hat Enterprise Linux Client release 5.*/) {
$release = '_RHEL5';
} elsif ($release_string =~ /^Red Hat Enterprise Linux Server release 5.*/) {
$release = '_RHEL5';
} elsif ($release_string =~ /^Red Hat Enterprise Linux Workstation release 6.*/) {
$release = '_RHEL6';
} elsif ($release_string =~ /^Red Hat Enterprise Linux Workstation release 7.*/) {
$release = '_RHEL7';
} elsif ($release_string =~ /^CentOS release 5.*/) {
$release = '_CentOS5';
} elsif ($release_string =~ /^CentOS release 6.*/) {
$release = '_CentOS6';
} elsif ($release_string =~ /^CentOS Linux release 7.*/) {
$release = '_CentOS7';
} elsif ($release_string =~ /^Scientific Linux SL release 5.*/ ) {
$release = '_SL5';
} elsif ($release_string =~ /^Scientific Linux release 6.*/ ) {
$release = '_SL6';
}
else {
print STDERR "unrecognized Red Hat release\n";
$release = '_RH';
}
} elsif (-e '/etc/lsb-release') { # Ubuntu
$distrib_id = `cat /etc/lsb-release | grep DISTRIB_ID`;
$distrib_id =~ s/DISTRIB_ID=//;
$distrib_release = `cat /etc/lsb-release | grep DISTRIB_RELEASE`;
$distrib_release =~ s/DISTRIB_RELEASE=//;
chomp $distrib_id;
chomp $distrib_release;
$release = "_${distrib_id}${distrib_release}";
} else {
$release = '';
}
} elsif ($uname eq 'SunOS') {
$release = '_' . `uname -r`;
chomp $release;
@toks = split(/\s/, `CC -V 2>&1`);
$CC_version = $toks[3];
$compiler_version = "CC${CC_version}";
} elsif ($uname eq 'Darwin') {
$release_string = `uname -r`;
if ($release_string =~ /^6.*/) {
$release = '_macosx10.2';
} elsif ($release_string =~ /^7.*/) {
$release = '_macosx10.3';
} elsif ($release_string =~ /^8.*/) {
$release = '_macosx10.4';
} elsif ($release_string =~ /^9.*/) {
$release = '_macosx10.5';
} elsif ($release_string =~ /^10.*/) {
$release = '_macosx10.6';
} elsif ($release_string =~ /^11.*/) {
$release = '_macosx10.7';
} elsif ($release_string =~ /^12.*/) {
$release = '_macosx10.8';
} elsif ($release_string =~ /^13.*/) {
$release = '_macosx10.9';
} elsif ($release_string =~ /^14.*/) {
$release = '_macosx10.10';
} elsif ($release_string =~ /^15.*/) {
$release = '_macosx10.11';
} else {
print STDERR "unrecognized Mac OS X (Darwin) release\n";
$release = '_macosx';
}
} else {
$release = '';
}
# Set the default compiler version number (may be overridden below)
$ccversion = `cc -dumpversion`;
chomp $ccversion;
# Decide if we are using gcc or clang or an "other" compiler type
$compiler_type = "cc";
$compiler_version_str = `cc -v 2>&1`;
if ($compiler_version_str =~ /\sgcc version\s/) {
$compiler_type = "gcc";
$ccversion = `gcc -dumpversion`;
chomp $ccversion;
} elsif ($compiler_version_str =~ /clang version\s+/) {
# clang seems to report different numbers for the version
# if you use "clang -dumpversion" or "clang -v". The former
# seems to correspond to the installed gcc version number
# while the later the actual clang version number. Extract
# the clang version number here, replacing the one obtained
# via "cc -dumpversion" from above.
$compiler_type = "clang";
$' =~ /\s/;
$ccversion = $`;
} elsif ($compiler_version_str =~ /Apple LLVM version\s+/) {
# Starting with OS X 10.9 (Mavericks) the "cc -v" command
# prints things like this:
# Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
# Target: x86_64-apple-darwin13.0.0
# Thread model: posix
#
# (The "-dumpversion" option still seems to report the gcc version
# as decribed above).
#
# It seems they've switched from reporting it as the "clang version"
# to the "LLVM version". We follow their lead here by making the compiler
# type "llvm".
$compiler_type = "llvm";
$' =~ /\s/;
$ccversion = $`;
}
# Set the processor type
# We fall back to the type reported by uname -p, but only if we
# can't get the type from the cc -v result. The reason is that on
# Mac OS X, uname -p will report "i386" even though the system
# is x86_64 and the compiler builds 64-bit executables.
$processor = `uname -p`;
chomp $processor;
if ( $compiler_version_str =~ /Target: x86_64/ ){
$processor = "x86_64";
}elsif ( $compiler_version_str =~ /Target: i686-apple-darwin/ ){
# stubborn Apple still tries to report i686 even for gcc
# compiler that produces x86_64 executables!!
$processor = "x86_64";
}
# If the compiler_version variable is not set, use the gcc version
if ($compiler_version eq '') {
$compiler_version = "${compiler_type}${ccversion}";
}
# If the processor variable is set to "unknown" (Ubuntu systems)
# then use the machine name.
if ($processor eq 'unknown') {
$processor = `uname -m`;
chomp $processor;
}
# Finally, form and print the complete string to stdout
print "${uname}${release}-${processor}-${compiler_version}\n";
exit;