src/Pure/Admin/build_polyml.scala
author wenzelm
Thu, 10 Nov 2016 22:54:46 +0100
changeset 64484 784e28e4dc57
parent 64483 bba1d341bdf6
child 64485 e996c0a5eca9
permissions -rw-r--r--
proper options; simplified command-line; 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
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    10
object Build_PolyML
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    11
{
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    12
  sealed case class Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    13
    options: List[String] = Nil,
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    14
    options_multilib: List[String] = Nil,
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    15
    shell_path: String = "",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    16
    copy_files: List[String] = Nil)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    17
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    18
  private val platform_info = Map(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    19
    "x86-linux" ->
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    20
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    21
        options_multilib =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    22
          List("--build=i386", "CFLAGS=-m32 -O3", "CXXFLAGS=-m32 -O3", "CCASFLAGS=-m32")),
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    23
    "x86_64-linux" -> Platform_Info(),
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    24
    "x86-darwin" ->
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    25
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    26
        options =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    27
          List("--build=i686-darwin", "CFLAGS=-arch i686 -O3 -I../libffi/include",
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    28
            "CXXFLAGS=-arch i686 -O3 -I../libffi/include", "CCASFLAGS=-arch i686 -O3",
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    29
            "LDFLAGS=-segprot POLY rwx rwx")),
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    30
    "x86_64-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=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include",
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    34
            "CXXFLAGS=-arch x86_64 -O3 -I../libffi/include", "CCASFLAGS=-arch x86_64",
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    35
            "LDFLAGS=-segprot POLY rwx rwx")),
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    36
    "x86-windows" ->
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    37
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    38
        options =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    39
          List("--host=i686-w32-mingw32", "CPPFLAGS=-I/mingw32/include", "--disable-windows-gui"),
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    40
        shell_path = "/mingw32/bin",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    41
        copy_files =
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    42
          List("/mingw32/bin/libgcc_s_dw2-1.dll",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    43
            "/mingw32/bin/libgmp-10.dll",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    44
            "/mingw32/bin/libstdc++-6.dll")),
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    45
    "x86_64-windows" ->
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    46
      Platform_Info(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    47
        options =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    48
          List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"),
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    49
        shell_path = "/mingw64/bin",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    50
        copy_files =
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    51
          List("/mingw64/bin/libgcc_s_seh-1.dll",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    52
            "/mingw64/bin/libgmp-10.dll",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    53
            "/mingw64/bin/libstdc++-6.dll")))
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    54
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    55
  lazy val default_platform = Isabelle_System.getenv_strict("ISABELLE_PLATFORM32")
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    56
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    57
  def build_polyml(
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    58
    source: Path,
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    59
    progress: Progress = Ignore_Progress,
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    60
    platform: String = default_platform,
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    61
    options: List[String] = Nil)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    62
  {
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    63
    source.is_dir || error("Bad source directory: " + source)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    64
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    65
    val info =
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    66
      platform_info.get(platform) getOrElse
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    67
        error("Bad platform identifier: " + quote(platform))
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    68
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    69
    val multilib =
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    70
      platform == "x86-linux" && Isabelle_System.getenv("ISABELLE_PLATFORM64") == "x86_64-linux"
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    71
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    72
    val configure_options =
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    73
      (if (multilib) info.options_multilib else info.options) :::
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    74
        List("--enable-intinf-as-int") ::: options
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    75
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    76
    Isabelle_System.bash(cwd = source.file,
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    77
      script =
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    78
        (if (info.shell_path == "") "" else "export PATH=\"" + info.shell_path + ":$PATH\"\n") +
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    79
        """
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    80
          [ -f Makefile ] && make distclean
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    81
          {
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    82
            ./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    83
            rm -rf target
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    84
            make compiler && make compiler && make install
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    85
          } || { echo "Build failed" >&2; exit 2; }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    86
        """,
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    87
      progress_stdout = progress.echo(_),
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    88
      progress_stderr = progress.echo(_)).check
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    89
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    90
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
    91
    val target = Path.explode(platform)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    92
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    93
    if (target.file.exists) {
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    94
      if (target.backup.file.exists) Isabelle_System.rm_tree(target.backup)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    95
      File.move(target, target.backup)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    96
    }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    97
    Isabelle_System.mkdirs(target)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    98
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
    99
    for {
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   100
      d <- List("target/bin", "target/lib")
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   101
      dir = source + Path.explode(d)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   102
      entry <- File.read_dir(dir)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   103
    } File.move(dir + Path.explode(entry), target)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   104
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   105
    for (file <- "~~/Admin/polyml/polyi" :: info.copy_files)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   106
      File.copy(Path.explode(file), target)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   107
  }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   108
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   109
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   110
  /* Isabelle tool wrapper */
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   111
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   112
  val isabelle_tool =
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   113
    Isabelle_Tool("build_polyml", "build Poly/ML from sources", args =>
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   114
    {
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   115
      Command_Line.tool0 {
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   116
        var options = List.empty[String]
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   117
        var platform = default_platform
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   118
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   119
        val getopts = Getopts("""
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   120
Usage: isabelle build_polyml [OPTIONS] [SOURCE]
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   121
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   122
  Options are:
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   123
    -O OPTS...   additional options ./configure (e.g. --with-gmp)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   124
    -p PLATFORM  platform identifier and target directory
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   125
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   126
  Build Poly/ML in SOURCE directory (default: .) for
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   127
  given PLATFORM (default: """ + default_platform + """).
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   128
""",
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   129
          "O:" -> (arg => options = options ::: List(arg)),
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   130
          "p:" -> (arg => platform = arg))
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   131
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   132
        val more_args = getopts(args)
64484
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   133
        val source =
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   134
          more_args match {
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   135
            case Nil => Path.current
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   136
            case List(source) => Path.explode(source)
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   137
            case _ => getopts.usage()
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   138
          }
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   139
        build_polyml(source,
784e28e4dc57 proper options;
wenzelm
parents: 64483
diff changeset
   140
          progress = new Console_Progress, platform = platform, options = options)
64483
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   141
      }
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   142
    }, admin = true)
bba1d341bdf6 build_polyml in Scala;
wenzelm
parents:
diff changeset
   143
}