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