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