author | wenzelm |
Fri, 09 Feb 2018 11:14:13 +0100 | |
changeset 67580 | eb64467e8bcf |
parent 66998 | 8905114fd23b |
child 67581 | 30f412d1d7c3 |
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", |
|
64503
365021be3c5b
clarified setup: avoid alternative C compiler tools, e.g. from Homebrew or MacPorts;
wenzelm
parents:
64502
diff
changeset
|
35 |
"LDFLAGS=-segprot POLY rwx rwx"), |
365021be3c5b
clarified setup: avoid alternative C compiler tools, e.g. from Homebrew or MacPorts;
wenzelm
parents:
64502
diff
changeset
|
36 |
setup = "PATH=/usr/bin:/bin:/usr/sbin:/sbin"), |
64483 | 37 |
"x86_64-darwin" -> |
38 |
Platform_Info( |
|
39 |
options = |
|
64484 | 40 |
List("--build=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include", |
41 |
"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
|
42 |
"LDFLAGS=-segprot POLY rwx rwx"), |
365021be3c5b
clarified setup: avoid alternative C compiler tools, e.g. from Homebrew or MacPorts;
wenzelm
parents:
64502
diff
changeset
|
43 |
setup = "PATH=/usr/bin:/bin:/usr/sbin:/sbin"), |
64483 | 44 |
"x86-windows" -> |
45 |
Platform_Info( |
|
46 |
options = |
|
64484 | 47 |
List("--host=i686-w32-mingw32", "CPPFLAGS=-I/mingw32/include", "--disable-windows-gui"), |
64494 | 48 |
setup = |
49 |
"""PATH=/usr/bin:/bin:/mingw32/bin |
|
50 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 51 |
copy_files = |
64504 | 52 |
List("$MSYS/mingw32/bin/libgcc_s_dw2-1.dll", |
53 |
"$MSYS/mingw32/bin/libgmp-10.dll", |
|
54 |
"$MSYS/mingw32/bin/libstdc++-6.dll")), |
|
64483 | 55 |
"x86_64-windows" -> |
56 |
Platform_Info( |
|
57 |
options = |
|
64484 | 58 |
List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"), |
64494 | 59 |
setup = |
60 |
"""PATH=/usr/bin:/bin:/mingw64/bin |
|
61 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 62 |
copy_files = |
64504 | 63 |
List("$MSYS/mingw64/bin/libgcc_s_seh-1.dll", |
64 |
"$MSYS/mingw64/bin/libgmp-10.dll", |
|
65 |
"$MSYS/mingw64/bin/libstdc++-6.dll"))) |
|
64483 | 66 |
|
67 |
def build_polyml( |
|
64489 | 68 |
root: Path, |
64495 | 69 |
sha1_root: Option[Path] = None, |
64909 | 70 |
progress: Progress = No_Progress, |
64493 | 71 |
arch_64: Boolean = false, |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
72 |
options: List[String] = Nil, |
65880 | 73 |
msys_root: Option[Path] = None) |
64483 | 74 |
{ |
64489 | 75 |
if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir)) |
76 |
error("Bad Poly/ML root directory: " + root) |
|
64483 | 77 |
|
64493 | 78 |
val platform = |
79 |
(if (arch_64) "x86_64" else "x86") + |
|
80 |
(if (Platform.is_windows) "-windows" else if (Platform.is_macos) "-darwin" else "-linux") |
|
81 |
||
64483 | 82 |
val info = |
83 |
platform_info.get(platform) getOrElse |
|
84 |
error("Bad platform identifier: " + quote(platform)) |
|
85 |
||
64504 | 86 |
val settings = |
87 |
msys_root match { |
|
88 |
case None if Platform.is_windows => |
|
89 |
error("Windows requires specification of msys root directory") |
|
90 |
case None => Isabelle_System.settings() |
|
91 |
case Some(msys) => Isabelle_System.settings() + ("MSYS" -> msys.expand.implode) |
|
92 |
} |
|
64492 | 93 |
|
64491 | 94 |
|
64495 | 95 |
/* bash */ |
96 |
||
64504 | 97 |
def bash( |
98 |
cwd: Path, script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result = |
|
99 |
{ |
|
100 |
val script1 = |
|
101 |
msys_root match { |
|
102 |
case None => script |
|
103 |
case Some(msys) => |
|
104 |
File.bash_path(msys + Path.explode("usr/bin/bash")) + " -c " + Bash.string(script) |
|
105 |
} |
|
106 |
progress.bash(script1, cwd = cwd.file, redirect = redirect, echo = echo) |
|
107 |
} |
|
64495 | 108 |
|
109 |
||
64491 | 110 |
/* configure and make */ |
111 |
||
64483 | 112 |
val configure_options = |
64493 | 113 |
(if (!arch_64 && Isabelle_System.getenv("ISABELLE_PLATFORM64") == "x86_64-linux") |
114 |
info.options_multilib |
|
115 |
else info.options) ::: List("--enable-intinf-as-int") ::: options |
|
64483 | 116 |
|
64495 | 117 |
bash(root, |
64487 | 118 |
info.setup + "\n" + |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
119 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
120 |
[ -f Makefile ] && make distclean |
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 |
./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
123 |
rm -rf target |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
124 |
make compiler && make compiler && make install |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
125 |
} || { echo "Build failed" >&2; exit 2; } |
64501 | 126 |
""", redirect = true, echo = true).check |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
127 |
|
64495 | 128 |
val ldd_files = |
66998 | 129 |
{ |
130 |
val ldd_pattern = |
|
131 |
if (Platform.is_linux) Some(("ldd", """\s*libgmp.*=>\s*(\S+).*""".r)) |
|
132 |
else if (Platform.is_macos) Some(("otool -L", """\s*(\S+libgmp.*dylib).*""".r)) |
|
133 |
else None |
|
134 |
ldd_pattern match { |
|
135 |
case Some((ldd, pattern)) => |
|
136 |
val lines = bash(root, ldd + " target/bin/poly").check.out_lines |
|
137 |
for { line <- lines; List(lib) <- pattern.unapplySeq(line) } yield lib |
|
138 |
case None => Nil |
|
64491 | 139 |
} |
66998 | 140 |
} |
64491 | 141 |
|
142 |
||
64495 | 143 |
/* sha1 library */ |
144 |
||
145 |
val sha1_files = |
|
146 |
if (sha1_root.isDefined) { |
|
147 |
val dir1 = sha1_root.get |
|
64501 | 148 |
bash(dir1, "./build " + platform, redirect = true, echo = true).check |
64505 | 149 |
|
64495 | 150 |
val dir2 = dir1 + Path.explode(platform) |
151 |
File.read_dir(dir2).map(entry => dir2.implode + "/" + entry) |
|
152 |
} |
|
153 |
else Nil |
|
154 |
||
155 |
||
64491 | 156 |
/* target */ |
64484 | 157 |
|
65880 | 158 |
val target = Path.explode(platform) |
64488 | 159 |
Isabelle_System.rm_tree(target) |
64483 | 160 |
Isabelle_System.mkdirs(target) |
161 |
||
162 |
for { |
|
64484 | 163 |
d <- List("target/bin", "target/lib") |
64489 | 164 |
dir = root + Path.explode(d) |
64483 | 165 |
entry <- File.read_dir(dir) |
166 |
} File.move(dir + Path.explode(entry), target) |
|
167 |
||
64495 | 168 |
for (file <- "~~/Admin/polyml/polyi" :: info.copy_files ::: ldd_files ::: sha1_files) |
64504 | 169 |
File.copy(Path.explode(file).expand_env(settings), target) |
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
|
170 |
|
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
|
171 |
|
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
|
172 |
/* rpath */ |
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 |
|
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
|
174 |
if (Platform.is_linux) bash(target, "chrpath -r '$ORIGIN' poly", echo = true).check |
64483 | 175 |
} |
176 |
||
177 |
||
64496 | 178 |
|
65880 | 179 |
/** skeleton for component **/ |
180 |
||
181 |
def build_polyml_component(component: Path, sha1_root: Option[Path] = None) |
|
182 |
{ |
|
183 |
if (component.is_dir) error("Directory already exists: " + component) |
|
184 |
||
185 |
val etc = component + Path.explode("etc") |
|
186 |
Isabelle_System.mkdirs(etc) |
|
187 |
File.copy(Path.explode("~~/Admin/polyml/settings"), etc) |
|
188 |
File.copy(Path.explode("~~/Admin/polyml/README"), component) |
|
64483 | 189 |
|
65880 | 190 |
sha1_root match { |
191 |
case Some(dir) => |
|
192 |
Mercurial.repository(dir). |
|
193 |
archive(File.standard_path(component + dir + Path.explode("sha1"))) |
|
194 |
case None => |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
||
199 |
||
200 |
/** Isabelle tool wrappers **/ |
|
201 |
||
202 |
val isabelle_tool1 = |
|
203 |
Isabelle_Tool("build_polyml", "build Poly/ML from sources", args => |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
204 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
205 |
Command_Line.tool0 { |
64504 | 206 |
var msys_root: Option[Path] = None |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
207 |
var arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
208 |
var sha1_root: Option[Path] = None |
64483 | 209 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
210 |
val getopts = Getopts(""" |
64489 | 211 |
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS] |
64483 | 212 |
|
213 |
Options are: |
|
64504 | 214 |
-M DIR msys root directory (for Windows) |
64493 | 215 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64499 | 216 |
-s DIR sha1 sources, see https://bitbucket.org/isabelle_project/sha1 |
64483 | 217 |
|
64499 | 218 |
Build Poly/ML in the ROOT directory of its sources, with additional |
64489 | 219 |
CONFIGURE_OPTIONS (e.g. --with-gmp). |
64483 | 220 |
""", |
64504 | 221 |
"M:" -> (arg => msys_root = Some(Path.explode(arg))), |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
222 |
"m:" -> |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
223 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
224 |
case "32" | "x86" => arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
225 |
case "64" | "x86_64" => arch_64 = true |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
226 |
case bad => error("Bad processor architecture: " + quote(bad)) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
227 |
}, |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
228 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
64483 | 229 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
230 |
val more_args = getopts(args) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
231 |
val (root, options) = |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
232 |
more_args match { |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
233 |
case root :: options => (Path.explode(root), options) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
234 |
case Nil => getopts.usage() |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
235 |
} |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
236 |
build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress, |
65880 | 237 |
arch_64 = arch_64, options = options, msys_root = msys_root) |
238 |
} |
|
239 |
}, admin = true) |
|
240 |
||
241 |
val isabelle_tool2 = |
|
242 |
Isabelle_Tool("build_polyml_component", "make skeleton for Poly/ML component", args => |
|
243 |
{ |
|
244 |
Command_Line.tool0 { |
|
245 |
var sha1_root: Option[Path] = None |
|
246 |
||
247 |
val getopts = Getopts(""" |
|
248 |
Usage: isabelle build_polyml_component [OPTIONS] TARGET |
|
249 |
||
250 |
Options are: |
|
251 |
-s DIR sha1 sources, see https://bitbucket.org/isabelle_project/sha1 |
|
252 |
||
253 |
Make skeleton for Poly/ML component in directory TARGET. |
|
254 |
""", |
|
255 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
|
256 |
||
257 |
val more_args = getopts(args) |
|
258 |
val component = |
|
259 |
more_args match { |
|
260 |
case List(arg) => Path.explode(arg) |
|
261 |
case _ => getopts.usage() |
|
262 |
} |
|
263 |
build_polyml_component(component, sha1_root = sha1_root) |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
264 |
} |
64502 | 265 |
}, admin = true) |
64483 | 266 |
} |