src/Pure/Admin/build_polyml.scala
author wenzelm
Thu, 14 Nov 2019 11:43:46 +0100
changeset 71117 2f6b092bbd25
parent 70977 397533bf0c3f
child 71396 c1c61d0d8e7c
permissions -rw-r--r--
updated MinGW installation: requires Cygwin from Isabelle2018 to avoid problems with address relocation;
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 = "",
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    20
    copy_files: List[String] = Nil,
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    21
    ldd_pattern: Option[(String, Regex)] = None)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    22
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    23
  private val platform_info = Map(
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    24
    "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
    25
      Platform_Info(
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    26
        options = List("LDFLAGS=-Wl,-rpath,_DUMMY_"),
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    27
        ldd_pattern = Some(("ldd", """\s*libgmp.*=>\s*(\S+).*""".r))),
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    28
    "darwin" ->
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    29
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    30
        options =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    31
          List("--build=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include",
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    32
            "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
    33
            "LDFLAGS=-segprot POLY rwx rwx"),
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    34
        setup = "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    35
        ldd_pattern = Some(("otool -L", """\s*(\S+lib(?:polyml|gmp).*dylib).*""".r))),
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    36
    "windows" ->
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    37
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    38
        options =
67597
fe6dc6d8451a more robust options;
wenzelm
parents: 67596
diff changeset
    39
          List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"),
64494
979520c83f30 proper CONFIG_SITE for msys;
wenzelm
parents: 64493
diff changeset
    40
        setup =
979520c83f30 proper CONFIG_SITE for msys;
wenzelm
parents: 64493
diff changeset
    41
          """PATH=/usr/bin:/bin:/mingw64/bin
71117
2f6b092bbd25 updated MinGW installation: requires Cygwin from Isabelle2018 to avoid problems with address relocation;
wenzelm
parents: 70977
diff changeset
    42
            export CONFIG_SITE=/mingw64/etc/config.site""",
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    43
        copy_files =
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    44
          List("$MSYS/mingw64/bin/libgcc_s_seh-1.dll",
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    45
            "$MSYS/mingw64/bin/libgmp-10.dll",
71117
2f6b092bbd25 updated MinGW installation: requires Cygwin from Isabelle2018 to avoid problems with address relocation;
wenzelm
parents: 70977
diff changeset
    46
            "$MSYS/mingw64/bin/libstdc++-6.dll",
2f6b092bbd25 updated MinGW installation: requires Cygwin from Isabelle2018 to avoid problems with address relocation;
wenzelm
parents: 70977
diff changeset
    47
            "$MSYS/mingw64/bin/libwinpthread-1.dll")))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    48
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    49
  def build_polyml(
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    50
    root: Path,
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    51
    sha1_root: Option[Path] = None,
64909
8007f10195af tuned signature;
wenzelm
parents: 64505
diff changeset
    52
    progress: Progress = No_Progress,
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64492
diff changeset
    53
    arch_64: Boolean = false,
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
    54
    options: List[String] = Nil,
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
    55
    msys_root: Option[Path] = None)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    56
  {
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    57
    if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir))
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
    58
      error("Bad Poly/ML root directory: " + root)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    59
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    60
    val platform_arch = if (arch_64) "x86_64" else "x86_64_32"
69726
461f0615faa3 clarified signature;
wenzelm
parents: 69704
diff changeset
    61
    val platform_os = Platform.os_name
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    62
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    63
    val platform = platform_arch + "-" + platform_os
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    64
    val platform_64 = "x86_64-" + platform_os
64493
a2eebcc8bb69 clarified platform selection;
wenzelm
parents: 64492
diff changeset
    65
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    66
    val info =
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    67
      platform_info.get(platform_os) getOrElse
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
    68
        error("Bad OS platform: " + quote(platform_os))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    69
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    70
    val settings =
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    71
      msys_root match {
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    72
        case None if Platform.is_windows =>
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    73
          error("Windows requires specification of msys root directory")
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    74
        case None => Isabelle_System.settings()
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    75
        case Some(msys) => Isabelle_System.settings() + ("MSYS" -> msys.expand.implode)
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    76
      }
64492
98215fa4f8d1 more robust Windows platform;
wenzelm
parents: 64491
diff changeset
    77
