author | wenzelm |
Thu, 10 Nov 2016 23:34:49 +0100 | |
changeset 64485 | e996c0a5eca9 |
parent 64484 | 784e28e4dc57 |
child 64486 | d562e173ee03 |
permissions | -rw-r--r-- |
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, |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
61 |
options: List[String] = Nil, |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
62 |
other_bash: String = "") |
64483 | 63 |
{ |
64 |
source.is_dir || error("Bad source directory: " + source) |
|
65 |
||
66 |
val info = |
|
67 |
platform_info.get(platform) getOrElse |
|
68 |
error("Bad platform identifier: " + quote(platform)) |
|
69 |
||
64484 | 70 |
val multilib = |
71 |
platform == "x86-linux" && Isabelle_System.getenv("ISABELLE_PLATFORM64") == "x86_64-linux" |
|
64483 | 72 |
|
73 |
val configure_options = |
|
64484 | 74 |
(if (multilib) info.options_multilib else info.options) ::: |
75 |
List("--enable-intinf-as-int") ::: options |
|
64483 | 76 |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
77 |
val script = |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
78 |
(if (info.shell_path == "") "" else "export PATH=\"" + info.shell_path + ":$PATH\"\n") + |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
79 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
80 |
[ -f Makefile ] && make distclean |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
81 |
{ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
82 |
./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
83 |
rm -rf target |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
84 |
make compiler && make compiler && make install |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
85 |
} || { echo "Build failed" >&2; exit 2; } |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
86 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
87 |
|
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
88 |
Isabelle_System.bash( |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
89 |
if (other_bash == "") script else Bash.string(other_bash) + " -c " + Bash.string(script), |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
90 |
cwd = source.file, |
64484 | 91 |
progress_stdout = progress.echo(_), |
92 |
progress_stderr = progress.echo(_)).check |
|
93 |
||
94 |
||
95 |
val target = Path.explode(platform) |
|
64483 | 96 |
|
97 |
if (target.file.exists) { |
|
98 |
if (target.backup.file.exists) Isabelle_System.rm_tree(target.backup) |
|
99 |
File.move(target, target.backup) |
|
100 |
} |
|
101 |
Isabelle_System.mkdirs(target) |
|
102 |
||
103 |
for { |
|
64484 | 104 |
d <- List("target/bin", "target/lib") |
105 |
dir = source + Path.explode(d) |
|
64483 | 106 |
entry <- File.read_dir(dir) |
107 |
} File.move(dir + Path.explode(entry), target) |
|
108 |
||
109 |
for (file <- "~~/Admin/polyml/polyi" :: info.copy_files) |
|
110 |
File.copy(Path.explode(file), target) |
|
111 |
} |
|
112 |
||
113 |
||
114 |
/* Isabelle tool wrapper */ |
|
115 |
||
116 |
val isabelle_tool = |
|
117 |
Isabelle_Tool("build_polyml", "build Poly/ML from sources", args => |
|
118 |
{ |
|
119 |
Command_Line.tool0 { |
|
120 |
var options = List.empty[String] |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
121 |
var other_bash = "" |
64483 | 122 |
var platform = default_platform |
123 |
||
124 |
val getopts = Getopts(""" |
|
64484 | 125 |
Usage: isabelle build_polyml [OPTIONS] [SOURCE] |
64483 | 126 |
|
127 |
Options are: |
|
128 |
-O OPTS... additional options ./configure (e.g. --with-gmp) |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
129 |
-b EXE other bash executable (notably for msys on Windows) |
64483 | 130 |
-p PLATFORM platform identifier and target directory |
131 |
||
64484 | 132 |
Build Poly/ML in SOURCE directory (default: .) for |
133 |
given PLATFORM (default: """ + default_platform + """). |
|
64483 | 134 |
""", |
135 |
"O:" -> (arg => options = options ::: List(arg)), |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
136 |
"b:" -> (arg => other_bash = arg), |
64483 | 137 |
"p:" -> (arg => platform = arg)) |
138 |
||
139 |
val more_args = getopts(args) |
|
64484 | 140 |
val source = |
141 |
more_args match { |
|
142 |
case Nil => Path.current |
|
143 |
case List(source) => Path.explode(source) |
|
144 |
case _ => getopts.usage() |
|
145 |
} |
|
146 |
build_polyml(source, |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
147 |
progress = new Console_Progress, platform = platform, options = options, |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
148 |
other_bash = other_bash) |
64483 | 149 |
} |
150 |
}, admin = true) |
|
151 |
} |