author | wenzelm |
Wed, 23 Jan 2019 20:45:03 +0100 | |
changeset 69726 | 461f0615faa3 |
parent 69704 | 3fb94d9b87b0 |
child 70977 | 397533bf0c3f |
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 |
||
69704 | 10 |
import scala.util.matching.Regex |
11 |
||
12 |
||
64483 | 13 |
object Build_PolyML |
14 |
{ |
|
65880 | 15 |
/** platform-specific build **/ |
64496 | 16 |
|
64483 | 17 |
sealed case class Platform_Info( |
18 |
options: List[String] = Nil, |
|
64487 | 19 |
setup: String = "", |
69704 | 20 |
copy_files: List[String] = Nil, |
21 |
ldd_pattern: Option[(String, Regex)] = None) |
|
64483 | 22 |
|
23 |
private val platform_info = Map( |
|
69704 | 24 |
"linux" -> |
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
|
25 |
Platform_Info( |
69704 | 26 |
options = List("LDFLAGS=-Wl,-rpath,_DUMMY_"), |
27 |
ldd_pattern = Some(("ldd", """\s*libgmp.*=>\s*(\S+).*""".r))), |
|
28 |
"darwin" -> |
|
64483 | 29 |
Platform_Info( |
30 |
options = |
|
64484 | 31 |
List("--build=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include", |
32 |
"CXXFLAGS=-arch x86_64 -O3 -I../libffi/include", "CCASFLAGS=-arch x86_64", |
|
67600
d515b6140381
no --enable-shared for x86_64-darwin: does not work on some test machine;
wenzelm
parents:
67599
diff
changeset
|
33 |
"LDFLAGS=-segprot POLY rwx rwx"), |
69704 | 34 |
setup = "PATH=/usr/bin:/bin:/usr/sbin:/sbin", |
35 |
ldd_pattern = Some(("otool -L", """\s*(\S+lib(?:polyml|gmp).*dylib).*""".r))), |
|
36 |
"windows" -> |
|
64483 | 37 |
Platform_Info( |
38 |
options = |
|
67597 | 39 |
List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"), |
64494 | 40 |
setup = |
41 |
"""PATH=/usr/bin:/bin:/mingw64/bin |
|
42 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 43 |
copy_files = |
64504 | 44 |
List("$MSYS/mingw64/bin/libgcc_s_seh-1.dll", |
45 |
"$MSYS/mingw64/bin/libgmp-10.dll", |
|
46 |
"$MSYS/mingw64/bin/libstdc++-6.dll"))) |
|
64483 | 47 |
|
48 |
def build_polyml( |
|
64489 | 49 |
root: Path, |
64495 | 50 |
sha1_root: Option[Path] = None, |
64909 | 51 |
progress: Progress = No_Progress, |
64493 | 52 |
arch_64: Boolean = false, |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
53 |
options: List[String] = Nil, |
65880 | 54 |
msys_root: Option[Path] = None) |
64483 | 55 |
{ |
64489 | 56 |
if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir)) |
57 |
error("Bad Poly/ML root directory: " + root) |
|
64483 | 58 |
|
69704 | 59 |
val platform_arch = if (arch_64) "x86_64" else "x86_64_32" |
69726 | 60 |
val platform_os = Platform.os_name |
69704 | 61 |
|
62 |
val platform = platform_arch + "-" + platform_os |
|
63 |
val platform_64 = "x86_64-" + platform_os |
|
64493 | 64 |
|
64483 | 65 |
val info = |
69704 | 66 |
platform_info.get(platform_os) getOrElse |
67 |
error("Bad OS platform: " + quote(platform_os)) |
|
64483 | 68 |
|
64504 | 69 |
val settings = |
70 |
msys_root match { |
|
71 |
case None if Platform.is_windows => |
|
72 |
error("Windows requires specification of msys root directory") |
|
73 |
case None => Isabelle_System.settings() |
|
74 |
case Some(msys) => Isabelle_System.settings() + ("MSYS" -> msys.expand.implode) |
|
75 |
} |
|
64492 | 76 |
|
64491 | 77 |
|
64495 | 78 |
/* bash */ |
79 |
||
64504 | 80 |
def bash( |
81 |
cwd: Path, script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result = |
|
82 |
{ |
|
83 |
val script1 = |
|
84 |
msys_root match { |
|
85 |
case None => script |
|
86 |
case Some(msys) => |
|
87 |
File.bash_path(msys + Path.explode("usr/bin/bash")) + " -c " + Bash.string(script) |
|
88 |
} |
|
89 |
progress.bash(script1, cwd = cwd.file, redirect = redirect, echo = echo) |
|
90 |
} |
|
64495 | 91 |
|
92 |
||
64491 | 93 |
/* configure and make */ |
94 |
||
64483 | 95 |
val configure_options = |
67783
839de121665c
more robust build: prevent problems seen with Poly/ML eb94e2820013 on Mac OS X;
wenzelm
parents:
67609
diff
changeset
|
96 |
List("--disable-shared", "--enable-intinf-as-int", "--with-gmp") ::: |
69704 | 97 |
info.options ::: options ::: (if (arch_64) Nil else List("--enable-compact32bit")) |
64483 | 98 |
|
64495 | 99 |
bash(root, |
64487 | 100 |
info.setup + "\n" + |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
101 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
102 |
[ -f Makefile ] && make distclean |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
103 |
{ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
104 |
./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
105 |
rm -rf target |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
106 |
make compiler && make compiler && make install |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
107 |
} || { echo "Build failed" >&2; exit 2; } |
64501 | 108 |
""", redirect = true, echo = true).check |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
109 |
|
64495 | 110 |
val ldd_files = |
66998 | 111 |
{ |
69704 | 112 |
info.ldd_pattern match { |
66998 | 113 |
case Some((ldd, pattern)) => |
114 |
val lines = bash(root, ldd + " target/bin/poly").check.out_lines |
|
115 |
for { line <- lines; List(lib) <- pattern.unapplySeq(line) } yield lib |
|
116 |
case None => Nil |
|
64491 | 117 |
} |
66998 | 118 |
} |
64491 | 119 |
|
120 |
||
64495 | 121 |
/* sha1 library */ |
122 |
||
123 |
val sha1_files = |
|
124 |
if (sha1_root.isDefined) { |
|
125 |
val dir1 = sha1_root.get |
|
69704 | 126 |
bash(dir1, "./build " + platform_64, redirect = true, echo = true).check |
64505 | 127 |
|
69704 | 128 |
val dir2 = dir1 + Path.explode(platform_64) |
64495 | 129 |
File.read_dir(dir2).map(entry => dir2.implode + "/" + entry) |
130 |
} |
|
131 |
else Nil |
|
132 |
||
133 |
||
64491 | 134 |
/* target */ |
64484 | 135 |
|
65880 | 136 |
val target = Path.explode(platform) |
64488 | 137 |
Isabelle_System.rm_tree(target) |
64483 | 138 |
Isabelle_System.mkdirs(target) |
139 |
||
67592
66253039d5ca
enforce shared libpoly on all platforms, with File.copy before File.move;
wenzelm
parents:
67589
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
|
64483 | 143 |
for { |
64484 | 144 |
d <- List("target/bin", "target/lib") |
64489 | 145 |
dir = root + Path.explode(d) |
64483 | 146 |
entry <- File.read_dir(dir) |
147 |
} File.move(dir + Path.explode(entry), target) |
|
148 |
||
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
|
149 |
|
67584 | 150 |
/* 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
|
151 |
|
67582
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
152 |
if (Platform.is_linux) { |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
153 |
bash(target, "chrpath -r '$ORIGIN' poly", echo = true).check |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
154 |
} |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
155 |
else if (Platform.is_macos) { |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
156 |
for (file <- ldd_files) { |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
157 |
bash(target, |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
158 |
"""install_name_tool -change """ + Bash.string(file) + " " + |
69366 | 159 |
Bash.string("@executable_path/" + Path.explode(file).file_name) + " poly").check |
67582
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
160 |
} |
bf5c69acf2be
built-in library path for (optional) libgmp on macos;
wenzelm
parents:
67581
diff
changeset
|
161 |
} |
67584 | 162 |
|
163 |
||
164 |
/* polyc: directory prefix */ |
|
165 |
||
166 |
{ |
|
167 |
val polyc_path = target + Path.explode("polyc") |
|
67587 | 168 |
|
169 |
val Header = "#! */bin/sh".r |
|
67584 | 170 |
val polyc_patched = |
171 |
split_lines(File.read(polyc_path)) match { |
|
67587 | 172 |
case Header() :: lines => |
173 |
val lines1 = |
|
174 |
lines.map(line => |
|
175 |
if (line.startsWith("prefix=")) "prefix=\"$(cd \"$(dirname \"$0\")\"; pwd)\"" |
|
176 |
else if (line.startsWith("BINDIR=")) "BINDIR=\"$prefix\"" |
|
67584 | 177 |
else if (line.startsWith("LIBDIR=")) "LIBDIR=\"$prefix\"" |
178 |
else line) |
|
67587 | 179 |
cat_lines("#!/usr/bin/env bash" ::lines1) |
67584 | 180 |
case lines => |
67587 | 181 |
error(cat_lines("Cannot patch polyc -- undetected header:" :: lines.take(3))) |
67584 | 182 |
} |
183 |
File.write(polyc_path, polyc_patched) |
|
184 |
} |
|
64483 | 185 |
} |
186 |
||
187 |
||
64496 | 188 |
|
65880 | 189 |
/** skeleton for component **/ |
190 |
||
191 |
def build_polyml_component(component: Path, sha1_root: Option[Path] = None) |
|
192 |
{ |
|
193 |
if (component.is_dir) error("Directory already exists: " + component) |
|
194 |
||
195 |
val etc = component + Path.explode("etc") |
|
196 |
Isabelle_System.mkdirs(etc) |
|
197 |
File.copy(Path.explode("~~/Admin/polyml/settings"), etc) |
|
198 |
File.copy(Path.explode("~~/Admin/polyml/README"), component) |
|
64483 | 199 |
|
65880 | 200 |
sha1_root match { |
201 |
case Some(dir) => |
|
67599 | 202 |
Mercurial.repository(dir).archive(File.standard_path(component + Path.explode("sha1"))) |
65880 | 203 |
case None => |
204 |
} |
|
205 |
} |
|
206 |
||
207 |
||
208 |
||
209 |
/** Isabelle tool wrappers **/ |
|
210 |
||
211 |
val isabelle_tool1 = |
|
212 |
Isabelle_Tool("build_polyml", "build Poly/ML from sources", args => |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
213 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
214 |
Command_Line.tool0 { |
64504 | 215 |
var msys_root: Option[Path] = None |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
216 |
var arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
217 |
var sha1_root: Option[Path] = None |
64483 | 218 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
219 |
val getopts = Getopts(""" |
64489 | 220 |
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS] |
64483 | 221 |
|
222 |
Options are: |
|
64504 | 223 |
-M DIR msys root directory (for Windows) |
69704 | 224 |
-m ARCH processor architecture (32=x86_64_32, 64=x86_64, default: 32) |
69691 | 225 |
-s DIR sha1 sources, see https://isabelle.sketis.net/repos/sha1 |
64483 | 226 |
|
64499 | 227 |
Build Poly/ML in the ROOT directory of its sources, with additional |
67593 | 228 |
CONFIGURE_OPTIONS (e.g. --without-gmp). |
64483 | 229 |
""", |
64504 | 230 |
"M:" -> (arg => msys_root = Some(Path.explode(arg))), |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
231 |
"m:" -> |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
232 |
{ |
69704 | 233 |
case "32" | "x86_64_32" => arch_64 = false |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
234 |
case "64" | "x86_64" => arch_64 = true |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
235 |
case bad => error("Bad processor architecture: " + quote(bad)) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
236 |
}, |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
237 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
64483 | 238 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
239 |
val more_args = getopts(args) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
240 |
val (root, options) = |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
241 |
more_args match { |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
242 |
case root :: options => (Path.explode(root), options) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
243 |
case Nil => getopts.usage() |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
244 |
} |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
245 |
build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress, |
65880 | 246 |
arch_64 = arch_64, options = options, msys_root = msys_root) |
247 |
} |
|
69277
258bef08b31e
support for user-defined Isabelle/Scala command-line tools;
wenzelm
parents:
67783
diff
changeset
|
248 |
}) |
65880 | 249 |
|
250 |
val isabelle_tool2 = |
|
251 |
Isabelle_Tool("build_polyml_component", "make skeleton for Poly/ML component", args => |
|
252 |
{ |
|
253 |
Command_Line.tool0 { |
|
254 |
var sha1_root: Option[Path] = None |
|
255 |
||
256 |
val getopts = Getopts(""" |
|
257 |
Usage: isabelle build_polyml_component [OPTIONS] TARGET |
|
258 |
||
259 |
Options are: |
|
69691 | 260 |
-s DIR sha1 sources, see https://isabelle.sketis.net/repos/sha1 |
65880 | 261 |
|
262 |
Make skeleton for Poly/ML component in directory TARGET. |
|
263 |
""", |
|
264 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
|
265 |
||
266 |
val more_args = getopts(args) |
|
267 |
val component = |
|
268 |
more_args match { |
|
269 |
case List(arg) => Path.explode(arg) |
|
270 |
case _ => getopts.usage() |
|
271 |
} |
|
272 |
build_polyml_component(component, sha1_root = sha1_root) |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
273 |
} |
69277
258bef08b31e
support for user-defined Isabelle/Scala command-line tools;
wenzelm
parents:
67783
diff
changeset
|
274 |
}) |
64483 | 275 |
} |