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