72414
|
1 |
/* Title: Pure/Admin/build_csdp.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Build Isabelle CSDP component from official downloads.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object Build_CSDP
|
|
11 |
{
|
|
12 |
/* build CSDP */
|
|
13 |
|
|
14 |
val component_name = "csdp-6.2.0"
|
|
15 |
|
|
16 |
val source_url = "https://github.com/coin-or/Csdp/archive/releases/6.2.0.tar.gz"
|
|
17 |
val windows_url = "https://github.com/coin-or/Csdp/files/2485584/csdp6.2.0win64.zip"
|
|
18 |
|
|
19 |
sealed case class Flags(platform: String, CFLAGS: String = "", LIBS: String = "")
|
|
20 |
{
|
|
21 |
def print: String =
|
|
22 |
" * " + platform + ":\n" +
|
|
23 |
List("CFLAGS=" + CFLAGS, "LIBS=" + LIBS).map(" " + _).mkString("\n")
|
|
24 |
|
|
25 |
def change(path: Path)
|
|
26 |
{
|
|
27 |
File.change(path, s =>
|
|
28 |
(for (line <- split_lines(s))
|
|
29 |
yield {
|
|
30 |
line.replaceAll("CFLAGS=.*", "CFLAGS=" + CFLAGS)
|
|
31 |
.replaceAll("LIBS=.*", "LIBS=" + LIBS)
|
|
32 |
}).mkString("\n"))
|
|
33 |
}
|
|
34 |
}
|
|
35 |
|
|
36 |
val build_flags: List[Flags] =
|
|
37 |
List(
|
|
38 |
Flags("arm64-linux",
|
|
39 |
CFLAGS = "-march=native -mtune=native -Ofast -ansi -Wall -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include",
|
|
40 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lm"),
|
|
41 |
Flags("x86_64-linux", // Ubuntu 16.04 LTS
|
|
42 |
CFLAGS = "-march=native -mtune=native -Ofast -ansi -Wall -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include",
|
|
43 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lquadmath -lm"),
|
|
44 |
Flags("x86_64-darwin",
|
|
45 |
CFLAGS = "-m64 -Ofast -ansi -Wall -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include",
|
|
46 |
LIBS = "-L../lib -lsdp -llapack -lblas -lm"))
|
|
47 |
|
|
48 |
def build_csdp(
|
|
49 |
pretend_windows: Boolean = false,
|
|
50 |
verbose: Boolean = false,
|
|
51 |
progress: Progress = new Progress,
|
|
52 |
target_dir: Path = Path.current)
|
|
53 |
{
|
|
54 |
Isabelle_System.with_tmp_dir("build")(tmp_dir =>
|
|
55 |
{
|
|
56 |
val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component_name))
|
|
57 |
progress.echo("Component " + component_dir)
|
|
58 |
|
|
59 |
|
|
60 |
/* platform */
|
|
61 |
|
|
62 |
val is_windows = Platform.is_windows || pretend_windows
|
|
63 |
|
|
64 |
val (platform_name, windows_name) =
|
|
65 |
if (is_windows) {
|
|
66 |
val Windows_Name = """^.*?([^/]+)\.zip$""".r
|
|
67 |
val windows_name =
|
|
68 |
windows_url match {
|
|
69 |
case Windows_Name(name) => name
|
|
70 |
case _ => error("Failed to determine base name from " + quote(windows_url))
|
|
71 |
}
|
|
72 |
("x86_64-windows", windows_name)
|
|
73 |
}
|
|
74 |
else {
|
|
75 |
val name =
|
|
76 |
proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64"))
|
|
77 |
.getOrElse(error("No 64bit platform"))
|
|
78 |
(name, "")
|
|
79 |
}
|
|
80 |
|
|
81 |
val platform_dir = Isabelle_System.make_directory(component_dir + Path.basic(platform_name))
|
|
82 |
|
|
83 |
|
|
84 |
/* download */
|
|
85 |
|
|
86 |
val archive_path = tmp_dir + Path.basic("src.tar.gz")
|
|
87 |
Isabelle_System.download(source_url, archive_path, progress = progress)
|
|
88 |
|
|
89 |
Isabelle_System.bash("tar xzf src.tar.gz", cwd = tmp_dir.file).check
|
|
90 |
val source_name =
|
|
91 |
File.read_dir(tmp_dir).filterNot(_ == "src.tar.gz") match {
|
|
92 |
case List(name) => name
|
|
93 |
case _ => error("Exactly one entry expected in archive " + quote(source_url))
|
|
94 |
}
|
|
95 |
Isabelle_System.bash(
|
|
96 |
"tar xzf " + archive_path + " && mv " + Bash.string(source_name) + " src",
|
|
97 |
cwd = component_dir.file).check
|
|
98 |
|
|
99 |
|
|
100 |
/* build */
|
|
101 |
|
|
102 |
if (is_windows) {
|
|
103 |
Isabelle_System.download(windows_url, tmp_dir + Path.basic("windows.zip"),
|
|
104 |
progress = progress)
|
|
105 |
Isabelle_System.bash("unzip -x windows", cwd = tmp_dir.file).check
|
|
106 |
|
|
107 |
val windows_dir = tmp_dir + Path.explode(windows_name)
|
|
108 |
File.copy(windows_dir + Path.explode("LICENSE"), component_dir)
|
|
109 |
File.copy(windows_dir + Path.explode("bin/csdp.exe"), platform_dir)
|
|
110 |
File.set_executable(platform_dir + Path.basic("csdp.exe"), true)
|
|
111 |
}
|
|
112 |
else {
|
|
113 |
progress.echo("Building CSDP ...")
|
|
114 |
|
|
115 |
val build_dir = tmp_dir + Path.basic(source_name)
|
|
116 |
build_flags.find(flags => flags.platform == platform_name) match {
|
|
117 |
case None => error("No build flags for platform " + quote(platform_name))
|
|
118 |
case Some(flags) => flags.change(build_dir + Path.basic("Makefile"))
|
|
119 |
}
|
|
120 |
Isabelle_System.bash("make",
|
|
121 |
cwd = build_dir.file,
|
|
122 |
progress_stdout = progress.echo_if(verbose, _),
|
|
123 |
progress_stderr = progress.echo_if(verbose, _)).check
|
|
124 |
File.copy(build_dir + Path.explode("solver/csdp"), platform_dir)
|
|
125 |
}
|
|
126 |
|
|
127 |
|
|
128 |
/* settings */
|
|
129 |
|
|
130 |
val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc"))
|
|
131 |
File.write(etc_dir + Path.basic("settings"),
|
|
132 |
"""# -*- shell-script -*- :mode=shellscript:
|
|
133 |
|
|
134 |
ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp"
|
|
135 |
""")
|
|
136 |
|
|
137 |
|
|
138 |
/* README */
|
|
139 |
|
|
140 |
File.write(component_dir + Path.basic("README"),
|
|
141 |
"""This distribution of CSDP is based on the official downloads:
|
|
142 |
""" + source_url + """
|
|
143 |
""" + windows_url + """
|
|
144 |
|
|
145 |
For Linux and macOS, it has been built from sources using the following
|
|
146 |
options in the Makefile:
|
|
147 |
|
|
148 |
""" + build_flags.map(_.print).mkString("\n\n") + """
|
|
149 |
|
|
150 |
For Windows, the existing binary distribution has been used.
|
|
151 |
|
|
152 |
Only the bare "csdp" program is required for Isabelle.
|
|
153 |
|
|
154 |
|
|
155 |
Makarius
|
|
156 |
""" + Date.Format.date(Date.now()) + "\n")
|
|
157 |
})
|
|
158 |
}
|
|
159 |
|
|
160 |
|
|
161 |
/* Isabelle tool wrapper */
|
|
162 |
|
|
163 |
val isabelle_tool =
|
|
164 |
Isabelle_Tool("build_csdp", "build prover component from official downloads",
|
|
165 |
args =>
|
|
166 |
{
|
|
167 |
var target_dir = Path.current
|
|
168 |
var pretend_windows = false
|
|
169 |
var verbose = false
|
|
170 |
|
|
171 |
val getopts = Getopts("""
|
|
172 |
Usage: isabelle build_csdp [OPTIONS]
|
|
173 |
|
|
174 |
Options are:
|
|
175 |
-D DIR target directory (default ".")
|
|
176 |
-W pretend that platform is Windows: download binary, no build
|
|
177 |
-v verbose
|
|
178 |
|
|
179 |
Build prover component from official downloads.
|
|
180 |
""",
|
|
181 |
"D:" -> (arg => target_dir = Path.explode(arg)),
|
|
182 |
"W" -> (_ => pretend_windows = true),
|
|
183 |
"v" -> (_ => verbose = true))
|
|
184 |
|
|
185 |
val more_args = getopts(args)
|
|
186 |
if (more_args.nonEmpty) getopts.usage()
|
|
187 |
|
|
188 |
val progress = new Console_Progress()
|
|
189 |
|
|
190 |
build_csdp(pretend_windows = pretend_windows, verbose = verbose, progress = progress,
|
|
191 |
target_dir = target_dir)
|
|
192 |
})
|
|
193 |
}
|