author | wenzelm |
Sat, 12 Nov 2016 12:06:42 +0100 | |
changeset 64502 | 271e98c1fa40 |
parent 64501 | 234571db1b90 |
child 64503 | 365021be3c5b |
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 |
{ |
|
64496 | 12 |
/** build_polyml **/ |
13 |
||
64483 | 14 |
sealed case class Platform_Info( |
15 |
options: List[String] = Nil, |
|
16 |
options_multilib: List[String] = Nil, |
|
64487 | 17 |
setup: String = "", |
64483 | 18 |
copy_files: List[String] = Nil) |
19 |
||
20 |
private val platform_info = Map( |
|
21 |
"x86-linux" -> |
|
22 |
Platform_Info( |
|
23 |
options_multilib = |
|
64484 | 24 |
List("--build=i386", "CFLAGS=-m32 -O3", "CXXFLAGS=-m32 -O3", "CCASFLAGS=-m32")), |
64483 | 25 |
"x86_64-linux" -> Platform_Info(), |
26 |
"x86-darwin" -> |
|
27 |
Platform_Info( |
|
28 |
options = |
|
64484 | 29 |
List("--build=i686-darwin", "CFLAGS=-arch i686 -O3 -I../libffi/include", |
30 |
"CXXFLAGS=-arch i686 -O3 -I../libffi/include", "CCASFLAGS=-arch i686 -O3", |
|
31 |
"LDFLAGS=-segprot POLY rwx rwx")), |
|
64483 | 32 |
"x86_64-darwin" -> |
33 |
Platform_Info( |
|
34 |
options = |
|
64484 | 35 |
List("--build=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include", |
36 |
"CXXFLAGS=-arch x86_64 -O3 -I../libffi/include", "CCASFLAGS=-arch x86_64", |
|
37 |
"LDFLAGS=-segprot POLY rwx rwx")), |
|
64483 | 38 |
"x86-windows" -> |
39 |
Platform_Info( |
|
40 |
options = |
|
64484 | 41 |
List("--host=i686-w32-mingw32", "CPPFLAGS=-I/mingw32/include", "--disable-windows-gui"), |
64494 | 42 |
setup = |
43 |
"""PATH=/usr/bin:/bin:/mingw32/bin |
|
44 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 45 |
copy_files = |
46 |
List("/mingw32/bin/libgcc_s_dw2-1.dll", |
|
47 |
"/mingw32/bin/libgmp-10.dll", |
|
48 |
"/mingw32/bin/libstdc++-6.dll")), |
|
49 |
"x86_64-windows" -> |
|
50 |
Platform_Info( |
|
51 |
options = |
|
64484 | 52 |
List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"), |
64494 | 53 |
setup = |
54 |
"""PATH=/usr/bin:/bin:/mingw64/bin |
|
55 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 56 |
copy_files = |
57 |
List("/mingw64/bin/libgcc_s_seh-1.dll", |
|
58 |
"/mingw64/bin/libgmp-10.dll", |
|
59 |
"/mingw64/bin/libstdc++-6.dll"))) |
|
60 |
||
61 |
def build_polyml( |
|
64489 | 62 |
root: Path, |
64495 | 63 |
sha1_root: Option[Path] = None, |
64483 | 64 |
progress: Progress = Ignore_Progress, |
64493 | 65 |
arch_64: Boolean = false, |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
66 |
options: List[String] = Nil, |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
67 |
other_bash: String = "") |
64483 | 68 |
{ |
64489 | 69 |
if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir)) |
70 |
error("Bad Poly/ML root directory: " + root) |
|
64483 | 71 |
|
64493 | 72 |
val platform = |
73 |
(if (arch_64) "x86_64" else "x86") + |
|
74 |
(if (Platform.is_windows) "-windows" else if (Platform.is_macos) "-darwin" else "-linux") |
|
75 |
||
64483 | 76 |
val info = |
77 |
platform_info.get(platform) getOrElse |
|
78 |
error("Bad platform identifier: " + quote(platform)) |
|
79 |
||
64493 | 80 |
if (Platform.is_windows && other_bash == "") |
64492 | 81 |
error("Windows requires other bash (for msys)") |
82 |
||
64491 | 83 |
|
64495 | 84 |
/* bash */ |
85 |
||
64501 | 86 |
def bash(cwd: Path, script: String, redirect: Boolean = false, echo: Boolean = false) |
87 |
: Process_Result = |
|
64495 | 88 |
progress.bash( |
89 |
if (other_bash == "") script else Bash.string(other_bash) + " -c " + Bash.string(script), |
|
64501 | 90 |
cwd = cwd.file, redirect = redirect, echo = echo) |
64495 | 91 |
|
92 |
||
64491 | 93 |
/* configure and make */ |
94 |
||
64483 | 95 |
val configure_options = |
64493 | 96 |
(if (!arch_64 && Isabelle_System.getenv("ISABELLE_PLATFORM64") == "x86_64-linux") |
97 |
info.options_multilib |
|
98 |
else info.options) ::: List("--enable-intinf-as-int") ::: options |
|
64483 | 99 |
|
64495 | 100 |
bash(root, |
64487 | 101 |
info.setup + "\n" + |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
102 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
103 |
[ -f Makefile ] && make distclean |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
104 |
{ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
105 |
./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
106 |
rm -rf target |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
107 |
make compiler && make compiler && make install |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
108 |
} || { echo "Build failed" >&2; exit 2; } |
64501 | 109 |
""", redirect = true, echo = true).check |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
110 |
|
64495 | 111 |
val ldd_files = |
64493 | 112 |
if (Platform.is_linux) { |
64495 | 113 |
val libs = bash(root, "ldd target/bin/poly").check.out_lines |
64491 | 114 |
val Pattern = """\s*libgmp.*=>\s*(\S+).*""".r |
115 |
for (Pattern(lib) <- libs) yield lib |
|
116 |
} |
|
117 |
else Nil |
|
118 |
||
119 |
||
64495 | 120 |
/* sha1 library */ |
121 |
||
122 |
val sha1_files = |
|
123 |
if (sha1_root.isDefined) { |
|
124 |
val dir1 = sha1_root.get |
|
64501 | 125 |
bash(dir1, "./build " + platform, redirect = true, echo = true).check |
64495 | 126 |
val dir2 = dir1 + Path.explode(platform) |
127 |
File.read_dir(dir2).map(entry => dir2.implode + "/" + entry) |
|
128 |
} |
|
129 |
else Nil |
|
130 |
||
131 |
||
64491 | 132 |
/* target */ |
64484 | 133 |
|
134 |
val target = Path.explode(platform) |
|
64488 | 135 |
Isabelle_System.rm_tree(target) |
64483 | 136 |
Isabelle_System.mkdirs(target) |
137 |
||
138 |
for { |
|
64484 | 139 |
d <- List("target/bin", "target/lib") |
64489 | 140 |
dir = root + Path.explode(d) |
64483 | 141 |
entry <- File.read_dir(dir) |
142 |
} File.move(dir + Path.explode(entry), target) |
|
143 |
||
64495 | 144 |
for (file <- "~~/Admin/polyml/polyi" :: info.copy_files ::: ldd_files ::: sha1_files) |
64483 | 145 |
File.copy(Path.explode(file), target) |
146 |
} |
|
147 |
||
148 |
||
64496 | 149 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
150 |
/** Isabelle tool wrapper **/ |
64483 | 151 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
152 |
val isabelle_tool = Isabelle_Tool("build_polyml", "build Poly/ML from sources", args => |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
153 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
154 |
Command_Line.tool0 { |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
155 |
var other_bash = "" |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
156 |
var arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
157 |
var sha1_root: Option[Path] = None |
64483 | 158 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
159 |
val getopts = Getopts(""" |
64489 | 160 |
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS] |
64483 | 161 |
|
162 |
Options are: |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
163 |
-b EXE other bash executable (notably for msys on Windows) |
64493 | 164 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64499 | 165 |
-s DIR sha1 sources, see https://bitbucket.org/isabelle_project/sha1 |
64483 | 166 |
|
64499 | 167 |
Build Poly/ML in the ROOT directory of its sources, with additional |
64489 | 168 |
CONFIGURE_OPTIONS (e.g. --with-gmp). |
64483 | 169 |
""", |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
170 |
"b:" -> (arg => other_bash = arg), |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
171 |
"m:" -> |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
172 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
173 |
case "32" | "x86" => arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
174 |
case "64" | "x86_64" => arch_64 = true |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
175 |
case bad => error("Bad processor architecture: " + quote(bad)) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
176 |
}, |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
177 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
64483 | 178 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
179 |
val more_args = getopts(args) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
180 |
val (root, options) = |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
181 |
more_args match { |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
182 |
case root :: options => (Path.explode(root), options) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
183 |
case Nil => getopts.usage() |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
184 |
} |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
185 |
build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress, |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
186 |
arch_64 = arch_64, options = options, other_bash = other_bash) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
187 |
} |
64502 | 188 |
}, admin = true) |
64483 | 189 |
} |