author | wenzelm |
Fri, 11 Nov 2016 15:24:56 +0100 | |
changeset 64493 | a2eebcc8bb69 |
parent 64492 | 98215fa4f8d1 |
child 64494 | 979520c83f30 |
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"), |
64487 | 40 |
setup = "PATH=/usr/bin:/bin:/mingw32/bin", |
64483 | 41 |
copy_files = |
42 |
List("/mingw32/bin/libgcc_s_dw2-1.dll", |
|
43 |
"/mingw32/bin/libgmp-10.dll", |
|
44 |
"/mingw32/bin/libstdc++-6.dll")), |
|
45 |
"x86_64-windows" -> |
|
46 |
Platform_Info( |
|
47 |
options = |
|
64484 | 48 |
List("--host=x86_64-w64-mingw32", "CPPFLAGS=-I/mingw64/include", "--disable-windows-gui"), |
64487 | 49 |
setup = "PATH=/usr/bin:/bin:/mingw64/bin", |
64483 | 50 |
copy_files = |
51 |
List("/mingw64/bin/libgcc_s_seh-1.dll", |
|
52 |
"/mingw64/bin/libgmp-10.dll", |
|
53 |
"/mingw64/bin/libstdc++-6.dll"))) |
|
54 |
||
55 |
def build_polyml( |
|
64489 | 56 |
root: Path, |
64483 | 57 |
progress: Progress = Ignore_Progress, |
64493 | 58 |
arch_64: Boolean = false, |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
59 |
options: List[String] = Nil, |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
60 |
other_bash: String = "") |
64483 | 61 |
{ |
64489 | 62 |
if (!((root + Path.explode("configure")).is_file && (root + Path.explode("PolyML")).is_dir)) |
63 |
error("Bad Poly/ML root directory: " + root) |
|
64483 | 64 |
|
64493 | 65 |
val platform = |
66 |
(if (arch_64) "x86_64" else "x86") + |
|
67 |
(if (Platform.is_windows) "-windows" else if (Platform.is_macos) "-darwin" else "-linux") |
|
68 |
||
64483 | 69 |
val info = |
70 |
platform_info.get(platform) getOrElse |
|
71 |
error("Bad platform identifier: " + quote(platform)) |
|
72 |
||
64493 | 73 |
if (Platform.is_windows && other_bash == "") |
64492 | 74 |
error("Windows requires other bash (for msys)") |
75 |
||
64491 | 76 |
|
77 |
/* configure and make */ |
|
78 |
||
64483 | 79 |
val configure_options = |
64493 | 80 |
(if (!arch_64 && Isabelle_System.getenv("ISABELLE_PLATFORM64") == "x86_64-linux") |
81 |
info.options_multilib |
|
82 |
else info.options) ::: List("--enable-intinf-as-int") ::: options |
|
64483 | 83 |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
84 |
val script = |
64487 | 85 |
info.setup + "\n" + |
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
86 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
87 |
[ -f Makefile ] && make distclean |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
88 |
{ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
89 |
./configure --prefix="$PWD/target" """ + Bash.strings(configure_options) + """ |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
90 |
rm -rf target |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
91 |
make compiler && make compiler && make install |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
92 |
} || { echo "Build failed" >&2; exit 2; } |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
93 |
""" |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
94 |
|
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
95 |
Isabelle_System.bash( |
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
96 |
if (other_bash == "") script else Bash.string(other_bash) + " -c " + Bash.string(script), |
64489 | 97 |
cwd = root.file, env = null, |
64484 | 98 |
progress_stdout = progress.echo(_), |
99 |
progress_stderr = progress.echo(_)).check |
|
100 |
||
64491 | 101 |
val lib_files = |
64493 | 102 |
if (Platform.is_linux) { |
64491 | 103 |
val libs = Isabelle_System.bash("ldd target/bin/poly", cwd = root.file).check.out_lines |
104 |
val Pattern = """\s*libgmp.*=>\s*(\S+).*""".r |
|
105 |
for (Pattern(lib) <- libs) yield lib |
|
106 |
} |
|
107 |
else Nil |
|
108 |
||
109 |
||
110 |
/* target */ |
|
64484 | 111 |
|
112 |
val target = Path.explode(platform) |
|
64488 | 113 |
Isabelle_System.rm_tree(target) |
64483 | 114 |
Isabelle_System.mkdirs(target) |
115 |
||
116 |
for { |
|
64484 | 117 |
d <- List("target/bin", "target/lib") |
64489 | 118 |
dir = root + Path.explode(d) |
64483 | 119 |
entry <- File.read_dir(dir) |
120 |
} File.move(dir + Path.explode(entry), target) |
|
121 |
||
64491 | 122 |
for (file <- "~~/Admin/polyml/polyi" :: info.copy_files ::: lib_files) |
64483 | 123 |
File.copy(Path.explode(file), target) |
124 |
} |
|
125 |
||
126 |
||
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
127 |
/** command line entry point **/ |
64483 | 128 |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
129 |
def main(args: Array[String]) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
130 |
{ |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
131 |
Command_Line.tool0 { |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
132 |
var other_bash = "" |
64493 | 133 |
var arch_64 = false |
64483 | 134 |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
135 |
val getopts = Getopts(""" |
64489 | 136 |
Usage: isabelle build_polyml [OPTIONS] ROOT [CONFIGURE_OPTIONS] |
64483 | 137 |
|
138 |
Options are: |
|
64485
e996c0a5eca9
support other bash executable (notably for msys on Windows);
wenzelm
parents:
64484
diff
changeset
|
139 |
-b EXE other bash executable (notably for msys on Windows) |
64493 | 140 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64483 | 141 |
|
64489 | 142 |
Build Poly/ML in its source ROOT directory of its sources, with additional |
143 |
CONFIGURE_OPTIONS (e.g. --with-gmp). |
|
64483 | 144 |
""", |
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
145 |
"b:" -> (arg => other_bash = arg), |
64493 | 146 |
"m:" -> |
147 |
{ |
|
148 |
case "32" | "x86" => arch_64 = false |
|
149 |
case "64" | "x86_64" => arch_64 = true |
|
150 |
case bad => error("Bad processor architecture: " + quote(bad)) |
|
151 |
}) |
|
64483 | 152 |
|
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
153 |
val more_args = getopts(args) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
154 |
val (root, options) = |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
155 |
more_args match { |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
156 |
case root :: options => (Path.explode(root), options) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
157 |
case Nil => getopts.usage() |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
158 |
} |
64493 | 159 |
build_polyml(root, progress = new Console_Progress, arch_64 = arch_64, options = options, |
64490
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
160 |
other_bash = other_bash) |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
161 |
} |
abc34a149690
prefer raw Admin tool, without Isabelle settings environment;
wenzelm
parents:
64489
diff
changeset
|
162 |
} |
64483 | 163 |
} |