72421
|
1 |
/* Title: Pure/System/mingw.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Support for MSYS2/MinGW64 on Windows.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object MinGW
|
|
11 |
{
|
|
12 |
def environment: List[(String, String)] =
|
|
13 |
List("PATH" -> "/usr/bin:/bin:/mingw64/bin", "CONFIG_SITE" -> "/mingw64/etc/config.site")
|
|
14 |
|
|
15 |
def environment_prefix: String =
|
|
16 |
(for ((a, b) <- environment) yield Bash.string(a) + "=" + Bash.string(b))
|
|
17 |
.mkString("/usr/bin/env ", " ", " ")
|
|
18 |
|
72424
|
19 |
val none: MinGW = new MinGW(None)
|
|
20 |
def root(path: Path) = new MinGW(Some(path))
|
|
21 |
}
|
|
22 |
|
|
23 |
class MinGW private(val root: Option[Path])
|
|
24 |
{
|
|
25 |
override def toString: String =
|
|
26 |
root match {
|
|
27 |
case None => "MinGW.none"
|
|
28 |
case Some(msys_root) => "MinGW.root(" + msys_root.toString + ")"
|
|
29 |
}
|
72421
|
30 |
|
72424
|
31 |
def bash_command(command: String): String =
|
|
32 |
root match {
|
|
33 |
case None => command
|
|
34 |
case Some(msys_root) =>
|
|
35 |
File.bash_path(msys_root + Path.explode("usr/bin/bash")) +
|
|
36 |
" -c " + Bash.string(MinGW.environment_prefix + command)
|
|
37 |
}
|
72421
|
38 |
|
72424
|
39 |
def get_root: Path =
|
|
40 |
if (!Platform.is_windows) error("Windows platform required")
|
|
41 |
else if (root.isEmpty) error("Windows platform needs specification of msys root directory")
|
|
42 |
else root.get
|
72421
|
43 |
|
72424
|
44 |
def check
|
|
45 |
{
|
|
46 |
if (Platform.is_windows) {
|
|
47 |
get_root
|
|
48 |
val result = Isabelle_System.bash(bash_command("uname -s")).check
|
|
49 |
if (!result.out.startsWith("MSYS")) error("Bad msys installation " + get_root)
|
72421
|
50 |
}
|
|
51 |
}
|
|
52 |
}
|