src/Pure/Admin/build_polyml.scala
author wenzelm
Fri, 02 Sep 2022 23:19:02 +0200
changeset 76041 4a1330addb4e
parent 75394 42267c650205
child 76518 b30b8e23383c
permissions -rw-r--r--
proper description;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/build_polyml.scala
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     3
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     4
Build Poly/ML from sources.
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     5
*/
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     6
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     7
package isabelle
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     8
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
     9
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    10
import scala.util.matching.Regex
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    11
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    12
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
    13
object Build_PolyML {
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
    14
  /** platform-specific build **/
64496
wenzelm
parents: 64495
diff changeset
    15
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    16
  sealed case class Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    17
    options: List[String] = Nil,
64487
b843bcdd40f0 more precise environment (for Windows);
wenzelm
parents: 64486
diff changeset
    18
    setup: String = "",
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
    19
    libs: Set[String] = Set.empty)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    20
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    21
  private val platform_info = Map(
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    22
    "linux" ->
67580
eb64467e8bcf more robust access to shared libraries for poly executable: avoid global change of LD_LIBRARY_PATH (e.g. relevant for subprocesses);
wenzelm
parents: 66998
diff changeset
    23
      Platform_Info(
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    24
        options = List("LDFLAGS=-Wl,-rpath,_DUMMY_"),
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
    25
        libs = Set("libgmp")),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    26
    "darwin" ->
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    27
      Platform_Info(
73666
4d0df84a5b88 clarified options: implicitly support both x86_64 and arm64;
wenzelm
parents: 73340
diff changeset
    28
        options = List("CFLAGS=-O3", "CXXFLAGS=-O3", "LDFLAGS=-segprot POLY rwx rwx"),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    29
        setup = "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
    30
        libs = Set("libpolyml", "libgmp")),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    31
    "windows" ->
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    32
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    33
        options =
67597
fe6dc6d8451a more robust options;
wenzelm
parents: 67596
diff changeset
    34
          List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"),
72427
def95a34df8e clarified signature;
wenzelm
parents: 72378
diff changeset
    35
        setup = MinGW.environment_export,
72468
60471f4bafd2 proper library names on Windows;
wenzelm
parents: 72462
diff changeset
    36
        libs = Set("libgcc_s_seh", "libgmp", "libstdc++", "libwinpthread")))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    37
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    38
  def build_polyml(
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    39
    root: Path,
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    40
    sha1_root: Option[Path] = None,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71686
diff changeset
    41
    progress: Progress = new Progress,
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64492
diff changeset
    42
    arch_64: Boolean = false,
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    43
    options: List[String] = Nil,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
    44
    mingw: MinGW = MinGW.none
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
    45
  ): Unit = {
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    46
    if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir))
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    47
      error("Bad Poly/ML root directory: " + root)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    48
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    49
    val platform = Isabelle_Platform.self
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    50
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 73666
diff changeset
    51
    val polyml_platform =
442460fba2a4 clarified platforms;
wenzelm
parents: 73666
diff changeset
    52
      (if (arch_64) platform.arch_64 else platform.arch_64_32) + "-" + platform.os_name
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    53
    val sha1_platform = platform.arch_64 + "-" + platform.os_name
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64492
diff changeset
    54
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    55
    val info =
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    56
      platform_info.getOrElse(platform.os_name,
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    57
        error("Bad OS platform: " + quote(platform.os_name)))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    58
72455
7bf67a58f54a clarified signature;
wenzelm
parents: 72431
diff changeset
    59
    if (platform.is_linux) Isabelle_System.require_command("chrpath")
70977
397533bf0c3f clarified error;
wenzelm
parents: 69726
diff changeset
    60
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    61
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    62
    /* bash */
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    63
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    64
    def bash(
73672
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    65
      cwd: Path, script: String,
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    66
      redirect: Boolean = false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
    67
      echo: Boolean = false
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
    68
    ): Process_Result = {
73672
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    69
      val script1 =
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    70
        if (platform.is_arm && platform.is_macos) {
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    71
          "arch -arch arm64 bash -c " + Bash.string(script)
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    72
        }
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    73
        else mingw.bash_script(script)
70d3c7009a65 proper support for macOS/Rosetta: let "uname -m" report arm64 instead of x86_64;
wenzelm
parents: 73667
diff changeset
    74
      progress.bash(script1, cwd = cwd.file, redirect = redirect, echo = echo)
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    75
    }
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    76
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    77
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    78
    /* configure and make */
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    79
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    80
    val configure_options =
