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