src/Pure/Admin/build_polyml.scala
author wenzelm
Wed, 14 Oct 2020 21:42:54 +0200
changeset 72474 0a868098fcc0
parent 72469 96f56191aaea
child 72763 3cc73d00553c
permissions -rw-r--r--
tuned;
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
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    13
object Build_PolyML
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    14
{
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
    15
  /** platform-specific build **/
64496
wenzelm
parents: 64495
diff changeset
    16
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    17
  sealed case class Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    18
    options: List[String] = Nil,
64487
b843bcdd40f0 more precise environment (for Windows);
wenzelm
parents: 64486
diff changeset
    19
    setup: String = "",
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
    20
    libs: Set[String] = Set.empty)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    21
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    22
  private val platform_info = Map(
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    23
    "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
    24
      Platform_Info(
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    25
        options = List("LDFLAGS=-Wl,-rpath,_DUMMY_"),
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
    26
        libs = Set("libgmp")),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    27
    "darwin" ->
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    28
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    29
        options =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    30
          List("--build=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include",
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    31
            "CXXFLAGS=-arch x86_64 -O3 -I../libffi/include", "CCASFLAGS=-arch x86_64",
67600
d515b6140381 no --enable-shared for x86_64-darwin: does not work on some test machine;
wenzelm
parents: 67599
diff changeset
    32
            "LDFLAGS=-segprot POLY rwx rwx"),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    33
        setup = "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
    34
        libs = Set("libpolyml", "libgmp")),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    35
    "windows" ->
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    36
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    37
        options =
67597
fe6dc6d8451a more robust options;
wenzelm
parents: 67596
diff changeset
    38
          List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"),
72427
def95a34df8e clarified signature;
wenzelm
parents: 72378
diff changeset
    39
        setup = MinGW.environment_export,
72468
60471f4bafd2 proper library names on Windows;
wenzelm
parents: 72462
diff changeset
    40
        libs = Set("libgcc_s_seh", "libgmp", "libstdc++", "libwinpthread")))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    41
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    42
  def build_polyml(
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    43
    root: Path,
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    44
    sha1_root: Option[Path] = None,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71686
diff changeset
    45
    progress: Progress = new Progress,
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64492
diff changeset
    46
    arch_64: Boolean = false,
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    47
    options: List[String] = Nil,
72429
7924c7d2d9d9 more explicit MinGW context;
wenzelm
parents: 72427
diff changeset
    48
    mingw: MinGW = MinGW.none)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    49
  {
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    50
    if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir))
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    51
      error("Bad Poly/ML root directory: " + root)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    52
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    53
    val platform = Isabelle_Platform.self
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    54
    val platform_arch =
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    55
      if (arch_64) platform.arch_64
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    56
      else if (platform.is_intel) "x86_64_32"
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    57
      else platform.arch_32
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    58
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    59
    val polyml_platform = platform_arch + "-" + platform.os_name
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    60
    val sha1_platform = platform.arch_64 + "-" + platform.os_name
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64492
diff changeset
    61
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    62
    val info =
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    63
      platform_info.getOrElse(platform.os_name,
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
    64
        error("Bad OS platform: " + quote(platform.os_name)))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    65
72455
7bf67a58f54a clarified signature;
wenzelm
parents: 72431
diff changeset
    66
    if (platform.is_linux) Isabelle_System.require_command("chrpath")