67783
839de121665c more robust build: prevent problems seen with Poly/ML eb94e2820013 on Mac OS X;
wenzelm
parents: 67609
diff changeset
    81
      List("--disable-shared", "--enable-intinf-as-int", "--with-gmp") :::
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    82
        info.options ::: options ::: (if (arch_64) Nil else List("--enable-compact32bit"))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    83
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    84
    bash(root,
64487
b843bcdd40f0 more precise environment (for Windows);
wenzelm
parents: 64486
diff changeset
    85
      info.setup + "\n" +
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    86
      """
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    87
        [ -f Makefile ] && make distclean
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    88
        {
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    89
          ./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    90
          rm -rf target
74635
b179891dd357 updated for pre-5.9 testing;
wenzelm
parents: 73672
diff changeset
    91
          make && make install
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    92
        } || { echo "Build failed" >&2; exit 2; }
64501
234571db1b90 tuned output;
wenzelm
parents: 64500
diff changeset
    93
      """, redirect = true, echo = true).check
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    94
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    95
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    96
    /* sha1 library */
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    97
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    98
    val sha1_files =
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    99
      if (sha1_root.isDefined) {
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   100
        val dir1 = sha1_root.get
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   101
        bash(dir1, "./build " + sha1_platform, redirect = true, echo = true).check
64505
545a7ab3c35f optional component setup;
wenzelm
parents: 64504
diff changeset
   102
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   103
        val dir2 = dir1 + Path.explode(sha1_platform)
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   104
        File.read_dir(dir2).map(entry => dir2 + Path.basic(entry))
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   105
      }
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   106
      else Nil
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   107
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   108
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   109
    /* install */
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   110
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   111
    val platform_dir = Path.explode(polyml_platform)
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   112
    Isabelle_System.rm_tree(platform_dir)
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   113
    Isabelle_System.make_directory(platform_dir)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   114
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 72763
diff changeset
   115
    for (file <- sha1_files) Isabelle_System.copy_file(file, platform_dir)
67592
66253039d5ca enforce shared libpoly on all platforms, with File.copy before File.move;
wenzelm
parents: 67589
diff changeset
   116
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   117
    for {
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   118
      d <- List("target/bin", "target/lib")
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
   119
      dir = root + Path.explode(d)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   120
      entry <- File.read_dir(dir)
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 72763
diff changeset
   121
    } Isabelle_System.move_file(dir + Path.explode(entry), platform_dir)
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   122
72469
96f56191aaea proper target directory for libraries;
wenzelm
parents: 72468
diff changeset
   123
    Executable.libraries_closure(
96f56191aaea proper target directory for libraries;
wenzelm
parents: 72468
diff changeset
   124
      platform_dir + Path.basic("poly").platform_exe, mingw = mingw, filter = info.libs)
96f56191aaea proper target directory for libraries;
wenzelm
parents: 72468
diff changeset
   125
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   126
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   127
    /* polyc: directory prefix */
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   128
72378
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   129
    val Header = "#! */bin/sh".r