70977
397533bf0c3f clarified error;
wenzelm
parents: 69726
diff changeset
    78
    if (Platform.is_linux && !Isabelle_System.bash("chrpath -v").ok) {
397533bf0c3f clarified error;
wenzelm
parents: 69726
diff changeset
    79
      error("""Missing "chrpath" executable on Linux""")
397533bf0c3f clarified error;
wenzelm
parents: 69726
diff changeset
    80
    }
397533bf0c3f clarified error;
wenzelm
parents: 69726
diff changeset
    81
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    82
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    83
    /* bash */
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    84
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    85
    def bash(
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    86
      cwd: Path, script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    87
    {
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    88
      val script1 =
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    89
        msys_root match {
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    90
          case None => script
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    91
          case Some(msys) =>
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    92
            File.bash_path(msys + Path.explode("usr/bin/bash")) + " -c " + Bash.string(script)
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    93
        }
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    94
      progress.bash(script1, cwd = cwd.file, redirect = redirect, echo = echo)
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
    95
    }
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    96
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
    97
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    98
    /* configure and make */
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
    99
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   100
    val configure_options =
67783
839de121665c more robust build: prevent problems seen with Poly/ML eb94e2820013 on Mac OS X;
wenzelm
parents: 67609
diff changeset
   101
      List("--disable-shared", "--enable-intinf-as-int", "--with-gmp") :::
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
   102
        info.options ::: options ::: (if (arch_64) Nil else List("--enable-compact32bit"))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   103
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   104
    bash(root,
64487
b843bcdd40f0 more precise environment (for Windows);
wenzelm
parents: 64486
diff changeset
   105
      info.setup + "\n" +
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   106
      """
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   107
        [ -f Makefile ] && make distclean
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   108
        {
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   109
          ./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   110
          rm -rf target
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   111
          make compiler && make compiler && make install
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   112
        } || { echo "Build failed" >&2; exit 2; }
64501
234571db1b90 tuned output;
wenzelm
parents: 64500
diff changeset
   113
      """, redirect = true, echo = true).check
64485
e996c0a5eca9 support other bash executable (notably for msys on Windows);
wenzelm
parents: 64484
diff changeset
   114
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   115
    val ldd_files =
66998
8905114fd23b support for libgmp on x86_64-darwin;
wenzelm
parents: 65880
diff changeset
   116
    {
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
   117
      info.ldd_pattern match {
66998
8905114fd23b support for libgmp on x86_64-darwin;
wenzelm
parents: 65880
diff changeset
   118
        case Some((ldd, pattern)) =>
8905114fd23b support for libgmp on x86_64-darwin;
wenzelm
parents: 65880
diff changeset
   119
          val lines = bash(root, ldd + " target/bin/poly").check.out_lines
8905114fd23b support for libgmp on x86_64-darwin;
wenzelm
parents: 65880
diff changeset
   120
          for { line <- lines; List(lib) <- pattern.unapplySeq(line) } yield lib
8905114fd23b support for libgmp on x86_64-darwin;
wenzelm
parents: 65880
diff changeset
   121
        case None => Nil
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
   122
      }
66998
8905114fd23b support for libgmp on x86_64-darwin;
wenzelm
parents: 65880
diff changeset
   123
    }
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
   124
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
   125
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   126
    /* sha1 library */
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   127
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   128
    val sha1_files =
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   129
      if (sha1_root.isDefined) {
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   130
        val dir1 = sha1_root.get
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
   131
        bash(dir1, "./build " + platform_64, redirect = true, echo = true).check
64505
545a7ab3c35f optional component setup;
wenzelm
parents: 64504
diff changeset
   132
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
   133
        val dir2 = dir1 + Path.explode(platform_64)
64495
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   134
        File.read_dir(dir2).map(entry => dir2.implode + "/" + entry)
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   135
      }
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   136
      else Nil
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   137
754e1b4634c3 build sha1 library;
wenzelm
parents: 64494
diff changeset
   138
64491
6a1a1bbfcb93 copy libgmp on Linux;
wenzelm
parents: 64490
diff changeset
   139
    /* target */
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   140
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   141
    val target = Path.explode(platform)
64488
bc77e19aad44 no backup of generated stuff;
wenzelm
parents: 64487
diff changeset
   142
    Isabelle_System.rm_tree(target)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   143
    Isabelle_System.mkdirs(target)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   144
67592
66253039d5ca enforce shared libpoly on all platforms, with File.copy before File.move;
wenzelm
parents: 67589
diff changeset
   145
    for (file <- info.copy_files ::: ldd_files ::: sha1_files)
66253039d5ca enforce shared libpoly on all platforms, with File.copy before File.move;
wenzelm
parents: 67589
diff changeset
   146
      File.copy(Path.explode(file).expand_env(settings), target)
66253039d5ca enforce shared libpoly on all platforms, with File.copy before File.move;
wenzelm
parents: 67589
diff changeset
   147
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   148
    for {
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   149
      d <- List("target/bin", "target/lib")
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
   150
      dir = root + Path.explode(d)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   151
      entry <- File.read_dir(dir)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   152
    } File.move(dir + Path.explode(entry), target)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   153
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
   154
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   155
    /* poly: library path */
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
   156
67582
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   157
    if (Platform.is_linux) {
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   158
      bash(target, "chrpath -r '$ORIGIN' poly", echo = true).check
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   159
    }
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   160
    else if (Platform.is_macos) {
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   161
      for (file <- ldd_files) {
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   162
        bash(target,
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   163
          """install_name_tool -change """ + Bash.string(file) + " " +
69366
b6dacf6eabe3 clarified signature;
wenzelm
parents: 69277
diff changeset
   164
            Bash.string("@executable_path/" + Path.explode(file).file_name) + " poly").check
67582
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   165
      }
bf5c69acf2be built-in library path for (optional) libgmp on macos;
wenzelm
parents: 67581
diff changeset
   166
    }
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   167
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   168
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   169
    /* polyc: directory prefix */
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   170
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   171
    {
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   172
      val polyc_path = target + Path.explode("polyc")
67587
wenzelm
parents: 67584
diff changeset
   173
wenzelm
parents: 67584
diff changeset
   174
      val Header = "#! */bin/sh".r
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   175
      val polyc_patched =
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   176
        split_lines(File.read(polyc_path)) match {
67587
wenzelm
parents: 67584
diff changeset
   177
          case Header() :: lines =>
wenzelm
parents: 67584
diff changeset
   178
            val lines1 =
wenzelm
parents: 67584
diff changeset
   179
              lines.map(line =>
wenzelm
parents: 67584
diff changeset
   180
                if (line.startsWith("prefix=")) "prefix=\"$(cd \"$(dirname \"$0\")\"; pwd)\""
wenzelm
parents: 67584
diff changeset
   181
                else if (line.startsWith("BINDIR=")) "BINDIR=\"$prefix\""
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   182
                else if (line.startsWith("LIBDIR=")) "LIBDIR=\"$prefix\""
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   183
                else line)
67587
wenzelm
parents: 67584
diff changeset
   184
            cat_lines("#!/usr/bin/env bash" ::lines1)
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   185
          case lines =>
67587
wenzelm
parents: 67584
diff changeset
   186
            error(cat_lines("Cannot patch polyc -- undetected header:" :: lines.take(3)))
67584
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   187
        }
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   188
      File.write(polyc_path, polyc_patched)
252d33ee6778 patch polyc: avoid hardwired directory prefix;
wenzelm
parents: 67582
diff changeset
   189
    }
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   190
  }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   191
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   192
64496
wenzelm
parents: 64495
diff changeset
   193
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   194
  /** skeleton for component **/
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   195
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   196
  def build_polyml_component(component: Path, sha1_root: Option[Path] = None)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   197
  {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   198
    if (component.is_dir) error("Directory already exists: " + component)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   199
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   200
    val etc = component + Path.explode("etc")
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   201
    Isabelle_System.mkdirs(etc)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   202
    File.copy(Path.explode("~~/Admin/polyml/settings"), etc)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   203
    File.copy(Path.explode("~~/Admin/polyml/README"), component)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   204
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   205
    sha1_root match {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   206
      case Some(dir) =>
67599
544a0293cadc proper target directory;
wenzelm
parents: 67598
diff changeset
   207
        Mercurial.repository(dir).archive(File.standard_path(component + Path.explode("sha1")))
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   208
      case None =>
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   209
    }
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   210
  }
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   211
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   212
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   213
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   214
  /** Isabelle tool wrappers **/
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   215
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   216
  val isabelle_tool1 =
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   217
    Isabelle_Tool("build_polyml", "build Poly/ML from sources", args =>
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   218
    {
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   219
      Command_Line.tool0 {
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
   220
        var msys_root: Option[Path] = None
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   221
        var arch_64 = false
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   222
        var sha1_root: Option[Path] = None
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   223
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   224
        val getopts = Getopts("""
64489
db1bc2732554 clarified command-line;
wenzelm
parents: 64488
diff changeset
   225
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS]
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   226
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   227
  Options are:
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
   228
    -M DIR       msys root directory (for Windows)
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
   229
    -m ARCH      processor architecture (32=x86_64_32, 64=x86_64, default: 32)
69691
9c6651cd6141 clarified URLs: prefer sketis over bitbucket;
wenzelm
parents: 69366
diff changeset
   230
    -s DIR       sha1 sources, see https://isabelle.sketis.net/repos/sha1
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   231
64499
wenzelm
parents: 64496
diff changeset
   232
  Build Poly/ML in the ROOT directory of its sources, with additional
67593
5efb88c90051 clarified command-line defaults;
wenzelm
parents: 67592
diff changeset
   233
  CONFIGURE_OPTIONS (e.g. --without-gmp).
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   234
""",
64504
e4707c2655eb clarified msys root;
wenzelm
parents: 64503
diff changeset
   235
          "M:" -> (arg => msys_root = Some(Path.explode(arg))),
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   236
          "m:" ->
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   237
            {
69704
3fb94d9b87b0 updated polyml platform: 32=x86_64_32;
wenzelm
parents: 69691
diff changeset
   238
              case "32" | "x86_64_32" => arch_64 = false
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   239
              case "64" | "x86_64" => arch_64 = true
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   240
              case bad => error("Bad processor architecture: " + quote(bad))
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   241
            },
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   242
          "s:" -> (arg => sha1_root = Some(Path.explode(arg))))
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   243
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   244
        val more_args = getopts(args)
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   245
        val (root, options) =
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   246
          more_args match {
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   247
            case root :: options => (Path.explode(root), options)
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   248
            case Nil => getopts.usage()
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   249
          }
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   250
        build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress,
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   251
          arch_64 = arch_64, options = options, msys_root = msys_root)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   252
      }
69277
258bef08b31e support for user-defined Isabelle/Scala command-line tools;
wenzelm
parents: 67783
diff changeset
   253
    })
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   254
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   255
  val isabelle_tool2 =
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   256
    Isabelle_Tool("build_polyml_component", "make skeleton for Poly/ML component", args =>
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   257
    {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   258
      Command_Line.tool0 {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   259
        var sha1_root: Option[Path] = None
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   260
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   261
        val getopts = Getopts("""
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   262
Usage: isabelle build_polyml_component [OPTIONS] TARGET
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   263
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   264
  Options are:
69691
9c6651cd6141 clarified URLs: prefer sketis over bitbucket;
wenzelm
parents: 69366
diff changeset
   265
    -s DIR       sha1 sources, see https://isabelle.sketis.net/repos/sha1
65880
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   266
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   267
  Make skeleton for Poly/ML component in directory TARGET.
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   268
""",
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   269
          "s:" -> (arg => sha1_root = Some(Path.explode(arg))))
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   270
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   271
        val more_args = getopts(args)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   272
        val component =
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   273
          more_args match {
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   274
            case List(arg) => Path.explode(arg)
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   275
            case _ => getopts.usage()
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   276
          }
54c6ec4166a4 clarified build_polyml_component;
wenzelm
parents: 64909
diff changeset
   277
        build_polyml_component(component, sha1_root = sha1_root)
64500
159ea1055b39 back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents: 64499
diff changeset
   278
      }
69277
258bef08b31e support for user-defined Isabelle/Scala command-line tools;
wenzelm
parents: 67783
diff changeset
   279
    })
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   280
}