70977
397533bf0c3f clarified error;
wenzelm
parents: 69726
diff changeset
    67
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    68
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    69
    /* bash */
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    70
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    71
    def bash(
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    72
      cwd: Path, script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    73
    {
72429
7924c7d2d9d9 more explicit MinGW context;
wenzelm
parents: 72427
diff changeset
    74
      progress.bash(mingw.bash_script(script), 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
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    91
          make compiler && make compiler && make install
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
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   115
    for (file <- sha1_files) File.copy(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)
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   121
    } File.move(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
72462
7c552a256ca5 misc tuning and clarification: prefer Executable.libraries_closure;
wenzelm
parents: 72455
diff changeset
   130
    File.change(platform_dir + Path.explode("polyc"), txt =>
72378
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   131
      split_lines(txt) match {
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   132
        case Header() :: lines =>
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   133
          val lines1 =
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   134
            lines.map(line =>
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   135
              if (line.startsWith("prefix=")) "prefix=\"$(cd \"$(dirname \"$0\")\"; pwd)\""
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   136
              else if (line.startsWith("BINDIR=")) "BINDIR=\"$prefix\""
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   137
              else if (line.startsWith("LIBDIR=")) "LIBDIR=\"$prefix\""
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   138
              else line)
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   139
          cat_lines("#!/usr/bin/env bash" ::lines1)
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   140
        case lines =>
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   141
          error(cat_lines("Cannot patch polyc -- undetected header:" :: lines.take(3)))
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   142
      }
075f3cbc7546 clarified signature;
wenzelm
parents: 72377
diff changeset
   143
    )
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   144
  }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   145
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   146
64496
wenzelm
parents: 64495
diff changeset
   147
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   148
  /** skeleton for component **/
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   149
72474
wenzelm
parents: 72469
diff changeset
   150
  private def extract_sources(source_archive: Path, component_dir: Path)
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   151
  {
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   152
    if (source_archive.get_ext == "zip") {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   153
      Isabelle_System.bash(
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   154
        "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
   155
    }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   156
    else {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   157
      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
   158
    }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   159
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   160
    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
   161
    File.read_dir(component_dir) match {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   162
      case List(s) => File.move(component_dir + Path.basic(s), src_dir)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   163
      case _ => error("Source archive contains multiple directories")
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   164
    }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   165
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   166
    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
   167
    val ml_files =
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   168
      for {
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   169
        line <- lines
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   170
        rest <- Library.try_unprefix("use", line)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   171
      } yield "ML_file" + rest
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   172
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   173
    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
   174
"""(* Poly/ML Compiler root file.
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   175
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   176
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
   177
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
   178
not affect the running ML session. *)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   179
""" + ml_files.mkString("\n", "\n", "\n"))
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   180
  }
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   181
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   182
  def build_polyml_component(
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   183
    source_archive: Path,
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   184
    component_dir: Path,
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   185
    sha1_root: Option[Path] = None)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   186
  {
72377
c7741f767e3e clarified signature;
wenzelm
parents: 72376
diff changeset
   187
    Isabelle_System.new_directory(component_dir)
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   188
    extract_sources(source_archive, component_dir)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   189
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   190
    File.copy(Path.explode("~~/Admin/polyml/README"), component_dir)
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   191
72376
04bce3478688 clarified signature;
wenzelm
parents: 72375
diff changeset
   192
    val etc_dir = Isabelle_System.make_directory(component_dir + Path.explode("etc"))
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   193
    File.copy(Path.explode("~~/Admin/polyml/settings"), etc_dir)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   194
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   195
    sha1_root match {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   196
      case Some(dir) =>
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   197
        Mercurial.repository(dir).archive(File.standard_path(component_dir + Path.explode("sha1")))
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   198
      case None =>
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
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   202
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   203
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   204
  /** Isabelle tool wrappers **/
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   205
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   206
  val isabelle_tool1 =
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   207
    Isabelle_Tool("build_polyml", "build Poly/ML from sources", args =>
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   208
    {
72429
7924c7d2d9d9 more explicit MinGW context;
wenzelm
parents: 72427
diff changeset
   209
      var mingw = MinGW.none
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   210
      var arch_64 = Isabelle_Platform.self.is_arm
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   211
      var sha1_root: Option[Path] = None
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   212
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   213
      val getopts = Getopts("""
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
   214
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS]
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   215
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   216
  Options are:
72429
7924c7d2d9d9 more explicit MinGW context;
wenzelm
parents: 72427
diff changeset
   217
    -M DIR       msys/mingw root specification for Windows
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   218
    -m ARCH      processor architecture (32 or 64, default: """ +
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   219
        (if (arch_64) "64" else "32") + """)
69691
9c6651cd6141 clarified URLs: prefer sketis over bitbucket;
wenzelm
parents: 69366
diff changeset
   220
    -s DIR       sha1 sources, see https://isabelle.sketis.net/repos/sha1
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   221
64499
wenzelm
parents: 64496
diff changeset
   222
  Build Poly/ML in the ROOT directory of its sources, with additional
67593
5efb88c90051 clarified command-line defaults;
wenzelm
parents: 67592
diff changeset
   223
  CONFIGURE_OPTIONS (e.g. --without-gmp).
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   224
""",
72431
b8b97c49e339 tuned signature;
wenzelm
parents: 72429
diff changeset
   225
        "M:" -> (arg => mingw = MinGW(Path.explode(arg))),
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   226
        "m:" ->
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   227
          {
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   228
            case "32" => arch_64 = false
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72351
diff changeset
   229
            case "64" => arch_64 = true
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   230
            case bad => error("Bad processor architecture: " + quote(bad))
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   231
          },
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   232
        "s:" -> (arg => sha1_root = Some(Path.explode(arg))))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   233
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   234
      val more_args = getopts(args)
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   235
      val (root, options) =
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   236
        more_args match {
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   237
          case root :: options => (Path.explode(root), options)
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   238
          case Nil => getopts.usage()
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   239
        }
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   240
      build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress,
72429
7924c7d2d9d9 more explicit MinGW context;
wenzelm
parents: 72427
diff changeset
   241
        arch_64 = arch_64, options = options, mingw = mingw)
69277
258bef08b31e support for user-defined Isabelle/Scala command-line tools;
wenzelm
parents: 67783
diff changeset
   242
    })
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   243
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   244
  val isabelle_tool2 =
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   245
    Isabelle_Tool("build_polyml_component", "make skeleton for Poly/ML component", args =>
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   246
    {
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   247
      var sha1_root: Option[Path] = None
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   248
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   249
      val getopts = Getopts("""
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   250
Usage: isabelle build_polyml_component [OPTIONS] SOURCE_ARCHIVE COMPONENT_DIR
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   251
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   252
  Options are:
69691
9c6651cd6141 clarified URLs: prefer sketis over bitbucket;
wenzelm
parents: 69366
diff changeset
   253
    -s DIR       sha1 sources, see https://isabelle.sketis.net/repos/sha1
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   254
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   255
  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
   256
  (zip or tar.gz).
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   257
""",
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   258
        "s:" -> (arg => sha1_root = Some(Path.explode(arg))))
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   259
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   260
      val more_args = getopts(args)
71396
c1c61d0d8e7c clarified build_polyml_component: include IDE entry point for ML compiler;
wenzelm
parents: 71117
diff changeset
   261
71686
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   262
      val (source_archive, component_dir) =
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   263
        more_args match {
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   264
          case List(archive, dir) => (Path.explode(archive), Path.explode(dir))
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   265
          case _ => getopts.usage()
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   266
        }
eb44cf7ae926 tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents: 71632
diff changeset
   267
      build_polyml_component(source_archive, component_dir, sha1_root = sha1_root)
69277
258bef08b31e support for user-defined Isabelle/Scala command-line tools;
wenzelm
parents: 67783
diff changeset
   268
    })
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   269
}