author | wenzelm |
Fri, 03 Nov 2017 22:36:32 +0100 | |
changeset 66998 | 8905114fd23b |
parent 65880 | 54c6ec4166a4 |
child 67580 | eb64467e8bcf |
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 = |
66998 | 125 |
{ |
126 |
val ldd_pattern = |
|
127 |
if (Platform.is_linux) Some(("ldd", """\s*libgmp.*=>\s*(\S+).*""".r)) |
|
128 |
else if (Platform.is_macos) Some(("otool -L", """\s*(\S+libgmp.*dylib).*""".r)) |
|
129 |
else None |
|
130 |
ldd_pattern match { |
|
131 |
case Some((ldd, pattern)) => |
|
132 |
val lines = bash(root, ldd + " target/bin/poly").check.out_lines |
|
133 |
for { line <- lines; List(lib) <- pattern.unapplySeq(line) } yield lib |
|
134 |
case None => Nil |
|
64491 | 135 |
} |
66998 | 136 |
} |
64491 | 137 |
|
138 |
||
64495 | 139 |
/* sha1 library */ |
140 |
||
141 |
val sha1_files = |
|
142 |
if (sha1_root.isDefined) { |
|
143 |
val dir1 = sha1_root.get |
|
64501 | 144 |
bash(dir1, "./build " + platform, redirect = true, echo = true).check |
64505 | 145 |
|
64495 | 146 |
val dir2 = dir1 + Path.explode(platform) |
147 |
File.read_dir(dir2).map(entry => dir2.implode + "/" + entry) |
|
148 |
} |
|
149 |
else Nil |
|
150 |
||
151 |
||
64491 | 152 |
/* target */ |
64484 | 153 |
|
65880 | 154 |
val target = Path.explode(platform) |
64488 | 155 |
Isabelle_System.rm_tree(target) |
64483 | 156 |
Isabelle_System.mkdirs(target) |
157 |
||
158 |
for { |
|
64484 | 159 |
d <- List("target/bin", "target/lib") |
64489 | 160 |
dir = root + Path.explode(d) |
64483 | 161 |
entry <- File.read_dir(dir) |
162 |
} File.move(dir + Path.explode(entry), target) |
|
163 |
||
64495 | 164 |
for (file <- "~~/Admin/polyml/polyi" :: info.copy_files ::: ldd_files ::: sha1_files) |
64504 | 165 |
File.copy(Path.explode(file).expand_env(settings), target) |
64483 | 166 |
} |
167 |
||
168 |
||
64496 | 169 |
|
65880 | 170 |
/** skeleton for component **/ |
171 |
||
172 |
def build_polyml_component(component: Path, sha1_root: Option[Path] = None) |
|
173 |
{ |
|
174 |
if (component.is_dir) error("Directory already exists: " + component) |
|
175 |
||
176 |
val etc = component + Path.explode("etc") |
|
177 |
Isabelle_System.mkdirs(etc) |
|
178 |
File.copy(Path.explode("~~/Admin/polyml/settings"), etc) |
|
179 |
File.copy(Path.explode("~~/Admin/polyml/README"), component) |
|
64483 | 180 |
|
65880 | 181 |
sha1_root match { |
182 |
case Some(dir) => |
|
183 |
Mercurial.repository(dir). |
|
184 |
archive(File.standard_path(component + dir + Path.explode("sha1"))) |
|
185 |
case None => |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
||
190 |
||
191 |
/** Isabelle tool wrappers **/ |
|
192 |
||
193 |
val isabelle_tool1 = |
|
194 |
Isabelle_Tool("build_polyml", "build Poly/ML from sources", args => |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
195 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
196 |
Command_Line.tool0 { |
64504 | 197 |
var msys_root: Option[Path] = None |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
198 |
var arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
199 |
var sha1_root: Option[Path] = None |
64483 | 200 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
201 |
val getopts = Getopts(""" |
64489 | 202 |
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS] |
64483 | 203 |
|
204 |
Options are: |
|
64504 | 205 |
-M DIR msys root directory (for Windows) |
64493 | 206 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64499 | 207 |
-s DIR sha1 sources, see https://bitbucket.org/isabelle_project/sha1 |
64483 | 208 |
|
64499 | 209 |
Build Poly/ML in the ROOT directory of its sources, with additional |
64489 | 210 |
CONFIGURE_OPTIONS (e.g. --with-gmp). |
64483 | 211 |
""", |
64504 | 212 |
"M:" -> (arg => msys_root = Some(Path.explode(arg))), |
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
213 |
"m:" -> |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
214 |
{ |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
215 |
case "32" | "x86" => arch_64 = false |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
216 |
case "64" | "x86_64" => arch_64 = true |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
217 |
case bad => error("Bad processor architecture: " + quote(bad)) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
218 |
}, |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
219 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
64483 | 220 |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
221 |
val more_args = getopts(args) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
222 |
val (root, options) = |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
223 |
more_args match { |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
224 |
case root :: options => (Path.explode(root), options) |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
225 |
case Nil => getopts.usage() |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
226 |
} |
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
227 |
build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress, |
65880 | 228 |
arch_64 = arch_64, options = options, msys_root = msys_root) |
229 |
} |
|
230 |
}, admin = true) |
|
231 |
||
232 |
val isabelle_tool2 = |
|
233 |
Isabelle_Tool("build_polyml_component", "make skeleton for Poly/ML component", args => |
|
234 |
{ |
|
235 |
Command_Line.tool0 { |
|
236 |
var sha1_root: Option[Path] = None |
|
237 |
||
238 |
val getopts = Getopts(""" |
|
239 |
Usage: isabelle build_polyml_component [OPTIONS] TARGET |
|
240 |
||
241 |
Options are: |
|
242 |
-s DIR sha1 sources, see https://bitbucket.org/isabelle_project/sha1 |
|
243 |
||
244 |
Make skeleton for Poly/ML component in directory TARGET. |
|
245 |
""", |
|
246 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
|
247 |
||
248 |
val more_args = getopts(args) |
|
249 |
val component = |
|
250 |
more_args match { |
|
251 |
case List(arg) => Path.explode(arg) |
|
252 |
case _ => getopts.usage() |
|
253 |
} |
|
254 |
build_polyml_component(component, sha1_root = sha1_root) |
|
64500
159ea1055b39
back to regular Isabelle tool (reverting abc34a149690);
wenzelm
parents:
64499
diff
changeset
|
255 |
} |
64502 | 256 |
}, admin = true) |
64483 | 257 |
} |