75205
wenzelm
parents: 75202
diff changeset
   130
    File.change_lines(platform_dir + Path.explode("polyc")) {
wenzelm
parents: 75202
diff changeset
   131
      case Header() :: lines =>
wenzelm
parents: 75202
diff changeset
   132
        val lines1 =
wenzelm
parents: 75202
diff changeset
   133
          lines.map(line =>
wenzelm
parents: 75202
diff changeset
   134
            if (line.startsWith("prefix=")) "prefix=\"$(cd \"$(dirname \"$0\")\"; pwd)\""
wenzelm
parents: 75202
diff changeset
   135
            else if (line.startsWith("BINDIR=")) "BINDIR=\"$prefix\""
wenzelm
parents: 75202
diff changeset
   136
            else if (line.startsWith("LIBDIR=")) "LIBDIR=\"$prefix\""
wenzelm
parents: 75202
diff changeset
   137
            else line)
wenzelm
parents: 75202
diff changeset
   138
        "#!/usr/bin/env bash" :: lines1
wenzelm
parents: 75202
diff changeset
   139
      case lines =>
wenzelm
parents: 75202
diff changeset
   140
        error(cat_lines("Cannot patch polyc -- undetected header:" :: lines.take(3)))
75202
4fdde010086f clarified signature;
wenzelm
parents: 74635
diff changeset
   141
    }
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   142
  }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   143
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   144
64496
wenzelm
parents: 64495
diff changeset
   145
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   146
  /** skeleton for component **/
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   147
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
   148
  private def extract_sources(source_archive: Path, component_dir: Path): Unit = {
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   149
    if (source_archive.get_ext == "zip") {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   150
      Isabelle_System.bash(
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   151
        "unzip -x " + File.bash_path(source_archive.absolute), cwd = component_dir.file).check
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   152
    }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   153
    else {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   154
      Isabelle_System.gnutar("-xzf " + File.bash_path(source_archive), dir = component_dir).check
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   155
    }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   156
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   157
    val src_dir = component_dir + Path.explode("src")
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   158
    File.read_dir(component_dir) match {
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 72763
diff changeset
   159
      case List(s) => Isabelle_System.move_file(component_dir + Path.basic(s), src_dir)
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   160
      case _ => error("Source archive contains multiple directories")
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   161
    }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   162
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   163
    val lines = split_lines(File.read(src_dir + Path.explode("RootX86.ML")))
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   164
    val ml_files =
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   165
      for {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   166
        line <- lines
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   167
        rest <- Library.try_unprefix("use", line)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   168
      } yield "ML_file" + rest
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   169
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   170
    File.write(src_dir + Path.explode("ROOT.ML"),
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   171
"""(* Poly/ML Compiler root file.
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   172
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   173
When this file is open in the Prover IDE, the ML files of the Poly/ML
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   174
compiler can be explored interactively. This is a separate copy: it does
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   175
not affect the running ML session. *)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   176
""" + ml_files.mkString("\n", "\n", "\n"))
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   177
  }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   178
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   179
  def build_polyml_component(
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   180
    source_archive: Path,
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   181
    component_dir: Path,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
   182
    sha1_root: Option[Path] = None
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75205
diff changeset
   183
  ): Unit = {
72377
c7741f767e3e clarified signature;
wenzelm
parents: 72376
diff changeset
   184
    Isabelle_System.new_directory(component_dir)
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   185
    extract_sources(source_archive, component_dir)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   186
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 72763
diff changeset
   187
    Isabelle_System.copy_file(Path.explode("~~/Admin/polyml/README"), component_dir)
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   188
72376
04bce3478688 clarified signature;
wenzelm
parents: 72375
diff changeset
   189
    val etc_dir = Isabelle_System.make_directory(component_dir + Path.explode("etc"))
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 72763
diff changeset
   190
    Isabelle_System.copy_file(Path.explode("~~/Admin/polyml/settings"), etc_dir)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   191
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   192
    sha1_root match {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   193
      case Some(dir) =>
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   194
        Mercurial.repository(dir).archive(File.standard_path(component_dir + Path.explode("sha1")))
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   195
      case None =>
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   196
    }
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   197
  }
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   198
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   199
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   200
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   201
  /** Isabelle tool wrappers **/
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   202
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   203
  val isabelle_tool1 =
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   204
    Isabelle_Tool("build_polyml", "build Poly/ML from sources", Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   205
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   206
        var mingw = MinGW.none
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   207
        var arch_64 = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   208
        var sha1_root: Option[Path] = None
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   209
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   210
        val getopts = Getopts("""
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
   211
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS]
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   212
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   213
  Options are:
72429
7924c7d2d9d9 more explicit MinGW context;
wenzelm
parents: 72427
diff changeset
   214
    -M DIR       msys/mingw root specification for Windows
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   215
    -m ARCH      processor architecture (32 or 64, default: """ +
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   216
        (if (arch_64) "64" else "32") + """)
69691
9c6651cd6141 clarified URLs: prefer sketis over bitbucket;
wenzelm
parents: 69366
diff changeset
   217
    -s DIR       sha1 sources, see https://isabelle.sketis.net/repos/sha1
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   218
64499
wenzelm
parents: 64496
diff changeset
   219
  Build Poly/ML in the ROOT directory of its sources, with additional
67593
5efb88c90051 clarified command-line defaults;
wenzelm
parents: 67592
diff changeset
   220
  CONFIGURE_OPTIONS (e.g. --without-gmp).
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   221
""",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   222
          "M:" -> (arg => mingw = MinGW(Path.explode(arg))),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   223
          "m:" ->
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   224
            {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   225
              case "32" => arch_64 = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   226
              case "64" => arch_64 = true
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   227
              case bad => error("Bad processor architecture: " + quote(bad))
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   228
            },
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   229
          "s:" -> (arg => sha1_root = Some(Path.explode(arg))))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   230
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   231
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   232
        val (root, options) =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   233
          more_args match {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   234
            case root :: options => (Path.explode(root), options)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   235
            case Nil => getopts.usage()
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   236
          }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   237
        build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   238
          arch_64 = arch_64, options = options, mingw = mingw)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   239
      })
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   240
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   241
  val isabelle_tool2 =
72763
3cc73d00553c added document antiquotation @{tool};
wenzelm
parents: 72474
diff changeset
   242
    Isabelle_Tool("build_polyml_component", "make skeleton for Poly/ML component",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   243
      Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   244
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   245
        var sha1_root: Option[Path] = None
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   246
  
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   247
        val getopts = Getopts("""
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   248
Usage: isabelle build_polyml_component [OPTIONS] SOURCE_ARCHIVE COMPONENT_DIR
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   249
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   250
  Options are:
69691
9c6651cd6141 clarified URLs: prefer sketis over bitbucket;
wenzelm
parents: 69366
diff changeset
   251
    -s DIR       sha1 sources, see https://isabelle.sketis.net/repos/sha1
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   252
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   253
  Make skeleton for Poly/ML component, based on official source archive
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   254
  (zip or tar.gz).
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   255
""",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   256
          "s:" -> (arg => sha1_root = Some(Path.explode(arg))))
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   257
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   258
        val more_args = getopts(args)
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   259
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   260
        val (source_archive, component_dir) =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   261
          more_args match {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   262
            case List(archive, dir) => (Path.explode(archive), Path.explode(dir))
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   263
            case _ => getopts.usage()
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   264
          }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   265
        build_polyml_component(source_archive, component_dir, sha1_root = sha1_root)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   266
      })
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   267
}