summaryrefslogtreecommitdiff
path: root/platform.pl.in
blob: ce2e694c900cd4714e309db7cd1fe46171ab4e7b (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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/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 --- #


$SCRIPTSDIR = "@scriptsdir@";
if ($SCRIPTSDIR =~ /^@scriptsdir[@]/)
{
    $SCRIPTSDIR = ".";
    $DOTIN = ".in";
}

require "$SCRIPTSDIR/parse.pl$DOTIN";
require "$SCRIPTSDIR/xml.pl$DOTIN";


$PLATFORM_INFO = {
  "debian-2.2"      => "Debian GNU/Linux 2.2 Potato",
  "debian-woody"    => "Debian GNU/Linux 3.0 Woody",
  "debian-sarge"    => "Debian GNU/Linux Sarge",
  "redhat-5.2"      => "Red Hat Linux 5.2 Apollo",
  "redhat-6.0"      => "Red Hat Linux 6.0 Hedwig",
  "redhat-6.1"      => "Red Hat Linux 6.1 Cartman",
  "redhat-6.2"      => "Red Hat Linux 6.2 Zoot",
  "redhat-7.0"      => "Red Hat Linux 7.0 Guinness",
  "redhat-7.1"      => "Red Hat Linux 7.1 Seawolf",
  "redhat-7.2"      => "Red Hat Linux 7.2 Enigma",
  "redhat-7.3"      => "Red Hat Linux 7.3 Valhalla",
  "redhat-8.0"      => "Red Hat Linux 8.0 Psyche",
  "redhat-9"        => "Red Hat Linux 9.0 Shrike",
  "mandrake-7.1"    => "Linux Mandrake 7.1",
  "mandrake-7.2"    => "Linux Mandrake 7.2 Odyssey",
  "mandrake-8.0"    => "Linux Mandrake 8.0 Traktopel",
  "mandrake-9.0"    => "Linux Mandrake 9.0 Dolphin",
  "mandrake-9.1"    => "Linux Mandrake 9.1 Bamboo",
  "suse-7.0"        => "SuSE Linux 7.0",
  "turbolinux-7.0"  => "Turbolinux 7.0",
  "slackware-8.0.0" => "Slackware 8.0.0",
  "slackware-8.1"   => "Slackware 8.1",
  "slackware-9.0.0" => "Slackware 9.0.0",
  "freebsd-4"       => "FreeBSD 4",
  "freebsd-5"       => "FreeBSD 5",
  "gentoo"          => "Gentoo Linux",
  "pld-1.0"         => "PLD 1.0 Ra"
};
  
sub check_lsb
{
  my ($ver, $dist);
  my %vermap =
      ("3.0" => "woody");
  
  my %distmap =
      ("Debian" => "debian"),
      ("Mandrake" => "mandrake");

  # gst_prefix not required here: parse already does that for us.
  $dist = lc (&gst_parse_sh ("/etc/lsb-release", "DISTRIB_ID"));
  $ver = lc (&gst_parse_sh ("/etc/lsb-release", "DISTRIB_RELEASE"));
  
  $ver = $vermap{$ver} if exists $vermap{$ver};
  $dist = $distmap{$dist} if exists $dirmap{$dir};

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

sub check_debian
{
  my ($ver, $i);
  my %vermap =
      ("3.0" => "woody",
       "testing/unstable" => "sarge");

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

  $ver = $vermap{$ver} if exists $vermap{$ver};
  
  return "debian-$ver";
}


sub check_redhat
{
  open RELEASE, "$gst_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, "$gst_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, "$gst_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, "$gst_prefix/etc/mandrake-release" or return -1;
  while (<MANDRAKE>)
  {
    $ver = $_;
    chomp ($ver);
    if ($ver =~ /^Linux Mandrake release (\S+)/)
    {
      close MANDRAKE;
      return "mandrake-$1";
    }
    elsif ($ver =~ /^Mandrake Linux release ([0-9\.]+)/)
    {
      close MANDRAKE;
      return "mandrake-$1";
    }
  }
  close MANDRAKE;
  return -1;
}

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

sub check_slackware
{
  open RELEASE, "$gst_prefix/etc/slackware-version" or return -1;
  while (<RELEASE>)
  {
    chomp;
    if (/^Slackware ([0-9.]+)/)
    {
        close RELEASE;
        return "slackware-$1";
    }
  }
  close RELEASE;
  return -1;
}

sub check_gentoo
{
  return "gentoo" if stat ("$gst_prefix/usr/portage");
  return -1;
}

sub check_linuxppc
{
  open RELEASE, "$gst_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_pld
{
  open RELEASE, "$gst_prefix/etc/pld-release" or return -1;
  while (<RELEASE>)
  {
    chomp;
               if(/^([0-9.]+) PLD Linux/)
    {
      close RELEASE;
      return "pld-$1";
    }
  }
  close RELEASE;
  return -1;
}

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

  $sysctl_cmd = &gst_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 ($fd, $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
  #
  $fd = &gst_file_run_pipe_read ("uname -r");
  return -1 if $fd eq undef;
  chomp ($dist = <$fd>);
  &gst_file_close ($fd);

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

sub gst_platform_guess
{
  my ($tool) = @_;
  local *FD;

  # get the output of 'uname -s', it returns the system we are running
  *FD = &gst_file_run_pipe_read ("uname -s");
  $$tool{"system"} = <FD>;
  chomp ($$tool{"system"});
  close FD;

  # set $gst_dist and $gst_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,
                 \&check_slackware, \&check_gentoo,  \&check_pld ],
    "FreeBSD" => [ \&check_freebsd ],
    "SunOS"    => [ \&check_solaris ]
               );
  my $plat;

  # Fool-the-backend hack.
  if (exists $ENV{"GST_DIST"})
  {
    $$tool{"platform"} = $gst_dist = $ENV{"GST_DIST"};
    return;
  }

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

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


# gst_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 gst_platform_ensure_supported
{
  my ($tool, @supported) = @_;

  $$tool{"platforms"} = [ @supported ];

  foreach $platform (@supported)
  {
    if ($platform eq $$tool{"platform"})
    {
      &gst_report ("platform_success", $platform, $$PLATFORM_INFO{$platform});
      return;
    }
  }

  # Not supported.
  if (exists $$tool{"platform"})
  {
    &gst_report ("platform_unsup", $$tool{"platform"});
  }
  else
  {
    &gst_report ("platform_undet");
  }
}


# A directive handler that sets the currently selected platform.
sub gst_platform_set
{
  my ($tool, $platform) = @_;
  my ($p);

  foreach $p (@{ $$tool{"platforms"}})
  {
    if ($p eq $platform)
    {
      $$tool{"platform"} = $gst_dist = $platform;
      &gst_report ("platform_success", $platform, $$PLATFORM_INFO{$platform});
      &gst_report_end ();
      return;
    }
  }

  &gst_report ("platform_unsup", $platform);
  &gst_report_end ();
}

sub gst_platform_print_list
{
  my ($platforms) = @_;
  my ($platform, $name);

  &gst_xml_print_begin ("platforms");
  foreach $platform (sort @$platforms)
  {
    $name = $$PLATFORM_INFO{$platform};

    &gst_xml_container_enter ("platform");
    &gst_xml_print_line ("<key>$platform</key>");
    &gst_xml_print_line ("<name>$name</name>");
    &gst_xml_container_leave ();
  }
  &gst_xml_print_end ("platforms");
}

sub gst_platform_list
{
  my ($tool) = @_;

  &gst_report_end ();
  &gst_platform_print_list ($$tool{"platforms"});
}

1;