author | wenzelm |
Fri, 11 Nov 2016 16:49:59 +0100 | |
changeset 64495 | 754e1b4634c3 |
parent 64494 | 979520c83f30 |
child 64496 | 50806c43e01b |
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 |
{ |
|
12 |
sealed case class Platform_Info( |
|
13 |
options: List[String] = Nil, |
|
14 |
options_multilib: List[String] = Nil, |
|
64487 | 15 |
setup: String = "", |
64483 | 16 |
copy_files: List[String] = Nil) |
17 |
||
18 |
private val platform_info = Map( |
|
19 |
"x86-linux" -> |
|
20 |
Platform_Info( |
|
21 |
options_multilib = |
|
64484 | 22 |
List("--build=i386", "CFLAGS=-m32 -O3", "CXXFLAGS=-m32 -O3", "CCASFLAGS=-m32")), |
64483 | 23 |
"x86_64-linux" -> Platform_Info(), |
24 |
"x86-darwin" -> |
|
25 |
Platform_Info( |
|
26 |
options = |
|
64484 | 27 |
List("--build=i686-darwin", "CFLAGS=-arch i686 -O3 -I../libffi/include", |
28 |
"CXXFLAGS=-arch i686 -O3 -I../libffi/include", "CCASFLAGS=-arch i686 -O3", |
|
29 |
"LDFLAGS=-segprot POLY rwx rwx")), |
|
64483 | 30 |
"x86_64-darwin" -> |
31 |
Platform_Info( |
|
32 |
options = |
|
64484 | 33 |
List("--build=x86_64-darwin", "CFLAGS=-arch x86_64 -O3 -I../libffi/include", |
34 |
"CXXFLAGS=-arch x86_64 -O3 -I../libffi/include", "CCASFLAGS=-arch x86_64", |
|
35 |
"LDFLAGS=-segprot POLY rwx rwx")), |
|
64483 | 36 |
"x86-windows" -> |
37 |
Platform_Info( |
|
38 |
options = |
|
64484 | 39 |
List("--host=i686-w32-mingw32", "CPPFLAGS=-I/mingw32/include", "--disable-windows-gui"), |
64494 | 40 |
setup = |
41 |
"""PATH=/usr/bin:/bin:/mingw32/bin |
|
42 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 43 |
copy_files = |
44 |
List("/mingw32/bin/libgcc_s_dw2-1.dll", |
|
45 |
"/mingw32/bin/libgmp-10.dll", |
|
46 |
"/mingw32/bin/libstdc++-6.dll")), |
|
47 |
"x86_64-windows" -> |
|
48 |
Platform_Info( |
|
49 |
options = |
|
64484 | 50 |
List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"), |
64494 | 51 |
setup = |
52 |
"""PATH=/usr/bin:/bin:/mingw64/bin |
|
53 |
export CONFIG_SITE=/etc/config.site""", |
|
64483 | 54 |
copy_files = |
55 |
List("/mingw64/bin/libgcc_s_seh-1.dll", |
|
56 |
"/mingw64/bin/libgmp-10.dll", |
|
57 |
"/mingw64/bin/libstdc++-6.dll"))) |
|
58 |
||
59 |
def build_polyml( |
|
64489 | 60 |
root: Path, |
64495 | 61 |
sha1_root: Option[Path] = None, |
64483 | 62 |
progress: Progress = Ignore_Progress, |
64493 | 63 |
arch_64: Boolean = false, |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
64 |
options: List[String] = Nil, |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
65 |
other_bash: String = "") |
64483 | 66 |
{ |
64489 | 67 |
if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir)) |
68 |
error("Bad Poly/ML root directory: " + root) |
|
64483 | 69 |
|
64493 | 70 |
val platform = |
71 |
(if (arch_64) "x86_64" else "x86") + |
|
72 |
(if (Platform.is_windows) "-windows" else if (Platform.is_macos) "-darwin" else "-linux") |
|
73 |
||
64483 | 74 |
val info = |
75 |
platform_info.get(platform) getOrElse |
|
76 |
error("Bad platform identifier: " + quote(platform)) |
|
77 |
||
64493 | 78 |
if (Platform.is_windows && other_bash == "") |
64492 | 79 |
error("Windows requires other bash (for msys)") |
80 |
||
64491 | 81 |
|
64495 | 82 |
/* bash */ |
83 |
||
84 |
def bash(cwd: Path, script: String, echo: Boolean = false): Process_Result = |
|
85 |
progress.bash( |
|
86 |
if (other_bash == "") script else Bash.string(other_bash) + " -c " + Bash.string(script), |
|
87 |
cwd = cwd.file, env = null, echo = echo) |
|
88 |
||
89 |
||
64491 | 90 |
/* configure and make */ |
91 |
||
64483 | 92 |
val configure_options = |
64493 | 93 |
(if (!arch_64 && Isabelle_System.getenv("ISABELLE_PLATFORM64") == "x86_64-linux") |
94 |
info.options_multilib |
|
95 |
else info.options) ::: List("--enable-intinf-as-int") ::: options |
|
64483 | 96 |
|
64495 | 97 |
bash(root, |
64487 | 98 |
info.setup + "\n" + |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
99 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
100 |
[ -f Makefile ] && make distclean |
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 |
./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
103 |
rm -rf target |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
104 |
make compiler && make compiler && make install |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
105 |
} || { echo "Build failed" >&2; exit 2; } |
64495 | 106 |
""", echo = true).check |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
107 |
|
64495 | 108 |
val ldd_files = |
64493 | 109 |
if (Platform.is_linux) { |
64495 | 110 |
val libs = bash(root, "ldd target/bin/poly").check.out_lines |
64491 | 111 |
val Pattern = """\s*libgmp.*=>\s*(\S+).*""".r |
112 |
for (Pattern(lib) <- libs) yield lib |
|
113 |
} |
|
114 |
else Nil |
|
115 |
||
116 |
||
64495 | 117 |
/* sha1 library */ |
118 |
||
119 |
val sha1_files = |
|
120 |
if (sha1_root.isDefined) { |
|
121 |
val dir1 = sha1_root.get |
|
122 |
bash(dir1, "./build " + platform, echo = true).check |
|
123 |
val dir2 = dir1 + Path.explode(platform) |
|
124 |
File.read_dir(dir2).map(entry => dir2.implode + "/" + entry) |
|
125 |
} |
|
126 |
else Nil |
|
127 |
||
128 |
||
64491 | 129 |
/* target */ |
64484 | 130 |
|
131 |
val target = Path.explode(platform) |
|
64488 | 132 |
Isabelle_System.rm_tree(target) |
64483 | 133 |
Isabelle_System.mkdirs(target) |
134 |
||
135 |
for { |
|
64484 | 136 |
d <- List("target/bin", "target/lib") |
64489 | 137 |
dir = root + Path.explode(d) |
64483 | 138 |
entry <- File.read_dir(dir) |
139 |
} File.move(dir + Path.explode(entry), target) |
|
140 |
||
64495 | 141 |
for (file <- "~~/Admin/polyml/polyi" :: info.copy_files ::: ldd_files ::: sha1_files) |
64483 | 142 |
File.copy(Path.explode(file), target) |
143 |
} |
|
144 |
||
145 |
||
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
146 |
/** command line entry point **/ |
64483 | 147 |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
148 |
def main(args: Array[String]) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
149 |
{ |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
150 |
Command_Line.tool0 { |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
151 |
var other_bash = "" |
64493 | 152 |
var arch_64 = false |
64495 | 153 |
var sha1_root: Option[Path] = None |
64483 | 154 |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
155 |
val getopts = Getopts(""" |
64489 | 156 |
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS] |
64483 | 157 |
|
158 |
Options are: |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
159 |
-b EXE other bash executable (notably for msys on Windows) |
64493 | 160 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64495 | 161 |
-s DIR root directory for sha1 library |
64483 | 162 |
|
64489 | 163 |
Build Poly/ML in its source ROOT directory of its sources, with additional |
164 |
CONFIGURE_OPTIONS (e.g. --with-gmp). |
|
64483 | 165 |
""", |
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
166 |
"b:" -> (arg => other_bash = arg), |
64493 | 167 |
"m:" -> |
168 |
{ |
|
169 |
case "32" | "x86" => arch_64 = false |
|
170 |
case "64" | "x86_64" => arch_64 = true |
|
171 |
case bad => error("Bad processor architecture: " + quote(bad)) |
|
64495 | 172 |
}, |
173 |
"s:" -> (arg => sha1_root = Some(Path.explode(arg)))) |
|
64483 | 174 |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
175 |
val more_args = getopts(args) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
176 |
val (root, options) = |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
177 |
more_args match { |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
178 |
case root :: options => (Path.explode(root), options) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
179 |
case Nil => getopts.usage() |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
180 |
} |
64495 | 181 |
build_polyml(root, sha1_root = sha1_root, progress = new Console_Progress, |
182 |
arch_64 = arch_64, options = options, other_bash = other_bash) |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
183 |
} |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
184 |
} |
64483 | 185 |
} |