summaryrefslogtreecommitdiff
path: root/platform.pl.in
blob: ae4f947e30533b12379479b8a94c7033f32b94e6 (plain)
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-

# Determine the platform we're running on.
#
# Copyright (C) 2000-2001 Ximian, Inc.
#
# Authors: Arturo Espinosa <arturo@ximian.com>
#          Hans Petter Jansson <hpj@ximian.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.


# --- System guessing --- #


require "___scriptsdir___/parse.pl";


sub check_lsb
{
  my ($ver, $dist);

  # xst_prefix not required here: parse already does that for us.
  $dist = lc (&xst_parse_sh ("/etc/lsb-release", "DISTRIB_ID"));
  $ver = lc (&xst_parse_sh ("/etc/lsb-release", "DISTRIB_RELEASE"));

  return -1 if ($dist eq "") || ($ver eq "");
  return "$dist-$ver";
}

sub check_debian
{
  my $ver;

  open DEBIAN, "$xst_prefix/etc/debian_version" or return -1;
  chomp ($ver = <DEBIAN>);
  close DEBIAN;
  return "debian-$ver";
}


sub check_redhat
{
  open RELEASE, "$xst_prefix/etc/redhat-release" or return -1;
  while (<RELEASE>)
  {
    chomp;
    if (/^Red Hat Linux.*\s+([0-9.]+)\s+.*/)
    {
      close RELEASE;
      return "redhat-$1";
    }
  }
  close RELEASE;
  return -1;
}


sub check_caldera
{
  open INSTALLED, "$xst_prefix/etc/.installed" or return -1;
  while (<INSTALLED>)
  {
    chomp;
    if (/^OpenLinux-(.*)-.*/)
    {
      close INSTALLED;
      return "caldera-$1";
    }
  }
  close INSTALLED;
  return -1;
}


sub check_suse
{
  open RELEASE, "$xst_prefix/etc/SuSE-release" or return -1;
  while (<RELEASE>)
  {
    chomp;
    if (/^VERSION\s*=\s*(\S+)/)
    {
      close RELEASE;
      return "suse-$1";
    }
  }
  close RELEASE;
  return -1;
}


sub check_mandrake
{
  open MANDRAKE, "$xst_prefix/etc/mandrake-release" or return -1;
  while (<MANDRAKE>)
  {
    chomp;
    if (/^Linux Mandrake release (\S+)/)
    {
      close MANDRAKE;
      return "mandrake-$1";
    }
  }
  close MANDRAKE;
  return -1;
}


sub check_turbolinux
{
  open RELEASE, "$xst_prefix/etc/turbolinux-release" or return -1;
  while (<RELEASE>)
  {
    chomp;
    if (/release\s([0-9.]+)\s.*/)
    {
      close RELEASE;
      return "turbolinux-$1";
    }
  }
  close RELEASE;
  return -1;
}


sub check_linuxppc
{
  open RELEASE, "$xst_prefix/etc/redhat-release" or return -1;
  while (<RELEASE>)
  {
    chomp;
    if (/^LinuxPPC\s+(\S+)/)
    {
      close RELEASE;
      return "linuxppc-$1";
    }
  }
  close RELEASE;
  return -1;
}

sub check_freebsd
{
  my ($sysctl_cmd, @output);

  $sysctl_cmd = &xst_file_locate_tool ("sysctl");
  @output = (readpipe("$sysctl_cmd -n kern.version"));
  foreach (@output)
  {
    chomp;
    if (/^FreeBSD\s(\S+)\.\S+.*/)
    {
      return "freebsd-$1";
    }
  }
  return -1;
}

sub check_solaris
{
  my $cmd_uname = &xst_file_locate_tool ("uname");
  my $dist;

  #
  # The file /etc/release is present for solaris-2.6
  # solaris 2.5 does not have the file.  Solaris-7.0 and 8.0 have not
  # been checked
  #
  # uname output
  # Solaris 2.5: 5.5(.1)
  # Solaris 2.6: 5.6
  # Solaris 7:   unknown, assume 7.0
  # Solaris 8:   unknown, assume 8.0
  #
  $pid = open (RELEASE, "$cmd_uname -r |") or return -1;
  chomp ($dist = <RELEASE>);
  close RELEASE;

  if ($dist =~ /^5\.(\d)/) { return "solaris-2.$1" }
  else { if ($dist =~ /^([78])\.\d/) { return "solaris-$1.0" } }
  return -1;
}

sub xst_platform_guess
{
  my ($tool) = @_;
  my $dir = "___scriptsdir___";
  
  if (! -f "$dir/system.guess")
  {
    system ("$dir/guess_system.sh 2> /dev/null > $dir/system.guess");
  }

  if (-f "$dir/system.guess")
  {
    open FILE, "$dir/system.guess";
  }
  else
  {
    open FILE, "$dir/guess_system.sh 2>/dev/null |";
  }

  chomp ($$tool{"system"} = <FILE>);
  close FILE;

  # set $xst_dist and $xst_dist_version
  
  my %check = (
    # Red Hat check must run after Mandrake
    "linux" => [ \&check_lsb,      \&check_debian,   \&check_caldera, \&check_suse, 
                 \&check_mandrake, \&check_linuxppc, \&check_redhat,  \&check_turbolinux],
    # Isn't just "freebsd" enough?
    "freebsdelf" => [ \&check_freebsd ],
    "solaris"    => [ \&check_solaris ]
               );
  my $plat;

  foreach $plat (keys %check)
  {
    if ($$tool{"system"} =~ /$plat/)
    {
      my ($check, $dist);
      
      foreach $check (@{$check{$plat}})
      {
        $dist = &$check ();
        if ($dist != -1)
        {
          $$tool{"platform"} = $xst_dist = $dist;
          return;
        }
      }
    }
  }

  $$tool{"platform"} = $xst_dist = "unknown";
}


# xst_platform_ensure_supported
#
# Takes a list of supported platforms and sees if the one detected is found in
# this list. If not, will report a list of supported platforms and fail.

sub xst_platform_ensure_supported
{
  my ($tool, @supported) = @_;

  foreach $platform (@supported)
  {
    if ($platform eq $xst_dist)
    {
      &xst_report ("platform_success", $platform);
      return;
    }
  }

  # Not supported. Now list the ones we do support, and die.

  foreach $platform (@supported)
  {
    &xst_report ("platform_list",  $platform);
  }

  if ($xst_dist)
  {
    &xst_report ("platform_unsup", $xst_dist);
    if (!$xst_report_threshold && !$xst_verbose)
    {
      print STDERR "Fatal error: Your platform is not supported.\n";
    }
  }
  else
  {
    &xst_report ("platform_undet");
    if (!$xst_report_threshold && !$xst_verbose)
    {
      print STDERR "Fatal error: Unable to determine host platform.\n";
    }
  }

  &xst_end ();
  exit (2);
}

1;