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