1/*  Title:      Pure/System/platform.scala
2    Author:     Makarius
3
4Raw platform identification.
5*/
6
7package isabelle
8
9
10import scala.util.matching.Regex
11
12
13object Platform
14{
15  /* main OS variants */
16
17  val is_linux = System.getProperty("os.name", "") == "Linux"
18  val is_macos = System.getProperty("os.name", "") == "Mac OS X"
19  val is_windows = System.getProperty("os.name", "").startsWith("Windows")
20
21
22  /* Platform identifiers */
23
24  private val Solaris = new Regex("SunOS|Solaris")
25  private val Linux = new Regex("Linux")
26  private val Darwin = new Regex("Mac OS X")
27  private val Windows = new Regex("Windows.*")
28
29  private val X86 = new Regex("i.86|x86")
30  private val X86_64 = new Regex("amd64|x86_64")
31  private val Sparc = new Regex("sparc")
32  private val PPC = new Regex("PowerPC|ppc")
33
34  lazy val jvm_platform: String =
35  {
36    val arch =
37      System.getProperty("os.arch", "") match {
38        case X86() => "x86"
39        case X86_64() => "x86_64"
40        case Sparc() => "sparc"
41        case PPC() => "ppc"
42        case _ => error("Failed to determine CPU architecture")
43      }
44    val os =
45      System.getProperty("os.name", "") match {
46        case Solaris() => "solaris"
47        case Linux() => "linux"
48        case Darwin() => "darwin"
49        case Windows() => "windows"
50        case _ => error("Failed to determine operating system platform")
51      }
52    arch + "-" + os
53  }
54
55
56  /* JVM version */
57
58  private val Version = new Regex("""1\.(\d+)\.0_(\d+)""")
59  lazy val jvm_version =
60    System.getProperty("java.version") match {
61      case Version(a, b) => a + "u" + b
62      case a => a
63    }
64
65
66  /* JVM name */
67
68  val jvm_name: String = System.getProperty("java.vm.name", "")
69}
70