| 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 | 
 | 
| 75393 |     10 | object MinGW {
 | 
| 72427 |     11 |   def environment: List[String] =
 | 
|  |     12 |     List("PATH=/usr/bin:/bin:/mingw64/bin", "CONFIG_SITE=/mingw64/etc/config.site")
 | 
| 72421 |     13 | 
 | 
| 72427 |     14 |   def environment_export: String =
 | 
|  |     15 |     environment.map(a => "export " + Bash.string(a)).mkString("", "\n", "\n")
 | 
| 72421 |     16 | 
 | 
| 72424 |     17 |   val none: MinGW = new MinGW(None)
 | 
| 72431 |     18 |   def apply(path: Path) = new MinGW(Some(path))
 | 
| 72424 |     19 | }
 | 
|  |     20 | 
 | 
| 75393 |     21 | class MinGW private(val root: Option[Path]) {
 | 
| 72424 |     22 |   override def toString: String =
 | 
|  |     23 |     root match {
 | 
|  |     24 |       case None => "MinGW.none"
 | 
| 72431 |     25 |       case Some(msys_root) => "MinGW(" + msys_root.toString + ")"
 | 
| 72424 |     26 |     }
 | 
| 72421 |     27 | 
 | 
| 72428 |     28 |   def bash_script(script: String): String =
 | 
| 72424 |     29 |     root match {
 | 
| 72428 |     30 |       case None => script
 | 
| 72424 |     31 |       case Some(msys_root) =>
 | 
|  |     32 |         File.bash_path(msys_root + Path.explode("usr/bin/bash")) +
 | 
| 72428 |     33 |           " -c " + Bash.string(MinGW.environment_export + script)
 | 
| 72424 |     34 |     }
 | 
| 72421 |     35 | 
 | 
| 72424 |     36 |   def get_root: Path =
 | 
|  |     37 |     if (!Platform.is_windows) error("Windows platform required")
 | 
| 72425 |     38 |     else if (root.isEmpty) error("Windows platform requires msys/mingw root specification")
 | 
| 72424 |     39 |     else root.get
 | 
| 72421 |     40 | 
 | 
| 75393 |     41 |   def check: Unit = {
 | 
| 72424 |     42 |     if (Platform.is_windows) {
 | 
|  |     43 |       get_root
 | 
| 72428 |     44 |       try { require(Isabelle_System.bash(bash_script("uname -s")).check.out.startsWith("MSYS")) }
 | 
| 72432 |     45 |       catch { case ERROR(msg) => cat_error("Bad msys/mingw installation " + get_root, msg) }
 | 
| 72421 |     46 |     }
 | 
|  |     47 |   }
 | 
|  |     48 | }
 |